Skip to content

A line detection program using python OpenCV framework. This tracks the black line in the video and also create an Occupancy Grid (to be used in ROS).

Notifications You must be signed in to change notification settings

Manish-git-tech/Line_detection-camera-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Line Detection and Occupancy Grid Mapping

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.


Features

โœ… 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


How It Works

  1. Preprocessing:

    • Convert each video frame to grayscale.
    • Apply Gaussian blur to reduce noise.
    • Use binary thresholding to highlight the black line.
  2. Line Detection:

    • Identify contours in the image.
    • Select the largest contour as the black line.
    • Fit a direction line using cv2.fitLine().
  3. 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
  4. 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.

Installation

Requirements

  • Python 3.x
  • OpenCV (pip install opencv-python)
  • NumPy (pip install numpy)

Running the Project

  1. Clone the repository:
    git clone https://github.com/Line_detection-camera-.git
    cd Line_detection-camera-
  2. Place your video file in the project directory.
  3. Update the video path in line.py:
    video_path = "vid.mp4"  # Change this to your video file path
  4. Run the script:
    python line.py
  5. Press 'q' to exit the visualization.

Code Overview

line.py

๐Ÿ”น 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.

Adjustable Parameters

  • grid_size: Changes the occupancy grid resolution.
  • line_length: Adjusts the detected pathโ€™s guide line length.

Example Output

๐Ÿ–ผ Real-time Frame with Line Detection
Frame with Detection

๐Ÿ–ผ Generated Occupancy Grid
Occupancy Grid


Challenges & Solutions

๐Ÿ”ธ 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.


Future Improvements

๐Ÿš€ Integrate with robot navigation for path-following applications.
๐ŸŽฏ Enhance contour filtering to handle complex environments.
๐Ÿ“ก Expand to multi-line detection for lane tracking.


Contributors

๐Ÿ‘ค Manish Kumar

About

A line detection program using python OpenCV framework. This tracks the black line in the video and also create an Occupancy Grid (to be used in ROS).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages