【发布时间】:2020-09-03 04:58:43
【问题描述】:
我遇到了这个错误。我已经从This website 复制了代码并进行了更改,以便代码实际工作。代码:
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help="Image Path")
args = vars(ap.parse_args())
img_path = args['image']
#Reading image with opencv
img = cv2.imread(img_path)
#Reading csv file with pandas and giving names to each column
index=["color","color_name","hex","R","G","B"]
csv = pd.read_csv('colors.csv', names=index, header=None)
cv2.namedWindow('image')
cv2.setMouseCallback('image', draw_function)
while(1):
#This is error line
cv2.imshow("image",img)
[...]
完整的追溯:
Traceback (most recent call last):
File "C:\Users\someone\Documents\python\____The Useless Installer____\PY\color_detection.py", line 39, in <module>
cv2.imshow("image",img)
cv2.error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
我看过here 和here,但我不明白如何解决这个问题,我认为这与我的问题也没有太大关系。如果这很明显,我很抱歉。我在这方面完全是新手。谢谢
【问题讨论】:
-
你是如何启动脚本的?你在传递
--imageargument() 吗?
标签: python opencv argparse cv2 imshow