Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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,POINT, 63, (0,0,255), -1)

    # 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),POINT, 63, (0,0,255), -1)

   # use a function to map the pixels

    # compare the results

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?