This project uses a YOLOv8 segmentation model to estimate the distance of objects (persons and monitors) from a CCTV camera in real-time.
- Object detection and segmentation: Detects and segments persons and monitors in CCTV footage using YOLOv8.
- Distance estimation: Calculates the distance of detected objects from the camera using the perceived width and known width of the objects.
- Real-time processing: Processes the CCTV stream in real-time to provide continuous distance estimations.
- Visualization: Displays the video feed with bounding boxes around detected objects and their estimated distances.
- Python 3.8 or higher
- ultralytics
- opencv-python
- numpy
- Clone the repository:
git clone https://github.com/omukesh/yolov8_distance_calculator
- Install dependencies:
pip install -r requirements.txt
- CCTV URL:
- Create a file named
config.py
in the project directory. - Add your CCTV URL to
config.py
:CCTV_URL = "your_cctv_url"
- Create a file named
- Focal Length Calibration:
- Run the
calculate_focal_length
method indistance_calculator.py
. - Place a known-sized object at a known distance from the camera.
- Measure the pixel width of the object in the captured frame.
- Update the
calculate_focal_length
method with the measured pixel width and known values.
- Run the
- Run the application:
python yolo_distance.py
- The application will open a window displaying the CCTV footage with bounding boxes and distance estimations.
- Press 'q' to exit the application.
- Ensure the class IDs for "Person" and "Monitor" are correct for your YOLOv8 model.
- Adjust the
known_width
value indistance_calculator.py
if necessary. - Accurate focal length calibration is crucial for accurate distance estimation.
- Performance may vary depending on hardware and scene complexity.
Contributions are welcome! Feel free to open issues or submit pull requests.
This project is done for educational and research purpose.