近期学习直接法时,单层直接法中有个计算每个像素点的误差和雅可比矩阵,其中得到GetPixelValue让我困惑了好久,研究许久后发表下自己的见解,如果有错误还希望各位大佬指出,我会虚心接受批评和指导。
1.计算像素点位置
这是部分源代码
J_img_pixel = Eigen::Vector2d(
0.5 * (GetPixelValue(img2, u + 1 + x, v + y) - GetPixelValue(img2, u - 1 + x, v + y)),
0.5 * (GetPixelValue(img2, u + x, v + 1 + y) - GetPixelValue(img2, u + x, v - 1 + y))
);
2.GetPixelValue代码
// bilinear interpolation
inline float GetPixelValue(const cv::Mat &img, float x, float y) {
// boundary check
if (x < 0) x = 0;
if (y < 0) y = 0;
if (x >= img.cols) x = img.cols - 1;//GetPixelValue(img2, u + 1 + x, v + y)其中的x对应的是-half_patch_size<x<half_patch_size
if (y >= img.rows) y = img.rows - 1;
uchar *data = &img.data[int(y) * img.step + int(x)];//img.step表示表示图像矩阵中每行所包含的字节数
float xx = x - floor(x);
float yy = y - floor(y);
return float(
(1 - xx) * (1 - yy) * data[0] +
xx * (1 - yy) * data[1] +
(1 - xx) * yy * data[img.step] +
xx * yy * data[img.step + 1]
);
}
a. for (int x = -half_patch_size; x <= half_patch_size; x++)这里对应着
-half_patch_size<x<half_patch_size
b.在JacobianAccumulator::accumulate_jacobian函数中定义了
const int half_patch_size = 1;
c.至于返回值其实对应的就是双线性插值法 可以参考下下面这位博主的文章
以及我的笔记 不过我还是没弄明白data[0]和data[1]咋对应的
参考资料:
1.https://blog.csdn.net/xbinworld/article/details/65660665 双线性插值法