c++ - OpenCV 简单的二维矩阵乘法失败
问题描述
我只是想将两个简单的二维矩阵相乘。
#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;
}
为什么我会得到核心转储(gemm)?
抛出'cv :: Exception'实例后调用终止what():OpenCV(4.1.0)/OpenCV/opencv-4.1.0/modules/core/src/matmul.dispatch.cpp:337:错误:(- 215: 断言失败) (type == (((5) & ((1 << 3) - 1)) + (((1)-1) << 3)) || type == (((6) & ((1 << 3) - 1)) + (((1)-1) << 3)) || 类型 == (((5) & ((1 << 3) - 1)) + ( ((2)-1) << 3)) || 类型 == (((6) & ((1 << 3) - 1)) + (((2)-1) << 3))) 在功能“宝石”
中止(核心转储)
解决方案
https://github.com/opencv/opencv/blob/master/modules/core/src/matmul.dispatch.cpp#L337
根据消息来源,似乎代码需要浮动,
CV_Assert_N( type == B.type(), (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) );
尝试Mat_<float>
(为我工作)
推荐阅读
- html - th 使用 col 宽度,即使它的外部 col
- mysql - SQL:对 2 列的值求和的最大值
- ruby-on-rails - 删除 www 子域,现在应用程序无法找到资产
- c++ - 使用 cmake 交叉编译 gRPC
- android - PlacePicker 位置显示在地图上
- python - 工作人员使用 ThreadPoolExecutor 跳过命令
- c# - 减少针对不同接口实现的 NUnit 测试中的重复
- git - VSCode 作为 Windows Subsystem for linux (WSL) 上的 Git 编辑器
- node.js - UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“集合”
- angular - ANGULAR 2+ 在创建后删除组件