Alt*_*haf 2 opencv multiview computer-vision homography
我正在尝试从 Homography 函数中找到旋转和平移。首先我计算相应的特征点并使用findHomography()我计算单应矩阵。然后,使用decomposeHomographyMat(),我得到了四个旋转和平移结果。
我使用的代码如下:
Mat frame_1, frame_2;
frame_1 = imread("img1.jpg", IMREAD_GRAYSCALE);
frame_2 = imread("img2.jpg", IMREAD_GRAYSCALE);
vector<KeyPoint> keypts_1, keypts_2;
Mat desc1, desc2;
Ptr<Feature2D> ORB = ORB::create(100 );
ORB->detectAndCompute(frame_1, noArray(), keypts_1, desc1);
ORB->detectAndCompute(frame_2, noArray(), keypts_2, desc2);
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming");
vector<DMatch> matches;
matcher->match(desc1, desc2, matches);
vector<Point2f>leftPts, rightPts;
for (size_t i = 0; i < matches.size(); i++)
{
//queryIdx is the left Image
leftPts.push_back(keypts_1[matches[i].queryIdx].pt);
//trainIdx is the right Image
rightPts.push_back(keypts_2[matches[i].trainIdx].pt);
}
Mat cameraMatrix = (Mat1d(3, 3) << 706.4034, 0, 277.2018, 0, 707.9991, 250.6182, 0, 0, 1);
Mat H = findHomography(leftPts, rightPts);
vector<Mat> R, t, n;
decomposeHomographyMat(H, cameraMatrix, R, t, n);
Run Code Online (Sandbox Code Playgroud)
现在什么是正确的旋转和平移,至少是最合适的。我什至使用下面的函数检查了旋转是否有效,发现所有都是有效的。
bool isRotationMatrix(Mat &R)
{
Mat Rt;
transpose(R, Rt);
Mat shouldBeIdentity = Rt * R;
Mat I = Mat::eye(3, 3, shouldBeIdentity.type());
return norm(I, shouldBeIdentity) < 1e-6;
}
Run Code Online (Sandbox Code Playgroud)
请有人建议我,我应该使用什么价值。与基本矩阵分解情况不同,生成的平移是否是缩放值,可以直接使用?如果有人能指导我找到这个,我非常感谢。
感谢您!
我使用了 Vaesper 的“filterHomographyDecompByVisibleRefpoints”函数。您可以在此处查看代码。
您只需要输入旋转矩阵、从decomposeHomographyMat 获得的法线以及用于获得单应矩阵的点对应关系。上述函数将返回 2 种可能的解决方案。你可以在 Ebya 的回答中看到更多关于这个想法的信息。
在获得 2 种可能的解决方案后,您将不得不根据您的情况以某种方式进行一些检查,以便找到正确的解决方案。由于我使用单位矩阵作为相机矩阵,因此获得的平移值以像素为单位,需要使用一些外部传感器进行缩放。在我的例子中,相机和平面物体之间的距离在 z 轴上是固定的,因此,我只是计算了 1 像素代表的世界单位。
| 归档时间: |
|
| 查看次数: |
3027 次 |
| 最近记录: |