• Register
0 votes
3.2k views

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

Please log in or register to answer this question.

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:

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

except Exception as e:
    print(str(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 37 views
37 views
Problem: HELP! I need help understanding this error and how I can fix it :Error: (-215:assertion failed) !ssize.empty() in function 'cv::resize'.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 72 views
72 views
Problem: error: (-215:assertion failed) !empty() in function 'cv::cascadeclassifier::detectmultiscale'
asked Feb 19 Lucky Guy 1.5k points
0 votes
1 answer 15 views
15 views
Problem: error: (-215) scn == 3 || scn == 4 in function cv::cvtcolor.
asked Feb 16 charles mathews 5.5k points
0 votes
1 answer 290 views
290 views
Problem: error: (-215) size.width>0 && size.height>0 in function cv::imshow
asked Feb 13 Shovo210 13.2k points
0 votes
1 answer 17 views
17 views
Problem: Help! I can not understand the following error: (-215:assertion failed) !_src.empty() in function 'cv::cvtcolor'.Who can help me to solve it?
asked Apr 3 ashik 10.6k points
0 votes
1 answer 5 views
5 views
Problem: HELP! I need help understanding this error? error: (-215:assertion failed) !_src.empty() in function 'cvtcolor'
asked Apr 1 Rohit kr 14.7k points
0 votes
1 answer 21 views
21 views
Problem: I am getting a problem showing in my computer that is error: (-215:assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'.Who can help me to solve it?
asked Apr 3 ashik 10.6k points
0 votes
2 answers 5 views
5 views
Problem: Any ideas on what I need to fix the issue>(-215) !empty() in function cv::cascadeclassifier::detectmultiscale?
asked Apr 3 ashik 10.6k points
0 votes
1 answer 2 views
2 views
Problem: What caused the problem," expected cv::umat for argument "src" "?
asked 1 day ago zayed1 24.7k points
0 votes
1 answer 12 views
12 views
Problem: how can i fix this problem ? Thank you , importerror: failed to import pydot. you must install pydot and graphviz for `pydotprint` to work..
asked Mar 7 Wafa Abu Yousef 6.1k points