Reputation: 5442
I have a list of directories and sub-directories with images. I am using JavaCV in order to read all images and by using cvShowImage to imshow those images. I am reading the files using listFilesForFolder function. My problem is that some images in those folders are not valid(corrupted). Thus I am getting Opencv exception errors:
OpenCV Error: Null pointer () in cvReleaseImage, file ..\..\..\..\opencv\modules\core\src\array.cpp, line 2983
Exception in thread "main" java.lang.RuntimeException: ..\..\..\..\opencv\modules\core\src\array.cpp:2983: error: (-27) in function cvReleaseImage
at org.bytedeco.javacpp.opencv_core.cvReleaseImage(Native Method)
How can I check in my code if an image is valid(corrupted) or not in order to continue the for-loop in which I read all my images? I am using the following function in order to read images:
public IplImage openImage(String name) {
IplImage img = cvLoadImage(name);
cvShowImage("hello", img);
cvWaitKey();
cvReleaseImage(img);
return img;
}
When I run the program I got issues in cvReleaseImage(img) line.
Upvotes: 1
Views: 530
Reputation: 16796
You have to check if the image is null
or not.
public IplImage openImage(String name) {
IplImage img = cvLoadImage(name);
if(img != null)
{
cvShowImage("hello", img);
cvWaitKey();
cvReleaseImage(img);
}
return img;
}
Upvotes: 4