-
Notifications
You must be signed in to change notification settings - Fork 0
/
demonstrator.py
47 lines (38 loc) · 1.95 KB
/
demonstrator.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
import cv2
from metricEvaluator import MetricsEvaluator
from cornerDetector import TemporalCornerDetector
from tester import Tester
def runDemonstration(video_path):
cap = cv2.VideoCapture(video_path)
detector = TemporalCornerDetector()
evaluator = MetricsEvaluator()
tester = Tester()
corners_history = {"conventional": [], "enhanced": []}
frame_count = 0
FRAME_RATIO_CONSTANT = 160
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame = cv2.resize(frame, (FRAME_RATIO_CONSTANT*4, FRAME_RATIO_CONSTANT*3))
conventional_corners = detector.adaptive_corner_detection(frame)
filtered_corners = detector.filter_corners_by_density(conventional_corners)
evaluator.update_metrics(filtered_corners, corners_history["conventional"][-1] if corners_history["conventional"] else None, "conventional")
corners_history["conventional"].append(filtered_corners)
enhanced_corners = detector.track_corners(frame, filtered_corners, frame_count)
smoothed_corners = detector.temporal_smoothing(corners_history["enhanced"])
evaluator.update_metrics(smoothed_corners, corners_history["enhanced"][-1] if corners_history["enhanced"] else None, "enhanced")
corners_history["enhanced"].append(enhanced_corners)
for corner in filtered_corners:
cv2.circle(frame, tuple(corner.ravel().astype(int)), 3, (0, 0, 255), -1) # Red for conventional corners
for corner in smoothed_corners:
cv2.circle(frame, tuple(corner.ravel().astype(int)), 3, (0, 255, 0), -1) # Green for enhanced corners
tester.evaluate_detection(filtered_corners, smoothed_corners)
cv2.imshow("Enhanced Temporal Consistency Corner Detection", frame)
frame_count += 1
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
evaluator.show_metrics()
tester.display_metrics()