Back to Ultralytics

Ultralytics YOLO OpenVINO Inference in C++

examples/cpp/OpenVINO/README.md

8.4.714.6 KB
Original Source

Ultralytics YOLO OpenVINO Inference in C++

A single C++ application that runs every Ultralytics YOLO task and model generation with the Intel OpenVINO™ toolkit and OpenCV. Point it at an OpenVINO IR (.xml) or an .onnx file — the program reads the class names from the model and picks the right post-processing automatically.

✨ Features

  • All tasks: detect, segment, pose, OBB, classify, and YOLO26 semantic segmentation.
  • All generations: YOLOv8, YOLO11, and YOLO26. Grid (YOLOv8/11) and end-to-end (YOLO26) outputs are detected automatically from the tensor shape.
  • Two formats: OpenVINO IR (.xml/.bin) and ONNX — the OpenVINO runtime reads both.
  • Automatic task detection: the IR carries no task field, so the task is inferred from the output shapes and class-label count. Class names come from the IR rt_info (labels); models without that metadata fall back to the 80 COCO names in ../common.
  • Shared post-processing: the parsing/NMS/mask/keypoint/semantic logic is the same common/yolo_postprocess.hpp used by the other examples.

📋 Dependencies

DependencyVersion
OpenVINO>=2023.3
OpenCV>=4.5.0
C++>=17
CMake>=3.12.0

📦 Exporting a Model

bash
yolo export model=yolo26n.pt imgsz=640 format=openvino # detect IR  (also -seg / -pose / -obb / -cls / -sem)
yolo export model=yolo26n.pt imgsz=640 format=onnx     # or ONNX, read directly by OpenVINO

YOLOv8 and YOLO11 grid models work too — the output layout is detected automatically.

See the Export documentation. The OpenVINO export produces a *_openvino_model/ directory containing the .xml, .bin, and metadata.

🛠️ Build

bash
git clone https://github.com/ultralytics/ultralytics.git
cd ultralytics/examples/cpp/OpenVINO
mkdir build && cd build
cmake .. && cmake --build . --config Release

OpenVINO is found via find_package(OpenVINO) and the shared helpers in ../common are added to the include path automatically.

🚀 Usage

bash
# Defaults: --model yolo26n.onnx --source bus.jpg --conf 0.25 --iou 0.45 --device AUTO --out result.jpg
./yolo_openvino --model yolo26n_openvino_model/yolo26n.xml --source bus.jpg
./yolo_openvino --model yolo26n-seg.onnx --source bus.jpg --out seg.jpg
./yolo_openvino --model yolo26n-pose.onnx --source bus.jpg --show
ArgumentDefaultDescription
--modelyolo26n.onnxOpenVINO IR (.xml) or ONNX (.onnx) model.
--sourcebus.jpgInput image.
--conf0.25Confidence threshold.
--iou0.45NMS IoU threshold (grid models only).
--deviceAUTOOpenVINO device: AUTO, CPU, or GPU.
--outresult.jpgOutput image path.
--showoffAlso open a display window.

The annotated result is always written to --out and the detections are printed to the console. The detected task is shown at startup, e.g. Model: yolo26n.xml | task: detect | classes: 80.

🤝 Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the main Ultralytics repository.