tensorflow在图像中加入标注框

tensorflow提供了给图像加入标注框的函数。tf.image.draw_bounding_boxes(img, boxes).img是目标图像,不过需要变成四维,增加一个维度,利用tf.expand_dims函数,这个函数。boxes是一个三维的数组,里面的元素有4个维度,分别表示框的位置,这些数值是相对位置,

例如:

import matplotlib.pyplot as plt;
import tensorflow as tf;

image_raw_data_jpg = tf.gfile.FastGFile('11.jpg', 'r').read()

with tf.Session() as sess:
	img_data_jpg = tf.image.decode_jpeg(image_raw_data_jpg)
	img_data_jpg = tf.expand_dims(tf.image.convert_image_dtype(img_data_jpg, dtype=tf.float32), 0)
	boxes = tf.constant([[[0.05, 0.5, 0.9, 0.7]]])
	result = tf.image.draw_bounding_boxes(img_data_jpg, boxes)
	# print sess.run(img_data_jpg).shape

	plt.figure(1)
	plt.imshow(result.eval().reshape([1200, 1920, 3]))
	plt.show()

结果:


评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值