Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use float number as opencv image pixel coordinates

Tags:

opencv

I have a texture image and some uv coordinators (some float 2D vectors). Is there any method in OpenCV can automatically interpolate the image and then I can directly use these float number as the pixel coordinator and get the correct pixel value?

I think it should be possible because in some computer vision algorithms like optic flow we will always have some sub pixel value...

like image 739
Neng Qian Avatar asked Sep 13 '25 05:09

Neng Qian


1 Answers

Remap is what you want, here is an example:

import cv2
import numpy as np

img = cv2.imread('myimage.png')
interpolated_pixel = cv2.remap(img, np.array([[2.4]], np.float32), np.array([[5.4]], np.float32), cv2.INTER_LINEAR)
print(interpolated_pixel)

You can play with different interpolation schemes, see interpolation flags

Of course you can also batch your request by providing multiple uv coordinates.

like image 153
shortcipher3 Avatar answered Sep 15 '25 20:09

shortcipher3