OpenCV 3.0.0 beta Python: Load error: 'module' object has no attribute 'Load'



I was trying to make a face detection program where it would use xml files to train classifiers and identify face, mouth, and eyes from a screenshot.


However when I tried to load the xml files, it gives me the error that cv2 has no 'Load' attribute. Since I had an attribute problem before with cv2 due to different versions and documentation (using 3.0.0-bet), I suspect that it is something as simple as a syntax error. However I am not really sure, can anyone tell me what is causing the problem and how do I fix it?


Error:



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'


Code:



# -*- 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()

No comments:

Post a Comment