学习参考
代码演示:
#include<opencv2/opencv.hpp>
#include<iostream>
#include<string>
using namespace cv;
using namespace std;
int main() {
Mat a = (Mat_<double>(3,3)<< 1,2,3,4,5,6,7,8,9);
Mat b = (Mat_<double>(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
Mat c,d;
//矩阵的乘法
c = a * b;
//矩阵的对应位乘法
d = a.mul(b);
cout << c <<endl<<d<<endl;
//矩阵的内积
Mat e = (Mat_<int>(1, 3) << 1, 2, 3);
Mat f = (Mat_<int>(1,3) << 4,5,6);
int g = e.dot(f);
cout << g << endl;
//waitKey(0);
return(0);
}
结果:
矩阵乘法
[30, 36, 42;
66, 81, 96;
102, 126, 150]
对应位相乘
[1, 4, 9;
16, 25, 36;
49, 64, 81]
内积
32