Skip to content

Hussain004/Line-Following

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Line Following using Canny Edge Detection and Hough Transform

showcase

Overview

This project demonstrates a line following algorithm using computer vision techniques on the DJI Robomaster EP Core robot platform. The robot is equipped with a camera that captures the video feed, which is then processed to detect the presence of lines and determine the appropriate steering angle to follow the line.

Key Features

Color-based Line Detection:

The robot uses Canny edge detection and Hough transform to identify lines in the camera's field of view. Different color masks are applied to detect lines of various colors, such as yellow, red, orange, green, and blue.

PID Controller:

A PID (Proportional-Integral-Derivative) controller is implemented to calculate the angular velocity needed to steer the robot and follow the detected line. The PID coefficients can be adjusted to optimize the robot's responsiveness and stability.

Real-time Visualization:

The processed video frames, including the detected edges and lines, are displayed in real-time using OpenCV's built-in display functions. This allows for visual feedback and debugging during the line following process.

Keyboard Control:

The user can interrupt the line following process by pressing the 'q' key on the keyboard, which will stop the video stream and close the robot connection.

Getting Started

To run this project, you will need the following:
  1. A DJI Robomaster EP Core robot.
  2. Python 3.x installed on your system.
  3. The following Python libraries installed:
    • OpenCV (cv2)
    • NumPy (numpy)
    • Robomaster SDK (robomaster)
    • Keyboard monitoring (keyboard)

Once you have the necessary setup, follow these steps:

  1. Clone the repository containing the project files.
  2. Ensure that the robot is connected to the same network as your computer.
  3. Run the Python script for the desired color line detection (e.g., Yellow.py, Red.py, Orange.py, Green.py, Blue.py).
  4. The robot will start the line following process, and the video feed with the detected lines will be displayed.
  5. Press 'q' on the keyboard to stop the program.

Project Structure

The project consists of the following Python files:
  • Yellow.py
  • Red.py
  • Orange.py
  • Green.py
  • Blue.py

Each file contains the same core functionality, with the only difference being the color mask used for line detection.

Customization

You can customize the project by modifying the following parameters:

PID Controller Coefficients:

Adjust the kp, ki, and kd values in the PIDController class to optimize the robot's line following performance.

Color Mask Range:

Update the lower_* and upper_* values in the color detection section to adjust the range of the color mask.

Canny Edge Detection Thresholds:

Modify the threshold1 and threshold2 values in the edge detection part to improve the line detection accuracy.

Hough Transform Parameters:

Adjust the parameters for the cv2.HoughLinesP() function, such as threshold, minLineLength, and maxLineGap, to fine-tune the line detection.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages