【发布时间】:2020-07-23 18:09:36
【问题描述】:
我正在尝试使用 cv2.imread 加载图像,但不断收到此错误
错误:(-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
我用谷歌搜索了这个错误,似乎大多数时候问题与文件名/路径拼写错误有关。 但是,我使用 mac 上的“复制路径”选项复制了文件路径。可能是什么问题?
我的代码:
import cv2
import numpy as np
from matplotlib import pyplot as plt
from scipy import ndimage
from skimage import measure, color, io
path='/Users/snysdh/Desktop/A1_Combined_T01.png'
img1=cv2.imread(path)
cv2.imshow("Red Image", img1)
【问题讨论】:
-
首先使用
ls -la /Users/snysdh/Desktop/A1_Combined_T01.png确认路径是否正确 -
文件损坏(或非标准 PNG 格式)的可能性很小,或者您的 python 脚本没有文件的读取权限。尝试其他路径中的其他文件(与 Python 文件相同的路径是一个不错的建议)。