我正在尝试制作一个人脸检测程序,它将使用xml文件来训练分类器,并从屏幕截图中识别人脸、嘴巴和眼睛。
然而,当我试图加载xml文件时,它给我的错误是cv2没有' load‘属性。由于之前由于版本和文档(使用3.0.0-bet)的不同,我在使用cv2时遇到了一个属性问题,所以我怀疑这只是一个语法错误。然而,我不是很确定,谁能告诉我是什么导致了这个问题,我该如何解决它?
错误:
Traceback (most recent call last):
File "/home/anthony/Documents/Programming/Python/Computer-Vision/Tests/nowayout.py", line 18, in <module>
haarFace = cv2.Load('haarcascade_frontalface_default.xml')
AttributeError: 'module' object has no attribute 'Load'代码:
# -*- coding: utf-8 -*-
from PIL import Image
from numpy import *
from pylab import *
import pyscreenshot as ImageGrab
import urllib
import cv2
#import cv
image=ImageGrab.grab()
ImageGrab.grab_to_file('image.png')
# input image
imcolor = cv2.imread('image.png')
# loading the classifiers
haarFace = cv2.Load('haarcascade_frontalface_default.xml')
haarEyes = cv2.Load('haarcascade_eye.xml')
haarMouth= cv2.Load('haarcascade_mcs_mouth.xml')
# running the classifiers
storage = cv2.CreateMemStorage()
detectedFace = cv2.HaarDetectObjects(imcolor, haarFace, storage)
detectedEyes = cv2.HaarDetectObjects(imcolor, haarEyes, storage)
detectedMouth = cv2.HaarDetectObjects(imcolor, haarMouth, storage)
# draw a green rectangle where the face is detected
if detectedFace:
for face in detectedFace:
cv2.Rectangle(imcolor,(face[0][0],face[0][1]),
(face[0][0]+face[0][2],face[0][1]+face[0][3]),
cv2.RGB(155, 105, 25),2)
# draw a purple rectangle where the eye is detected
if detectedEyes:
for face in detectedEyes:
cv2.Rectangle(imcolor,(face[0][0],face[0][1]),
(face[0][0]+face[0][2],face[0][1]+face[0][3]),
cv2.RGB(155, 55, 200),2)
# draw a purple rectangle where the eye is detected
if detectedMouth:
for face in detectedMouth:
cv2.Rectangle(imcolor,(face[0][0],face[0][1]),
(face[0][0]+face[0][2],face[0][1]+face[0][3]),
cv2.RGB(255, 0, 0),2)
cv2.NamedWindow('Face Detection', cv.CV_WINDOW_AUTOSIZE)
cv2.ShowImage('Face Detection', imcolor)
cv2.WaitKey()发布于 2015-01-04 14:52:24
尝试将Load()更改为CascadeClassifier(),并将所有cv2.YourMethods更改为cv2.cv.YourMethods,看看是否有帮助。
https://stackoverflow.com/questions/27763133
复制相似问题