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<Mat>& 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() .

 

附上程序運行的結果:還是挺有意思的:

 

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com 联系我们: