我有一个opencv 3的python函数.它在没有虚拟环境的情况下工作.我还在venvv上安装了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()