高速积分图计算

void GetGrayIntegralImage(Mat &src, Mat &integral)
{
    int *ColSum = (int*)calloc(src.cols, sizeof(int)); // 用的calloc函数, 自动内存清0
    
    for (int r = 0; r < src.rows; r++) // 原图像的每1行
    {
        unsigned char *LineSrc = src.ptr<uchar>(r); // 原图像1行的指针.

        //int *LinePInt = integral.ptr<int>(r) + 1; // 没用.
        int *LineNInt = integral.ptr<int>(r+1) + 1;

        LineNInt[-1] = 0; // 积分图中,从第2行开始, 每行第1个元素值为0.

        for (int c = 0; c < src.cols; c++) // 原图像列号.
        {
            ColSum[c] += LineSrc[c];
            LineNInt[c] = LineNInt[c - 1] + ColSum[c];
        }
    }
    
    free(ColSum);
}

猜你喜欢

转载自blog.csdn.net/gbz3300255/article/details/108828648
今日推荐