Build OpenCV and OpenVINO for Windows 10 with VS 2022
- Author: lartpang
- Link: https://github.com/lartpang/blog/issues/1
Build OpenCV and OpenVINO for Windows 10 with VS 2022
In this guide, I will build the two powerful open-source libraries, i.e., OpenCV and OpenVINO for running my deeplearning model on windows 10.
Interestingly, both libraries are closely associated with Intel ???.
OpenCV ??
First of all, we must download the related code projects (opencv and opencv_contrib containing some plugins for opencv) into our computer from this links:
Make sure the selected versions of the two libararies are the same.
Here, I choice the latest version 4.7.0.
Because we will recompiling them by ourselves, we can just download the source code zip files.
Put the two unpacked libraries into the same parent folder opencv_dir as follows:
-opencv_dir
-opencv-4.7.0
-...
-opencv_contrib-4.7.0
-modules
-...
NOTE: To avoid the network issue that may be encountered during using CMake, we need to add the url proxy prefix https://ghproxy.com/ before the urls of some setting of the relevant modules like https://ghproxy.com/https://raw.github***:
.cmakeinopencv-4.7.0/3rdparty/ippicv.cmakeinopencv-4.7.0/3rdparty/ffmpegCMakeLists.txtinopencv_contrib-4.7.0/modules/face- Files in
cmakeofopencv_contrib-4.7.0/modules/xfeatures2d CMakeLists.txtinopencv_contrib-4.7.0/modules/wechat_qrcodeCMakeLists.txtinopencv_contrib-4.7.0/modules/cudaoptflow
Next, start compiling OpenCV.
- Create the build folder:
cd opencv_dir && mkdir opencv-build-vs2022 - Configure and generate the VS solution by CMake with some config items:
- General:
- source folder:
<opencv-4.7.0> - build folder:
<opencv-build-vs2022> BUILD_OPENCV_WORLD=ONCMAKE_BUILD_TYPE=RELEASEOPENCV_ENABLE_NONFREE=ONBUILD_opencv_dnn=ONOPENCV_EXTRA_MODULES_PATH=<opencv_contrib-4.7.0/modules>
- source folder:
- CUDA:
WITH_CUDA=ONWITH_CUDNN=ONWITH_CUBLAS=ONWITH_CUFFT=ONCUDA_FAST_MATH=ONCUDA_ARCH_BIN=7.5(We can fill the single value corresponding to the real GPU for accelerating the compilation process.)OPENCV_DNN_CUDA=ON
- Go to the build directory:
cd <opencv-build-vs2022> - Start build by cmake and msvc compiler:
cmake --build . --config Release --verbose -j8 - Install the built opencv into the
installfolder in the current path:cmake --install . --prefix install - Add the
bindirectory into the user environment:<path>\install\x64\vc17\bin - In VS:
- add the
<path>\install\includedirectory into "解決方案資源管理器->右鍵點(diǎn)擊屬性->VC++目錄->外部包含目錄" - add the
<path>\install\x64\vc17\libdirectory into "解決方案資源管理器->右鍵點(diǎn)擊屬性->VC++目錄->庫目錄" - add the
opencv_world470.libinto "解決方案資源管理器->右鍵點(diǎn)擊屬性->鏈接器->輸入->附加依賴項(xiàng)"
- add the
OpenVINO ??
The document of OpenVINO is intuitive and the readability is better than OpenCV.
The relevant content about building and installing the libirary is listed in these links:
- https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/build_windows.md
- https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/cmake_options_for_custom_comiplation.md
- https://github.com/openvinotoolkit/openvino/blob/master/docs/dev/installing.md
After building and install the OpenCV library, it's time to move on to OpenVINO.
- We need clone the project and the sub modules.
git clone https://github.com/openvinotoolkit/openvino.git cd openvino git submodule update --init --recursive - Create the build folder:
mkdir build && cd build - Configure and generate the VS solution by CMake:
ENABLE_INTEL_GPU=OFF(We only use the Intel CPU.)- Disable some frontend items:
ENABLE_OV_PDPD_FRONTEND=OFFENABLE_OV_TF_FRONTEND=OFFENABLE_OV_TF_LITE_FRONTEND=OFFENABLE_OV_PYTORCH_FRONTEND=OFF
- For Python:
ENABLE_PYTHON=ONIt seems thatopenvino-devneeds to be installed first in the detected environment, otherwise a warning message will be thrown in the cmake-gui window.PYTHON_EXECUTABLE=<python.exe>PYTHON_INCLUDE_DIR=<incude directory>PYTHON_LIBIRARY=<pythonxx.lib in libs directory>
- For OpenCV:
ENABLE_OPENCV=ONOpenCV_DIR=<opencv-build-vs2022/install>
- Build the library:
cmake --build . --config Release --verbose -j8 - Install the library into the
installdirectory:cmake --install . --prefix install - Add the
bindirectory into the environment:<path>\install\runtime\bin\intel64\Release<path>\install\runtime\3rdparty\tbb\bin
- In VS:
- add the
<path>\install\runtime\includedirectory into "解決方案資源管理器->右鍵點(diǎn)擊屬性->VC++目錄->外部包含目錄" - add the
<path>\install\runtime\lib\intel64\Releasedirectory into "解決方案資源管理器->右鍵點(diǎn)擊屬性->VC++目錄->庫目錄" - add the ??
openvino.lib, ??openvino_onnx_frontend.lib,openvino_c.libinto "解決方案資源管理器->右鍵點(diǎn)擊屬性->鏈接器->輸入->附加依賴項(xiàng)"
- add the
Set DLL path in IDE
- VS: "right click on solution -> Properties -> Debugging -> Environment ->
PATH=<path>\install\x64\vc17\bin;%PATH%" - Qt Creator: "Projects -> Build & Run -> Build/Run -> Environment -> Details -> Eidt %PATH% -> Add
<path>\install\x64\vc17\bin"

浙公網(wǎng)安備 33010602011771號(hào)