GullyDRS.LBW.Predictorapp / trajectory.py
viswanani's picture
Update trajectory.py
a4c5608 verified
raw
history blame contribute delete
669 Bytes
import numpy as np
import cv2
def fit_curve(points):
if len(points) < 3:
return None, None
xs = [x for x, y in points]
ys = [y for x, y in points]
coeffs = np.polyfit(xs, ys, 2)
return coeffs, np.poly1d(coeffs)
def draw_trajectory_overlay(frame, coeffs, x_range=(0, 1280)):
if coeffs is None:
return frame
a, b, c = coeffs
points = []
for x in range(x_range[0], x_range[1], 10):
y = int(a * x**2 + b * x + c)
if 0 <= y < frame.shape[0]:
points.append((x, y))
if len(points) >= 2:
cv2.polylines(frame, [np.array(points, np.int32)], False, (255, 0, 0), 2)
return frame