![]() |
OpenCV 5.1.0-dev
Open Source Computer Vision
|
| Original authors | Abhishek Gola & Kirti Jindal |
| Compatibility | OpenCV >= 5.0, C++17, Python >= 3.6 |
The objective of this tutorial is to show how to configure a local build environment to use pre-built OpenCV 5.0 binaries that are already present on your device.
By the end of this guide you will know how to reference, link, and use an existing OpenCV installation from your own C++ or Python application, without rebuilding the library from source.
When OpenCV is installed via an installer, a system package manager (apt, Homebrew, vcpkg), or built into a local workspace directory, it exports configuration scripts that let build tools locate and link it automatically.
Because OpenCV 5.0 modernizes its build requirements, keep two things in mind:
${OpenCV_LIBS} variable from find_package(OpenCV), or by naming the specific libraries on the compiler command line.You can link against your pre-built binaries with CMake (recommended for cross-platform stability) or by invoking g++ directly.
On Linux or macOS you can compile with a single command, without generating build files.
/usr/local/include/opencv5 and /usr/local/lib/path/to/opencv/build/include and /path/to/opencv/build/libcalib3d module was split into four modules: geometry, calib, stereo, and ptcloud. Link the specific one(s) you need, e.g. -lopencv_geometry, -lopencv_calib, -lopencv_stereo, or -lopencv_ptcloud, instead of -lopencv_calib3d.If your device already has the pre-compiled Python bindings (cv2), you can use them directly.
If you are using a local or custom build, ensure your system can locate the generated cv2 binary by setting the PYTHONPATH environment variable:
/path/to/opencv/build/lib with the actual path to the directory containing your compiled cv2 module (usually inside your local build/lib or build/lib/python3 folder).Once the path is set, run the following command to verify that the module imports cleanly and prints the correct version:
Write a short app.py that imports cv2, loads an image, and displays it to confirm the bindings work.
cmake -DOpenCV_DIR=/path/to/opencv/build/ ..-std=c++17 to the g++ command, or set(CMAKE_CXX_STANDARD 17) before find_package in CMake.