赞
踩
1,尝试打开前置摄像头
import cv2
#打开摄像头
cap=cv2.VideoCapture(0)
while True:
#获取视频图像
ok,img=cap.read()
if ok:
cv2.imshow("",img)
cv2.waitKey(1)
结果:可以打开电脑或者手机前置摄像头
2,识别手关节,并让关节连线
import cv2 import mediapipe as mp mhands=mp.solutions.hands hands=mhands.Hands() mdraw = mp.solutions.drawing_utils #手势对象 cap=cv2.VideoCapture(0) while True: ok,img=cap.read() if ok: #彩色图片转为黑白 img2=cv2.cvtColor(img, cv2.COLOR_BGR2RGB) #计算手关节的坐标 rs=hands.process(img2) if rs.multi_hand_landmarks: #遍历关节坐标 for lms in rs.multi_hand_landmarks: for lm in lms.landmark: h,w,d=img.shape cx=int(lm.x*w) cy=int(lm.y*h) cv2.circle(img,(cx,cy),int(w/50),(0,0,200)) mdraw.draw_landmarks(img,lms,mhands.HAND_CONNECTIONS) cv2.imshow("",img) cv2.waitKey(1)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。