inversion 矩阵_矩阵逆的最快方法

小编典典

在OpenCV2.x中,有一个称为Mat::inv(int

method)计算矩阵逆的新接口。请参阅参考。

C ++:MatExpr Mat :: inv(int method = DECOMP_LU)const

参数:方法–

Matrix inversion method. Possible values are the following:

DECOMP_LU is the LU decomposition. The matrix must be non-

singular.

DECOMP_CHOLESKY is the Cholesky LL^T decomposition for

symmetrical positively defined matrices only. This type is about twice

faster than LU on big matrices.

DECOMP_SVD is the SVD decomposition. If the matrix is singular

or even non-square, the pseudo inversion is computed.

我对每种方法进行了测试,结果表明DECOMP_CHOLESKY对于测试用例最快,LU提供了类似的结果。

#include

#include

#include

#include

int main(void)

{

cv::Mat img1 = cv::imread("2.png");

cv::Mat img2, img3, img;

cv::cvtColor(img1, img2, CV_BGR2GRAY);

img2.convertTo(img3, CV_32FC1);

cv::resize(img3, img, cv::Size(200,200));

double freq = cv::getTickFrequency();

double t1 = 0.0, t2 = 0.0;

t1 = (double)cv::getTickCount();

cv::Mat m4 = img.inv(cv::DECOMP_LU);

t2 = (cv::getTickCount()-t1)/freq;

std::cout << "LU:" << t2 << std::endl;

t1 = (double)cv::getTickCount();

cv::Mat m5 = img.inv(cv::DECOMP_SVD);

t2 = (cv::getTickCount()-t1)/freq;

std::cout << "DECOMP_SVD:" << t2 << std::endl;

t1 = (double)cv::getTickCount();

cv::Mat m6 = img.inv(cv::DECOMP_CHOLESKY);

t2 = (cv::getTickCount()-t1)/freq;

std::cout << "DECOMP_CHOLESKY:" << t2 << std::endl;

cv::waitKey(0);

}

这是正在运行的结果:

LU:0.000423759

DECOMP_SVD:0.0583525

DECOMP_CHOLESKY:9.3453e-05

2020-07-28

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值