jisoochoi / cvblob

Automatically exported from code.google.com/p/cvblob
GNU Lesser General Public License v3.0
0 stars 0 forks source link

advance a pointer instead of calcuating it every time? #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In the cvRenderBlob r iterates over rows and c iterates over columns.
On each step you calculate three pointers but instead you can advance the 
pointer and access the matrix elements in less overhead.

an example:
float s = 0.0f;
  for(int row=0; row<mat->rows; row++ ) {
    const float* ptr = (const float*)(mat->data.ptr + row * mat->step);
    for( col=0; col<mat->cols; col++ ) {
      s += *ptr++;
    }
  }
  return( s );
}

instead of something like:
for (unsigned int r=blob->miny; r<blob->maxy; r++, labels+=stepLbl, 
source+=stepSrc, imgData+=stepDst)
{
    for (unsigned int c=blob->minx; c<blob->maxx; c++)
    {
        if (labels[c]==blob->label)
        {
            imgData[imgDest->nChannels*c+0] = (unsigned char)((1.-alpha)*source[imgSource->nChannels*c+0]+alpha*color.val[0]);
            imgData[imgDest->nChannels*c+1] = (unsigned char)((1.-alpha)*source[imgSource->nChannels*c+1]+alpha*color.val[1]);
            imgData[imgDest->nChannels*c+2] = (unsigned char)((1.-alpha)*source[imgSource->nChannels*c+2]+alpha*color.val[2]);
        }
    }
}

Original issue reported on code.google.com by pablo.platt@gmail.com on 17 Nov 2010 at 10:56

GoogleCodeExporter commented 8 years ago
Sorry, I think I'm wrong.

Original comment by pablo.platt@gmail.com on 17 Nov 2010 at 11:21

GoogleCodeExporter commented 8 years ago
Hi Pablo,

It's possible that this loop can be optimized. I'll take a look.

Thanks!

Original comment by grendel....@gmail.com on 18 Nov 2010 at 9:15