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:
- AttributeError: module ‘cv2’ has no attribute ‘SIFT’ [How to Solve]
- [Solved] OpenCV 4 (C++) Error: “error: ‘CV_FOURCC’ was not declared in this scope”
- loaded some nib but the view outlet was not set
- AttributeError: module ‘cv2’ has no attribute ‘CV_HAAR_SCALE_IMAGE’
- Python OpenCV Save Image error: (-215:Assertion failed) !_img.empty()
- [Solved] Ubuntu 18.04 Compile opencv-3.4.16 Error: “c++: internal compiler error: Killed (program cc1plus)”
- Java call opencv face recognition error insufficient out of memory
- MAC OS Install opencv ModuleNotFoundError: No module named ‘cv2’
- [Solved] PyTorch error: TypeError: ‘builtin_function_or_method‘ object is unsubscriptable
- [Solved] Opencv3.4.0 Install error: fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory