This project detects a black line in a video and represents it as an occupancy grid, similar to a ROS-style mapping system. It processes video frames in real time using OpenCV, applies image processing techniques, and generates an adjustable occupancy grid using NumPy.
โ
Detects a black line from video frames
โ
Generates an occupancy grid without using ROS
โ
Adjustable grid size for different use cases
โ
Real-time processing with OpenCV
โ
Highlights line direction and contours for visualization
-
Preprocessing:
- Convert each video frame to grayscale.
- Apply Gaussian blur to reduce noise.
- Use binary thresholding to highlight the black line.
-
Line Detection:
- Identify contours in the image.
- Select the largest contour as the black line.
- Fit a direction line using
cv2.fitLine()
.
-
Grid Mapping:
- Resize the detected line into a 100x100 (or custom) occupancy grid.
- Use NumPy to assign grid values:
100
for occupied (line detected)0
for free space
-
Visualization:
- Display the original video frame with detected contours.
- Generate a zoomed-in occupancy grid with grid lines and labels.
- Highlight the detected pathโs direction using a red guiding line.
- Python 3.x
- OpenCV (
pip install opencv-python
) - NumPy (
pip install numpy
)
- Clone the repository:
git clone https://github.com/Line_detection-camera-.git cd Line_detection-camera-
- Place your video file in the project directory.
- Update the video path in
line.py
:video_path = "vid.mp4" # Change this to your video file path
- Run the script:
python line.py
- Press 'q' to exit the visualization.
๐น Reads video frames and applies preprocessing.
๐น Detects the largest black contour as the main path.
๐น Fits a directional line for better visualization.
๐น Generates and displays an occupancy grid.
grid_size
: Changes the occupancy grid resolution.line_length
: Adjusts the detected pathโs guide line length.
๐ผ Real-time Frame with Line Detection
๐ธ No ROS Support: Used NumPy to manually create an occupancy grid.
๐ธ Noisy Image Data: Applied Gaussian blur and thresholding.
๐ธ Processing Speed: Resized frames for faster performance.
๐ธ Unwanted Contours: Selected only the largest detected contour.
๐ Integrate with robot navigation for path-following applications.
๐ฏ Enhance contour filtering to handle complex environments.
๐ก Expand to multi-line detection for lane tracking.
๐ค Manish Kumar