解决AttributeError: module ‘cv2‘ has no attribute ‘CV_HAAR_SCALE_IMAGE‘

解决AttributeError: module ‘cv2’ has no attribute ‘CV_HAAR_SCALE_IMAGE’


Problem Description:

Code:

frontalFaces = faceCascade.detectMultiScale(image, scaleFactor=1.3, minNeighbors=5, minSize=(30, 30), flags = cv2.cv.CV_HAAR_SCALE_IMAGE)

The error is reported as follows:

AttributeError: module 'cv2' has no attribute 'cv'

(Change 'cv' to 'cv2' here. Error: AttributeError: module 'cv2' has no attribute 'cv2')

Change to

frontalFaces = faceCascade.detectMultiScale(image, scaleFactor=1.3, minNeighbors=5, minSize=(30, 30), flags = cv2.CV_HAAR_SCALE_IMAGE)

The error is reported as follows:

AttributeError: module 'cv2' has no attribute 'CV_HAAR_SCALE_IMAGE'

Cause Analysis:

The submodule cv has been removed from opencv 3.0.


solution:

Will be cv2.cv.CV_HAAR_SCALE_IMAGEchanged to cv2.CASCADE_SCALE_IMAGE
personally tested and effective! ! !


I also saw a blog post where I encountered a similar OpenCV version problem and gave me some guidance →

AttributeError: module ‘cv2.cv2’ has no attribute ‘cv’

Guess you like

Origin blog.csdn.net/qq_39691492/article/details/123006947