Ask Your Question
2

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:

.
.
.


    integral(Img,M);

    CvRect region;

    region.x=0; 
    region.y=0; 
    region.width=Img.cols;
    region.height=Img.rows; //calculating sum on entire image


      double regionSum;

      int tl= IntegralImage.at<double>((region.y),(region.x));
      int tr= IntegralImage.at<double>((region.y),(region.x+region.width+1));
      int bl= IntegralImage.at<double>((region.y+region.height+1),(region.x));
      int br= IntegralImage.at<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
5

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:

isum.at<int>(row,col);
edit flag offensive delete link more

Comments

THANKS! This help me a lot!

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

Question Tools

Stats

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

Seen: 12,290 times

Last updated: Mar 25 '13