-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (29 loc) · 940 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
35
from cvzone.HandTrackingModule import HandDetector
import cv2
import socket
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
success, img = cap.read()
h, w, _ = img.shape
detector = HandDetector(detectionCon=0.8, maxHands=1)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serverAddressPort = ("127.0.0.1", 5052)
while True:
# Get image frame
success, img = cap.read()
# Find the hand and its landmarks
hands, img = detector.findHands(img) # with draw
# hands = detector.findHands(img, draw=False) # without draw
data = []
if hands:
# Hand 1
hand = hands[0]
lmList = hand["lmList"] # List of 21 Landmark points
for lm in lmList:
data.extend([lm[0], h - lm[1], lm[2]])
sock.sendto(str.encode(str(data)), serverAddressPort)
# Display
img = cv2.resize(img, (0, 0), None, 0.5, 0.5)
cv2.imshow("Image", img)
cv2.waitKey(1)