Ask Your Question

Revision history [back]

You can compute percentage of colors by cvMean

var
   img: pIplImage;;
    channels:array[0..2] of   pIplImage;
    BGRSum :Array[0..2] of TCvScalar;
begin
    object_filename := 'd:\1.bmp';
    img := cvLoadImage(pcvchar(@object_filename[1]), 1);

    for i :=0 to 2 do
     channels[i] := cvCreateImage(cvGetImageSize(img),8,1);

     cvSplit(img,channels[0],channels[1],channels[2],0);

    for i:=0 to 2 do
       BGRSum[i] := cvSum(channels[i]);

      total := img^.width * img^.height * 255;
    writeln('red:',BGRSum[2].val[0] / total * 100);
    writeln('green:',BGRSum[1].val[0] / total * 100);
    writeln('blue:',BGRSum[0].val[0] / total * 100);

    readln;
 end.

You can compute percentage of colors by cvMeanwith cvSum.

var
   img: pIplImage;;
    channels:array[0..2] of   pIplImage;
    BGRSum :Array[0..2] of TCvScalar;
begin
    object_filename := 'd:\1.bmp';
    img := cvLoadImage(pcvchar(@object_filename[1]), 1);

    for i :=0 to 2 do
     channels[i] := cvCreateImage(cvGetImageSize(img),8,1);

     cvSplit(img,channels[0],channels[1],channels[2],0);

    for i:=0 to 2 do
       BGRSum[i] := cvSum(channels[i]);

      total := img^.width * img^.height * 255;
    writeln('red:',BGRSum[2].val[0] / total * 100);
    writeln('green:',BGRSum[1].val[0] / total * 100);
    writeln('blue:',BGRSum[0].val[0] / total * 100);

    readln;
 end.