11

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

hypadr1v3
  • 543
  • 4
  • 26
Gkan
  • 385
  • 1
  • 5
  • 20

6 Answers6

12

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

Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
Rick
  • 191
  • 1
  • 8
  • Thank you so much, i didn't see face submodule. so it is working now. – Gkan Nov 17 '15 at 21:24
  • How do I build it for Windows?? – Gokul NC Sep 05 '16 at 09:34
  • OpenCV's official website has a very clear introduction on installation. [Click here](http://docs.opencv.org/3.0-beta/doc/tutorials/introduction/windows_install/windows_install.html) – Rick Sep 07 '16 at 02:30
5

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

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Chandan Purohit
  • 2,283
  • 1
  • 17
  • 16
4

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()
Siddhartha
  • 155
  • 1
  • 3
2

for python versions as 3.6 uses:

rec = cv2.face.LBPHFaceRecognizer_create();
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Sleider
  • 31
  • 1
0

For windows users using python 3, you can get the opencv_contrib from here. My system is 64 bit so opencv_python‑3.3.0+contrib‑cp36‑cp36m‑win_amd64.whl is what I used. If you are 32 bit then choose the 32 bit version.

Open command prompt and navigate to the download folder and use the command

pip install opencv_python-3.3.0+contrib-cp36-cp36m-win_amd64.whl

Note: Use a command similar to the file you just downloaded and make sure to uninstall an older version before installing the new one with the contrib. I had to run:

pip uninstall opencv_python-3.3.0-cp36-cp36m-win_amd64.whl

before making the new installation.

Then make sure it's successful

>>>import cv2
>>>cv2.face
<module 'cv2.face'>

Instead of createLBPHFaceRecognizer(), you must use LBPHFaceRecognizer_create()

0

For Python version 3.6.x, do this:

Open your terminal and install opencv-contrib-python

python -m pip install opencv-contrib-python

when you done with it use this

recoginizer = cv2.face.LBPHFaceRecognizer_create()

For More option you can do it like this way:

print(help(cv2.face))
Harsh Patel
  • 6,334
  • 10
  • 40
  • 73