图像积分图代码实现(c代码)

来源:互联网 发布:电子书签制作软件 编辑:程序博客网 时间:2024/06/08 16:03
// src 输入图像,灰度图(单通道)// width 输入图像的宽// height输入图像的高// dest 输出的积分图(外部开空间为 (width + 1)* (height + 1) * sizeof(int))// dest结果的第一行第一列都为0// 经过验证,结果和opencv的结果一样,可以放心使用。int integral(unsigned char * src, int width, int height, int * dest){    int destW = width + 1;    int destH = height + 1;    memset(dest, 0, destW * destH * sizeof(char));    int dx = 0;    int dy = 0;    for (int i = 0; i < height; i++)    {        dy = i + 1;        for (int j = 0; j < width; j++)        {            dx = j + 1;            dest[dy * destW + dx] = src[i * width + j] + dest[dy * destW + dx - 1] + dest[(dy - 1) * destW + dx] - dest[(dy - 1) * destW + dx -1];        }    }    return 0;}
原创粉丝点击