-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoc-2.py
More file actions
36 lines (26 loc) · 987 Bytes
/
poc-2.py
File metadata and controls
36 lines (26 loc) · 987 Bytes
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
import cv2
import easyocr
camera = cv2.VideoCapture(0)
reader = easyocr.Reader(['en'])
scale_percent = 40 # e.g., shrink to 50% of original size
while True:
ret, frame = camera.read()
if not ret:
print("Failed to grab frame.")
break
width = int(frame.shape[1] * scale_percent / 100)
height = int(frame.shape[0] * scale_percent / 100)
dim = (width, height)
resized = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA)
gray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
results = reader.readtext(gray)
for bbox, text, confidence in results:
conf_pct = int(confidence * 100) # Convert to percent as int
print(f"Detected: {text}, Confidence: {conf_pct}%")
# print(f"Detected: {letter}") # You might want to process/format this output
cv2.imshow('Frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break # Exit on pressing 'q'
# Release resources
camera.release()
cv2.destroyAllWindows()