SVD分解 Eigen库 opencv库

如题,使用库函数进行svd分解,形如 A = U * S * VT.

Eigen 库:

#include 
#include 
#include   
  
//using Eigen::MatrixXf;  
using namespace Eigen;  
using namespace Eigen::internal;  
using namespace Eigen::Architecture;  

int main()
{
//-------------------------------svd测试    eigen
	Matrix3f A;
	A(0,0)=1,A(0,1)=0,A(0,2)=1;
	A(1,0)=0,A(1,1)=1,A(1,2)=1;
	A(2,0)=0,A(2,1)=0,A(2,2)=0;
	JacobiSVD 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"<



OpenCV库:


#include 
#include 
#include"opencv2/imgproc/imgproc.hpp"
#include 
 
using namespace std;
using namespace cv;

void print(CvMat& m){
	for (int row = 0; row < m.rows; row++){
		float* ptr = (float*)(m.data.ptr + row * m.step);//第row行数据的起始指针
		for (int col = 0; col < m.cols; col++)
			cout<<*(ptr+3*col)<<"     ";
		std::cout<





你可能感兴趣的:(算法学习,eigen,库,opencv)