python - 如何在图像上绘制区域?
问题描述
下载模型后,我在 customvision.ai 上训练了模型。现在我想在图像上绘制区域,但是当我在特定位置的图像上绘制矩形框时,它显示绘制不同的位置。但是当我在 customvision.ai 中进行快速测试时,它会显示确切的位置。
Image_info=[{'height': 0.12021917,
'left': 0.34261709,
'top': 0.42452715,
'width': 0.13535754},
{'height': 0.0932456,
'left': 0.28444971,
'top': 0.24215404,
'width': 0.09772345},
{'height': 0.10766733,
'left': 0.28987014,
'top': 0.68129019,
'width': 0.11658862}]
我的代码:
import cv2
img = tf.image.decode_image(open('path of image','rb').read(),channels=3)
img=img.numpy()
for i in range(len(boxes)):
wh = np.flip(img.shape[0:2])
x1y1 = tuple((np.array(boxes[i][0:2]) * wh).astype(np.int32))
x2y2 = tuple((np.array(boxes[i][2:4]) * wh).astype(np.int32))
img = cv2.rectangle(img, x1y1, x2y2, (255,255,0), 5)
plt.imshow(img, cmap='gray')
plt.show()
我已经使用了高度、左、上、右的所有组合,但没有任何效果。请帮帮我!!!
解决方案
x = int(left * img.shape[0])
y = int(top * img.shape[1])
width = x + int(width * img.shape[0])
height = y + int(height * img.shape[1])
img = cv2.rectangle(img, (x, y), (width, height), (0, 0, 255), 2)
plt.imshow(img, cmap='gray')
plt.show()
推荐阅读
- c++ - 有没有更好的方法来反转循环中布尔值的值?
- java - 模拟 MSPaint 程序在 java 中绘制以前的笔画而不是仅绘制当前笔画
- google-sheets - 多行两列的总和
- javascript - 从消息中心访问消息
- java - 检查接口的两个对象是否相等(不覆盖)
- email - 重叠的多部分“无媒体类型”
- mysql - (SQL) 在另一个字符串列中查找实体
- arrays - 为什么我会收到“数组索引必须是正整数或逻辑值”。
- python-3.x - 我正在编写一个函数,该函数将几个字典和一个数据框作为输入并输出一个新的数据框
- python - 获取列表中给定项目的计数(不使用 numpy)