Spaces:
Runtime error
Runtime error
Commit
·
ae00f23
1
Parent(s):
816ef5d
process video
Browse files
camera.py
CHANGED
|
@@ -11,8 +11,8 @@ MAX_DISTANCE: int = 10000
|
|
| 11 |
HIT_COUNTER_MAX: int = 30
|
| 12 |
|
| 13 |
# SOURCE = 'rtsp://admin:PRE001@10.0.0.194:554/profile1'
|
| 14 |
-
|
| 15 |
-
SOURCE = '/home/prevantec/Downloads/video.mp4'
|
| 16 |
|
| 17 |
|
| 18 |
def yolo_to_norfair(yolo_detections):
|
|
@@ -41,7 +41,7 @@ def cut_top_bottom(image, top=0.1, bottom=0):
|
|
| 41 |
return image[int(height * top):int(height * (1 - bottom)), :]
|
| 42 |
|
| 43 |
|
| 44 |
-
def run(source=):
|
| 45 |
tracker = Tracker(
|
| 46 |
distance_function="iou_opt",
|
| 47 |
distance_threshold=DISTANCE_THRESHOLD_BBOX,
|
|
@@ -68,30 +68,31 @@ def run(source=):
|
|
| 68 |
if obj.last_detection is not None and obj.age > 10:
|
| 69 |
bbox = obj.last_detection.points
|
| 70 |
bbox = int(bbox[0][0]), int(bbox[0][1]), int(bbox[1][0]), int(bbox[1][1])
|
| 71 |
-
|
|
|
|
| 72 |
crop = imcrop(frame, bbox)
|
| 73 |
text = detect_chars(crop)
|
| 74 |
plates[obj.id] = text
|
| 75 |
# thread = Thread(target=send_request, args=(frame_copy, text, bbox))
|
| 76 |
# thread.start()
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
cv2.imshow("frame", frame)
|
| 96 |
final_video.write(frame)
|
| 97 |
if cv2.waitKey(1) & 0xFF == ord("q"):
|
|
|
|
| 11 |
HIT_COUNTER_MAX: int = 30
|
| 12 |
|
| 13 |
# SOURCE = 'rtsp://admin:PRE001@10.0.0.194:554/profile1'
|
| 14 |
+
SOURCE = './costarica/videos/video4.mp4'
|
| 15 |
+
# SOURCE = '/home/prevantec/Downloads/video.mp4'
|
| 16 |
|
| 17 |
|
| 18 |
def yolo_to_norfair(yolo_detections):
|
|
|
|
| 41 |
return image[int(height * top):int(height * (1 - bottom)), :]
|
| 42 |
|
| 43 |
|
| 44 |
+
def run(source=SOURCE):
|
| 45 |
tracker = Tracker(
|
| 46 |
distance_function="iou_opt",
|
| 47 |
distance_threshold=DISTANCE_THRESHOLD_BBOX,
|
|
|
|
| 68 |
if obj.last_detection is not None and obj.age > 10:
|
| 69 |
bbox = obj.last_detection.points
|
| 70 |
bbox = int(bbox[0][0]), int(bbox[0][1]), int(bbox[1][0]), int(bbox[1][1])
|
| 71 |
+
area = (bbox[2] - bbox[0]) * (bbox[3] - bbox[1])
|
| 72 |
+
if obj.id not in plates.keys() and area > 1000:
|
| 73 |
crop = imcrop(frame, bbox)
|
| 74 |
text = detect_chars(crop)
|
| 75 |
plates[obj.id] = text
|
| 76 |
# thread = Thread(target=send_request, args=(frame_copy, text, bbox))
|
| 77 |
# thread.start()
|
| 78 |
+
if obj.id in plates.keys():
|
| 79 |
+
cv2.rectangle(
|
| 80 |
+
frame,
|
| 81 |
+
(bbox[0], bbox[1]),
|
| 82 |
+
(bbox[2], bbox[3]),
|
| 83 |
+
(0, 255, 0),
|
| 84 |
+
2,
|
| 85 |
+
)
|
| 86 |
+
draw_text(frame, plates[obj.id], (bbox[0], bbox[1]))
|
| 87 |
+
cv2.putText(
|
| 88 |
+
frame,
|
| 89 |
+
plates[obj.id],
|
| 90 |
+
(bbox[0], bbox[1]),
|
| 91 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
| 92 |
+
1,
|
| 93 |
+
(0, 255, 0),
|
| 94 |
+
2,
|
| 95 |
+
)
|
| 96 |
cv2.imshow("frame", frame)
|
| 97 |
final_video.write(frame)
|
| 98 |
if cv2.waitKey(1) & 0xFF == ord("q"):
|