在bash脚本中检测损坏的图像 [英] Detecting corrupted images in bash script

查看:179
本文介绍了在bash脚本中检测损坏的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自网络摄像头流的2000张图片(对于延时视频),我需要删除所有不完整的&损坏的图像,然后将它们传递给编辑最终视频的php-gd脚本。

I have >2000 images from a webcam stream (for a time-lapse video), I need to delete all incomplete & corrupted images, before passing them to a php-gd script that edits them for the final video.

是否可以使用imagemagick或其他工具检测损坏的文件?如果我尝试用feh打开损坏的图像,它会在控制台中显示 libpng错误:读取错误

Is it possible to detect corrupted files with imagemagick or some other tool? If i try to open the corrupted image with feh it displays libpng error: Read Error in console

提前致谢!

UPDATE:在我的情况下,建议的识别方法似乎接受了错误的图像。以下是损坏的 http://imgur.com/YcB9n

UPDATE: It seems that the suggested identify method accepts the bad images in my case. Here is an example of a corrupted one http://imgur.com/YcB9n

推荐答案

尝试ImageMagick的识别命令。从手册页:

Try ImageMagick's identify command. From the man page:


Identify描述一个或多个图像
文件的格式和
特征。它还会报告图像
是不完整还是损坏。

Identify describes the format and characteristics of one or more image files. It will also report if an image is incomplete or corrupt.

示例:

$ identify foo.png
identify: NotAPNGImageFile (foo.png).

$ echo $?
1

另一种方法是使用 PIL(Python Imaging Library)

from PIL import Image

im = Image.open("foo.png")
im.verify()

来自文档


im.verify()

im.verify()

尝试确定文件是否为
损坏,而不实际解码
图像数据。如果此方法发现任何
问题,则会引发合适的
异常。此方法仅适用于
新打开的图像;如果图像已加载
,则结果为
undefined。此外,如果您需要在使用此方法后加载
图像,则
必须重新打开图像文件。

Attempts to determine if the file is broken, without actually decoding the image data. If this method finds any problems, it raises suitable exceptions. This method only works on a newly opened image; if the image has already been loaded, the result is undefined. Also, if you need to load the image after using this method, you must reopen the image file.

这篇关于在bash脚本中检测损坏的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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