从单应性中提取变换和旋转矩阵?

时间:2011-09-12 13:44:50

标签: vb.net opencv matrix emgucv homography

我有2张来自相机的连续图像,我想估计相机姿势的变化: two pictures with camera movement

我计算光流:

Const MAXFEATURES As Integer = 100
imgA = New Image(Of [Structure].Bgr, Byte)("pic1.bmp")
imgB = New Image(Of [Structure].Bgr, Byte)("pic2.bmp")
grayA = imgA.Convert(Of Gray, Byte)()
grayB = imgB.Convert(Of Gray, Byte)()
imagesize = cvGetSize(grayA)
pyrBufferA = New Emgu.CV.Image(Of Emgu.CV.Structure.Gray, Byte) _
    (imagesize.Width + 8, imagesize.Height / 3)
pyrBufferB = New Emgu.CV.Image(Of Emgu.CV.Structure.Gray, Byte) _
    (imagesize.Width + 8, imagesize.Height / 3)
features = MAXFEATURES
featuresA = grayA.GoodFeaturesToTrack(features, 0.01, 25, 3)
grayA.FindCornerSubPix(featuresA, New System.Drawing.Size(10, 10),
                       New System.Drawing.Size(-1, -1),
                       New Emgu.CV.Structure.MCvTermCriteria(20, 0.03))
features = featuresA(0).Length
Emgu.CV.OpticalFlow.PyrLK(grayA, grayB, pyrBufferA, pyrBufferB, _
                          featuresA(0), New Size(25, 25), 3, _
                          New Emgu.CV.Structure.MCvTermCriteria(20, 0.03D),
                          flags, featuresB(0), status, errors)
pointsA = New Matrix(Of Single)(features, 2)
pointsB = New Matrix(Of Single)(features, 2)
For i As Integer = 0 To features - 1
    pointsA(i, 0) = featuresA(0)(i).X
    pointsA(i, 1) = featuresA(0)(i).Y
    pointsB(i, 0) = featuresB(0)(i).X
    pointsB(i, 1) = featuresB(0)(i).Y
Next
Dim Homography As New Matrix(Of Double)(3, 3)
cvFindHomography(pointsA.Ptr, pointsB.Ptr, Homography, HOMOGRAPHY_METHOD.RANSAC, 1, 0)

看起来正确,相机向左上方移动: optical flow 现在我想知道相机移动和旋转了多少。如果我宣布我的相机位置以及它正在看什么:

' Create camera location at origin and lookat (straight ahead, 1 in the Z axis)
Location = New Matrix(Of Double)(2, 3)
location(0, 0) = 0 ' X location
location(0, 1) = 0 ' Y location
location(0, 2) = 0 ' Z location
location(1, 0) = 0 ' X lookat
location(1, 1) = 0 ' Y lookat
location(1, 2) = 1 ' Z lookat

如何计算新位置和外观?

如果我这样做错了或者有更好的方法,那么非常欢迎任何建议,谢谢!

2 个答案:

答案 0 :(得分:8)

对于纯相机旋转R = A -1 HA。为了证明这一点,考虑图像到平面的单应性H1 = A和H2 = AR,其中A是相机固有矩阵。然后H12 = H2 * H1 -1 = A -1 RA,从中可以得到R

相机翻译难以估算。如果摄像机翻译你必须首先找到基本矩阵(不是单应性):x T Fx = 0然后将其转换为基本矩阵E = A T FA;然后,您可以将E分解为旋转和平移E = t x R,其中t x 表示矢量积矩阵。分解不明显,见this

您获得的旋转将是精确的,而翻译向量只能按比例找到。直观地说,这种缩放意味着仅从两个图像中就无法确定对象是近距离还是小距离还是远距离大。为了消除歧义,我们可以使用熟悉的尺寸对象,两点之间的已知距离等。

最后请注意,人类视觉系统也有类似的问题:虽然我们知道"我们的眼睛之间的距离,当它们聚集在物体上时,视差始终为零,仅仅由于视差,我们无法说出距离是多少。人类视觉依赖于眼睛版本信号的三角测量来计算绝对距离。

答案 1 :(得分:5)