有没有办法改善-subimage-search性能

时间:2017-02-09 10:34:15

标签: image-processing imagemagick image-recognition

我有1600x1600px的大图像和50x50px的小图像。运行测试大约需要3分20秒。预计小图像仅在50 x 500px的区域内出现在大图像内。

我尝试了这个,但它不起作用: StringTokenizer

1 个答案:

答案 0 :(得分:3)

让我们big.gif

convert -size 1600x1600 xc:yellow -fill black -draw "rectangle 5,130 14,139" big.gif

enter image description heresmall.gif

convert -size 10x10 xc:black small.gif

enter image description here

现在让我们看一下裁剪的搜索区域:

convert big.gif -crop 50x500+0+118 x.gif

enter image description here

所以,你需要的命令是:

convert big.gif -crop 50x500+0+118 +repage miff:- | compare -metric mse -subimage-search miff:- small.gif null:
0 (0) @ 5,12

将搜索时间从91秒降低到0.7秒。

如果你真正的问题更难,更大或更紧迫,你可以将图像分成两部分并平行地做两部分 - 记住按照你所寻找的子图像的大小重叠两半:

convert big.gif -crop 50x260+0+118 +repage miff:- | compare -metric mse -subimage-search miff:- small.gif null: &
convert big.gif -crop 50x260+0+368 +repage miff:- | compare -metric mse -subimage-search miff:- small.gif null: &
wait

现在需要0.4秒: - )