{"id":14977700,"url":"https://github.com/banderlog/opencv-python-inference-engine","last_synced_at":"2025-10-28T05:30:57.050Z","repository":{"id":38238418,"uuid":"174980558","full_name":"banderlog/opencv-python-inference-engine","owner":"banderlog","description":"Wrapper package for OpenCV with Inference Engine python bindings.","archived":false,"fork":false,"pushed_at":"2023-01-04T11:19:06.000Z","size":16532,"stargazers_count":33,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-24T08:28:04.605Z","etag":null,"topics":["dldt","inference-engine","movidius","myriad","openblas","opencv","opencv-python","openvino","precompiled","python","python-3","wheel","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/banderlog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-11T10:50:13.000Z","updated_at":"2022-09-19T13:21:42.000Z","dependencies_parsed_at":"2023-02-02T10:01:19.666Z","dependency_job_id":null,"html_url":"https://github.com/banderlog/opencv-python-inference-engine","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banderlog%2Fopencv-python-inference-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banderlog%2Fopencv-python-inference-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banderlog%2Fopencv-python-inference-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banderlog%2Fopencv-python-inference-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/banderlog","download_url":"https://codeload.github.com/banderlog/opencv-python-inference-engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238603665,"owners_count":19499488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dldt","inference-engine","movidius","myriad","openblas","opencv","opencv-python","openvino","precompiled","python","python-3","wheel","wrapper"],"created_at":"2024-09-24T13:56:09.924Z","updated_at":"2025-10-28T05:30:56.567Z","avatar_url":"https://github.com/banderlog.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Downloads](https://pepy.tech/badge/opencv-python-inference-engine)](https://pepy.tech/project/opencv-python-inference-engine) [![Downloads](https://pepy.tech/badge/opencv-python-inference-engine/month)](https://pepy.tech/project/opencv-python-inference-engine/month) [![Downloads](https://pepy.tech/badge/opencv-python-inference-engine/week)](https://pepy.tech/project/opencv-python-inference-engine/week)\n\n# opencv-python-inference-engine\n\n---\n\n$${\\color{red}It \\space is \\space deprecated \\space now, \\space all \\space future \\space updates \\space are \\space improbable}$$\n\nA lot has changed during my military leave:\n\n1. Everything [changed since OpenVINO 2021.1](https://github.com/openvinotoolkit/openvino/releases/tag/2022.1.0), now there should be [two separate libs](https://opencv.org/how-to-use-opencv-with-openvino/), building process and inference engine API have changed dramatically, *without backwards compatibility* (btw, opencv-python now *official* python builds).\n2. Now opencv has [small package installations via pip](https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/download.html), so the main reason for creating that package is gone.\n3. Just [look at the current official way](https://github.com/banderlog/opencv-python-inference-engine/tree/dev/create_wheel/cv2) of importing cv2 cxx lib into the python module via 5 python scripts -- I do not want to mess with this growing lump of crutches\n\nMy advice is to use openvino and opencv-python packages, see rewritten examples in [`tests_openvino`](https://github.com/banderlog/opencv-python-inference-engine/tree/master/tests_openvino)\n\n---\n\nThis is *Unofficial* pre-built OpenCV with the inference engine part of [OpenVINO](https://github.com/openvinotoolkit/openvino) package for Python.\n\n## Installing from `pip3`\n\nRemove previously installed versions of `cv2`\n\n```bash\npip3 install opencv-python-inference-engine\n```\n\n## Examples of usage\n\nPlease see the `examples.ipynb` in the `tests` folder.\n\nYou will need to preprocess data as a model requires and decode the output. A description of the decoding *should* be in the model documentation with examples in open-vino documentation, however, in some cases, the original article may be the only information source. Some models are very simple to encode/decode, others are tough (e.g., PixelLink in tests).\n\n\n## Downloading intel models\n\nThe official way is awkward because you need to git clone the whole [model_zoo](https://github.com/opencv/open_model_zoo) ([details](https://github.com/opencv/open_model_zoo/issues/522))\n\nBetter to find a model description [here](https://github.com/opencv/open_model_zoo/blob/master/models/intel/index.md) and download manually from [here](https://download.01.org/opencv/2021/openvinotoolkit/2021.2/open_model_zoo/models_bin/3/)\n\n\n## Description\n\n\n### Why\n\nI needed an ability to fast deploy a small package that able to run models from [Intel's model zoo](https://github.com/openvinotoolkit/open_model_zoo) and use [Movidius NCS](https://software.intel.com/en-us/neural-compute-stick).\nWell-known [opencv-python](https://github.com/skvark/opencv-python) can't do this.\nThe official way is to use OpenVINO, but it is big and clumsy (just try to use it with python venv or fast download it on cloud instance).\n\n\n### Limitations\n\n+ Package comes without contrib modules.\n+ You need to [add udev rules](https://www.intel.com/content/www/us/en/support/articles/000057005/boards-and-kits.html) if you want working MYRIAD plugin.\n+ It was tested on Ubuntu 18.04, Ubuntu 18.10 as Windows 10 Subsystem and Gentoo.\n+ It will not work for Ubuntu 16.04 and below (except v4.1.0.4).\n+ I had not made builds for Windows or MacOS.\n+ It built with `ffmpeg` and `v4l` support (`ffmpeg` libs included).\n+ No GTK/QT support -- use `matplotlib` for plotting your results.\n+ It is 64 bit.\n\n### Main differences from `opencv-python-headless`\n\n+ Usage of `AVX2` instructions\n+ No `JPEG 2000`, `WEBP`, `OpenEXR` support\n+ `TBB` used as a parallel framework\n+ Inference Engine with `MYRIAD` plugin\n\n### Main differences from OpenVINO\n\n+ No model-optimizer\n+ No [ITT](https://software.intel.com/en-us/articles/intel-itt-api-open-source)\n+ No [IPP](https://software.intel.com/en-us/ipp)\n+ No [Intel Media SDK](https://software.intel.com/en-us/media-sdk)\n+ No [OpenVINO IE API](https://github.com/opencv/dldt/tree/2020/inference-engine/ie_bridges/python/src/openvino/inference_engine)\n+ No python2 support (it is dead)\n+ No Gstreamer (use ffmpeg)\n+ No GTK (+16 MB and a lot of problems and extra work to compile Qt\\GTK libs from sources.)\n\nFor additional info read `cv2.getBuildInformation()` output.\n\n### Versioning\n\n`YYYY.MM.DD`, because it is the most simple way to track opencv/openvino versions.\n\n## Compiling from source\n\nYou will need ~7GB RAM and ~10GB disk space\n\nI am using Ubuntu 18.04 (python 3.6) [multipass](https://multipass.run/) instance: `multipass launch -c 6 -d 10G -m 7G 18.04`.\n\n### Requirements\n\nFrom [opencv](https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html), [dldt](https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html),\n [ffmpeg](https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu), and [ngraph](https://www.ngraph.ai/documentation/buildlb)\n\n```bash\n# We need newer `cmake` for dldt (fastest way I know)\n# \u003e=cmake-3.16\nsudo apt remove --purge cmake\nhash -r\nsudo snap install cmake --classic\n\n# nasm for ffmpeg\n# libusb-1.0-0-dev for MYRIAD plugin\nsudo apt update\nsudo apt install build-essential git pkg-config python3-dev nasm python3 virtualenv libusb-1.0-0-dev chrpath shellcheck\n\n# for ngraph\n# the `dldt/_deps/ext_onnx-src/onnx/gen_proto.py` has `#!/usr/bin/env python` string and will throw an error otherwise\nsudo ln -s  /usr/bin/python3 /usr/bin/python\n```\n\n### Preparing\n\n```bash\ngit clone https://github.com/banderlog/opencv-python-inference-engine\ncd opencv-python-inference-engine\n# git checkout dev\n./download_all_stuff.sh\n```\n\n### Compilation\n\n```bash\ncd build/ffmpeg\n./ffmpeg_setup.sh \u0026\u0026\n./ffmpeg_premake.sh \u0026\u0026\nmake -j6 \u0026\u0026\nmake install\n\ncd ../dldt\n./dldt_setup.sh \u0026\u0026\nmake -j6\n\n# NB: check `-D INF_ENGINE_RELEASE` value\n# should be in form YYYYAABBCC (e.g. 2020.1.0.2 -\u003e 2020010002)\")\ncd ../opencv\n./opencv_setup.sh \u0026\u0026\nmake -j6\n```\n\n### Wheel creation\n\n```bash\n# get all compiled libs together\ncd ../../\ncp build/opencv/lib/python3/cv2.cpython*.so create_wheel/cv2/cv2.so\n\ncp dldt/bin/intel64/Release/lib/*.so create_wheel/cv2/\ncp dldt/bin/intel64/Release/lib/*.mvcmd create_wheel/cv2/\ncp dldt/bin/intel64/Release/lib/plugins.xml create_wheel/cv2/\ncp dldt/inference-engine/temp/tbb/lib/libtbb.so.2 create_wheel/cv2/\n\ncp build/ffmpeg/binaries/lib/*.so create_wheel/cv2/\n\n# change RPATH\ncd create_wheel\nfor i in  cv2/*.so; do chrpath -r '$ORIGIN' $i; done\n\n# final .whl will be in /create_wheel/dist/\n# NB: check version in the `setup.py`\n../venv/bin/python3 setup.py bdist_wheel\n```\n\n### Optional things to play with\n\n+ [dldt build instruction](https://github.com/openvinotoolkit/openvino/wiki/CMakeOptionsForCustomCompilation)\n+ [dldt cmake flags](https://github.com/openvinotoolkit/openvino/blob/master/inference-engine/cmake/features.cmake)\n+ [opencv cmake flags](https://github.com/opencv/opencv/blob/master/CMakeLists.txt)\n\n**NB:** removing `QUIET` from `find_package()` in project Cmake files, could help to solve some problems -- сmake will start to log them.\n\n\n#### GTK2\n\nMake next changes in `opencv-python-inference-engine/build/opencv/opencv_setup.sh`:\n1. change string `-D WITH_GTK=OFF \\`  to `-D WITH_GTK=ON \\`\n2. `export PKG_CONFIG_PATH=$ABS_PORTION/build/ffmpeg/binaries/lib/pkgconfig:$PKG_CONFIG_PATH` -- you will need to\n   add absolute paths to `.pc` files. On Ubuntu 18.04 they here:\n   `/usr/lib/x86_64-linux-gnu/pkgconfig/:/usr/share/pkgconfig/:/usr/local/lib/pkgconfig/:/usr/lib/pkgconfig/`\n\nExporting `PKG_CONFIG_PATH` for `ffmpeg` somehow messes with default values.\n\nIt will add ~16MB to the package.\n\n#### Integrated Performance Primitives\n\nJust set `-D WITH_IPP=ON` in `opencv_setup.sh`.\n\nIt will give +30MB to the final `cv2.so` size. And it will boost _some_ opencv functions.\n\n[Official Intel's IPP benchmarks](https://software.intel.com/en-us/ipp/benchmarks) (may ask for registration)\n\n#### MKL\n\nYou need to download MKL-DNN release and set two flags:`-D GEMM=MKL` , `-D MKLROOT` ([details](https://github.com/opencv/dldt/issues/327))\n\nOpenVino comes with 30MB `libmkl_tiny_tbb.so`, but [you will not be able to compile it](https://github.com/intel/mkl-dnn/issues/674), because it made from proprietary MKL.\n\nOur opensource MKL-DNN experiment will end with 125MB `libmklml_gnu.so` and inference speed compatible with 5MB openblas ([details](https://github.com/banderlog/opencv-python-inference-engine/issues/5)).\n\n\n#### CUDA\n\nI did not try it. But it cannot be universal, it will only work with the certain combination of GPU+CUDA+cuDNN for which it will be compiled for.\n\n+ [Compile OpenCV’s ‘dnn’ module with NVIDIA GPU support](https://www.pyimagesearch.com/2020/02/10/opencv-dnn-with-nvidia-gpus-1549-faster-yolo-ssd-and-mask-r-cnn/)\n+ [Use OpenCV’s ‘dnn’ module with NVIDIA GPUs, CUDA, and cuDNN](https://www.pyimagesearch.com/2020/02/03/how-to-use-opencvs-dnn-module-with-nvidia-gpus-cuda-and-cudnn/)\n\n\n#### OpenMP\n\nIt is possible to compile OpenBLAS, dldt and OpenCV with OpenMP. I am not sure that the result would be better than now, but who knows.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanderlog%2Fopencv-python-inference-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbanderlog%2Fopencv-python-inference-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanderlog%2Fopencv-python-inference-engine/lists"}