opencv AttributeError: 'module' object has no attribute 'CV_LOAD_IMAGE_COLOR'

1.opencv  AttributeError: 'module' object has no attribute 'CV_LOAD_IMAGE_COLOR'

 解决办法:That means you're likely compiling against opencv 3.0. The symbol "CV_LOAD_IMAGE_COLOR" has been replaced with "cv::IMREAD_COLOR". Just edit the file and you should be good. It's the only deprecated symbol used in Caffe.


2.Traceback (most recent call last):
File "/Users/n1/Desktop/FaceDetection/face.py", line 8, in
gray = imread(fname, CV_LOAD_IMAGE_GRAYSCALE )
NameError: name 'CV_LOAD_IMAGE_GRAYSCALE' is not defined

解决办法:

>>> import cv2
>>> help(cv2)
...
IMREAD_ANYCOLOR = 4
IMREAD_ANYDEPTH = 2
IMREAD_COLOR = 1
IMREAD_GRAYSCALE = 0   #that will be it ;)
IMREAD_LOAD_GDAL = 8
IMREAD_UNCHANGED = -1
...
VERSION
    3.0.0-dev
CV_LOAD_IMAGE_GRAYSCALE 替换成 IMREAD_GRAYSCALE
3.

OpenCV 3.0 came with some namespace changes, and this might be one of them. The function reference given in the other answer is for OpenCV 2.4.11, and unfortunately there are significant renamings, including enumerated parameters.

According to the OpenCV 3.0 Example here, the correct parameter is cv2.IMREAD_COLOR.

According to the OpenCV 3.0 Reference Manual for C, CV_LOAD_IMAGE_COLOR is still there.

And my conclusion from the above resources and here, they changed it in OpenCV 3.0 python implementation.

For now, the best to use seems like the following:

img = cv2.imread("link_to_your_file/file.jpg", cv2.IMREAD_COLOR) 

你可能感兴趣的:(opencv AttributeError: 'module' object has no attribute 'CV_LOAD_IMAGE_COLOR')