虚拟环境中的Opencv3和Python 2.7 - AttributeError:'module'对象没有属性'createLBPHFaceRecognizer'

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (1653)

我有一个opencv 3的python函数。它在没有虚拟环境的情况下工作。我还在venv上安装了opencv:pyimagesearch。我试图在venv上运行该python函数,然后它给出一个错误:

AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'

在终端没有venv:

gkhan@Gkan ~/Masaüstü/face_recognizer $ python face_recognizer.py
Yol :./sinif/114.jpg.
114 Yuz Tanindi 12

与终端的venv:

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'

我的python代码:

#!/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()
...

我在Linux Mint 64 Bit上使用python 2.7运行Opencv3

提问于
用户回答回答于

从OpenCV 3开始,您必须获取并构建opencv_contrib存储库。然后你可以使用子模块“face”。

cv2中模块cv2.face的帮助:

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

瞧〜你现在可以使用了 cv2.face.createLBPHFaceRecognizer()

用户回答回答于

尝试这个

运行此命令以安装contrib

python -m pip install opencv-contrib-python

完成此操作后,请使用此属性

recoginizer = cv2.face.LBPHFaceRecognizer_create()

扫码关注云+社区

领取腾讯云代金券