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

StackOverflow https://stackoverflow.com/questions/16439792

  •  14-04-2022
  •  | 
  •  

質問

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?

役に立ちましたか?

解決

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.

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top