OpenCV中的Matlab SVD输出 [英] Matlab SVD output in opencv
问题描述
在Matlab SVD函数中输出三个矩阵:
in Matlab SVD function outputs three Matrices:
[U,S,V] = svd(X)
,我们可以使用S矩阵找到尽可能少的分量,以减小X的维数以保留足够的方差.
我的问题是如何使用Opencv找到S
矩阵(不是U
矩阵),是否可以使用OpenCV SVD中的构建找到S矩阵?我的意思是OpenCV SVD函数输出类似于Matlab的三个矩阵,但是我不知道它们是否相同.
这是OpenCV中的SVD:
and we can use the S Matrix to find to smallest possible number of component to reduce the dimension of X to retain enough variance.
My question is how can I find the S
Matrix (not the U
Matrix) using Opencv , Is it possible to find S Matrix using build in OpenCV SVD? I mean OpenCV SVD function outputs three matrices like the Matlab one, But I don't know if they are the same or not.
this is the SVD in OpenCV:
SVD::compute(InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags=0 )
这是Matlab SVD:
and this is Matlab SVD:
[U,S,V] = svd(X).
谢谢.
推荐答案
Matlab中的S
与OpenCV中的w
之间有一个简单的区别.
There is a simple difference between S
in Matlab and w
in OpenCV.
以这个例子为例:
A = [2, 4;
1, 3;
0, 0;
0, 0]
在Matlab中,S
为:
In Matlab, S
would be:
S = [5.47, 0 ;
0 , 0.37;
0 , 0 ;
0 , 0 ]
但是openCV给出以下内容作为w
:
But openCV gives the following as w
:
w = [5.47; 0.37]
因此,OpenCV提供了一个奇异值数组,如果您确实想要S矩阵,则可以创建一个新矩阵并将w
的元素放在对角线中.
So, OpenCV gives an array of singular values, if you really want to have the S matrix, you may create a new matrix and put w
's elements in its diagonal.
这篇关于OpenCV中的Matlab SVD输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!