Problems calculating determinant of larger (>= 4x4) matrices (Bug #2715)
Description
cv::determinant() has hardcoded solutions for 2x2 and 3x3 matrices and uses LU for larger ones.
For some reason trying to calculate determinant of 4x4 CV_64FC1 matrices fail and always return 0.
For example I created a random 4x4 matrix M:
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
When using MATLAB to calculate M's determinant I get -0.0262. OpenCV with CV_64FC1 matrices returns 0. If I use CV_32FC1 matrix type, I get 0.00119369 which is still not correct.
Much simpler cases fail as well:
det(I) where I is an identity matrix of any NxN dimensions should be 1.
When calculating using OpenCV:
Det 3x3 identity with doubles: 1
Det 3x3 identity with floats: 1
Det 4x4 identity with doubles: 0
Det 4x4 identity with floats: 0
Something with generic solution is seriously broken at the moment. This was tested with latest Git version from yesterday.
Associated revisions
Merge pull request #2715 from akarsakov:fix_corner_min_eigen
History
Updated by Vadim Pisarevsky about 12 years ago
looks like the bug is in your code, or your compiler is buggy.
Here is what I get on Mac with Xcode 4.5.2 (clang 4.1 compiler) and the following code:
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 }; Mat A(4, 4, CV_64F, a); printf("det(64f)=%g, det(32f)=%g\n", determinant(A), determinant(Mat_<float>(A)));
output:
det(64f)=-0.0261654, det(32f)=-0.0261654
- Status changed from Open to Cancelled
Updated by Jukka Holappa about 12 years ago
Thanks for quick feedback.
I'm currently suspecting my compiler as I needed to upgrade it very recently.