本文介绍了在 Tensorflow 对象检测 API 中将图像裁剪到边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Tensorflow 中将图像裁剪到边界框?我正在使用 Python API.

来自文档,

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

将图像裁剪到指定的边界框.

此操作从图像中切出矩形部分.返回图像的左上角在offset_height,offset_width in image,右下角在offset_height + target_height, offset_width + target_width.

我可以在标准化坐标中获得边界框的坐标,

 ymin = box[0,i,0]xmin = 盒子[0,i,1]ymax = 盒子[0,i,2]xmax = 盒子[0,i,3]

并将这些转换为绝对坐标,

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

但是我不知道如何在 crop_to_bounding_box 函数中使用这些坐标.

解决方案

由于我们认为 x 是水平的,而 y 是垂直的,下面将裁剪指定框的图像.

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

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)

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 and y as vertical, following would crop the image with specified box.

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

这篇关于在 Tensorflow 对象检测 API 中将图像裁剪到边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 17:01
查看更多