Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compute SVD and and verify that the ratio of the first-to-last singular value is sane with OpenCV?

Tags:

opencv

svd

I want to verify that homography matrix will give good results and this this answer has an answer for it - but, I don't know how to implement the answer.
So can anyone recommend how I may use OpenCV to compute SVD and and verify that the ratio of the first-to-last singular value is sane?

like image 400
Tony Avatar asked Mar 25 '23 01:03

Tony


2 Answers

There are several ways to compute the SVD in OpenCV:

cv::SVD homographySVD(homography, cv::SVD::FULL_UV); // constructor
// or: 
homographySVD(newHomography, cv::SVD::FULL_UV); // operator ()
homographySVD.w.at<double>(0, 0); // access the first singular value

// alternatives:
cv::SVD::compute(homography, w); // compute just the singular values
cv::eigen(homography, w);

Have a look at the documentation for cv::SVD and cv::eigen for more details.

like image 117
bjoernz Avatar answered Apr 24 '23 08:04

bjoernz


You can compute SVD in python using numpy. For example:

    import numpy as np
    U, s, V = np.linalg.svd(a, full_matrices=True)

which factors the matrix a of dimension M x N as u * np.diag(s) * v, where u and v are unitary and s is a 1-d array of a's singular values.

More can be found here.

like image 27
gaya Avatar answered Apr 24 '23 09:04

gaya