虚拟环境上的Opencv3和Python 2.7-AttributeError:“模块”对象没有属性“ createLBPHFaceRecognizer”
我在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位上使用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()