单目测距中的H矩阵

本文介绍如何通过H矩阵进行点的坐标变换,并展示了findHomography函数在计算图像点到真实地面点映射中的应用,通过TransportpointforH函数验证计算结果。关键词包括H矩阵、单映射、findHomography、点变换。
    // 计算经过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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值