Skip to content

Vehicle speed estimation using the optical flow algorithm from a mono camera(CCTV)

Notifications You must be signed in to change notification settings

swhan0329/vehicle_speed_estimation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vehicle Speed Estimation

Overview

This project uses the optical flow algorithm, specifically the Lucas-Kanade tracker, to estimate vehicle speeds from mono camera (CCTV) footage.

Prerequisites

  • Python 3.x
  • Required libraries: opencv-python, numpy

Setup

  1. Clone the Repository

    git clone https://github.com/swhan0329/vehicle_speed_estimation.git
    cd vehicle_speed_estimation
  2. Install Dependencies

    pip install -r requirements.txt

Usage

  1. With an Input Video

    python main.py [input video name]

    Replace [input video name] with the path to your video file.

  2. Without an Input Video The script will automatically use the webcam on your computer.

    python main.py
  3. Additional Options

    python main.py [input video name] --output output.mp4 --show

File Descriptions

  • main.py: The main script to run the vehicle speed estimation.
  • video.py: Contains functions to handle video input and processing.
  • common.py: Includes common functions and utilities used across the project.
  • tst_scene_render.py: Test and render scenes for visualization.

Example

To run the speed estimation on a sample video:

python main.py sample_video.mp4

To use the webcam for live speed estimation:

python main.py

Additional Notes

  • Ensure that your video has a clear view of the road and vehicles for accurate speed estimation.
  • Adjust parameters in common.py if needed to fit specific requirements or to improve performance.
  • The road-region settings are hardcoded for a specific camera view in main.py:
    • view_polygon
    • cal_polygon
    • polygon1 ~ polygon5 (lane areas)
  • These coordinates must be re-collected and re-tuned manually for each new road/camera angle/resolution.
    If not updated, lane assignment and speed estimates can be incorrect.
  • Pixel-to-meter scale values are also hardcoded (px2m1 ~ px2m5) and should be recalibrated per camera setup.

Running Tests

Execute the unit tests with Python's built-in test runner:

python -m unittest discover -s tests

About

Vehicle speed estimation using the optical flow algorithm from a mono camera(CCTV)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages