我最近开始使用 openCV 和 python 并决定分析一些示例代码以了解事情是如何完成的。
但是,我找到的示例代码不断抛出此错误:
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'
我使用的代码可以在下面找到:
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 的指南。