0

I have trained model on customvision.ai after I have downloaded model. Now I want to draw region on images but when I draw rectangle boxes on images on particular location it show draw different location. But when I Quick test in customvision.ai it show exact location.

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}]

My code:

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

I have used all combination of height, left, top, right but nothing works. Please help me out!!!

BhuriStray
  • 87
  • 1
  • 12

2 Answers2

0

https://docs.opencv.org/master/d6/d6e/group__imgproc__draw.html#ga07d2f74cadcf8e305e810ce8eed13bc9

"The function cv::rectangle draws a rectangle outline or a filled rectangle whose two opposite corners are pt1 and pt2."

height and width is not point you must be add a top left point coordinates and find bottom right point and use it

also normalization required

Birol Kuyumcu
  • 1,195
  • 7
  • 17
  • I have create all combination of height, left, top, right and check which is combination is correct but nothing combination works fine – BhuriStray Aug 15 '21 at 07:23
0
        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()
BhuriStray
  • 87
  • 1
  • 12