gpt4 book ai didi

python - OpenCV 3.0.0 测试版 Python : Load error: 'module' object has no attribute 'Load'

转载 作者:太空宇宙 更新时间:2023-11-03 21:46:01 25 4
gpt4 key购买 nike

我试图制作一个人脸检测程序,它会使用 xml 文件来训练分类器并从屏幕截图中识别人脸、嘴巴和眼睛。

然而,当我尝试加载 xml 文件时,它给我一个错误,即 cv2 没有“加载”属性。由于版本和文档不同(使用 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()

最佳答案

尝试将 Load() 更改为 CascadeClassifier(),并将所有 cv2.YourMethods 更改为 cv2.cv.YourMethods 看看是否有帮助。

关于python - OpenCV 3.0.0 测试版 Python : Load error: 'module' object has no attribute 'Load' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27763133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com