tensorflow下图片的标注

import tensorflow as tf
import matplotlib.pyplot as plt

image_bytes = tf.gfile.FastGFile("dog.jpg", 'rb').read()  #  字节
with tf.Session() as session:
    img = tf.image.decode_jpeg(image_bytes)
    # 调整图片大小
    img_resize = tf.image.resize_image_with_crop_or_pad(img, 300, 300)
    # 按比例截取图片
    boxes = tf.constant([[[0.31, 0.22, 0.46, 0.38], [0.38, 0.53, 0.53, 0.71]]])  # 两个标注框
    # boxes = tf.constant([[[0.31, 0.22, 0.46, 0.38]]])  # 设置一个RGB,设置四个角的比例位置
    # 给原始图片添加一个图层, #因为draw_bounding_boxes输入为一个batch的很多图片所以为四维矩阵,
#这里需要加一维
    batched = tf.expand_dims(tf.image.convert_image_dtype(img_resize, tf.float32), 0)
    # 把boxes标注的框画到原始图片上
    image_with_boxes = tf.image.draw_bounding_boxes(batched, boxes)
    # 重新将原始图片设置为RGB
    image_with_boxes = tf.reshape(image_with_boxes, [300, 300, 3])
    img_array = image_with_boxes.eval()
    plt.imshow(img_array)
    plt.show()

image_with_boxes函数是用来重新将四维图片变为三维的,300*300是图像切割后的值,用原图像的话就加入print(sess.run(img_data).shape)

代码来寻找。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值