This project implements real-time object detection using YOLOv8 and OpenCV, featuring rotated bounding boxes and real-time dimension measurements. The system can detect objects, calculate their dimensions in centimeters, and provide enhanced visualization with rotation-aware bounding boxes.
- Real-time object detection using YOLOv8
- Rotated bounding box detection
- Dimension measurements in centimeters
- Enhanced image processing for better edge detection
- Confidence threshold filtering
- On-screen display of measurements and confidence scores
- Real-time webcam processing
python >= 3.8
opencv-python
numpy
ultralytics- Clone the repository:
git clone https://github.com/yourusername/object-detection.git
cd object-detection- Install required packages:
pip install opencv-python numpy ultralytics- Download or prepare your YOLOv8 model weights and update the model path in the code.
├── object_detection.py # Main script with all implementations
├── README.md # Project documentation
└── requirements.txt # Project dependencies
rescaleFrame(): Resizes input frames for processingenhance_image(): Enhances image quality using CLAHEget_binary_mask(): Creates binary mask for object segmentationget_accurate_rotated_bbox(): Calculates rotated bounding boxes
pixel_to_cm(): Converts pixel measurements to centimeterscalibrate_focal_length(): Calibrates camera focal lengthprocess_frame(): Main processing pipeline for object detection and measurement
- Update the YOLO model path in main():
model = YOLO('path_to_your_model.pt')- Run the script:
python object_detection.py- Press 'q' to exit the program
For accurate measurements:
- Uncomment the calibration section in main()
- Use a reference object of known dimensions
- Adjust the focal_length_pixels value
- Modify depth_cm parameter based on your setup
For optimal results:
- Ensure good lighting conditions
- Position camera parallel to object plane
- Maintain consistent depth for measurements
- Calibrate system with known reference objects
- Use appropriate confidence thresholds
- Accuracy depends on camera calibration
- Fixed depth assumption (100cm default)
- Requires consistent lighting
- Performance depends on hardware capabilities
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
- YOLO by Ultralytics
- OpenCV community
- NumPy developers
For questions or feedback, please open an issue in the repository.