Important Notes
- Installing CMake serves two main purposes: compiling OpenCV and building your own projects.
- While project compilation has no strict version requirements, compiling OpenCV does. Using incompatible versions may cause errors.
- The version number provided here is a reference based on project compatibility.
cmake version 3.15.7
Download Link. Select version cmake-3.15.7-win64-x64.msi. After downloading, run the installer and note the installation path.
Notes
- Other versions on the same page are also acceptable.
Important Notes
- While CUDA is likely already installed, note that installing CUDA before Visual Studio may cause compilation failures in VS Code.
- CUDA libraries for Windows C++ programs require
cl.exe(the Visual Studio compiler). The VS compiler version must match CUDA's requirements. - CUDA 11.6 requires VS2019, whose official standalone installer is no longer available.
- Installing CUDA after VS may cause unrecognized library errors.
Download via link. During installation, select components as shown below:
- Follow standard tutorials. During CUDA installation, choose Custom Installation and select all available options (except pre-installed drivers).
- After installation, verify that
~\binand~\libpaths are added to system environment variables.
Notes
- Selecting all options ensures necessary compute libraries are included.
bincontains precompiled binaries – missing PATH entries cause runtime errors (e.g., "missing xx file").libcontains dynamic libraries – missing PATH entries cause linking errors during execution.- OpenCV and TensorRT have similar dependencies.
Important Notes
- OpenCV offers precompiled binaries or self-compiled versions. Precompiled versions (e.g.,
opencv_world) are simpler but lack CUDA acceleration. - This guide focuses on compiling OpenCV with CUDA support.
- Successful compilation requires zero errors; otherwise, the
installstep will fail.
- Download from official site. Select version 4.5.5 and choose
Sources.
- Launch
C:\Program Files\CMake\bin\cmake-gui.exe. - Configure as shown below:
- Source code path (OpenCV folder).
- Build directory (new empty folder).
- Specify generator: Visual Studio 2019.
- Click
Configure→Generate.
Why Reconfigure?
- Initial configuration often fails due to missing dependencies.
- CUDA acceleration requires the
opencv_contribmodule.
- Python mismatch: Disable Python-related options by searching
PYTHONin CMake and unchecking all entries. - Download failures: Manually download missing 3rd-party libraries:
- Visit OpenCV 3rdparty.
- Locate the cache folder (e.g.,
C:\opencv_s\opencv-4.5.5\.cache\ffmpeg). - Download the required branch (e.g.,
ffmpeg/src), rename files to match cache hashes, and replace them.
- Search
CUDAand enable all CUDA-related options. - Download opencv_contrib 4.5.5.
- Set
OPENCV_EXTRA_MODULES_PATHto the extractedopencv_contrib/modulespath. - Disable unused modules (e.g.,
wechat_qrcode,xfeatures2d) if they cause errors.
- Re-run
Configure→Generate. Resolve any remaining errors. - Ensure no red entries appear before proceeding.
- Click
Open Projectin CMake to launch VS2019. - Navigate to Build → Batch Build. Check
INSTALLunderDebugorRelease. - Compilation takes ~4 hours.
- If minor errors occur, manually deselect problematic modules. After successful build:
- Add
~\install\x64\vc16\binand~\install\x64\vc16\libto system PATH.
- Add
Download version TensorRT-10.12.0.36 from the official site. Extract the package, then add ~\TensorRT-10.12.0.36\bin and ~\TensorRT-10.12.0.36\lib to system PATH.
- Download libtorch-win-shared-with-deps-1.13.0+cu116.zip from this link.
- Extract the package, then add
binandlibfolders to system PATH.



