【发布时间】:2019-05-12 17:20:25
【问题描述】:
我正在使用 imagemagick 来识别文件夹中截断图像的过早结束。我编写的脚本成功识别了图像,但是速度很慢。这可能是因为它必须将整个图像加载到内存中,但考虑到我将文件复制到磁盘所花费的时间,这应该不会超过几个小时的操作。我正在分析超过 700,000 张图像,以目前的速度完成该操作需要一个多月的时间,更不用说极高的 CPU 使用率了。
foreach (string f in files)
{
Tuple<int, string> result = ImageCorrupt(f);
int exitCode = result.Item1;
if (exitCode != 0)...
}
public static Tuple<int, string> ImageCorrupt(string pathToImage)
{
var cmd = "magick identify -regard-warnings -verbose \"" + pathToImage + "\"";
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = "/C " + cmd,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
var process = new Process
{
StartInfo = startInfo
};
process.Start();
string output = process.StandardOutput.ReadToEnd();
if (!process.WaitForExit(30000))
{
process.Kill();
}
return Tuple.Create(process.ExitCode, process.StandardError.ReadToEnd());
}
这是我试图在图像中识别的问题的example。
有没有办法优化我的脚本以提高性能?还是有更快的方法来识别图像的问题?
【问题讨论】:
-
尝试“magick identify -ping”,这应该会阻止您加载整个图像。在这种情况下它可能对你有用
-
Ping 不会发现截断的图像,不幸的是,它只是加载标题,
标签: c# imagemagick