# SVD Compute returns matrix with 0 dimension

Hello. Here is an odd problem, and i would be grateful for any advice for this simple use case of svd.

Code...

cv::Mat x1Tx2 = cv::Mat::zeros(2,2, CV_64FC1 );

cv::Mat UT = cv::Mat::zeros(2,2, CV_64FC1 );

cv::Mat V = cv::Mat::zeros(2,2, CV_64FC1 );

cv::Mat tempW = cv::Mat::zeros(2,2, CV_64FC1 );

cv::Mat VUT = cv::Mat::zeros(2,2, CV_64FC1 );

//Some code ... !!! EVEN IF THIS IS REMOVED ISSUE STILL OCCURS !!!

cout << tempW.size() << " " << V.size() << "" << UT.size() << " " << VUT.size() << endl;

cv::SVD::compute(x1Tx2, tempW, UT, V,CV_SVD_U_T);

cout << tempW.size() << " " << V.size() << "" << UT.size() << " " << VUT.size() << endl;

Output

[2 x 2] [2 x 2][2 x 2] [2 x 2]

[1 x 2] [2 x 0][2 x 0] [2 x 2]

Clearly the SVD function has changed the size of the cv::Mat which results in unusable matrices with 0 size dimensions. Any clues?

If cv::Mat not initialised, then svd produces.... [1 x 2] [0 x 0][0 x 0] [0 x 0]

edit retag close merge delete

Sort by » oldest newest most voted

I think you're passing an invalid flag, CV_SVD_U_T. The documentation for SVD::compute says

• flags – operation flags - see SVD::SVD().

There are 3 options

• SVD::MODIFY_A
• SVD::NO_UV
• SVD::FULL_UV

Maybe you want SVD::FULL_UV ?

more

Official site

GitHub

Wiki

Documentation