Ask Your Question
2

Different result with fixed size matrices vs dynamic

asked 2017-05-08 22:07:47 -0500

jnuevo gravatar image

updated 2017-05-08 23:53:02 -0500

When multiplying small matrices, I get different results when using a 2x3 fixed sized matrix than a dynamic Mat_<float>.

cv::Mat_<float> B = (cv::Mat_<float>(2, 3) << 658.95428, -21.682049,
                   10.625885, 21.246431, 660.61816, 22.65921);
cv::Mat_<float> H = B.t() * B;
cv::Matx23f Bx (B);
cv::Matx33f Hx = Bx.t() * Bx;
std::cout << cv::norm(H, cv::Mat_<float>(Hx, false)) << "\n";
//0.000410005

Is this really expected?

I'm using 3.2, compiling with Clang++ and -O3, but GCC 5.4 returns the same error.

More results: Doing these operations with Eigen 3.3, the results are the same as with the fixed sized matrices. Using Octave with double precision, the results are very close to the dynamic matrix's result. It looks like the dynamic matrices use doubles inside, irrespectively of the float32 type of the operands.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-05-09 03:17:51 -0500

LBerger gravatar image

In my configuration results are differents because api called to multiply matrices is not the same.

First call :

cv::Mat_<float> H = B.t() * B;

It is cv::gemm with intel lapack in my configuration. Check which implementation is used un your configuration here

Second call cv::Matx33f Hx = Bx.t() * Bx;

it is matx implementation here

Now there is no problem in double

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-05-08 22:07:47 -0500

Seen: 143 times

Last updated: May 09 '17