Resize and Remap
I have a camera which only provides 4K image, and I cannot really do the image processing I want to do on these images. It's extremely slow.
I thought of resizing the image before the processing starts, but then all the pixel coordinates shift and I cannot get the world coordinates correct, so remapping is needed.
In order to learn how the function works, I am having the following:
import cv2
import numpy as np
import argparse
RESIZE_FACTOR = 0.3 # make it this smaller
POINT = (447, 63)
if __name__ == '__main__':
# read the input image
ap = argparse.ArgumentParser()
ap.add_argument('-i', '--image', required=True, help='Path to the image')
args = vars(ap.parse_args())
raw_img = cv2.imread(args['image'], 1)
# draw a point on the raw image
cv2.circle(raw_img,POINT, 63, (0,0,255), -1)
cv2.imshow('raw',raw_img)
# resize the raw image and redraw
raw_img = cv2.imread(args['image'], 1)
resized_img = cv2.resize(raw_img, (0,0), fx=RESIZE_FACTOR, fy=RESIZE_FACTOR)
cv2.circle(resized_img,POINT, 63, (0,0,255), -1)
# use a function to map the pixels
# compare the results
cv2.imshow('resized',resized_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
As you can imagine, the red dot I drew shifted greatly between the raw and resized images, expectedly. Now I would like to use a function (possibly called remap()
) to get the actual pixel coordinate of the dot on the raw image.
However, I am not sure if this function would do the magic, neither I am sure how to use it. I think I need to find homography between these images, and it's not a straightforward process.
Is there a simple way of doing what I am having in mind?
i don't think, you need remapping at all.
if you scale an image by a size factor, you scale the coords by the same, that should be simply it, no ?
I don't think we could simply multiply the pixels with a float (factor). That sounds too good to be true.
You can give a try at least.
the coords, not the pixels ....