首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV 3.0.0测试版Python:加载错误:'module‘对象没有' Load’属性

OpenCV 3.0.0测试版Python:加载错误:'module‘对象没有' Load’属性
EN

Stack Overflow用户
提问于 2015-01-04 14:42:43
回答 1查看 6.4K关注 0票数 2

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

然而,当我试图加载xml文件时,它给我的错误是cv2没有' load‘属性。由于之前由于版本和文档(使用3.0.0-bet)的不同,我在使用cv2时遇到了一个属性问题,所以我怀疑这只是一个语法错误。然而,我不是很确定,谁能告诉我是什么导致了这个问题,我该如何解决它?

错误:

代码语言:javascript
复制
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'

代码:

代码语言:javascript
复制
# -*- 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()
EN

回答 1

Stack Overflow用户

发布于 2015-01-04 14:52:24

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27763133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档