-
Notifications
You must be signed in to change notification settings - Fork 0
/
webin.py
50 lines (34 loc) · 1.39 KB
/
webin.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
import pytesseract
import cv2
import numpy as np
font_scale = 1.5
font = cv2.FONT_HERSHEY_PLAIN
cap =cv2.VideoCapture(1)
if not cap.isOpened():
cap =cv2.VideoCapture(0)
if not cap.isOpened():
raise IOError("Cannot open video")
counter= 0;
while True:
ret,frame=cap.read()
counter +=1;
if ((counter%20)==0):
imgH, imgW,_ = frame.shape
x1,y1,w1,h1 = 0,0,imgH,imgW
imgchar = pytesseract.image_to_string(frame)
imgboxes = pytesseract.image_to_boxes(frame)
for boxes in imgboxes.splitlines():
boxes = boxes.split(' ')
x,y,w,h = int(boxes[1]), int(boxes[2]), int(boxes[3]), int(boxes[4])
cv2.rectangle(frame, (x, imgH-y), (w,imgH-h), (0,0,255),3)
# cv2.putText(frame, imgchar, (x1 + int(w1/50), y1 + int(h1/50)), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255,0,0), 2)
# font = cv2.FONT_HERSHEY_SIMPLEX
# cv2.imshow('Text Detection Tutorial',frame)
# Display the live stream with extracted text
text = pytesseract.image_to_string(frame, config='--psm 6')
cv2.putText(frame, text, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.imshow("ESP32-CAM Live Stream", frame)
if cv2.waitKey(2) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()