SVD在Matlab和OpenCV中计算不同的结果 [英] SVD computing different result in Matlab and OpenCV

查看:382
本文介绍了SVD在Matlab和OpenCV中计算不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么在Matlab和OpenCV中SVD计算的结果会有符号差异.我输入了相同的矩阵

I wonder why there is sign difference in result for SVD computing in Matlab and OpenCV. I input the same matrix

          3.65E+06  -2.09E+06   0
 YY =    -2.09E+06  2.45E+06    0
           0         0          0

[U,S,V] = svd(YY);//Matlab


        -0.798728902689475  0.601691066917623   0
   V =  0.601691066917623   0.798728902689475   0
         0                  0                   1

cv::SVD::compute(YY, S, U, V);//opencv

     0.798839   -0.601544   0
V =  0.601544   0.798839    0
     0          0           1

我知道他们使用相同的算法,为什么会有符号差异? 谢谢

I know that they use the same algo, why there is sign difference? Thanks

推荐答案

您正在使用哪个版本的OpenCV?

Which version of OpenCV are you using?

来自 http://code.opencv.org/issues/1498 似乎OpenCV的最新版本不再使用LAPACK来进行SVD​​(我认为是Matlab使用的). 因此,使用相同算法的假设可能不正确.

From http://code.opencv.org/issues/1498 it seems recent versions of OpenCV no longer use LAPACK to do SVD (as used by Matlab, I think). So the assumption that the same algorithm is being used might not be correct.

当然YY = U S V'

Of course YY=USV'

如果否定U和V的第一列:

If you negate the first columns of U and V:

U(:,1)=-U(:,1);
V(:,1)=-V(:,1)

您会发现U S V'仍等于YY.这适用于您的特定情况,因为YY是对称的(YY = YY').

You will find USV' still equals YY. This works for your particular case because YY is symmetric (YY=YY').

这篇关于SVD在Matlab和OpenCV中计算不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆