step 1: 函数功能说明
mixChannels主要就是把输入的矩阵(或矩阵数组)的某些通道拆分复制给对应的输出矩阵(或矩阵数组)的某些通道中,其中的对应关系就由fromTo参数制定.
step 2: 函数原型讲解
C++: void mixChannels (const Mat* src , int nsrc , Mat* dst , int ndst , const int* fromTo , size_t npairs );
src– Input array or vector of matrices. All the matrices must have the same size and the same depth.
输入矩阵,可以为一个也可以为多个,但是矩阵必须有相同的大小和深度.
nsrcs– Number of matrices in src.
输入矩阵的个数。
dst– Output array or vector of matrices. All the matrices must be allocated. Their size and depth must be the same as in src[0].
输出矩阵,可以为一个也可以为多个,但是所有的矩阵必须事先分配空间(如用create),大小和深度须与输入矩阵等同.
ndsts– Number of matrices in dst.
输出矩阵的个数。
fromTo – Array of index pairs specifying which channels are copied and where. fromTo[k*2] is a 0-based index of the input channel in src.
fromTo[k*2+1] is an index of the output channel in dst. The continuous channel numbering is used: the first input image channels
are indexed from 0 to src[0].channels()-1 , the second input image channels are indexed from src[0].channels() to src[0].
channels() + src[1].channels()-1, and so on. The same scheme is used for the output image channels. As a special case,
when fromTo[k*2] is negative, the corresponding output channel is filled with zero .
设置输入矩阵的通道对应输出矩阵的通道,规则如下:首先用数字标记输入矩阵的各个通道。输入矩阵个数可能多于一个并且每个矩阵的通道可能不一样,
第一个输入矩阵的通道标记范围为:0 ~ src[0].channels()-1,第二个输入矩阵的通道标记范围为:src[0].channels() ~ src[0].channels()+src[1].channels()-1,
以此类推;其次输出矩阵也用同样的规则标记,第一个输出矩阵的通道标记范围为:0 ~ dst[0].channels()-1,第二个输入矩阵的通道标记范围为:dst[0].channels()
~ dst[0].channels()+dst[1].channels()-1,以此类推;最后,数组fromTo的第一个元素即fromTo[0]应该填入输入矩阵的某个通道标记,而fromTo的第二个元素即
fromTo[1]应该填入输出矩阵的某个通道标记,这样函数就会把输入矩阵的fromTo[0]通道里面的数据复制给输出矩阵的fromTo[1]通道。fromTo后面的元素也是这个
道理,总之就是一个输入矩阵的通道标记后面必须跟着个输出矩阵的通道标记。
npairs– Number of index pairs in fromTo.
即参数fromTo中的有几组输入输出通道关系,其实就是参数fromTo的数组元素个数除以2.
step 3: 源码案例