tensorflow画方框图

import matplotlib.pyplot as plt
import tensorflow as tf
# 读取图像数据
img = tf.gfile.FastGFile('/path/to/picture/3.jpg','rb').read()

with tf.Session() as sess:
    img_data_jpg = tf.image.decode_jpeg(img)
    img_data_jpg = tf.image.convert_image_dtype(img_data_jpg, dtype=tf.float32)
    img_data_jpg=tf.image.resize_images(img_data_jpg,(180,267), method=1)
    # tf.image.draw_bounding_boxes要求图像矩阵中的数字为实数
    # 利用tf.image.convert_image_dtype将图像矩阵转化为实数
    batched = tf.expand_dims(tf.image.convert_image_dtype(img_data_jpg, tf.float32), 0)
    # 边界框坐标是相对于宽度和宽度在[0.0,1.0]内的浮点数,即这里给出的都是图像的相对位置[0.1, 0.2, 0.8, 0.8]即(0.1*wide, 0.2*high)到(0.8*wide, 0.8*high)
    boxes = tf.constant([[[0.05, 0.05, 0.9, 0.7],[0.35,0.47,0.5,0.56]]])
    # 在图像上绘制边界框
    result = tf.image.draw_bounding_boxes(batched, boxes)
    plt.subplot(121), plt.imshow(img_data_jpg.eval()), plt.title('original')
    plt.subplot(122), plt.imshow(result[0].eval()), plt.title('result')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值