Skip to content

Commit 0e2d2b2

Browse files
authored
Update ROIinOpenCV.py
1 parent 9aeefc8 commit 0e2d2b2

File tree

1 file changed

+17
-47
lines changed

1 file changed

+17
-47
lines changed

ROIinOpenCV.py

+17-47
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,7 @@
99

1010

1111
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))
4413

4514

4615
def keras_predict(model, image):
@@ -55,18 +24,18 @@ def keras_process_image(img):
5524
image_x = 28
5625
image_y = 28
5726
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+
6228
return img
6329

6430

6531
def crop_image(image, x, y, width, height):
6632
return image[y:y + height, x:x + width]
6733

6834
def main():
69-
while True:
35+
l = []
36+
37+
while True:
38+
7039
cam_capture = cv2.VideoCapture(0)
7140
_, image_frame = cam_capture.read()
7241
# Select ROI
@@ -76,25 +45,26 @@ def main():
7645
image_grayscale_blurred = cv2.GaussianBlur(image_grayscale, (15,15), 0)
7746
im3 = cv2.resize(image_grayscale_blurred, (28,28), interpolation = cv2.INTER_AREA)
7847

79-
80-
81-
#ar = np.array(resized_img)
82-
#ar = resized_img.reshape(1,784)
83-
84-
48+
8549

8650
im4 = np.resize(im3, (28, 28, 1))
8751
im5 = np.expand_dims(im4, axis=0)
8852

8953

9054
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+
9361

9462

9563
# 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+
9868
#cv2.imshow("Image4",resized_img)
9969
cv2.imshow("Image3",image_grayscale_blurred)
10070

0 commit comments

Comments
 (0)