OpenCV中 Mat 按行或按列合并程序
生活随笔
收集整理的這篇文章主要介紹了
OpenCV中 Mat 按行或按列合并程序
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
按行合并
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;Mat mergeRows(Mat A, Mat B)
{CV_ASSERT(A.cols == B.cols&&A.type() == B.type());int totalRows = A.rows + B.rows;Mat mergedDescriptors(totalRows, A.cols, A.type());Mat submat = mergedDescriptors.rowRange(0, A.rows);A.copyTo(submat);submat = mergedDescriptors.rowRange(A.rows, totalRows);B.copyTo(submat);return mergedDescriptors;
}int main()
{Mat B = (cv::Mat_<double>(1, 2) << 1,2);Mat C = (cv::Mat_<double>(2, 2) << 3, 2,3,2);Mat A = mergeRows(B,C);cout << "A:" << A << endl;
}
測試結(jié)果如圖1
按列合并:
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;Mat mergeRows(Mat A, Mat B)
{assert(A.rows == B.rows&&A.type() == B.type());int totalCols = A.cols + B.cols;Mat mergedDescriptors(A.rows, totalCols, A.type());Mat submat = mergedDescriptors.colRange(0, A.cols);A.copyTo(submat);submat = mergedDescriptors.colRange(A.cols, totalCols);B.copyTo(submat);return mergedDescriptors;
}
int main()
{Mat B = (cv::Mat_<double>(2, 1) << 1,2);Mat C = (cv::Mat_<double>(2, 2) << 3, 2,3,2);Mat A = mergeRows(B,C);cout << "A:" << A << endl;
}
測試結(jié)果如圖2,
總結(jié)
以上是生活随笔為你收集整理的OpenCV中 Mat 按行或按列合并程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenCV中图像Mat存储格式和MAT
- 下一篇: 如何查看OpenCV自带函数的源代码