Problem Description
The source code is as follows:
import cv
from opencv.cv import *
from opencv.highgui import *
img = cv.LoadImage("test.jpg")
cap = cv.CreateCameraCapture(0)
while cv.WaitKey(1) != 10:
img = cv.QueryFrame(cap)
cv.ShowImage("cam view", img)
cascade = cv.LoadHaarClassifierCascade('haarcascade_frontalface_alt.xml', cv.Size(1,1))
I get this error when I run the code:
AttributeError: 'module' object has no attribute 'LoadImage'
Solutions
The reason for the problem: The "module" object has no attribute "LoadImage" .
Guess import cv
and from opencv.cv import *
this conflict, so try to comment f rom opencv.cv import *
.
problem solved
When I changed the code to the following:
import cv
#from opencv.cv import *
#from opencv.highgui import *
img = cv.LoadImage("test.jpg")
cap = cv.CreateCameraCapture(0)
while cv.WaitKey(1) != 10:
img = cv.QueryFrame(cap)
cv.ShowImage("cam view", img)
cascade = cv.LoadHaarClassifierCascade('haarcascade_frontalface_alt.xml', cv.Size(1,1))
Now the first error has been resolved and another error has appeared again.
AttributeError: 'module' object has no attribute 'LoadHaarClassifierCascade'
Learned by searching information:
To load the haar classifier in OpenCV (in the python interface anyway) just use it cv.load
.
as follows:
import cv
cascade = cv.Load('haarcascade_frontalface_alt.xml')
Problem solved successfully! ! ! !