opencv中的图像有效性检查(cvImage) [英] image validness check in opencv (cvImage)

查看:527
本文介绍了opencv中的图像有效性检查(cvImage)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我有以下代码进行图像验证:



Hello

I have following code for image validation:

sprintf(imageFileName_jp2, "%s\\image_%03d.jp2", fileMenu.m_logPath, tmp_no);
cvImage = imread(imageFileName_jp2, IMREAD_COLOR);
if (cvImage.data == NULL)
    continue;





如果图像不适合阅读(当某些图像数据由于通信问题而不完美时),我想忽略图像。 br />


但是,imread()需要时间并且会使代码变慢。



还有另一种方法可以验证图像?



谢谢。



If an image is not suitable to be read (when some image data is imperfect due to communication problem), I want to ignore the image.

But, imread() takes time and it makes the code slow.

Is there another method to validate the image?

Thank you.

推荐答案

我不认为还有其他方式。

问题是你需要执行加载和解码的整个过程,以确保图像文件有效,即使是使用JPEG压缩图像进行健全性检查也是不够的。在这样的图像中,只有在解压缩期间才能检测到错误的字节。

我可以给你的唯一建议是在尝试加载图像之前进行两次快速的健全性检查:

1.检查文件尺寸,如果它小于合理长度你可以丢弃它

2.读取图像文件的前2个字节,它们包含一个JPEG SOI标记= 0xFFD8

3.然后是JFIF-APP0标记段:

I don't think that there is any other way.
The problem is that you need to perform the whole process of loading and decoding to be sure that the image file is valid, even sanity checks are not enough because you are using JPEG compressed images. In such images a wrong byte can be detected only during decompression.
The only suggestion I can give you is to make two fast sanity check before trying to load the image:
1. check file dimension, if it is shorter than a reasonable length you can discard it
2. Read the first 2 bytes of the image file, they contain a JPEG SOI marker = 0xFFD8
3. Then a JFIF-APP0 marker segment:
Field       Size (bytes)     Description
APP0 marker       2             FF E0
Length            2             Length of segment excluding APP0 marker
Identifier        5             4A 46 49 46 00 = "JFIF" in ASCII, terminated by a null byte
JFIF version      2             First byte for major version, second byte for minor version (01 02 for 1.02)
Density units     1             Units for the following pixel density fields
                                  00 : No units; width:height pixel aspect ratio = Xdensity:Ydensity
                                  01 : Pixels per inch (2.54 cm)
                                  02 : Pixels per centimeter
Xdensity          2             Horizontal pixel density. Must not be zero.
Ydensity          2             Vertical pixel density. Must not be zero.
Xthumbnail        1             Horizontal pixel count of the following embedded RGB thumbnail. May be zero.
Ythumbnail        1             Vertical pixel count of the following embedded RGB thumbnail. May be zero.
Thumbnail data    3 × n         Uncompressed 24 bit RGB (8 bits per color channel) raster thumbnail data in the order R0, G0, B0, ... Rn, Gn, Bn; with n = Xthumbnail × Ythumbnail.



此外,您还可以检查合理的价值。



更多细节请参见此处 [ ^ ]。


这篇关于opencv中的图像有效性检查(cvImage)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆