-
Notifications
You must be signed in to change notification settings - Fork 0
dist_calc.py
dist_calc.py - estimate the distance between two bounding boxes selected successively by the user
python dist_calc.py
This Python script performs the following steps:
- Imports the Ultralytics solutions and the OpenCV packages
- Defines the video source and recording data
- Processes each frame from the video source
- Uses the method in the solutions package to estimate the distance between the centroids of the bounding boxes
Click on any two bounding boxes with Left Mouse click for distance calculation
A list of all environment variables that affect the program or function and how they affect it.
A list of the files the program or function uses, such as configuration files, startup files, and files the program directly operates on.
A description of any standards or conventions that relate to the function or command. Commonly just a list of standards.
Adapted from the Ultralytics website.
- Mouse left-click will draw points between successive selections
- Mouse right-click will delete all drawn points
A FourCC code is a 4-byte code used to specify the video codec. It's a crucial parameter when initializing a VideoWriter object in OpenCV.
- Codec Selection: The FourCC code determines the codec used to compress and encode the video frames.
- Compatibility: Different codecs have varying levels of compression, quality, and compatibility with different video players and devices.
VideoWriter_fourcc(char c1, char c2, char c3, char c4)
c1, c2, c3, c4
: The four characters that form the FourCC code
#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
// Create a VideoWriter object with MJPEG codec
VideoWriter video("output.avi", VideoWriter::fourcc('M', 'J', 'P', 'G'), 30, Size(640, 480));
// ... (rest of your code)
}
- MJPG: Motion JPEG, a lossy codec that is widely supported
- XVID: MPEG-4 codec, offering good compression and quality
- DIVX: Another MPEG-4 codec, known for its high compression ratio
- H264: A high-efficiency video coding standard, offering excellent compression and quality
- FFMPEG: A versatile codec that supports a wide range of formats
The best codec for your application depends on several factors, including:
- Desired Video Quality: Higher quality often requires larger file sizes.
- Required Compression Ratio: A higher compression ratio results in smaller file sizes, but may impact quality
- Compatibility: Ensure the chosen codec is supported by your target devices and platforms
- Real-time Requirements: Some codecs are more computationally intensive than others
Since the bounding boxes are limited to 2D space, this method cannot calculate the accurate distance between the detected objects owing to the absence of data in the third dimension real-world space.
- Localization Precision: Enhances accurate spatial positioning in computer vision tasks
- Size Estimation: Allows estimation of object size for better contextual understanding
- Scene Understanding: Enhances 3D scene comprehension, aiding improved decision-making in applications like autonomous driving and surveillance.
Name | Type | Default | Description |
---|---|---|---|
model | str | None | Path to Ultralytics YOLO Model File |
line_width | int | 2 | Line thickness for bounding boxes |
show | bool | False | Flag to control whether to display the video stream |
n/a
n/a
$ python dist_calc.py
armw
Model Prediction with Ultralytics YOLO
A description of the command-line options accepted by a program and how they change its behavior.
This script uses a recorded video file. If a real-time video source is used then minor modifications to the script will be necessary to permit a graceful exit from processing.
- Python package:
- Ultralytics - solutions
- Python interpreter - 3.11 or later
The scrpt will not proceed to the calculation of the distance if the input video source file is inaccessible.
There are no explicit versions of this script. The repository contains trackable commits, pushes and merges.
Keep on learning!