Tensorflow深度学习之三十五:tf.image.draw_bounding_boxes

一、函数定义

tf.image.draw_bounding_boxes(
    images,
    boxes,
    name=None
)

  Draw bounding boxes on a batch of images.
  在一个batch的每一张图片上绘制边界框。
   Outputs a copy of images but draws on top of the pixels zero or more bounding boxes specified by the locations in boxes. The coordinates of the each bounding box in boxes are encoded as [y_min, x_min, y_max, x_max]. The bounding box coordinates are floats in [0.0, 1.0] relative to the width and height of the underlying image.
  输出images的一个副本,在图片上像素上绘制boxes中由位置指定的零个或多个边界框的。 框中每个边界框的坐标编码为[y_min,x_min,y_max,x_max]。 边界框坐标相对于底层图像的宽度和高度浮动在[0.0,1.0]中。
  For example, if an image is 100 x 200 pixels (height x width) and the bounding box is [0.1, 0.2, 0.5, 0.9], the upper-left and bottom-right coordinates of the bounding box will be (40, 10) to (180, 50) (in (x,y) coordinates).
  例如,如果图像为100 x 200像素(高x宽)并且边界框为“[0.1,0.2,0.5,0.9]”,则边界框的左上角和右下角坐标为(40, 10)(180, 50)(在(x,y)坐标中)。
  Parts of the bounding box may fall outside the image.
  边界框的某些部分可能会落在图像之外。

  需要注意的是边界框的坐标信息是相对于长宽的小数,而不是实际的像素坐标。

二、参数

参数
imagesA Tensor. Must be one of the following types: float32, half. 4-D with shape [batch, height, width, depth]. A batch of images.一个Tensor,数据类型必须为float32, half。4-D形状[batch, height, width, depth]。 表示一个batch的图片。
boxesA Tensor of type float32. 3-D with shape [batch, num_bounding_boxes, 4] containing bounding boxes.一个Tensor,数据类型为float32,shape为 [batch, num_bounding_boxes, 4]的包含边界框的秩为3的矩阵。
nameA name for the operation (optional).名称(可选参数)

三、代码
  原图如下:
在这里插入图片描述

import tensorflow as tf
import cv2
import numpy as np

tf.enable_eager_execution()

img = cv2.imread("timg.jpeg") / 255.0

bbox = [[0, 0.1, 0.5, 0.5], [0.6, 0.7, 0.9, 1.0]]

bbox_img = tf.image.draw_bounding_boxes([img], [bbox])

cv2.imwrite('bbox.jpg', np.asarray(bbox_img.numpy()[0] * 255, np.uint8))

  结果如下:
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值