A handy tool for calibrating perspective transformation points, specifically designed for use with vehicle speed estimation using Roboflow Supervision.
I would recommend watching this great tutorial video from Roboflow. Our tool helps you calculate the transformation and set the coordinates s required for perspective transformation in speed estimation projects. It's particularly useful for the speed estimation example from Roboflow - and maybe for similar tasks using other tools.
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install requirements
pip install -r requirements.txt
- Run with a video or image:
python perspective_calibrator.py --video your_video.mp4
# OR
python perspective_calibrator.py --image your_image.jpg
-
Click to place 4 points in this order:
- Top left
- Top right (same distance from camera as top left)
- Bottom right
- Bottom left (same distance from camera as bottom right)
-
Use keyboard controls:
r
- Reset pointsp
- Preview transformations
- Save points to 'source_points.npy'q
- Quit
The tool will output the coordinates in the format needed for the speed estimation example:
SOURCE = np.array([
[x1, y1], # Top left
[x2, y2], # Top right
[x3, y3], # Bottom right
[x4, y4] # Bottom left
])
The speed estimation example uses perspective transformation to convert video footage into a birds-eye view for accurate speed calculations. Getting these SOURCE points right is crucial for accurate speed measurements.
Instead of manually trying coordinates, this tool lets you:
- Visually select points
- See the transformation in real-time
- Get properly formatted points for the speed estimation code
- Python 3.8+
- OpenCV >= 4.8.0
- NumPy >= 1.24.0
MIT License