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

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


问题描述:

代码:

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

报错如下:

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

(此处将’cv’改为’cv2’ 报错:AttributeError: module ‘cv2’ has no attribute ‘cv2’)

改为

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

报错如下:

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

原因分析:

子模块cv已从opencv 3.0中移除。


解决方案:

cv2.cv.CV_HAAR_SCALE_IMAGE改为cv2.CASCADE_SCALE_IMAGE
亲测有效!!!


另看到一篇博文遇到类似的OpenCV的版本问题,指路→

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

猜你喜欢

转载自blog.csdn.net/qq_39691492/article/details/123006947