Repository navigation
Description
Description
Bug Summary & Feature Limitations
In Finding_Lanes/lanes.py, several critical computer vision bugs, filtering defects, missing temporal tracking, and CLI limitations affect the reliability of the lane detection pipeline:
-
Color Channel Zeroing in
roi()for Multi-Channel Images:- The docstring for
roi(image, polygons=None)states that it accepts both single-channel edge maps and 3-channel color images:Args: image: Single-channel edge map or 3-channel image.
- However, the mask is created with:
mask = np.zeros_like(image) cv2.fillPoly(mask, polygons, 255) masked_image = cv2.bitwise_and(image, mask)
- When
imageis a 3-channel BGR/RGB image, passing the scalar255tocv2.fillPolysets only channel 0 (blue) to 255, while leaving channel 1 (green) and channel 2 (red) as 0. Consequently,cv2.bitwise_andzeroes out the green and red channels entirely ([200, 200, 200]becomes[200, 0, 0]), corrupting color images passed to the ROI mask.
- The docstring for
-
Unconstrained Slope Averaging & Cross-Lane Contamination:
- In
average_lines_intercept(), candidate line segments are partitioned intoleft_fitandright_fitsolely based on the mathematical sign of the slope:if slope < -min_slope: left_fit.append((slope, intercept)) elif slope > min_slope: right_fit.append((slope, intercept))
- Road scenes frequently have shadows, road wear, dashed divider lines, or guardrails on the right half of the road that have a negative slope. Because there was no spatial check against the vehicle/image midpoint, these right-side artifacts were averaged into
left_fit, severely distorting the left lane line and causing it to cut diagonally across the driving path.
- In
-
Frame-to-Frame Video Jitter & Dash Dropouts (Missing Temporal Tracking):
- On video streams (
video.mp4or live webcam), individual frames with dashed road markings frequently experience brief detection dropouts (when the vehicle is between dashes or under uneven lighting). - Because each frame was processed completely statelessly, lane lines would flicker, disappear for isolated frames, or violently jitter. There was no exponential moving average (EMA) filter or tracking state to stabilize lines across frames.
- On video streams (
-
Unintended Constant Brightness Offset in
cv2.addWeighted:- In
process_frame():combo_image = cv2.addWeighted(frame, 0.8, line_image, 1.0, 1.0)
- The 5th parameter
gamma=1.0adds a constant scalar offset of +1 to every pixel in the entire image. Standard alpha blending requiresgamma=0.0.
- In
-
Silently Swallowed CLI Errors (Zero Exit Code on Failure):
- When a user provided an invalid file path via CLI (e.g.,
python lanes.py --image missing.jpg), the script printed an error message to stderr but terminated with return code0. CI/CD pipelines and automated batch scripts would falsely evaluate the execution as successful.
- When a user provided an invalid file path via CLI (e.g.,
-
Missing
requirements.txt:README.mdinstructed users to runpip install -r requirements.txt, but norequirements.txtexisted inFinding_Lanes/, resulting inFileNotFoundError.
-
Missing Drivable Corridor Visualization Feature:
- Standard lane detection systems highlight the drivable lane corridor between the left and right boundary lines. Adding a
--fill-laneoption significantly improves project presentation and utility.
- Standard lane detection systems highlight the drivable lane corridor between the left and right boundary lines. Adding a
Type of issue
- Bug
- Feature (Enhancement)
- Documentation
Checklist:
- I have read the project guidelines.
- I have checked previous issues to avoid duplicates.
- This issue will be meaningful for the project.
- I have added steps to reproduce the bug
- I have proposed a possible solution for the bug
Steps to Reproduce the Bug:
-
Verify 3-Channel ROI Color Zeroing Bug:
import numpy as np import cv2 from lanes import roi img = np.full((100, 100, 3), 200, dtype=np.uint8) poly = np.array([[[10, 10], [90, 10], [50, 90]]], dtype=np.int32) result = roi(img, poly) print("Pixel value inside polygon:", result[30, 50])
Observed Output:
Pixel value inside polygon: [200 0 0]
Notice channels 1 and 2 (green and red) are completely zeroed out instead of preserving
[200, 200, 200]. -
Verify Cross-Lane Contamination:
Runaverage_lines_interceptwith a genuine left segment on the left half and an erroneous negative-slope segment on the right half:import numpy as np from lanes import average_lines_intercept frame = np.zeros((720, 1280, 3), dtype=np.uint8) left_seg = [[300, 720, 580, 450]] # Genuine left lane corrupt_seg = [[1100, 700, 1150, 600]] # Negative slope on right side lines = np.array([left_seg, corrupt_seg]) lanes = average_lines_intercept(frame, lines) print("Detected lanes count:", len(lanes))
Observed Output:
corrupt_segis averaged directly into the left lane fit, distorting its trajectory across the vehicle center. -
Verify Missing
requirements.txt:cd Finding_Lanes pip install -r requirements.txtObserved Output:
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
Proposed Solution:
- Fix
roi(): Usefill_color = (255,) * image.shape[2] if image.ndim == 3 else 255so all color channels are preserved in multi-channel inputs. - Add Spatial Midpoint Filtering in
average_lines_intercept(): Ensure left segments satisfy(x1 + x2) / 2 < midpointand right segments satisfy(x1 + x2) / 2 > midpoint. - Implement
LaneTrackerClass: Add an exponential moving average (EMA) filter with dropout retention buffer to eliminate video jitter and preserve lane stability. - Fix
cv2.addWeighted: Changegammafrom1.0to0.0. - Add Drivable Corridor Visualization (
--fill-lane): Draw a semi-transparent filled polygon between detected lane lines. - Fix CLI Exit Codes: Return exit code 1 when input files cannot be found or read.
- Create
requirements.txt: Specifyopencv-python,numpy, andmatplotlib. - Add Comprehensive Unit Tests: Expand
test_lanes.pyto 22 test cases covering all edge cases, color preservation, EMA smoothing, and corridor fill.
Activity