A real-time object detection application using YOLOv3 implemented in C++ with OpenCV. This application can process live camera feeds or video files and detect objects in real-time.
- Real-time object detection using YOLOv3
- Support for both camera input and video file input
- Multi-threaded processing for better performance
- Video recording capability
- Screenshot functionality
- Filter detection by specific object types
- C++11 or higher
- OpenCV 4.x with DNN module
- pthread library
On Ubuntu/Debian:
sudo apt-get update
sudo apt-get install libopencv-dev python3-opencvOn macOS with Homebrew:
brew install opencvOn Windows: Download and install OpenCV from opencv.org
Compile the program with the following command:
g++ main.cpp src/*.cpp -o output -std=c++11 `pkg-config --cflags --libs opencv` -pthreadOr if you're using a Makefile approach:
make./output --camera 0 --label --save_image true./output --camera 0 --label "person" --save_image true- Change camera by changing the number after
--camera(e.g.,--camera 1) - During streaming, press 0/1/2 to switch cameras
./output --video "video_name.extension" --label --save_image true- Press
ESCto stop the program - Press
ato save the current frame as an image - Press
0,1, or2to switch cameras during live streaming
.
├── main.cpp # Main application entry point
├── include/
│ ├── Queue.h # Thread-safe queue implementation
│ ├── ObjectDetector.h # Object detection functionality
│ ├── VideoCapture.h # Video capture functionality
│ ├── VideoWriter.h # Video writing functionality
│ └── Utils.h # Utility functions
├── src/
│ ├── Queue.cpp # Queue implementation
│ ├── ObjectDetector.cpp # Object detection implementation
│ ├── VideoCapture.cpp # Video capture implementation
│ ├── VideoWriter.cpp # Video writing implementation
│ └── Utils.cpp # Utility functions implementation
├── yolov3.cfg # YOLOv3 configuration file
├── yolov3.weights # YOLOv3 pre-trained weights
├── coco.names # COCO dataset class names
└── README.md # This file
- Video Capture: Captures frames from camera or video file
- Object Detection: Processes frames using YOLOv3 neural network
- Post-processing: Applies Non-Maximum Suppression to remove duplicate detections
- Visualization: Draws bounding boxes and labels on detected objects
- Output: Displays results in real-time and optionally saves video/images
yolov3.cfg: YOLOv3 configuration fileyolov3.weights: Pre-trained YOLOv3 weights (download separately)coco.names: Class names for COCO dataset
Download the YOLOv3 weights from here and place them in the project root directory.
If you encounter compilation errors related to OpenCV headers:
- Make sure OpenCV is properly installed
- Try using pkg-config to get the correct flags:
g++ main.cpp src/*.cpp -o output -std=c++11 `pkg-config --cflags --libs opencv4` -pthread
- Ensure the
coco.namesfile is in the working directory - Verify that the model files (
yolov3.cfgandyolov3.weights) are present - Check that camera devices are accessible
This project is licensed under the MIT License - see the LICENSE file for details.
- YOLOv3 implementation based on the original Darknet model
- OpenCV for computer vision capabilities
- COCO dataset for training data