I have a python function with opencv 3. it works without virtual environment.Also I installed opencv on venv from:pyimagesearch. i am trying to run that python function on venv, then it gives an error :
AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'
without venv in terminal:
gkhan@Gkan ~/Masaüstü/face_recognizer $ python face_recognizer.py
Yol :./sinif/114.jpg.
114 Yuz Tanindi 12
with venv in terminal:
gkhan@Gkan ~/Masaüstü/face_recognizer $ workon cv
(cv)gkhan@Gkan ~/Masaüstü/face_recognizer $ python face_recognizer.py
Traceback (most recent call last):
File "face_recognizer.py", line 15, in <module>
recognizer = cv2.createLBPHFaceRecognizer()
AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'
my python code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cv2, os
import numpy as np
from PIL import Image
# For Test
if 0==0:
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath)
recognizer = cv2.createLBPHFaceRecognizer()
...
I am running Opencv3 with python 2.7 on Linux Mint 64 Bit
run this command to install the contrib
python -m pip install opencv-contrib-python
after this is done use this attribute
recoginizer = cv2.face.LBPHFaceRecognizer_create()
From OpenCV 3, you have to get and build the opencv_contrib repo. Then you can use the submodule "face".
Help on module cv2.face in cv2:
NAME
cv2.face
FILE
(built-in)
FUNCTIONS
createEigenFaceRecognizer(...)
createEigenFaceRecognizer([, num_components[, threshold]]) -> retval
createFisherFaceRecognizer(...)
createFisherFaceRecognizer([, num_components[, threshold]]) -> retval
createLBPHFaceRecognizer(...)
createLBPHFaceRecognizer([, radius[, neighbors[, grid_x[, grid_y[, threshold]]]]]) -> retval
Voila~ You can now use cv2.face.createLBPHFaceRecognizer()
The easiest way for me was to use anaconda package:
conda install -c menpo opencv3=3.1.0
Once installed, use cv2.face.createLBPHFaceRecognizer()
or other face recognizers. Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With