2015-05-14 165 views
0

我正在使用OpenCV从文件夹中读取图像。很多这样的消息显示:opencv read image“JPEG文件过早结束”

Corrupt JPEG data: premature end of data segment 
Premature end of JPEG file 
Premature end of JPEG file 
Premature end of JPEG file 

如何捕捉此异常并删除这些图像文件?

+0

and ..................?显示一些代码。 –

回答

0

既然你说你正在阅读'图像'(多个图像),你会循环浏览文件夹中的文件。 在这种情况下,如果你检查图像是否有效使用以下:

Mat image; 
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file 

if(! image.data)        // Check for invalid input 
{ 
    cout << "Could not open or find the image" << std::endl ; 
    return -1; 
} 

然后你可以继续删除其腐败/坏文件。

+0

似乎有推荐使用imdecode()来解决你的问题,参见[this] -image -with-imread-in-opencv /) 和[this SO post](http://stackoverflow.com/questions/4271489/little-help-with-cvimdecode) –