使用Eigen 库:进行svd分解,形如 A = U * S * V。

JacobiSVD<MatrixXd> svd(J, ComputeThinU | ComputeThinV);

U = svd.matrixU();

V = svd.matrixV();

A = svd.singularValues();

SVD分解的c++代码(Eigen 库)-LMLPHP

SVD分解的c++代码(Eigen 库)-LMLPHP

Eigen::JacobiSVD< _Matrix_Type_ > svd(a ,Eigen::ComputeThinU | Eigen::ComputeThinV);  

SVD分解的c++代码(Eigen 库)-LMLPHP

// EigenTest.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
#include <Eigen/SVD>
#include <Eigen/Dense> //using Eigen::MatrixXf;
using namespace Eigen;
using namespace Eigen::internal;
using namespace Eigen::Architecture; int main()
{
Matrix3f A;
A(,)=,A(,)=,A(,)=;
A(,)=,A(,)=,A(,)=;
A(,)=,A(,)=,A(,)=;
JacobiSVD<Eigen::MatrixXf> svd(A, ComputeThinU | ComputeThinV );
Matrix3f V = svd.matrixV(), U = svd.matrixU();
Matrix3f S = U.inverse() * A * V.transpose().inverse(); // S = U^-1 * A * VT * -1
std::cout<<"A :\n"<<A<<std::endl;
std::cout<<"U :\n"<<U<<std::endl;
std::cout<<"S :\n"<<S<<std::endl;
std::cout<<"V :\n"<<V<<std::endl;
std::cout<<"U * S * VT :\n"<<U * S * V.transpose()<<std::endl;
system("pause");
return ;
}

SVD分解 Eigen库 opencv库 - CSDN博客 https://blog.csdn.net/ouyangying123/article/details/68491414

05-23 09:26