Advanced level · Module 10: Edge Computer Vision · Lesson 3 of 4
Optional: C++ Inference for Performance
An optional lesson for learners with C++ experience: running the same ONNX model with the ONNX Runtime C++ API and OpenCV C++, and measuring whether the speed gain justifies the extra complexity.
In this lesson you will
- Run an ONNX model from C++
- Judge when C++ is worth the effort
Key concepts
ONNX Runtime C++ APIOpenCV C++ (cv::Mat)build with CMakePython overheadmaintainability trade-off
The lesson
Python is the primary language of this programme. In most vision pipelines, the heavy work already runs in optimised C++ inside OpenCV and ONNX Runtime, so rewriting the surrounding code in C++ often gains little.
Where per-frame Python overhead matters (very high frame rates, very weak devices), the same ONNX model can be run with the ONNX Runtime C++ API, with OpenCV C++ (cv::Mat) for image handling and CMake for building. Rescue Academy's C++ programme covers the language itself.
Measure end-to-end frame rates in both versions. Choose C++ only if the gain is significant for the application and the team can maintain it.
Step by step
- Build a minimal C++ program that loads the ONNX model and processes one image.
- Process a video in C++ and in Python.
- Compare frames per second.
- Write a recommendation including maintenance cost.
Practice activity
Optional: compare Python and C++ inference speed and write a recommendation.
Expected result: A measured comparison and a realistic recommendation.
Check your understanding
-
Why does rewriting in C++ often gain little?
Show answer
The heavy computation already runs in optimised C++ inside the libraries.
-
What besides speed should decide the choice of C++?
Show answer
Whether the team can build and maintain it.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.