- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So i was trying to use cv2.face.LBPHFaceRecognizer_create() in my face recognition program. When i run my program in python compiler everything worked perfectly , but when i try to run this program with NCS2 inside OpenVINO environment it create an error :
Traceback ( most recent call last ) :
File "vino_recognizer.py", line 13, in <module>
recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2' has no attribute 'face'
I already tried reinstalling opencv and opencv-contrib-python but it does not seems to working at all. Can someone help me with this problem ? Thank you.
Here is my code:
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi zapp02,
Installing prebuilt OpenCV (pip install opencv-contrib-python) allows you to use cv2.face.LBPHFaceRecognizer_create(). However, using this prebuilt OpenCV, OpenCV DNN module cannot be used.
To use OpenCV DNN module, OpenCV is required to be built with OpenVINO™ Inference Engine (OpenVINO™ backend). You can use OpenCV from OpenVINO™. It's already compiled with OpenVINO Inference Engine. (Assuming you’re using OpenVINO™ 2021.4.2 since starting from 2022.1.1 release, OpenVINO™ does not include OpenCV.)
Anyhow, OpenCV from OpenVINO™ doesn't include the extra modules in OpenCV_Contrib which results in getting the following error if use cv2.face.LBPHFaceRecognizer_create().
AttributeError: module 'cv2' has no attribute 'face'
In this case, you have to build custom OpenCV along with OpenVINO Inference Engine and extra modules in opencv_contrib.
Steps to build custom OpenCV 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) You might need to install some additional dependencies for OpenCV.
sudo apt install libcanberra-gtk-module libtbb-dev
6. (Optional) 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 l_openvino_toolkit_ubuntu20_2022.2.0.7713.af16ea1d79a_x86_64.tgz/setupvars.sh
8. Compile and install OpenCV.
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=/home/pse/Downloads/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.
Regards,
Peh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the respond and suggestion, sorry it's taken me a few days for the update or reply. We gonna try and do your suggestion after a few days of vacation out of town, we currently do not have access to the Raspberry Pi 4 and the NCS 2, both are university properties.
Please wait for further update, Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi zapp02,
As of today, we have not heard back from you. Therefore, this thread will no longer be monitored.
Please open a new case if you have further questions and we'll be happy to help you.
Regards,
Peh

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page