Problem solved successfully in Python: attributeerror: ‘module’ object has no attribute ‘loadimage‘

How did “people you might know” find you on social software>>>

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))

This error occurred while running the code:

AttributeError: 'module' object has no attribute 'LoadImage'

Solutions

The reason for the problem is that the object “module” has no attribute “loadimage”

Guess that Import CV and from OpenCV. CV import * conflict, so try to annotate f ROM OpenCV. CV import *

Problem solving

When I change 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 mistake has been solved, and another one has appeared

AttributeError: 'module' object has no attribute 'LoadHaarClassifierCascade'

Through searching for information, we know that:

to load Haar classifier in opencv (in Python interface anyway), just use cv. Load

As follows:

import cv
cascade = cv.Load('haarcascade_frontalface_alt.xml')

The problem has been solved successfully

Similar Posts: