c++ opencv 分离r,g,b三通道

今天学习了c++ opencv 分离通道的方法 ,操作很奇怪的...

 

 

 

Mat bgr_res[3];
	Mat bgr[3];
	for( int j = 0 ; j < 3; j++)
	{
		split(src, bgr);
		for (int i=0; i<3; ++i)
		{
			if (i != j )
				bgr[i] = Mat::zeros(src.size(), bgr[0].type());
		}
		merge(bgr, 3, bgr_res[j]);
	}


merge:

 

Composes a multi-channel array from several single-channel arrays.

C++: void merge (const Mat* mv, size_t count, OutputArray dst )
C++: void merge (const vector& mv, OutputArray dst )
Python: cv2. merge (mv [, dst ] ) → dst ¶
C: void cvMerge (const CvArr* src0, const CvArr* src1, const CvArr* src2, const CvArr* src3, CvArr* dst )
Python: cv. Merge (src0, src1, src2, src3, dst ) → None ¶
Parameters:
  • mv – Source array or vector of matrices to be merged. All the matrices in mv  must have the same size and the same depth.
  • count – Number of source matrices when  mv  is a plain C array. It must be greater than zero.
  • dst – Destination array of the same size and the same depth as mv[0] . The number of channels will be the total number of channels in the matrix array.

The functions mergemerge several arrays to make a single multi-channel array. That is, each element of the output array will be a concatenation of the elements of the input arrays, where elements of i-th input array are treated asmv[i].channels()-element vectors.

The functionsplit() does the reverse operation. If you need to shuffle channels in some other advanced way, usemixChannels() .

 

附上程序运行的结果:还是挺有意思的:

 

 

你可能感兴趣的:(OPENCV,c++,concatenation,arrays,merge,dst,parameters)