1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| void sommeImage(IplImage* image, int h, int w, CvMat* sum, CvMat* sqsum)
{
cvmSet(sum, 0, 0, cvGet2D(image, 0, 0).val[0]);
cvmSet(sqsum, 0, 0, cvGet2D(image, 0, 0).val[0]*cvGet2D(image, 0, 0).val[0]);
// Remplissage de la première colonne :
for (int y=1;y<h;y++)
{
cvmSet(sum, y, 0, cvGet2D(image, y, 0).val[0]+cvmGet(sum, y-1, 0));
cvmSet(sqsum, y, 0, cvGet2D(image, y, 0).val[0]*cvGet2D(image, y, 0).val[0]+cvmGet(sqsum, y-1, 0));
}
// Remplissage de la première ligne :
for (int x=1;x<w;x++)
{
cvmSet(sum, 0, x, cvGet2D(image, 0, x).val[0]+cvmGet(sum, 0, x-1));
cvmSet(sqsum, 0, x, cvGet2D(image, 0, x).val[0] * cvGet2D(image, 0, x).val[0]+cvmGet(sqsum, 0, x-1));
}
// Calcul sur les autres pixels :
for (int y=1;y<h;y++)
{
for (int x=1;x<w;x++)
{
cvmSet(sum, y, x, cvGet2D(image, y, x).val[0]+cvmGet(sum, y, x-1)+cvmGet(sum, y-1, x)-cvmGet(sum, y-1, x-1));
cvmSet(sqsum, y, x, cvGet2D(image, y, x).val[0]*cvGet2D(image, y, x).val[0]+cvmGet(sqsum, y, x-1)+cvmGet(sqsum, y-1, x)-cvmGet(sqsum, y-1, x-1));
}
}
} |
Partager