How can I crop an image to the bounding box in Tensorflow? I am using the Python API.
From the documentation,
tf.image.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width)
Crops an image to a specified bounding box.
This op cuts a rectangular part out of image. The top-left corner of the returned image is at offset_height, offset_width in image, and its lower-right corner is at offset_height + target_height, offset_width + target_width.
I can get the coordinates of a bounding box in normalized coordinates as,
ymin = boxes[0,i,0]
xmin = boxes[0,i,1]
ymax = boxes[0,i,2]
xmax = boxes[0,i,3]
and convert these to absolute coordinates,
(xminn, xmaxx, yminn, ymaxx) = (xmin * im_width, xmax * im_width, ymin * im_height, ymax * im_height)
However I cant figure out how to use these coordinates in the crop_to_bounding_box
function.
Since we consider
x
as horizontal andy
as vertical, following would crop the image with specified box.