我想要处理这两张图片:
最终得到的结果如下:
我已经使用了
compare
和fuzz
来定义发生变化的部分。是否可以获取该区域的边界框并裁剪第二个帧?compare
和fuzz
来定义发生变化的部分。是否可以获取该区域的边界框并裁剪第二个帧?我会这样做:
convert a.jpg b.jpg -colorspace gray -blur 0x2 \
-compose difference -composite \
-threshold 20% out.jpg
将图像转换为灰度,并进行轻微模糊以隐藏小差异,然后计算差异和阈值,以生成二值化的图像,如下所示:
然后我会进行连通组件分析,以查找图像中最大的对象,如下所示:
convert a.jpg b.jpg -colorspace gray -blur 0x2 \
-compose difference -composite -threshold 20% \
-define connected-components:verbose=true \
-define connected-components:area-threshold=100 \
-connected-components 8 out.jpg
Objects (id: bounding-box centroid area mean-color):
0: 1029x1079+0+0 515.0,538.4 1102870 srgb(0,0,0)
17: 76x147+326+564 366.5,641.4 5827 srgb(252,252,252)
22: 18x50+358+612 365.1,635.3 568 srgb(0,0,0)
11: 34x31+810+345 825.5,361.1 317 srgb(255,255,255)
16: 57x97+25+539 52.3,587.2 286 srgb(255,255,255)
14: 46x65+120+414 144.0,444.3 203 srgb(255,255,255)
18: 27x49+23+579 36.9,601.0 118 srgb(255,255,255)
24: 16x8+703+641 710.6,644.5 102 srgb(255,255,255)
-define connected-components:verbose=true
参数会将各个blob以文本输出,以便进行解析。
-define connected-components:area-threshold=100
参数表示只输出面积大于100像素的blob。
-connected-components 8
参数表示允许考虑与同一对象相连通的8个像素点。8个像素点包括标准的北、东、南、西4个相邻像素点,以及斜向相邻的4个像素点。默认情况下,ImageMagick
仅考虑4个相邻像素点 - 这样做更快。
而您的玩家是物品id 17
,位于第二行。您可以看到其边界框,并使用以下命令从原始图像中提取出该部分:
convert b.jpg -crop 76x147+326+564 player.jpg
注意:进行连通组件分析需要使用ImageMagick 6.8.9-10或更高版本。