forked from ajinkya110001/ERC-HandDetectionAssignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (26 loc) · 953 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import cv2 as cv
import mediapipe as mp
from google.protobuf.json_format import MessageToDict
cap=cv.VideoCapture(0)
#TODO: Add required mediapipe functions
mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils
while True:
success, frame=cap.read()
whichHands = ""
frame = cv.flip(frame,1)
imgRGB = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
results = hands.process(imgRGB)
if results.multi_handedness:
for idx, hand_handedness in enumerate(results.multi_handedness):
hand_handedness_dict = MessageToDict(hand_handedness)
whichHands = hand_handedness_dict['classification'][0]['label']
cv.putText(frame, whichHands, (10,50),cv.FONT_HERSHEY_TRIPLEX,1,(225,0,225),thickness=1)
cv.imshow("Hand Detection",frame)
#TODO: Implement the functions
if cv.waitKey(1) & 0xFF==ord('q'):
break
cap.release()
cv.destroyAllWindows()
cv.waitKey(0)