A native C++ object detector that runs a YOLOv10 model with ONNX Runtime and OpenCV. It loads an image, runs inference on the CPU, draws the detected bounding boxes, and shows the annotated result in a window.
- YOLOv10 inference via ONNX Runtime C++ API
- Letterbox preprocessing (aspect-ratio-preserving resize + padding)
- HWC → CHW tensor conversion and
[0,1]normalization - Confidence-threshold filtering and bounding-box rendering with OpenCV
- CMake ≥ 3.20 and a C++17 compiler
- OpenCV (
core,imgproc,imgcodecs,highgui,dnn) - ONNX Runtime
- A YOLOv10 model exported to ONNX
On macOS with Homebrew:
brew install opencv onnxruntime cmakeThe ONNX model is not committed to the repo (weights are large and excluded via .gitignore). Export one with Ultralytics and drop it into models/:
pip install ultralytics
yolo export model=yolov10m.pt format=onnx
mkdir -p models && mv yolov10m.onnx models/mkdir -p build && cd build
cmake ..
cmake --build .If ONNX Runtime is installed somewhere other than the Homebrew default, override the paths:
cmake -DONNXRUNTIME_INCLUDE_DIR=/your/include \
-DONNXRUNTIME_LIB=/your/lib/libonnxruntime.dylib ..# From the project root:
./build/yolo_detector [model.onnx] [image]
# Examples
./build/yolo_detector # models/yolov10m.onnx + assets/test.jpeg
./build/yolo_detector models/yolov10m.onnx dog.jpgModel and image paths are read from the command line (with the defaults above), so the project is portable — no absolute paths baked into the source.
yolo10proj/
├── CMakeLists.txt # OpenCV + ONNX Runtime build config
├── src/main.cpp # detector class + entry point
├── config/classes.txt # COCO class names
├── models/ # place your .onnx model here (gitignored)
└── assets/ # sample images
- Detection labels currently show only the confidence score; wiring
config/classes.txtinto the label text (argmax over class scores) is a natural next step. - CPU inference only; GPU execution providers are not configured.