Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Get the color percentage

Hello,

I'm using Delphi XE4 with openCV. I tried to get the color percentage of RGB(ex red 50%, green 25% and blue %25) in an image, so i tried with this:

var
    mat : TCvMat;
    res : TCvScalar;
begin
    object_filename := 'd:\1.bmp';
    image := cvLoadImage(pcvchar(@object_filename[1]), CV_LOAD_IMAGE_UNCHANGED);

    mat := cvMat(image.width, image.height, 0, image);
   for i := 0 to mat.rows - 1 do
     for j := 0 to mat.cols - 1 do
     begin
         res := cvGet2D(@mat, i, j);
         writeln('red: ', res.val[0]:2:2);
         writeln('green: ', res.val[1]:2:2);
         writeln('Blue: ', res.val[2]:2:2);
         writeln('Gray: ', res.val[3]:2:2);
         writeln;
    end;

    readln;
 end.

the problem is that only "red.val[0]" got a real value, the rest of the array is 0.

what am i doing wrong here.

Thank you.