split将(矩阵或者向量)按通道分开,merge反之;
split:
Copies each plane of a multi-channel matrix into an array.
C++: void gpu::split(const GpuMat& src, GpuMat* dst, Stream& stream=Stream::Null())
C++: void gpu::split(const GpuMat& src, vector& dst, Stream& stream=Stream::Null())
Parameters:
src – Source matrix.
dst – Destination array/vector of single-channel matrices.//有数组和容器两种形式
stream – Stream for the asynchronous version.
merge:
Makes a multi-channel matrix out of several single-channel matrices.
C++: void gpu::merge(const GpuMat* src, size_t n, GpuMat& dst, Stream& stream=Stream::Null())
C++: void gpu::merge(const vector& src, GpuMat& dst, Stream& stream=Stream::Null())
Parameters:
src – Array/vector of source matrices. //数组和容器两种形式
n – Number of source matrices.// 使用数组时指定原文件数量
dst – Destination matrix.
stream – Stream for the asynchronous version.
例:
#include <QCoreApplication>
#include <opencv2/opencv.hpp>
int main(int argc, char *argv[])
{
//QCoreApplication a(argc, argv);
cv::Mat image = cv::imread("E:/image/images/opencv-logo.png");
// cv::Mat dst[3]; //mat数组
cv::vector<cv::Mat> dst; //mat 容器
cv::Mat merge;
cv::split(image,dst); // dst 为数组与容器均可
//cv::merge(dst,3,merge); //dst为数组
cv::merge(dst,merge); //dst为容器
cv::imshow("show",image);
cv::imshow("1",dst[0]);
cv::imshow("2",dst[1]);
cv::imshow("3",dst[2]);
cv::imshow("merge",merge);
cv::waitKey();
//return a.exec();
}
其中
// cv::Mat dst[3]; //函数原型中声明为 GpuMat* dst
cv::vector<cv::Mat> dst; //原型vector<GpuMat>& dst
//还可以用std::vector
cv::vector<cv::Mat> dst;
定义方式与使用应牢记