首页 > 解决方案 > 如何在图像上绘制区域?

问题描述

下载模型后,我在 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()

我已经使用了高度、左、上、右的所有组合,但没有任何效果。请帮帮我!!!

标签: pythonazuretensorflowdeep-learningmicrosoft-custom-vision

解决方案


        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()

推荐阅读