cvSplit()是openCV中的一个函数,它分别复制每个通道到多个单通道图像。
void cvSplit( const CvArr* src, CvArr* dst0, CvArr* dst1, CvArr* dst2, CvArr* dst3 );.cvSplit()函数将复制src的各个通道到图像dst0,dst1,dst2和dst3中。如果源图像少于4个通道的情况下,那么传递给cvSplit()的不必要的目标参数可设置为NULL。
cvSum函数
其结构
CvScalar cvSum(//计算arr各通道所有像素总和 CvArr* arr//目标矩阵 );
program cv_Sum;{$APPTYPE CONSOLE}
{$R *.res}usesSystem.SysUtils,ocv.highgui_c,ocv.core_c,ocv.core.types_c,ocv.imgproc_c,ocv.imgproc.types_c,uResourcePaths;constfilename = cResourceMedia + 'cat2.jpg';varimg: pIplImage;channels: array [0 .. 2] of pIplImage;BGRSum: Array [0 .. 2] of TCvScalar;i, total: Integer;begintryimg := cvLoadImage(filename);for i := 0 to 2 dochannels[i] := cvCreateImage(cvGetSize(img), 8, 1);cvSplit(img, channels[0], channels[1], channels[2]);for i := 0 to 2 doBGRSum[i] := cvSum(channels[i]);total := img^.width * img^.height * 255;WriteLn('Color percentage of RGB(ex red 50%, green 25% and blue %25) in an image is');WriteLn('red: ', BGRSum[2].val[0] / total * 100:2:2);WriteLn('green: ', BGRSum[1].val[0] / total * 100:2:2);WriteLn('blue: ', BGRSum[0].val[0] / total * 100:2:2);cvNamedWindow('channels0');cvShowImage('channels0', channels[0]);cvNamedWindow('channels1');cvShowImage('channels1', channels[1]);cvNamedWindow('channels2');cvShowImage('channels2', channels[2]);cvWaitKey();readln;excepton E: Exception doWriteLn(E.ClassName, ': ', E.Message);end;end.