Ask Your Question

Revision history [back]

Calculating sum using integral image

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.rows;
    region.height=Img.cols; //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.

Calculating sum using integral image

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.rows;
    region.height=Img.cols; 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.