I'm having a problem with OpenCV and the Assertion failed error. It seems to be having a problem reading the image so the function imread() fails silently and then in resize() function it crashes because the input image is empty.
I've checked the path and it's ok, in fact if I print the path that I'm trying to read and do open path in a terminal image opens just fine. Also, if I take this path that I printed and put it in a string variable code works. So the problem seems to be with ss object. I just don't know what.
Here's my code:
int main(int argc, char** argv ){
cout << "Prueba OpenCV \n";
char* path;
Mat input;
if(argc >= 2 )
{
path = argv[1];
for(int j=0; j< numFiles; j++){
cout << "Character "<< OCR::strCharacters[1] << " file: " << j << "\n";
stringstream ss(stringstream::in | stringstream::out);
ss << path << OCR::strCharacters[1] << "/" << j << ".jpg" << "\n";
cout << "Character file: " << ss.str() << "\n";
Mat img=imread(ss.str(), 0);
/*if (img.cols == 0) {
cout << "Error reading file " << ss << endl;
return -1;
}*/
Mat lowData;
resize(img, lowData, Size(5, 5) );
}
}
}
run this with:
./PruebaOpenCV samples/
I found this link in stack that had a similar problem but the answer just was a piece of code to know if the image is properly read (commented code above). I know mine isn't but path is ok.