From 6b9c865827610af547b952a7f82b8a8eb85cb10d Mon Sep 17 00:00:00 2001 From: Aleksandr Voron Date: Tue, 2 Aug 2022 15:28:25 +0200 Subject: [PATCH] Created BuildOpenCV4OpenVINO (markdown) --- BuildOpenCV4OpenVINO.md | 136 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 BuildOpenCV4OpenVINO.md diff --git a/BuildOpenCV4OpenVINO.md b/BuildOpenCV4OpenVINO.md new file mode 100644 index 0000000..637945a --- /dev/null +++ b/BuildOpenCV4OpenVINO.md @@ -0,0 +1,136 @@ +# Build OpenCV for OpenVINO + +OpenVINO does not provide custom OpenCV drop since 2022.1.1 release. +If OpenVINO user needs OpenCV functionality there are 2 approaches how to get it: +1. Get OpenCV from another sources (system repositories, pip, conda, homebrew). It is easy to follow this approach, however it has several disadvantages: + * OpenCV version is out-of-date + * OpenCV does not contain G-API module (e.g. some OMZ demos use G-API functionality) + * OpenCV does not use available CPU instructions since it has build to cover wide range of hardware + * OpenCV does not support Intel TBB, Intel Media SDK + * OpenCV DNN module can not use OpenVINO as computational backend +2. Compile OpenCV from source code. This approach solves the issues mentioned above. + +The instruction below shows how to build OpenCV for OpenVINO. + +## Ubuntu + +1. Install OpenVINO according to the [instruction](https://docs.openvino.ai/latest/openvino_docs_install_guides_installing_openvino_linux.html) +2. Copy OpenCV repository: +> git clone --recurse-submodules https://github.com/opencv/opencv.git +3. Install the following packages: +> sudo apt-get install \\\ +build-essential \\\ +cmake \\\ +ninja-build \\\ +libgtk-3-dev \\\ +libpng-dev \\\ +libjpeg-dev \\\ +libwebp-dev \\\ +libtiff5-dev \\\ +libopenexr-dev \\\ +libopenblas-dev \\\ +libx11-dev \\\ +libavutil-dev \\\ +libavcodec-dev \\\ +libavformat-dev \\\ +libswscale-dev \\\ +libavresample-devlibavutil-dev \\\ +libavcodec-dev \\\ +libavformat-dev \\\ +libswscale-dev \\\ +libavresample-dev \\\ +ffmpeg-dev \\\ +libtbb2 \\\ +libssl-dev \\\ +libva-dev \\\ +libmfx-dev \\\ +libgstreamer1.0-dev \\\ +libgstreamer-plugins-base1.0-dev +4. Create build directory and enter into it: +> mkdir ~/build-opencv && cd ~/build-opencv +5. Compile OpenCV: +> cmake -G Ninja \\\ +-D BUILD_INFO_SKIP_EXTRA_MODULES=ON \\\ +-D BUILD_EXAMPLES=OFF \\\ +-D BUILD_JASPER=OFF \\\ +-D BUILD_JAVA=OFF \\\ +-D BUILD_JPEG=ON \\\ +-D BUILD_APPS_LIST=version \\\ +-D BUILD_opencv_apps=ON \\\ +-D BUILD_opencv_java=OFF \\\ +-D BUILD_OPENEXR=OFF \\\ +-D BUILD_PNG=ON \\\ +-D BUILD_TBB=OFF \\\ +-D BUILD_WEBP=OFF \\\ +-D BUILD_ZLIB=ON \\\ +-D WITH_1394=OFF \\\ +-D WITH_CUDA=OFF \\\ +-D WITH_EIGEN=OFF \\\ +-D WITH_GPHOTO2=OFF \\\ +-D WITH_GSTREAMER=ON \\\ +-D OPENCV_GAPI_GSTREAMER=OFF \\\ +-D WITH_GTK_2_X=OFF \\\ +-D WITH_IPP=ON \\\ +-D WITH_JASPER=OFF \\\ +-D WITH_LAPACK=OFF \\\ +-D WITH_MATLAB=OFF \\\ +-D WITH_MFX=ON \\\ +-D WITH_OPENCLAMDBLAS=OFF \\\ +-D WITH_OPENCLAMDFFT=OFF \\\ +-D WITH_OPENEXR=OFF \\\ +-D WITH_OPENJPEG=OFF \\\ +-D WITH_QUIRC=OFF \\\ +-D WITH_TBB=OFF \\\ +-D WITH_TIFF=OFF \\\ +-D WITH_VTK=OFF \\\ +-D WITH_WEBP=OFF \\\ +-D CMAKE_USE_RELATIVE_PATHS=ON \\\ +-D CMAKE_SKIP_INSTALL_RPATH=ON \\\ +-D ENABLE_BUILD_HARDENING=ON \\\ +-D ENABLE_CONFIG_VERIFICATION=ON \\\ +-D ENABLE_PRECOMPILED_HEADERS=OFF \\\ +-D ENABLE_CXX11=ON \\\ +-D INSTALL_PDB=ON \\\ +-D INSTALL_TESTS=ON \\\ +-D INSTALL_C_EXAMPLES=ON \\\ +-D INSTALL_PYTHON_EXAMPLES=ON \\\ +-D CMAKE_INSTALL_PREFIX=install \\\ +-D OPENCV_SKIP_PKGCONFIG_GENERATION=ON \\\ +-D OPENCV_SKIP_PYTHON_LOADER=OFF \\\ +-D OPENCV_SKIP_CMAKE_ROOT_CONFIG=ON \\\ +-D OPENCV_GENERATE_SETUPVARS=OFF \\\ +-D OPENCV_BIN_INSTALL_PATH=bin \\\ +-D OPENCV_INCLUDE_INSTALL_PATH=include \\\ +-D OPENCV_LIB_INSTALL_PATH=lib \\\ +-D OPENCV_CONFIG_INSTALL_PATH=cmake \\\ +-D OPENCV_3P_LIB_INSTALL_PATH=3rdparty \\\ +-D OPENCV_SAMPLES_SRC_INSTALL_PATH=samples \\\ +-D OPENCV_DOC_INSTALL_PATH=doc \\\ +-D OPENCV_OTHER_INSTALL_PATH=etc \\\ +-D OPENCV_LICENSES_INSTALL_PATH=etc/licenses \\\ +-D OPENCV_INSTALL_FFMPEG_DOWNLOAD_SCRIPT=ON \\\ +-D BUILD_opencv_world=OFF \\\ +-D BUILD_opencv_python2=OFF \\\ +-D BUILD_opencv_python3=ON \\\ +-D PYTHON3_PACKAGES_PATH=install/python/python3 \\\ +-D PYTHON3_LIMITED_API=ON \\\ +-D HIGHGUI_PLUGIN_LIST=all \\\ +-D OPENCV_PYTHON_INSTALL_PATH=python \\\ +-D CPU_BASELINE=SSE2 \\\ +-D OPENCV_IPP_GAUSSIAN_BLUR=ON \\\ +-D WITH_INF_ENGINE=ON \\\ +-D InferenceEngine_DIR=/runtime/cmake/ \\\ +-D ngraph_DIR=/runtime/cmake/ \\\ +-D INF_ENGINE_RELEASE=2022010000 \\\ +-D VIDEOIO_PLUGIN_LIST=ffmpeg,gstreamer,mfx \\\ +-D CMAKE_EXE_LINKER_FLAGS=-Wl,--allow-shlib-undefined \\\ +-D CMAKE_BUILD_TYPE=Release && \\\ +ninja + +OpenCV package is available at ~/build-opencv directory. +To compile application that uses OpenCV, the following environment variables should be specified: +> export OpenCV_DIR="\~/build-opencv/cmake" \ +> export LD_LIBRARY_PATH="\~/build-opencv/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \ +> export PYTHONPATH="~/build-opencv/python_loader${PYTHONPATH:+:$PYTHONPATH}" + +