Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv3 and Python 2.7 on Virtual Environment - AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'

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

like image 659
Gkan Avatar asked Nov 09 '15 23:11

Gkan


3 Answers

try this

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()
like image 141
Siddhartha Avatar answered Oct 21 '22 10:10

Siddhartha


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()

like image 29
Rick Avatar answered Oct 21 '22 12:10

Rick


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

like image 21
Chandan Purohit Avatar answered Oct 21 '22 12:10

Chandan Purohit