C++, OpenCV : Assertion failed in Resize
Not going to solve the problem in this case, but this assertion can also be caused by trying to resize a Mat
with a signed type like CV_8SC3
. For example:
Mat wrong = Mat::zeros(4, 4, CV_8SC3); // <- Notice 'S'
Mat right = Mat::zeros(4, 4, CV_8UC3); // <- Notice 'U'
imshow("OK", right);
imshow("ASSERTS", wrong);
Note that checking wrong.cols != 0
will not prevent this from crashing.
The only reason for resize to crush is absence of Image. Even if you checked that some of the images were read properly it doesn't mean that all of them were - some of them may be missing. Reading files from disk is a very common point of failure for programs because you never can be sure if the read was successfully or not. As a result every time you read an image you really really should verify that it is not empty:
if (Image.cols == 0) {
cout << "Error reading file " << ss << endl;
return -1;
}