ORB-SLAM-单应性变换(Homography)

ORB-SLAM-单应性变换(Homography)

在ORB-SLAM初始化的时候,作者提到,如果场景是平面,或者近似平面,或者低视差时,需要用到单应性矩阵(homography),所以简单了解下单应性变换。

单应性变换就是一个平面到另一个平面的映射关系。在OpenCV中利用两个图像中至少四个对应的特征点就能够利用findHomography函数求解一个单应性矩阵(homography matrix),然后用这个单应性矩阵H能够将源图像中的某个坐标(u,v)变换到目标图像中对应的位置(u′,v′)。

// pts_src and pts_dst are vectors of points in source

// and destination images. They are of type vector.

// We need at least 4 corresponding points.

// The calculated homography can be used to warp

// the source image to destination. im_src and im_dst are

// of type Mat. Size is the size (width,height) of im_dst.

warpPerspective(im_src, im_dst, h, size);

两个图像能够计算homography的前提是两个图像对应区域必须是同一平面。Homography是一个3*3矩阵,所以 两张图间的H映射关系就可以表示成:

ORB-SLAM-单应性变换(Homography)

Homography应用:图像矫正

假设你有一张如下所示的图片

ORB-SLAM-单应性变换(Homography)

你想点击图中书的四个顶点,然后得到正放的书:

ORB-SLAM-单应性变换(Homography)

该如何做?

1) 首先获取书本四个顶点的坐标 pts_src 。

2) 然后我们需要知道书本的宽高比,此书的宽高比是3/4,所以可使输出图像的size 为300*400,就可设其四个点的坐标为(0,0),(299,0),(299,399),(0,399)保存在pts_dst中。

3) 通过pts_src和pts_dst 获取homography。

Mat h = findHomography(pts_src, pts_dst);

4.对原图应用homography 得到输出。

warpPerspective(im_src, im_dst, h, size);


分享到:


相關文章: