-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathdata_collection_final.py
112 lines (88 loc) · 3.9 KB
/
data_collection_final.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
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import cv2
from cvzone.HandTrackingModule import HandDetector
import numpy as np
import os as oss
import traceback
capture = cv2.VideoCapture(0)
hd = HandDetector(maxHands=1)
hd2 = HandDetector(maxHands=1)
count = len(oss.listdir("D:\\sign2text_dataset_3.0\\AtoZ_3.0\\A\\"))
c_dir = 'A'
offset = 15
step = 1
flag=False
suv=0
white=np.ones((400,400),np.uint8)*255
cv2.imwrite("C:\\Users\\devansh raval\\PycharmProjects\\pythonProject\\white.jpg",white)
while True:
try:
_, frame = capture.read()
frame = cv2.flip(frame, 1)
hands= hd.findHands(frame, draw=False, flipType=True)
white = cv2.imread("C:\\Users\\devansh raval\\PycharmProjects\\pythonProject\\white.jpg")
if hands:
hand = hands[0]
x, y, w, h = hand['bbox']
image =np.array( frame[y - offset:y + h + offset, x - offset:x + w + offset])
handz,imz = hd2.findHands(image, draw=True, flipType=True)
if handz:
hand = handz[0]
pts = hand['lmList']
# x1,y1,w1,h1=hand['bbox']
os=((400-w)//2)-15
os1=((400-h)//2)-15
for t in range(0,4,1):
cv2.line(white,(pts[t][0]+os,pts[t][1]+os1),(pts[t+1][0]+os,pts[t+1][1]+os1),(0,255,0),3)
for t in range(5,8,1):
cv2.line(white,(pts[t][0]+os,pts[t][1]+os1),(pts[t+1][0]+os,pts[t+1][1]+os1),(0,255,0),3)
for t in range(9,12,1):
cv2.line(white,(pts[t][0]+os,pts[t][1]+os1),(pts[t+1][0]+os,pts[t+1][1]+os1),(0,255,0),3)
for t in range(13,16,1):
cv2.line(white,(pts[t][0]+os,pts[t][1]+os1),(pts[t+1][0]+os,pts[t+1][1]+os1),(0,255,0),3)
for t in range(17,20,1):
cv2.line(white,(pts[t][0]+os,pts[t][1]+os1),(pts[t+1][0]+os,pts[t+1][1]+os1),(0,255,0),3)
cv2.line(white, (pts[5][0]+os, pts[5][1]+os1), (pts[9][0]+os, pts[9][1]+os1), (0, 255, 0), 3)
cv2.line(white, (pts[9][0]+os, pts[9][1]+os1), (pts[13][0]+os, pts[13][1]+os1), (0, 255, 0), 3)
cv2.line(white, (pts[13][0]+os, pts[13][1]+os1), (pts[17][0]+os, pts[17][1]+os1), (0, 255, 0), 3)
cv2.line(white, (pts[0][0]+os, pts[0][1]+os1), (pts[5][0]+os, pts[5][1]+os1), (0, 255, 0), 3)
cv2.line(white, (pts[0][0]+os, pts[0][1]+os1), (pts[17][0]+os, pts[17][1]+os1), (0, 255, 0), 3)
skeleton0=np.array(white)
zz=np.array(white)
for i in range(21):
cv2.circle(white,(pts[i][0]+os,pts[i][1]+os1),2,(0 , 0 , 255),1)
skeleton1=np.array(white)
cv2.imshow("1",skeleton1)
frame = cv2.putText(frame, "dir=" + str(c_dir) + " count=" + str(count), (50,50),
cv2.FONT_HERSHEY_SIMPLEX,
1, (255, 0, 0), 1, cv2.LINE_AA)
cv2.imshow("frame", frame)
interrupt = cv2.waitKey(1)
if interrupt & 0xFF == 27:
# esc key
break
if interrupt & 0xFF == ord('n'):
c_dir = chr(ord(c_dir)+1)
if ord(c_dir)==ord('Z')+1:
c_dir='A'
flag = False
count = len(oss.listdir("D:\\sign2text_dataset_3.0\\AtoZ_3.0\\" + (c_dir) + "\\"))
if interrupt & 0xFF == ord('a'):
if flag:
flag=False
else:
suv=0
flag=True
print("=====",flag)
if flag==True:
if suv==180:
flag=False
if step%3==0:
cv2.imwrite("D:\\sign2text_dataset_3.0\\AtoZ_3.1\\" + (c_dir) + "\\" + str(count) + ".jpg",
skeleton1)
count += 1
suv += 1
step+=1
except Exception:
print("==",traceback.format_exc() )
capture.release()
cv2.destroyAllWindows()