Skip to content

Commit 46f4521

Browse files
committed
Implement linear interpolation for dot position smoothing in lane detection
1 parent d50a6b9 commit 46f4521

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

line_detection_output.mp4

-587 KB
Binary file not shown.

src/lane_center.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ def calculate_dot_positions(lines):
200200
dot_positions = np.array(dot_positions)
201201
return dot_positions
202202

203+
def lerp(a: np.ndarray, b: np.ndarray, t: float) -> np.ndarray:
204+
"""
205+
Linearly interpolate between two arrays a and b by factor t.
206+
"""
207+
return a + t * (b - a)
208+
203209
def main():
204210
video_path = "videos/Better test.mp4"
205211
cap = cv2.VideoCapture(video_path)
@@ -229,7 +235,7 @@ def main():
229235
if prev_dot_positions is None or prev_dot_positions.shape[0] != dot_positions.shape[0]:
230236
smoothed_dot_positions = dot_positions
231237
else:
232-
smoothed_dot_positions = SMOOTHING_FACTOR * dot_positions + (1 - SMOOTHING_FACTOR) * prev_dot_positions
238+
smoothed_dot_positions = lerp(prev_dot_positions, dot_positions, SMOOTHING_FACTOR)
233239

234240
prev_dot_positions = smoothed_dot_positions
235241
processed_frame, curvature = stay_in_center(frame, smoothed_dot_positions)
@@ -255,4 +261,4 @@ def main():
255261
cv2.destroyAllWindows()
256262

257263
if __name__ == "__main__":
258-
main()
264+
main()

0 commit comments

Comments
 (0)