前言
opencv中Mat存在各種類型,其中mat有一個type()的函數可以返回該Mat的類型。類型表示了矩陣中元素的類型以及矩陣的通道個數,它是一系列的預定義的常量,其命名規則為CV_(位數)+(數據類型)+(通道數)。U表示無符號整數,S表示有符號整數,F表示浮點數。
具體的有以下值:
err:
OpenCV Error: Assertion failed (type == B.type()) in gemm, file /home/nvidia/build-opencv/opencv/modules/core/src/matmul.cpp, line 1558 terminate called after throwing an instance of 'cv::Exception' what(): /home/nvidia/build-opencv/opencv/modules/core/src/matmul.cpp:1558: error: (-215) type == B.type() in function gemm Aborted (core dumped)
code:
cv::Mat rot_tmp; rot.convertTo(rot_tmp, CV_32FC1); cv::Mat P = (cv::Mat_<float>(3,4) << 0, lineL, 0, 0, 0, 0, -lineL, 0, 0, 0, 0, -lineL); std::cout << "rot.type: " << rot.type()<< std::endl; std::cout << "rot_tmp.type: " << rot_tmp.type()<< std::endl; std::cout << "P.type: " << P.type()<< std::endl; P = rot_tmp.rowRange(0,2)*P;
注意
矩陣乘法,AB = A * B,
三者中A的列數與B的行數相等,且三者的數據類型必須完全一致, 且只能是CV_32F、 CV_64FC1、 CV_32FC2、 CV_64FC2四種數據類型中其一,否則會出錯。
terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(3.4.3) /***/modules/core/src/matmul.cpp:1558: 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
參考
1. OpenCV中Mat的type;
2. opencv_mat;
完