对于图像的关键点数据提取openpose

import cv2
import matplotlib.pyplot as plt
import copy
import numpy as np

from src import model
from src import util
from src.body import Body
from src.hand import Hand

# 初始化模型,
body_estimation = Body('model/body_pose_model.pth')
hand_estimation = Hand('model/hand_pose_model.pth')

# 从指定路径读取一张测试图像,并存储在oriImg变量中。图像以 B(蓝色)、G(绿色)、R(红色)的顺序存储。
test_image = 'images/demo.jpg'
oriImg = cv2.imread(test_image)  # B,G,R order
# 使用body_estimation模型对输入图像进行人体姿态估计,
# 得到候选关键点candidate和连接信息subset。然后创建一个原始图像的副本canvas,
# 并使用util.draw_bodypose函数在canvas上绘制人体姿态。
candidate, subset = body_estimation(oriImg)
canvas = copy.deepcopy(oriImg)
canvas = util.draw_bodypose(canvas, candidate, subset)
# print(canvas)
# detect hand
# 使用util.handDetect函数根据人体姿态估计的结果检测手部区域,
# 得到手部区域的列表hands_list,其中每个元素包含手部区域的左上角坐标(x, y)、
# 宽度w以及是否为左手的标志is_left。
hands_list = util.handDetect(candidate, subset, oriImg)
# 创建一个空列表all_hand_peaks用于存储所有手部关键点
all_hand_peaks = []
for x, y, w, is_left in hands_list:
    # cv2.rectangle(canvas, (x, y), (x+w, y+w), (0, 255, 0), 2, lineType=cv2.LINE_AA)
    # cv2.putText(canvas, 'left' if is_left else 'right', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)

    # if is_left:
    # plt.imshow(oriImg[y:y+w, x:x+w, :][:, :, [2, 1, 0]])
    # plt.show()
    # 使用hand_estimation模型对手部区域图像进行手部姿态估计,得到关键点peaks。
    # 对于关键点的横坐标,如果为 0,则保持为 0,
    # 否则加上手部区域左上角的横坐标x,对纵坐标进行类似处理,这样将局部坐标转换为全局坐标
    peaks = hand_estimation(oriImg[y:y + w, x:x + w, :])
    peaks[:, 0] = np.where(peaks[:, 0] == 0, peaks[:, 0], peaks[:, 0] + x)
    peaks[:, 1] = np.where(peaks[:, 1] == 0, peaks[:, 1], peaks[:, 1] + y)
    # else:
    #     peaks = hand_estimation(cv2.flip(oriImg[y:y+w, x:x+w, :], 1))
    #     peaks[:, 0] = np.where(peaks[:, 0]==0, peaks[:, 0], w-peaks[:, 0]-1+x)
    #     peaks[:, 1] = np.where(peaks[:, 1]==0, peaks[:, 1], peaks[:, 1]+y)
    #     print(peaks)
    all_hand_peaks.append(peaks)
canvas = util.draw_handpose(canvas, all_hand_peaks)

plt.imshow(canvas[:, :, [2, 1, 0]])
plt.axis('off')
plt.show()

对上述关键点,提取,与直接在模型body、hand提取出的有很大的差异。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值