bash - 在 bash 脚本中检测损坏的图像

标签 bash image-processing png

<分区>

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

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

提前致谢!

更新:在我的案例中,建议的识别方法似乎接受了不良图像。这是一个损坏的示例 http://imgur.com/YcB9n

最佳答案

试试 ImageMagick 的 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 图像库):

from PIL import Image

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

来自documentation :

im.verify()

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 - 在 bash 脚本中检测损坏的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4780424/

相关文章:

windows - 如何将 bash 脚本输出通过管道传输到 Windows 上的文件

c++ - 从点云中检测一组平面

matlab - matlab 图像中的自主接缝检测

image-processing - 以下用于图像调整大小的 c++ 双三次插值代码有什么问题

c# - 使用 wpf 存储在外部 dll 中的引用图像

linux - 如何删除基于另一个文件的行?

java - 如何在 Mac bash 上从命令行运行 Gradle

bash - 在 bash 中,如何强制刷新打印到终端的不完整行

css - 在IE6中,如何使用过滤器定位透明PNG?

css - 在 CSS 中为 PNG 图像投影