Ask Your Question

Calculating sum using integral image

asked 2013-03-24 22:06:51 -0600

updated 2013-03-24 22:11:17 -0600

I am attempting to calculate sums over rectangular areas in images using the Viola & Jones trick with the integral image.

Im using c++ and the cv::Mat class.

Here is what I am doing:



    CvRect region;

    region.height=Img.rows; //calculating sum on entire image

      double regionSum;

      int tl=<double>((region.y),(region.x));
      int tr=<double>((region.y),(region.x+region.width+1));
      int bl=<double>((region.y+region.height+1),(region.x));
      int br=<double>((region.y+region.height+1),(region.x+region.width+1));

      regionSum = br-bl-tr+tl;

      cout<<"tl: "<<tl<<" tr: "<<tr<<" bl: "<<bl<<" br: "<<br<<" sum: "<<regionSum<<endl;

For some images those parameters output zero, for others there is a result but that doesn't really make sense, so obviously I am doing something wrong-

Thanks in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-03-25 02:02:54 -0600

berak gravatar image

your integral img has int type(by default), you're accessing it as double.

so either specify the right type:

integral(img,isum,CV_64F); // omitting the type param makes an int image

or access it as int:<int>(row,col);
edit flag offensive delete link more


THANKS! This help me a lot!

IKS gravatar imageIKS ( 2014-07-23 02:50:01 -0600 )edit

Question Tools


Asked: 2013-03-24 22:06:51 -0600

Seen: 12,115 times

Last updated: Mar 25 '13