-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_paint.py
More file actions
60 lines (40 loc) · 1.02 KB
/
virtual_paint.py
File metadata and controls
60 lines (40 loc) · 1.02 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import cv2
import time
import numpy as np
import hand_tracking_module as htm
import math
import os
# folderPath = "pic_paint"
# myList = os.listdir(folderPath)
# print(myList)
# overlayList = []
img2 = cv2.imread("handtracking/pxfuel.jpg")
# cv2.imshow("ori", img2)
cropped_img2 = img2[365:490 , 0:1280]
# cv2.imshow("cropped", cropped_img2)
pTime = 0
cTime = 0
cap = cv2.VideoCapture('/dev/video2')
detector = htm.handDetector(detectionCon=0.7)
cap.set (3, 1280)
cap.set (4, 720)
while True:
success, img = cap.read()
# 2. Find Hand
img = detector.findHands(img)
lmList = detector.findPosition(img, draw=False)
if len(lmList) != 0:
print(lmList)
# 3. Check finger
# 4. Check if touching
# 5. move robot
img[0:125 , 0:1280] = cropped_img2
cTime = time.time()
fps = 1/(cTime-pTime)
pTime = cTime
cv2.putText(img, str(int(fps)), (10,70), cv2.FONT_HERSHEY_PLAIN,3, (255,0,255), 3)
cv2.imshow("Video", img)
if cv2.waitKey(20) & 0xFF==ord('d'):
break
cap.release()
cv2.destroyAllWindows()