Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YOLOv10 ONNX Detector (C++)

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.

Features

  • 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

Requirements

  • 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 cmake

Model

The 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/

Build

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 ..

Run

# 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.jpg

Model 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.

Project structure

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

Notes / TODO

  • Detection labels currently show only the confidence score; wiring config/classes.txt into the label text (argmax over class scores) is a natural next step.
  • CPU inference only; GPU execution providers are not configured.

About

Real-time object detection in C++ using YOLOv10, ONNX Runtime, and OpenCV.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages