简体   繁体   中英

OpenCV simple 2D matrix multiplication fails

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)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM