Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controls/sae_2025_ws/src/uav/uav/cv/calibrate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import cv2
import scipy.stats as stats
from recalibrate import detect_contour
from confidence import confidence
from .recalibrate import detect_contour
from .confidence import confidence


def calibrate(frame):
Expand Down
25 changes: 15 additions & 10 deletions controls/sae_2025_ws/src/uav/uav/cv/track.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np
import cv2
from calibrate import calibrate
from recalibrate import recalibrate
from threshold import threshold
from confidence import confidence
from .calibrate import calibrate
from .recalibrate import recalibrate
from .threshold import threshold
from .confidence import confidence

range = ((0, 0, 180), (225, 225, 255))

Expand All @@ -19,28 +19,33 @@ def process_video(input_path: str):
cap = cv2.VideoCapture(input_path)

opened, first_frame = cap.read()
if not opened or first_frame is None:
raise ValueError(f"Could not read first frame from {input_path}")

prev_frame = first_frame
prev_center = (0, 0)

threshold_range = calibrate(first_frame)

while cap.isOpened():
_, frame = cap.read()
ok, frame = cap.read()
if not ok or frame is None:
break

if recalibrate(frame, prev_frame, range):
threshold_range = calibrate(frame)

points, center = threshold(threshold_range, prev_center, frame)

new_points = [conversion(p, 100) for p in points]
print(new_points)
if points is not None and center is not None:
new_points = [conversion(p, 100) for p in points]
print(new_points)

conf = confidence(points, -1, *frame[:2])
print(f"{conf:.2f}, {center}")
conf = confidence(points, -1, *frame.shape[:2])
print(f"{conf:.2f}, {center}")
prev_center = center

prev_frame = frame
prev_center = center

if cv2.waitKey(1) & 0xFF == ord("q"):
break
Expand Down
Loading