import cv2 import matplotlib.pyplot as plt import numpy as np import time import os import mediapipe as mp mphands = mp.solutions.hands mpdraw = mp.solutions.drawing_utils wcap , hcap = 640 , 480 #定义摄像头的宽 和 高 cap = cv2.VideoCapture(0) cap.set(3,wcap) cap.set(4,hcap) pTime = 0 while True: ret , img = cap.read() imgRGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB) #转换rgb为bgr bgr mediapipe才可识别 with mphands.Hands(min_detection_confidence=0.65,min_tracking_confidence=0.65) as hands: result = hands.process(imgRGB) # print(result.multi_hand_landmarks) if result.multi_hand_landmarks: for hand_landmarks in result.multi_hand_landmarks: mpdraw.draw_landmarks(img,hand_landmarks,mphands.HAND_CONNECTIONS) cTime = time.time() fps = 1/(cTime - pTime) pTime = cTime cv2.putText(img,f'fps:{int(fps)}',(20,45),cv2.FONT_HERSHEY_COMPLEX,1,(255,0,0),2,8,0) cv2.imshow("image",img) if cv2.waitKey(1) == 27: break cap.release() #释放摄像头 cv2.destroyWindow() #窗口关闭
人丑不好意思哈哈哈哈