OpenCV中的矩阵乘法 [英] Matrix multiplication in OpenCV

查看:396
本文介绍了OpenCV中的矩阵乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OpenCV中有两个Mat图像:

I have two Mat images in OpenCV:

Mat ft = Mat::zeros(src.rows,src.cols,CV_32FC1);
Mat h = Mat::zeros(src.rows,src.cols,CV_32FC1);

两个图像的尺寸相同,并且是从单个源图像计算得出的.

Both images are the same dimension and are calculated from a single source image.

我想将这两个图像相乘,但尝试同时使用这两个图像

I would like to multiply these two images but have tried using both

Mat multiply1 = h*ft;

Mat multiply2;
gemm(h,ft,1,NULL,0,multiply2);

但都会导致以下断言失败:

but both result in the following assertion failure:

OpenCV错误:未知函数,文件... matmul.cpp中的断言失败(a_size.width == len) 抛出"cv :: exception"后终止调用

OpenCV Error: Assertion failed (a_size.width == len) in unknown function, file ...matmul.cpp Termination called after throwing 'cv::exception'

我在做什么错了?

推荐答案

您说矩阵的维数相同,但是您尝试对它们执行矩阵乘法.具有相同维数的矩阵只有在正方形的情况下才可以相乘.在您的情况下,您会遇到断言错误,因为尺寸不是正方形的.乘法矩阵时必须要小心,因为乘法有两种可能的含义.

You say that the matrices are the same dimensions, and yet you are trying to perform matrix multiplication on them. Multiplication of matrices with the same dimension is only possible if they are square. In your case, you get an assertion error, because the dimensions are not square. You have to be careful when multiplying matrices, as there are two possible meanings of multiply.

矩阵乘法 是其中两个矩阵直接相乘.此操作将大小为[a x b]的矩阵A与大小为[b x c]的矩阵B相乘,以生成大小为[a x c]的矩阵C.在OpenCV中,使用简单的*运算符即可实现:

C = A * B

逐元素乘法 是通过将矩阵A中的该像素乘以矩阵B中其对应的条目而形成输出矩阵中的每个像素的地方.输入矩阵的大小应相同,输出矩阵的大小也应相同.这是通过mul()函数实现的:

output = A.mul(B);

这篇关于OpenCV中的矩阵乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆