Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

imagemagickのdefineオプションを使う その1:オブジェクトIDをふる

実際のところ

$ fswebcam -c fswebcam_1.conf sample.png

f:id:shuzo_kino:20211020225137p:plain

$ convert sample.png -alpha off -colorspace gray -negate -threshold 10% \
-define connected-components:verbose=true  \
-define connected-components:area-threshold=100 \
-connected-components 8 -auto-level - | imvr -

f:id:shuzo_kino:20211020223618p:plain

画像情報

画像情報は"log:"で出すことができます。

$ convert sample.png -alpha off -colorspace gray -negate -threshold 10% \
-define connected-components:verbose=true \
-define connected-components:area-threshold=100 \
-connected-components 8 -auto-level log:

すると出力がこんな感じ

Objects (id: bounding-box centroid area mean-color):
  0: 640x480+0+0 321.7,239.7 298576 srgb(255,255,255)
  1: 121x99+183+184 243.9,230.2 6863 srgb(0,0,0)
  2: 48x46+217+219 241.5,241.4 1761 srgb(255,255,255)

ためしにターゲットのないbad.pngを用意して先ほどの奴を実行すると
f:id:shuzo_kino:20211021003358p:plain

$ convert bad.png -alpha off -colorspace gray -negate -threshold 10% \
-define connected-components:verbose=true \
-define connected-components:area-threshold=100 \
-connected-components 8 -auto-level log:
Objects (id: bounding-box centroid area mean-color):
  0: 640x480+0+0 319.5,239.5 307200 srgb(255,255,255)