• Register
0 votes

Problem :

I am beginner to opencv and keras on python. Currently I am trying to apply the Keras' image classifier to my existing project, but I am facing below error.

Error: (-215:assertion failed) !ssize.empty() in function 'cv::resize'

Earlier with the same code I was able to use OpenCV to read and train my images, but recently I switching to the new batch of images and so I am facing above error. So I guess there is something wrong with the file type

Below is from a batch which got the error:

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

Below is from a batch that was error free:

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

My file type are exactly the same so now I am confused. Can somebody help me in fixing my problem ?

8 4 2
2,300 points

2 Answers

0 votes

Solution :

I have gone through your question and I think solution for your problem is pretty simple.

You just need to add a try/exception so your code can bypass problematic images:

    myimg=cv2.imread(mypath, cv2.IMREAD_GRAYSCALE)
   my img=cv2.resize(myimg, (img_rows,img_cols))

except Exception as e:

Hope it fixes your problem

5 2 1
4,980 points
0 votes

You might want to check bounds of detected object’s box.

I faced the same error and the cause was that bounds were either negative or more than image size. ( Simply put, a portion of detected object was lying outside image. )

0 points

Related questions

0 votes
1 answer 1.6K views
Problem : I am getting following pydot error importerror: failed to import pydot. you must install pydot and graphviz for `pydotprint` to work.
asked Nov 8, 2019 peterlaw 6.9k points
0 votes
1 answer 4 views
Explain me with a example in a clear way.
asked Oct 13 jagruthi 560 points
0 votes
1 answer 214 views
Problem: I have recently installed opencv with all the dependencies. After the successful installation I have tried to import matplotlib for the very simple example. I have started facing below error when I only tried to install matplotlib via the pip with pip install ... linux-gnu.so' Consider using the `--user` option or check the permissions. How can I install matplotlib without any error?
asked Aug 26 Raphael Pacheco 4.9k points
0 votes
1 answer 630 views
Problem : While trying to import the OpenCV, using import cv2 I facing the below error: /usr/local/lib/python2.7/dist-packages/cv2/__init__.py in <module>() 12 13 # make IDE's (PyCharm) autocompletion happy ----> 14 from .cv2 import * 15 16 # wildcard import ... - I am trying to play around with the Google's new Colaboratory tool. Please let me know if someone have solution for the above issue.
asked Dec 18, 2019 alecxe 7.5k points
0 votes
1 answer 246 views
Problem : I am trying to execute below commands. import numpy as np import cv But I am getting following error on my console: >>> runfile('/Users/isaiahnields/.spyder2/temp.py', wdir='/Users/isaiahnields/.spyder2') RuntimeError: module compiled against API version a but this ... it is not working. I had added cv.py to the python2.7 folder in Spyder-Py2 is there anything else I need to add?
asked Dec 4, 2019 alecxe 7.5k points