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.