首页 > 解决方案 > How does the "compressed form" of `cv::convertMaps` work?

问题描述

The documentation for convertMaps says that it supports the following transformation:

(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.

I understand that (CV_32FC1, CV_32FC1) is encoding (x, y) coordinates as floats. How does the fixed point format work? What is encoded in each 2-channel entry of the CV_16SC2 matrix? What interpolation tables does the CV_16UC1 matrix index into?

标签: opencvinterpolation

解决方案


我会按照我上次调查时记得的内容进行。一粒盐等等。

定点格式将 (x,y) 坐标的整数和小数部分拆分为不同的地图。

它是“紧凑的”,即CV_32FC22xCV_32FC1每个像素使用 8 个字节,而每个像素CV_16SC2 + CV_16UC1使用 6 个字节。它也是仅整数,因此使用它可以释放浮点计算资源用于其他工作。

整数部分进入第一个映射,即 2 通道。那里没有惊喜。

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

生成的有趣数字的范围为0 .. 10230b00000_00000 .. 0b11111_11111,分别编码小数部分 (0.0, 0.0) 和 (0.96875, 0.96875)(即 31/32)。

在重新映射期间...

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

分数图被视为“插值表”的索引,该表是 OpenCV 内部的。它包含将几个采样像素正确混合为一个结果像素所需的任何因素和变化,所有这些都使用整数数学。我想有多个表,每个插值方法(线性,三次,...)一个。


推荐阅读