Ask Your Question
0

use of SVD

asked 2015-11-30 09:41:54 -0600

Carl Pun gravatar image

I would like to calculate the best fit plane with the svd class in opencv. But I do not know how to use it. I have a vector of point3f. What is the correction way to us SVD class. My problem is mainly do not know how to pass the correct parameter into the function. Would anyone provide me a sample code so that I can follow?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-11-30 15:51:34 -0600

LBerger gravatar image

updated 2015-12-01 11:57:44 -0600

My data are 9 points (0,0,1) (1,0,3) (2,0,5) (0,1,4) , (1,1,8) (2,1,7) (0,2,7) (1,2,8) (2,2,8)

I want to solve z = M p where p=[ a b c] and a xi+ byi +c =zi

Mat z=(Mat_<double>(9,1) << 1, 3, 5, 4, 8, 7, 7, 8, 8);
Mat m=(Mat_<double>(9,3) << 0, 0 ,1/**/,1,0 ,1/**/,2 ,0 ,1/**/,0 ,1 ,1/**/,1 ,1, 1/**/, 2, 1, 1/**/, 0,2, 1/**/, 1,2,1/**/, 2, 2, 1);
SVD s(m);
Mat dst;
Mat singularValue;
s.backSubst(z,dst);
cout<<"Solution z= m dst"<< dst<<endl;
s.compute(m,singularValue);
cout<<"singular value :"<<singularValue<<endl;
Mat mp=(Mat_<double>(9,4) << 0, 0 ,1,1/**/,1,0 ,3,1/**/,2 ,0 ,5,1/**/,0 ,1 ,4,1/**/,1 ,1, 8,1/**/,2, 1, 7,1/**/, 0, 2, 7,1/**/, 1,2,8,1/**/, 2, 2, 8,1);
SVD s2(mp);
Mat a;
s2.solveZ(mp,a);
cout<<"Solution mp *a =0"<<a<<endl;

and it gives answer :

Solution z= m dst[1.333333333333331;
 2.333333333333332;
 2.000000000000002]
singular value :[5.592252381884617;
 2.449489742783178;
 1.314044632919994]
Solution mp *a =0[0.3330915074747192;
 0.6439188217126393;
 -0.2753503146060172;
 0.6313484005989033]

I hope it will help you

edit flag offensive delete link more

Comments

Thank you very much. I have an additional question. What is the difference betweeen backSubst and the direct SVD calculation?(link: http://docs.opencv.org/master/df/df7/... last two public member functions

Carl Pun gravatar imageCarl Pun ( 2015-12-01 05:41:55 -0600 )edit

I have update answer.

LBerger gravatar imageLBerger ( 2015-12-01 11:58:14 -0600 )edit

I see. Thank you

Carl Pun gravatar imageCarl Pun ( 2015-12-02 07:10:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-11-30 09:41:54 -0600

Seen: 1,146 times

Last updated: Dec 01 '15

Related questions