9
9
10
10
11
11
def prediction (pred ):
12
- if pred == 0 :
13
- print ('A' )
14
- elif pred == 1 :
15
- print ('B' )
16
-
17
- elif pred == 2 :
18
- print ('C' )
19
-
20
- elif pred == 3 :
21
- print ('D' )
22
-
23
- elif pred == 14 :
24
- print ('O' )
25
-
26
- elif pred == 8 :
27
- print ('I' )
28
-
29
- elif pred == 20 :
30
- print ('U' )
31
-
32
- elif pred == 21 :
33
- print ('V' )
34
-
35
- elif pred == 22 :
36
- print ('W' )
37
-
38
- elif pred == 24 :
39
- print ('Y' )
40
-
41
- elif pred == 11 :
42
- print ('L' )
43
-
12
+ return (chr (pred + 65 ))
44
13
45
14
46
15
def keras_predict (model , image ):
@@ -55,18 +24,18 @@ def keras_process_image(img):
55
24
image_x = 28
56
25
image_y = 28
57
26
img = cv2 .resize (img , (1 ,28 ,28 ), interpolation = cv2 .INTER_AREA )
58
- #img = get_square(img, 28)
59
- #img = np.reshape(img, (image_x, image_y))
60
-
61
-
27
+
62
28
return img
63
29
64
30
65
31
def crop_image (image , x , y , width , height ):
66
32
return image [y :y + height , x :x + width ]
67
33
68
34
def main ():
69
- while True :
35
+ l = []
36
+
37
+ while True :
38
+
70
39
cam_capture = cv2 .VideoCapture (0 )
71
40
_ , image_frame = cam_capture .read ()
72
41
# Select ROI
@@ -76,25 +45,26 @@ def main():
76
45
image_grayscale_blurred = cv2 .GaussianBlur (image_grayscale , (15 ,15 ), 0 )
77
46
im3 = cv2 .resize (image_grayscale_blurred , (28 ,28 ), interpolation = cv2 .INTER_AREA )
78
47
79
-
80
-
81
- #ar = np.array(resized_img)
82
- #ar = resized_img.reshape(1,784)
83
-
84
-
48
+
85
49
86
50
im4 = np .resize (im3 , (28 , 28 , 1 ))
87
51
im5 = np .expand_dims (im4 , axis = 0 )
88
52
89
53
90
54
pred_probab , pred_class = keras_predict (model , im5 )
91
- #print(pred_class, pred_probab)
92
- prediction (pred_class )
55
+
56
+ curr = prediction (pred_class )
57
+
58
+ cv2 .putText (image_frame , curr , (700 , 300 ), cv2 .FONT_HERSHEY_COMPLEX , 4.0 , (255 , 255 , 255 ), lineType = cv2 .LINE_AA )
59
+
60
+
93
61
94
62
95
63
# Display cropped image
96
-
97
- cv2 .imshow ("Image2" ,im2 )
64
+ cv2 .rectangle (image_frame , (300 , 300 ), (600 , 600 ), (255 , 255 , 00 ), 3 )
65
+ cv2 .imshow ("frame" ,image_frame )
66
+
67
+
98
68
#cv2.imshow("Image4",resized_img)
99
69
cv2 .imshow ("Image3" ,image_grayscale_blurred )
100
70
0 commit comments