// 计算经过H矩阵转换的点位置
/**
* @brief TransportpointforH
* @param inpoint 输入点
* @param outpoint 输出点
* @param H 转换矩阵
*/
void TransportpointforH(Point2f &inpoint, Point2f &outpoint, Mat H) {
cv::Mat_<double> mat_point(3, 1);
mat_point(0, 0) = inpoint.x;
mat_point(1, 0) = inpoint.y;
mat_point(2, 0) = 1;
Mat mat_tmp = H * mat_point;
// std::cout << "mat_tmp=\n" << mat_tmp << std::endl;
double a1 = mat_tmp.at<double>(0, 0);
double a2 = mat_tmp.at<double>(1, 0);
double a3 = mat_tmp.at<double>(2, 0);
outpoint.x = a1 / a3; // 归一化
outpoint.y = a2 / a3; // 归一化
}
findHomography: 计算多个二维点对之间的最优单映射变换矩阵 H(3行x3列) ,使用最小均方误差或者RANSAC方法
函数功能:找到两个平面之间的转换矩阵。
Mat cv::findHomography ( InputArray srcPoints,
InputArray dstPoints,
int method = 0,
double ransacReprojThreshold = 3,
OutputArray mask = noArray(),
const int maxIters = 2000,
const double confidence = 0.995
)
具体实现
//
vector<Point2f> imgp,groundp;
// 图像点像素坐标(pixel)
imgp.push_back(Point2f(1260,864));
imgp.push_back(Point2f(1165,784));
imgp.push_back(Point2f(630,852));
imgp.push_back(Point2f(733,773));
// 真实地面点实际距离(m)
groundp.push_back(Point2f(0.9,3.32));
groundp.push_back(Point2f(0.9,4.82));
groundp.push_back(Point2f(-1.1,3.32));
groundp.push_back(Point2f(-1.1,4.85));
Mat H = findHomography(imgp, groundp);
Point2f pout;
TransportpointforH(Point2f(733, 773), pout, H);//验证,用新的点,这里就用计算的点代替
cout << pout <<endl;
本文介绍如何通过H矩阵进行点的坐标变换,并展示了findHomography函数在计算图像点到真实地面点映射中的应用,通过TransportpointforH函数验证计算结果。关键词包括H矩阵、单映射、findHomography、点变换。
1万+

被折叠的 条评论
为什么被折叠?



