我在此错误中遇到麻烦(-215:Assertion失败)!opencv中的函数'resize'中的!ssize.empty() [英] I am having trouble with this error (-215:Assertion failed) !ssize.empty() in function 'resize' in opencv

查看:859
本文介绍了我在此错误中遇到麻烦(-215:Assertion失败)!opencv中的函数'resize'中的!ssize.empty()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Keras的图像分类器应用于我的项目,但是后来我陷入了困境.虽然以前使用相同的代码,但我可以使用OpenCV读取和训练图像,但是在切换到新的一批图像后,它就陷入了错误.所以我推测我的文件类型有问题:

I am trying to apply a Keras' image classifier to my project, but down the road I got stuck with this. Though previously, with the same code I could use OpenCV to read and train images, but after switching to a new batch of images it got caught with the error . So my speculation is that there's something wrong with my file type:

这是从出现错误的批次中提取的:

This is from the batch that got the error:

traf.204.jpg:JPEG图像数据,JFIF标准1.01,长宽比, 密度1x1,段长度16,基线,精度8,480x294,帧 1

traf.204.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 480x294, frames 1

这是没有被错误捕获的批次:

This is from the batch that didn't get caught with the error:

bear.290.jpg:JPEG图像数据,JFIF标准1.01,长宽比, 密度1x1,线段长度16,基线,精度8,224x224,帧 3

bear.290.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 224x224, frames 3

但是文件类型似乎完全相同(分辨率除外).请帮助我解决这个问题,我仍然不熟悉python上的opencv和keras.

But the file type seems to be exactly the same (except for the resolution). Please help me with this problem, I am still new to opencv and keras on python.

推荐答案

谢谢,我想通了,我应该添加一个try/exception,以便我的代码可以绕过丑陋"的图像:

Thanks guys, I figured it out, I was supposed to add a try/exception so my code could bypass "ugly" images:

try:
    path=os.path.join(mypath,n)
    img=cv2.imread(path, cv2.IMREAD_GRAYSCALE)
    img=cv2.resize(img, (img_rows,img_cols))

except Exception as e:
    print(str(e))

cv2.resize()应该在此处捕获该错误,因为它无法调整损坏"的图像的大小.

cv2.resize() was where it was supposed to caught the error since it can't resize a "broken" image.

这篇关于我在此错误中遇到麻烦(-215:Assertion失败)!opencv中的函数'resize'中的!ssize.empty()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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