Search code examples
pythonmacosopencvpython-3.6opencv-contrib

Opencv contrib face library


I am trying to use LBPHfacerecognizer in my python3.6 code.

recognizer = cv2.face.createLBPHFaceRecognizer()

I am aware that face module is in opencv_contrib module. I even uninstalled openCV and installed again with contrib module. I compiled OpenCV with it and python still gives an error which is:

AttributeError: module 'cv2.cv2' has no attribute 'face'

Although in opencv/build/lib I have libopencv_face.dylib, it doesn't compile with python3 and opencv.

I tried everything I can think of but I am running out of ideas.

Any ideas?

edit: Python doesn't give an error when I am working under python3 environment anymore but I still have the same error when I try to run my code in the terminal.

What I am trying to run:

python3 main.py

Any ideas why I have this problem or how I can fix it?


Solution

  • Firstly, the first mistake of mine was after making cmake for few times, I didn't delete old cv2.so file and replace it with new cv2.so.

    And it turned out that for working opencv_contrib face module, I have to put this new cv2.so file in the same file that my main.py exists. I don't know if this is the way how should be in the first place. I totally find out this coincidently by myself.

    After this, my code worked without any error.