在图像上查找特定颜色坐标
Find an especific color coordenates on an image
我想找到图像上某种颜色(例如绿色)首次出现的坐标,以便可以在 bash 脚本中使用。
我一直在尝试使用 Imagemagick,但找不到解决问题的方法。
这可以用 Imagemagick 完成还是我应该使用其他任何东西?
这是在 ImageMagick 中使用 sparse-color 的一种方法:(前提是图像完全不透明)。 Sparse-color 将读出所有完全不透明像素的 x,y 坐标和颜色。然后就可以用unix工具搞定第一个了
创建红色和蓝色图像:
convert -size 10x10 xc:red xc:blue -append x.png
找到第一个 rgb(0,0,255) 即蓝色像素
convert x.png sparse-color: | tr " " "\n" | grep "srgb(0,0,255)" | head -n 1
结果
0,10,srgb(0,0,255)
使用 txt: 代替 sparse-color 可以获得类似的结果。但是用于过滤的unix命令会有点不同。
我想找到图像上某种颜色(例如绿色)首次出现的坐标,以便可以在 bash 脚本中使用。
我一直在尝试使用 Imagemagick,但找不到解决问题的方法。
这可以用 Imagemagick 完成还是我应该使用其他任何东西?
这是在 ImageMagick 中使用 sparse-color 的一种方法:(前提是图像完全不透明)。 Sparse-color 将读出所有完全不透明像素的 x,y 坐标和颜色。然后就可以用unix工具搞定第一个了
创建红色和蓝色图像:
convert -size 10x10 xc:red xc:blue -append x.png
找到第一个 rgb(0,0,255) 即蓝色像素
convert x.png sparse-color: | tr " " "\n" | grep "srgb(0,0,255)" | head -n 1
结果
0,10,srgb(0,0,255)
使用 txt: 代替 sparse-color 可以获得类似的结果。但是用于过滤的unix命令会有点不同。