简体   繁体   中英

opencv matlab svd return different result

in my Opencv, I wrote

 float a[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
    cv::Mat M = cv::Mat(3,4,CV_32F,a);
    cv::Mat e,U,V;
    cv::SVDecomp(M, e, U, V, cv::SVD::FULL_UV);
    transpose(V,V);
    cout<<v<<endl;

And I got the V matrix:

   0.40361759    0.73286617    0.3848317    0.38974935

   0.46474412    0.2898497    -0.22260696  -0.80650246

   0.52587074   -0.1531668    -0.70928121   0.44375682

   0.58699721   -0.59618312    0.54795656  -0.027003769

But in matlab, I wrote:

>> M = [1 2 3 4; 5 6 7 8;9 10 11 12];
>> [U,e,V] = svd(M,0)

the result is:

-0.4036    0.7329    0.4453    0.3190

-0.4647    0.2898   -0.8314   -0.0934

-0.5259   -0.1532    0.3270   -0.7701

-0.5870   -0.5962    0.0591    0.5445

Why the last two columns are totally different? And how can I fix it?

Because the rank of matrix M is only 2, so the last two column vectors don't matter.

try with a full rank matrix, say M = [1,2,-1,4;5,-6,7,8;-9,10,11,12;17,43,21,-9]; and you will get the correct answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM