OpenCV学习笔记(二十一)---三通道和四通道之间的区别

    xiaoxiao2021-03-25  160

    三通道和四通道之间的区别:

    void mixChannels(const vector<Mat>& src, vector<Mat>& dst, const int* fromTo, int npairs)

    src –矩阵的输入数组或向量。所有矩阵必须具有相同的大小和相同的深度。nsrc –src中的矩阵数。dst –输出数组或矩阵向量。所有矩阵必须分配。它们的大小和深度必须与src [0]一致。ndst – dst中的矩阵数。fromTo –指定复制哪些通道和位置的索引对数组。 fromTo [k * 2]是src中输入通道的基于0的索引。npairs –fromTo的索引对数.

    #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; int main() { Mat rgba( 4, 4, CV_8UC4, Scalar(1,2,3,4) ); cout<<"rgba ="<<endl<<rgba<<endl; cout<<"rgba.rows="<<rgba.rows<<",rgba.cols="<<rgba.cols<<endl; Mat bgr( rgba.rows, rgba.cols, CV_8UC3 ); Mat alpha( rgba.rows, rgba.cols, CV_8UC1 ); // forming an array of matrices is a quite efficient operation, // because the matrix data is not copied, only the headers Mat out[] = { bgr, alpha }; //注意out[]的含义,分裂到一个Mat数组中 // rgba[0] -> bgr[2], rgba[1] -> bgr[1], // rgba[2] -> bgr[0], rgba[3] -> alpha[0] int from_to[] = { 0,2, 1,1, 2,0, 3,3 }; //指定分裂规则 mixChannels( &rgba, 1, out, 2, from_to, 4 ); cout<<"bgr ="<<endl<<bgr<<endl; cout<<"alpha ="<<endl<<alpha<<endl; system("pause"); waitKey(0); return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-8772.html

    最新回复(0)