//2020.6.14_OpenCV_p46_Mat的乘法_双通道矩阵相乘
//两个Mat只能同时是float,或double类型
//2020.6.14_OpenCV_p46_Mat的乘法_双通道矩阵相乘
//两个Mat只能同时是float,或double类型
#include <opencv2/core.hpp>
using namespace cv;
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
Mat src3 = (Mat_<float>(2,3)<<1,2,3,4,5,6);
Mat src4 = (Mat_<float>(3,2)<<6,5,4,3,2,1);
Mat dst1 = src3 * src4;
for (int r = 0; r < dst1.rows; r++)
{
const float *ptr = dst1.ptr<float>(r);
//如果写成cost int *ptr=dst1.ptr<int>(r);则会计算错误。
for (int c = 0; c < dst1.cols; c++)
cout << ptr[c] << ",";
cout << endl;
}
cout << "双通道矩阵相乘" << endl;
Mat src5 = (Mat_<Vec2f>(2, 1) << Vec2f(1, 2), Vec2f(3, 4));
Mat src6 = (Mat_<Vec2f>(1, 2) << Vec2f(10, 20), Vec2f(5, 15));
Mat dst2 = src5 * src6;
for (int r = 0; r < dst2.rows; r++)
{
const Vec2f *ptr = dst2.ptr<Vec2f>(r);
//如果写成cost int *ptr=dst2.ptr<int>(r);则会计算错误。
for (int c = 0; c < dst2.cols; c++)
cout << ptr[c] << ",";
cout << endl;
}
}