Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Different result with fixed size matrices than dynamic

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.

Different result with fixed size matrices than vs dynamic

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.

Different result with fixed size matrices vs dynamic

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.