欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

OpenCV和Eigen求解线性方程Ax=B

时间:2023-05-30

#include #include #include #include #include int test_opencv(){ printf("nSolve equation:AX=bnn"); cv::Mat A = (cv::Mat_(4, 3) << 2926.36, 2607.79, 1, 587.093, 2616.89, 1, 537.031, 250.311, 1, 1160.53, 1265.21, 1);// 4x3 cv::Mat B = (cv::Mat_(4, 3) << 320.389, 208.197, 1, 247.77, 209.726, 1, 242.809, 283.182, 1, 263.152, 253.715, 1); cv::Mat X; std::cout << "A=" << std::endl << A << std::endl; std::cout << "B=" << std::endl << B << std::endl; cv::solve(A, B, X, cv::DECOMP_SVD); std::cout << "X=" << std::endl << X << std::endl; cv::Mat a1 = (cv::Mat_(1, 3) << 1864, 1273, 1); cv::Mat b1 = a1*X; std::cout << "b1=" << std::endl << b1 << std::endl; std::cout << "真实值为:" << "283.265, 253.049, 1" << std::endl; return 0;}void SVD(){ double _a[12] = {2926.36, 2607.79, 1, 587.093, 2616.89, 1, 537.031, 250.311, 1, 1160.53, 1265.21, 1}; double _b[12] = {320.389, 208.197, 1, 247.77, 209.726, 1, 242.809, 283.182, 1, 263.152, 253.715, 1}; auto A = Eigen::Map(_a, 3, 4).transpose(); auto B = Eigen::Map(_b, 3, 4).transpose(); std::cout<< "A=n"< svd(A, Eigen::ComputeThinU | Eigen::ComputeThinV); auto x = svd.solve(B); std::cout<< "x=n"<

输出:

Solve equation:AX=bA=[2926.3601, 2607.79, 1; 587.09302, 2616.8899, 1; 537.03101, 250.311, 1; 1160.53, 1265.21, 1]B=[320.38901, 208.19701, 1; 247.77, 209.726, 1; 242.80901, 283.18201, 1; 263.15201, 253.715, 1]X=[0.031037141, -0.00071162981, 4.425834e-11; 0.0014961162, -0.031319518, -2.7852835e-11; 225.57526, 292.40707, 1.0000001]b1=[285.33304, 251.21085, 1.0000001]真实值为:83.265, 253.049, 1===================================A=2926.36 2607.79 1587.093 2616.89 1537.031 250.311 11160.53 1265.21 1B=320.389 208.197 1 247.77 209.726 1242.809 283.182 1263.152 253.715 1x= 0.0310371 -0.000711644 2.71051e-20 0.00149613 -0.0313195 5.42101e-20 225.575 292.407 1

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。