|
楼主 |
发表于 2020-1-16 14:11:07
|
显示全部楼层
demo里面跑的检测食指2个点的,如果想检测全部的手部点,可以用这份代码。
- import math
- import time
- import argparse
- from rockx import RockX
- import cv2
- if __name__ == '__main__':
- # 参数解析
- parser = argparse.ArgumentParser(description="RockX Finger Demo")
- parser.add_argument('-c', '--camera', help="camera index", type=int, default=0)
- parser.add_argument('-d', '--device', help="target device id", type=str)
- args = parser.parse_args()
- # 创建RockX手指关键点句柄
- pose_finger_handle = RockX(RockX.ROCKX_MODULE_POSE_FINGER_21, target_device=args.device)
- # 从摄像头获取1280x720的图像
- cap = cv2.VideoCapture(args.camera)
- cap.set(3, 1280)
- cap.set(4, 720)
- last_face_feature = None
- while True:
- # 按帧读取图像
- ret, frame = cap.read()
- in_img_h, in_img_w = frame.shape[:2]
- # 使用RockX进行手指关键点识别
- ret, result = pose_finger_handle.rockx_pose_finger(frame, in_img_w, in_img_h, RockX.ROCKX_PIXEL_FORMAT_BGR888)
- # 在图像上绘制关键点
- for p in result.points:
- cv2.circle(frame, (p.x, p.y), 3, (0, 255, 0), 3)
- # 使用线条连接对应的关键点
- for pairs in RockX.ROCKX_POSE_FINGER_21_KEYPOINTS_PAIRS:
- pt1 = result.points[pairs[0]]
- pt2 = result.points[pairs[1]]
- if pt1.x <= 0 or pt1.y <= 0 or pt2.x <= 0 or pt2.y <= 0:
- continue
- cv2.line(frame, (pt1.x, pt1.y), (pt2.x, pt2.y), (255, 0, 0), 2)
- # 显示结果图像
- cv2.imshow('RockX Finger - ' + str(args.device), frame)
- # 按下'q'键退出
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- # 释放资源
- cap.release()
- cv2.destroyAllWindows()
- pose_finger_handle.release()
|
|