`cv::convertMaps` 的 "compressed form" 是如何工作的?

How does the "compressed form" of `cv::convertMaps` work?

documentation for convertMaps表示支持以下转换:

(CV_32FC1, CV_32FC1)→(CV_16SC2, CV_16UC1) This is the most frequently used conversion operation, in which the original floating-point maps (see remap) are converted to a more compact and much faster fixed-point representation. The first output array contains the rounded coordinates and the second array (created only when nninterpolation=false) contains indices in the interpolation tables.

我了解到 (CV_32FC1, CV_32FC1)(x, y) 坐标编码为浮点数。定点格式如何工作? CV_16SC2 矩阵的每个 2 通道条目中编码的内容是什么? CV_16UC1矩阵索引到什么插值表?

我将按照上次调查时的记忆进行操作。一粒盐等等。

定点格式将 (x,y) 坐标的整数部分和小数部分拆分到不同的映射中。

它的“紧凑”之处在于 CV_32FC2 或 2x CV_32FC1 每个像素使用 8 个字节,而 CV_16SC2 + CV_16UC1 每个像素使用 6 个字节。而且它仅是整数,因此使用它可以释放浮点计算资源用于其他工作。

整数部分进入第一个图,它是 2 通道的。没有惊喜。

小数部分被转换为 5 位整数,即它们乘以 32。然后将它们打包在一起,一个坐标的最低 5 位,另一个坐标的高 5 位。

得到的有趣数字的范围是 0 .. 1023,或 0b00000_00000 .. 0b11111_11111,分别编码小数部分 (0.0, 0.0) 和 (0.96875, 0.96875)(即 31/32)。

重新映射期间...

整数映射用于为每个结果像素查找源图像中插值所需的几个像素。

分数图被用作 OpenCV 内部的“插值 table”的索引。它包含将多个采样像素正确混合为一个结果像素所需的任何因素和偏移,所有这些都使用整数数学。我猜有多个 tables,每个插值方法(线性、立方、...)。