找不到cv2.imread标志 [英] cv2.imread flags not found

查看:966
本文介绍了找不到cv2.imread标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用openCV和python,并决定分析一些示例代码来了解事情的完成方式.

I recently started working with openCV and python and decided to analyze some sample code to get an idea of how things are done.

但是,我发现的示例代码不断抛出此错误:

However, the sample code I found, keeps throwing this error:

Traceback (most recent call last):
File "test.py", line 9, in <module>
img = cv2.imread(sys.argv[1],cv2.CV_LOAD_IMAGE_COLOR) ## Read image file
AttributeError: 'module' object has no attribute 'CV_LOAD_IMAGE_COLOR'

我正在使用的代码可以在下面找到:

The code I was using can be found below:

import cv2
import sys
import numpy as np

if len(sys.argv) != 2: ## Check for error in usage syntax
    print "Usage : python display_image.py <image_file>"

else:
    img = cv2.imread(sys.argv[1], cv2.CV_LOAD_IMAGE_COLOR) ## Read image file

if img == None: ## Check for invalid input
    print "Could not open or find the image"
else:
    cv2.namedWindow('Display Window') ## create window for display
    cv2.imshow('Display Window', img) ## Show image in the window
    print "size of image: ", img.shape ## print size of image
    cv2.waitKey(0) ## Wait for keystroke
    cv2.destroyAllWindows() ## Destroy all windows

这是我的安装问题吗?我使用此网站作为安装python和openCV的指南.

Is this a problem with my installation? I used this website as a guide to install python and openCV.

推荐答案

OpenCV 3.0带有一些名称空间更改,这可能是其中之一.另一个答案中给出的功能参考是针对OpenCV 2.4.11的,不幸的是,其中存在大量的重命名,包括枚举的参数.

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.

根据此处的OpenCV 3.0示例,正确的参数是cv2.IMREAD_COLOR.

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

根据 OpenCV 3.0参考手册,CV_LOAD_IMAGE_COLOR仍然存在.

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

上述资源和此处的结论,它们在OpenCV 3.0 python实现中对其进行了更改.

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) 

这篇关于找不到cv2.imread标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆