Ask Your Question
3

Different behaviour when using cv::Mat and cv::Matx types

asked 2013-01-18 06:51:27 -0600

jukkaho gravatar image

There seem to be very different results when using cv::Mat and cv::Matx types for doing some operations. For example:

double a[] = {
    0.8147, 0.6324, 0.9575, 0.9572,
    0.9058, 0.0975, 0.9649, 0.4854,
    0.1270, 0.2785, 0.1576, 0.8003,
    0.9134, 0.5469, 0.9706, 0.1419
};
cv::Mat A(4, 4, CV_64F, a);

std::cout << "Using Mat: " << cv::determinant(A) << std::endl;

cv::Matx44d A2(0.8147, 0.6324, 0.9575, 0.9572,
               0.9058, 0.0975, 0.9649, 0.4854,
               0.1270, 0.2785, 0.1576, 0.8003,
               0.9134, 0.5469, 0.9706, 0.1419);

std::cout << "Using Matx: " << cv::determinant(A2) << std::endl;

Produces:

Using Mat: -0.0261654
Using Matx: 0

Does anyone know what might be causing this kind of differences? The values passed to the function should be exactly the same and seem to work with smaller matrices even with cv::Matx. The result is only correct when using cv::Mat type.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-01-20 09:51:43 -0600

Mat and Matx uses different implementations of determinant function. Both of them uses LU factorization for matrices with size more then 3. Different results look like a bug. I add issue on bug tracker.

edit flag offensive delete link more
2

answered 2013-01-20 08:46:39 -0600

Michael Burdinov gravatar image

I guess it is a bug. I checked determinant() with Matx of sizes 2x2 and 3x3, and everything was computed OK. But for Matx 4x4 and larger determinant() always return 0. Maybe it simply was not implemented for Matx over certain size... Anyway this shouldn't happen so please report this issue at bug tracker.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-01-18 06:51:27 -0600

Seen: 2,092 times

Last updated: Jan 20 '13