1
votes

I am just trying to multiply two simple 2d matrixs.

#include <iostream>
#include "opencv2/core.hpp"

using namespace std;
using namespace cv;

int main(const int argc,const char* argv[])
{

    Mat A = (Mat_<char>(2,2) << 1,2,3,4);
    Mat B = (Mat_<char>(2,2) << 2,2,2,2);
    Mat C = A*B;

    cout << C << endl;

    return 0;
}

Why do i get a core dump (gemm) ?

terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.1.0) /OpenCV/opencv-4.1.0/modules/core/src/matmul.dispatch.cpp:337: error: (-215:Assertion failed) (type == (((5) & ((1 << 3) - 1)) + (((1)-1) << 3)) || type == (((6) & ((1 << 3) - 1)) + (((1)-1) << 3)) || type == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3)) || type == (((6) & ((1 << 3) - 1)) + (((2)-1) << 3))) in function 'gemm'

Aborted (core dumped)

1

1 Answers

0
votes

https://github.com/opencv/opencv/blob/master/modules/core/src/matmul.dispatch.cpp#L337

According to the sources, it seems that the code expects floats,

CV_Assert_N( type == B.type(), (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) );

try with Mat_<float> (worked for me)