Skip to content

Latest commit

 

History

History
75 lines (49 loc) · 2.77 KB

File metadata and controls

75 lines (49 loc) · 2.77 KB

Hello everyone, This repository contains the source code of a script designed to detect cars in video or camera frames and draw rectangular boxes around them.

The ML algorithms used for detecting cars and bounding boxes coordinates is a pretrained cascade model Haarcascade car.

Become a patron

Where is the full article ?

The full article for this project is originally published on my blog with an article with title Real-time vehicle detection in python

Getting started

To begin, we need to clone the project repository or download the project's zip file and extract it.

git clone https://github.com/Kalebu/Real-time-Vehicle-Dection-Python
cd Real-time-Vehicle-Dection-Python
Real-time-Vehicle-Dection-Python ->

Dependencies

Now that we have the project repository in our local directory, let's proceed to install the dependencies required to run our script.

pip install opencv-python

Sample video

The sample video we used in this project is cars.mp4 which will come as you download or clone the repository. If you want to use a different video with a different filename, you may need to make some changes to the source code accordingly.

def Simulator():
    CarVideo = cv2.VideoCapture('cars.mp4') # change cars.mp4 to name of your vidoe
    while CarVideo.isOpened():
        ret, frame = CarVideo.read()
        controlkey = cv2.waitKey(1)
        if ret:        
            cars_frame = detect_cars(frame)
            cv2.imshow('frame', cars_frame)
        else:
            break
        if controlkey == ord('q'):
            break

    CarVideo.release()
    cv2.destroyAllWindows()

running our script

Now you can launch your scripts;

python app.py 

If you use the provided sample video, the output of the script will resemble the image depicted below:;

drawing

Issues ?

If you encounter any issues while running the script, please feel free to raise an issue on the project repository. I will promptly address the problem and provide a solution as soon as possible. Your feedback is valuable, and I am committed to ensuring a smooth experience.

Credits

  1. All the credits to kalebu
  2. Others