Back to Ultralytics

Shared Helpers for the Inference in C++

examples/cpp/common/README.md

8.4.711.9 KB
Original Source

Shared Helpers for the Inference in C++

Header-only utilities shared across the Ultralytics YOLO C++ examples. They have no dependencies beyond OpenCV and the C++ standard library, so an example can use them by adding this folder to its include path:

cmake
target_include_directories(your_target PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../common)
HeaderProvides
yolo_types.hppyolo::Task (the task enum) and yolo::Result (the unified per-detection result: box, mask, keypoints, angle).
yolo_cli.hppCommand-line helpers yolo::ArgValue, yolo::HasFlag, and yolo::NameOf used by every example main.
yolo_postprocess.hppBackend-agnostic pre/post-processing Preprocess, ToBlob, InferTask, and the per-task Postprocess*.
yolo_draw.hppAnnotation matching the Python Annotator Color, Label, DrawBox, DrawMask, DrawPose, DrawObb, DrawSemantic.
yolo_render.hppyolo::RenderAndPrint, the shared per-task draw and console-print path used by every example main.
yolo_show.hppyolo::ShowRequested/yolo::Show optional display window controlled by --show.
coco_names.hppyolo::CocoNames() the 80 COCO class names, a fallback for models without baked-in names metadata.

Models exported by Ultralytics embed their class names (and imgsz, task, stride) in the model metadata, so prefer reading names from the model directly and use coco_names.hpp only as a fallback.