Skip To Main Content
Support Knowledge Base

Unable to Use OpenCV* ‘Face’ Module When Using OpenCV* Provided with OpenVINO™ Installer Package

Content Type: Install & Setup   |   Article ID: 000093622   |   Last Reviewed: 02/06/2023

Description

  • Ran face recognition program using cv2.face.LBPHFaceRecognizer_create()in OpenVINO™ environment.
  • Received error: AttributeError: module 'cv2' has no attribute 'face'
  • Installed OpenCV* from PyPI: pip install opencv-contrib-python
  • Ran face recognition program successfully using OpenCV* from PyPI but encountered another error when using OpenCV* DNN module:

    cv2.error: OpenCV(4.6.0) /io/opencv/modules/dnn/src/net_openvino.cpp:511: error: (-2:Unspecified error) Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'readFromModelOptimizer'

Resolution

OpenCV* provided with OpenVINO™ installer package does not include build with extra modules from opencv_contrib GitHub repository. While OpenCV* from PyPI does not include build with OpenVINO™ support.

Build custom OpenCV* which includes OpenVINO™ Inference Engine and extra modules from opencv_contrib GitHub repository with minimal set of compilation flags:

  1. (Recommend) Uninstall pre-built OpenCV*.

    pip uninstall opencv opencv-contrib-python

  2. Download OpenCV* from opencv/opencv repository.

    git clone --recurse-submodules  https://github.com/opencv/opencv.git

  3. Download OpenCV’s extra modules from opencv/opencv_contrib repository.

    git clone --recurse-submodules  https://github.com/opencv/opencv_contrib.git

  4. Create build directory and navigate to the build directory.

    cd opencv

    mkdir build && cd build

  5. (Optional) Install some additional dependencies for OpenCV*.

    sudo apt install libcanberra-gtk-module libtbb-dev

  6. Download and install OpenVINO™.

    https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/download.html

  7. Setup environment variables to detect Inference Engine.

    source <installed_openvino>/setupvars.sh

  8. Compile and install OpenCV*.

    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=<downloaded_dir>/opencv_contrib/modules -DWITH_OPENVINO=ON -DPYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages ..

    make -j5

    sudo make install

  9. Open new Terminal and import OpenCV* with Python*.

Related Products

This article applies to 3 products.
Intel® Xeon Phi™ Processor Software OpenVINO™ toolkit Performance Libraries