2017-08-19 13 views
2

Tensorflowで画像を境界ボックスにトリミングするにはどうすればよいですか?私はPython APIを使用しています。ドキュメントから Tensorflowオブジェクト検出APIの画像を境界ボックスにトリミングする

tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width) 

作物指定されたバウンディングボックスの画像。

このオペレーションは、画像から長方形の部分を切り取ります。返される画像の左上隅はoffset_height、imageのoffset_widthにあり、その右下隅はoffset_height + target_height、offset_width + target_widthにあります。

私は

ymin = boxes[0,i,0] 
    xmin = boxes[0,i,1] 
    ymax = boxes[0,i,2] 
    xmax = boxes[0,i,3] 

、として正規化座標でのバウンディングボックスの座標を取得し、私はこれらを使用する方法を見つけ出すカントしかし

(xminn, xmaxx, yminn, ymaxx) = (xmin * im_width, xmax * im_width, ymin * im_height, ymax * im_height) 

、絶対座標にこれらを変換することができますcrop_to_bounding_box機能の座標。

+0

あなたがこの記事:) https://blog.twitter.com/engineering/en_us/topics/infrastructure/2018/Smart-Auto-Cropping-of-Images.html?utm_content=buffer611dd&utm_medium=social&utm_sourceを好むかもしれません= linkedin.com&utm_campaign = buffer –

答えて

3

xを水平とみなし、yを垂直と見なすので、以下のように指定したボックスで画像を切り抜くことができます。

cropped_image = tf.image.crop_to_bounding_box(image, yminn, xminn, 
             ymaxx - yminn, xmaxx - xminn) 
+0

ありがとうございました!それは完璧に働いた! – Ahmad

+0

@IshantMrinal:また、境界ボックスの内側に色を塗りつぶす方法も知っていますか?私がイメージの一部を検閲したいとします。私はここで気付きました:https://github.com/tensorflow/models/blob/master/research/object_detection/utils/visualization_utils.py#L169 それはPIL描画矩形を使用し、fill引数も初期化しますが、矩形を色で塗りつぶしてください! これに関して私を助けることができますか? – Breeze

関連する問題