【问题标题】:Crop image to bounding box in Tensorflow Object Detection API在 Tensorflow 对象检测 API 中将图像裁剪到边界框
【发布时间】:2017-08-19 12:25:39
【问题描述】:

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

从文档中,

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

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

此操作从图像中切出一个矩形部分。返回的图片左上角在图片中的offset_height,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 函数中使用这些坐标。

【问题讨论】:

标签: tensorflow


【解决方案1】:

由于我们认为x 是水平的,y 是垂直的,因此以下将裁剪带有指定框的图像。

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

【讨论】:

  • @IshantMrinal:你是否也知道,我们如何用颜色填充边界框的内部?假设我想审查图像中的某些部分。我在这里注意到:github.com/tensorflow/models/blob/master/research/… 它使用 PIL 绘制矩形,并且它还初始化了填充参数,但是它没有用任何颜色填充矩形!你能在这方面帮助我吗?
猜你喜欢
  • 2019-01-05
  • 2021-08-15
  • 2014-03-23
  • 2021-05-27
  • 1970-01-01
  • 1970-01-01
  • 2018-04-27
  • 2020-07-23
  • 2019-04-22
相关资源
最近更新 更多