0

I am building a robot with face detection and recognition function. I have got the face detection part working. However for face recognition I am getting the following error (using python):

Traceback (most recent call last):
  File "02_face_training.py", line 21, in <module>
    recognizer = cv2.face.LBPHFaceRecognizer_create()
AttributeError: 'module' object has no attribute 'face'

I was on opencv 3.2 so I upgraded to opencv 3.4.6 but get the same error.

So I started digging in the source code, and sure enough I don't see any cpp code that defines the Face class, so I am not sure what's going on. I even downloaded 4.1 (did not install) just to go through its source and even that did not have any implementation related to face recognition (or at least I could not find it).

This is the code that is causing the issue:

import cv2
import numpy as np
from PIL import Image
import os

# Path for face image database
path = 'dataset'

recognizer = cv2.face.LBPHFaceRecognizer_create()
detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml");

Is there some separate module that I need to install for face recognition in opencv?

I am using python 2.7.

Any help will be appreciated. Thanks.

2
  • How did you install OpenCV? if you built it fromsource, did you include the contrib modules as described here: How to build OpenCV with extra modules Jun 6, 2019 at 17:53
  • Yes I was building from the source. Thanks. This did it.
    – shah
    Jun 7, 2019 at 4:42

1 Answer 1

0

As mentioned by steeldriver, I needed to download opencv contrib modules and compile them with opencv to get the face recognition features.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .