本文主要是介绍2020.6.14_OpenCV_p46_Mat的乘法_双通道矩阵相乘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//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;}}
这篇关于2020.6.14_OpenCV_p46_Mat的乘法_双通道矩阵相乘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!