OpenCV报错:AttributeError: module ‘cv2‘ has no attribute ‘data‘

OpenCV报错:AttributeError: module ‘cv2’ has no attribute 'data’
运行人脸检测代码时会出现如下报错:

face_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_frontalface_alt2.xml")
eye_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_eye.xml")
smile_detector = cv.CascadeClassifier(cv.data.haarcascades + "haarcascade_smile.xml")


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

解决办法:卸载你现有的opencv-python,安装我这个版本的opencv

1.打开Anaconda prompt,输入

pip uninstall opencv-python

2.再输入

pip install opencv-python -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com

注意事项:卸载opencv要选y,爆红不用管

你可能感兴趣的:(opencv错误解决,opencv,计算机视觉,人工智能)