From 20ebff70fa9754aa2e9930d53a08717626740b0c Mon Sep 17 00:00:00 2001 From: YunQi Lv <434658198@qq.com> Date: Thu, 31 Mar 2022 09:11:36 +0000 Subject: [PATCH] Update --- hand.py | 43 +++++++++++++++++++++++++++++++++++++++++++ requirements.txt | Bin 0 -> 1142 bytes 2 files changed, 43 insertions(+) create mode 100644 hand.py create mode 100644 requirements.txt diff --git a/hand.py b/hand.py new file mode 100644 index 0000000..07996fe --- /dev/null +++ b/hand.py @@ -0,0 +1,43 @@ +import cv2 +import mediapipe as mp +import time + +# 打开计算机自带摄像头 +cap = cv2.VideoCapture(0, cv2.CAP_DSHOW) + +mpHands = mp.solutions.hands +hands = mpHands.Hands() # 设置参数,详见 hands.py 中的 __init__ +mpDraw = mp.solutions.drawing_utils # 将检测出的手上的标记点连接起来 + +# 定义时间用于后边的fps计算 +pTime = 0 +cTime = 0 + +while True: + success, img = cap.read() + imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # 将BGR格式图像转换为RGB + results = hands.process(imgRGB) # 对输入图像进行处理,探索图像中是否有手 + # print(results.multi_hand_landmarks) # 如果有手,输出手所有0~20个标记点的比例坐标,如果没有,输出None + if results.multi_hand_landmarks: + for handLms in results.multi_hand_landmarks: # 捕捉画面中的每一只手 + for id, lm in enumerate(handLms.landmark): + # print(id, lm) + h, w, c = img.shape + cx, cy = int(lm.x * w), int(lm.y * h) # 根据比例还原出每一个标记点的像素坐标 + print(id, cx, cy) # 根据手上标记点的id打印出其相应所在图像中中的像素位置 + if id == 4: # 可以根据手上标记点的id获得任意id对应的标记点的信息 + cv2.circle(img, (cx, cy), 10, (255, 0, 255), cv2.FILLED) # 这里加粗强调了大拇指上的一个标记点 + + mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS) # 给画面中的每一只手进行标点、连线的操作 + + # 得到fps + cTime = time.time() + fps = 1/(cTime - pTime) + pTime = cTime + # 在画面上显示fps + cv2.putText(img, 'FPS:' + str(int(fps)), (10, 70), cv2.FONT_ITALIC, 1, (0, 0, 255), 3) + cv2.imshow("Image", img) + cv2.waitKey(1) + # 点击窗口X按钮关闭窗口 + if cv2.getWindowProperty('Image',cv2.WND_PROP_VISIBLE) < 1: + break \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..7779ad343a0afe6de441199c79f2528071c76226 GIT binary patch literal 1142 zcmah|?M{P05ZvD;J_-#7+K(T;gRg*BT8S-CI9lt&t24WBG^vScu3x)1J2N}{d>8U2 zy&NQwR<81bmy?C0dLHFL3eqy5gr<2x-;(=Z$N{Q}7YH9H6s0=FkQWU#w{M|UDK%MH# z$bE-OjY`000~FIh_POdXg*zG0F(SRPTIcbQ=h)sPWgD8bar84lAG zYVUNWB_Lo6{Fe;Kkqmg2_;ruKIse^g!P&!$0x7D1yjN^XiLoLlW`jHA+zdOkI(1pk ztJdk!MSEDWO_P;*!tI>K4YEf5ZuGB(O8VQt-2u}khn;$7+Ng#Md-O5)bEXU_RR{j= zO4PRoI{Q0kXHD}ah(c%h)Xc6hJ7m6!lO}f)Y@azPHHq}fP!~5TBqsA#!?R3T1f5de zctQrI!`vExNWIgu%T)5ow$zc^r%qyK9a1pe=CeSDnASXYWZJP&_E%MB+qO+Hr`*;r Dba