-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoc-4.py
More file actions
71 lines (54 loc) · 1.85 KB
/
poc-4.py
File metadata and controls
71 lines (54 loc) · 1.85 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
71
print ("program: Loading ML models...")
import cv2
import easyocr
from VideoDriver import VideoDriver
camera = None
reader = easyocr.Reader(['en'])
scale_percent = 40 # e.g., shrink to 50% of original
ack_frozen = False
def main():
# Using:
global camera, ack_frozen, scale_percent
# Next:
camera = VideoDriver()
camera.initialize()
# camera = cv2.VideoCapture(0)
if camera.platform == "DRONE":
scale_percent = 50 # Upscale the video for better results
print(camera.drone.get_battery())
while True:
key = cv2.waitKey(1) & 0xFF
if key == ord('p'):
camera.set_freeze(not camera.frozen)
elif key == ord('q'):
break # Exit on pressing 'q'
ret, frame = camera.read()
if not ret:
print("Failed to grab frame.")
continue
if ret == 2:
if not ack_frozen:
print("Camera is frozen.")
ack_frozen = True
continue
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)
# Release resources
camera.release()
cv2.destroyAllWindows()
try:
main()
except KeyboardInterrupt:
# Checks if camera is an instance of VideoDriver
if isinstance(camera, VideoDriver):
camera.release()
cv2.destroyAllWindows()