0

有人可以帮我,我们如何计算转换图像中关键点的新位置,关键点是在原始图像中检测到的。我正在使用 opencv 单应矩阵和 warpPerspective 来制作转换后的图像。

这是一个代码..

...
 std::vector< Point2f > points1,points2;
 for( int i = 0; i < matches1.size(); i++ )
    {
     points1.push_back( keypoints_input1[matches1[i].queryIdx ].pt );
     points2.push_back( keypoints_input2[matches1[i].trainIdx ].pt );
    }
 /* Find the Homography Matrix for current and next frame*/
 Mat H1 = findHomography( points2, points1, CV_RANSAC );
 /* Use the Homography Matrix to warp the images*/
cv::Mat result1;
warpPerspective(input2, result1, H1, Size(input2.cols+150, input2.rows+150),              
INTER_CUBIC);
...
}

现在我想计算结果 1 图像中点 2 的新位置。

例如在下面的转换图像中,我们知道角点。现在我想计算转换前关键点的新位置 {(x1,y1),(x2,y2),(x3,y3)...},我们如何计算它?

更新:opencv 'perspectiveTransform' 做了我想做的事。

4

1 回答 1

2

让我们称使用单应性I'扭曲图像获得的图像。IH

如果您在原始图像中提取了关键点m i = (x i , y i , 1) ,则可以使用单应变换获得扭曲图像中I的关键点m' iI': S * m' i = H * m i。注意比例因子 S,如果您想要以像素为单位的关键点坐标,则必须缩放m' i以使第三个元素为 1。

如果您想了解比例因子的来源,请查看Homogeneous Coordinates

此外,还有一个 OpenCV 函数可以将此转换应用于点数组:(perspectiveTransform文档

于 2014-03-18T07:52:48.153 回答