I am trying to access pixel values to calculate WH kernel(summed area table) using OpenCV

104 views Asked by At
integral(img,isum,CV_32F); //calculating integral of the image.




for(int i=0;i<e2;i++)//e2 is columns
{
        for(int j=0;j<=e1;j++)//e1 is rows
        {
            /*intensity = isum.at<Vec3f>(j,i);
            m1v = intensity.val[0];

            intensity = isum.at<Vec3f>((j+(p/2)),i);
            m2v=  intensity.val[0];*/

            /*intensity = isum.at<Vec3f>((j+p),i);
            m3v= intensity.val[0];*/

            /*intensity = isum.at<Vec3f>(j,(i+p));
            m4v= intensity.val[0];*/


            intensity = isum.at<Vec3f>((j+(p/2)),i+p);
            m5v= intensity.val[0];

            /*intensity = isum.at<Vec3f>(j+p,i+p);
            m6v= intensity.val[0];

            //2*(m2v)+m6v+m4v-2*(m5v)-m1v-m3v;
            featurev=2*(m5v)+m1v+m3v-2*(m2v)-m4v-m6v;
            featurev/=(p*p);

            cout<<k<<". featureV: "<<featurev<<endl;
            k++;*/
        }
}// p is patch size.

when I run this code it is causing an exception. I have tried interchanging the coordinates. I am finding the integral of an input image and accessing the pixels of isum. Please help me with the code. Thanks.

1

There are 1 answers

8
berak On BEST ANSWER

classic buffer overflow...

for(int i=0;i<e2;i++)//e2 is columns
{
   //...
   intensity = isum.at<Vec3f>((j+(p/2)),i+p); // <- this will overflow 

if you add an amount p to i, you'll either need to save a border of size p at the right end,

for(int i=0;i<e2-p;i++)//e2 is columns

or do manual bounds checking :

if ( i+p < cols ) ...

same applies to j/rows