I have an image of size 720 x 1280, and I can resize it to 256 x 256 like this
import cv2
img = cv2.imread('sample_img.jpg')
img_small = cv2.resize(img, (256, 256), interpolation=cv2.INTER_CUBIC)
Say I have a bounding box in the original image (top left corner (50, 100), bottom right corner (350, 300)), how do I get the coordinates of new bounding box?
You can do it by simply using the scale of your resize operation. Like this -
import numpy as np# Get the scaling factor
# img_shape = (y, x)
# reshaped_img_shape = (y1, x1)
# the scaling factor = (y1/y, x1/x)
scale = np.flipud(np.divide(reshaped_img_shape, img_shape)) # you have to flip because the image.shape is (y,x) but your corner points are (x,y)#use this on to get new top left corner and bottom right corner coordinates
new_top_left_corner = np.multiply(top_left_corner, scale )
new_bottom_right_corner = np.multiply(bottom_right_corner, scale )