OpenCV Remap with maps of shape map1 (h,w,2) and shape map2 (h,w)

Viewed 565

What does cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR) do when the map1 has a shape (h,w,2) and map2 a shape (h,w). These maps come as an output to the cv2.fisheye.initUndistortRectifyMap but the documentation is not very clear. If I change the map2 variable for a numpy.array([],dtype=np.int16) it will still give me a output that looks close to the one without omitting map2 but there are differences.

Does cv2.remap change the data type of img during this process?

1 Answers

Yes, the documentation is unfortunately not quite clear on this. However, if you take a look at cv2.remap and cv2.computeMaps this tells you what they actually mean.

In summary, the output of cv2.fisheye.initUndistortRectifyMap provides two maps where the first map is a two channel matrix where the first channel are the x coordinates and the second channel are the y coordinates for the remapping. Now what is different is that this is a result of fixed-point precision instead of a typical floating-point precision matrix. Fixed-point is primarily used for computational speedups in calculating the remapped image. The second map is a table of interpolation coefficients so that when you use this in concert with the first map, it provides nearly identical results compared to using the normal floating-point precision matrices but with great computational savings.

By omitting the second map, you are still getting decent results, but the second map being empty produces a loss of precision as you are not providing the interpolation table to produce what would have been created if you used a floating-point precision map. This is why you are viewing an image with somewhat lower quality.

Related