-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcode.txt
More file actions
executable file
·71 lines (50 loc) · 1.43 KB
/
Copy pathcode.txt
File metadata and controls
executable file
·71 lines (50 loc) · 1.43 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
61
62
63
64
65
66
67
68
69
70
import numpy as np
import cv2
import os
image_x = 200
image_y = 100
image_w = 200
image_h = 200
pic_no = 0
total_pic = 1200
flag_capturing = False
if not os.path.exists('signs'):
os.mkdir('signs')
sign = input("Enter Sign ")
if not os.path.exists('signs/' + sign):
os.mkdir('signs/' + sign)
save_path = 'signs/' + sign
images = []
vc = cv2.VideoCapture(0)
while True:
rval, frame = vc.read()
if not rval:
continue
frame = cv2.flip(frame, 1)
cv2.rectangle(frame, (image_x,image_y), (image_x + image_w,image_y + image_h), (0,255,0), 2)
hand = frame[image_y:image_y+image_h, image_x:image_x+image_w]
hand = cv2.cvtColor(hand, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(hand, (11,11), 0)
blur = cv2.medianBlur(blur, 15)
thresh = cv2.threshold(blur,215,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]
thresh = cv2.bitwise_not(thresh)
if flag_capturing:
pic_no += 1
img = cv2.resize( thresh, (50,50) )
images.append( np.array(img) )
cv2.putText(frame, "Capturing "+str(pic_no)+'/'+str(total_pic), (30, 40), cv2.FONT_HERSHEY_TRIPLEX, 1, (255, 255, 0))
cv2.imshow("image", frame)
cv2.imshow("hand", thresh)
keypress = cv2.waitKey(1)
if pic_no == total_pic:
flag_capturing = False
break
if keypress == ord('q'):
break
elif keypress == ord('c'):
flag_capturing = True
vc.release()
cv2.destroyAllWindows()
print ("Saving Images ... ")
for i in range( len(images) ):
cv2.imwrite(save_path + "/" + str(i) + ".jpg", img)