gpt4 book ai didi

c++ - iOS - C/C++ - 加速积分图像计算

转载 作者:行者123 更新时间:2023-11-30 02:49:45 25 4
gpt4 key购买 nike

我有一种计算计算机视觉应用程序中常用的积分图像 ( description here ) 的方法。

float *Integral(unsigned char *grayscaleSource, int height, int width, int widthStep)
{
// convert the image to single channel 32f
unsigned char *img = grayscaleSource;

// set up variables for data access
int step = widthStep/sizeof(float);
uint8_t *data = (uint8_t *)img;
float *i_data = (float *)malloc(height * width * sizeof(float));

// first row only
float rs = 0.0f;
for(int j=0; j<width; j++)
{
rs += (float)data[j];
i_data[j] = rs;
}

// remaining cells are sum above and to the left
for(int i=1; i<height; ++i)
{
rs = 0.0f;
for(int j=0; j<width; ++j)
{
rs += data[i*step+j];
i_data[i*step+j] = rs + i_data[(i-1)*step+j];
}
}

// return the integral image
return i_data;
}

我正在努力让它尽可能快。在我看来,这应该能够利用 Apple 的 Accelerate.framework,或者也许是 ARM 的 neon 内在函数,但我看不出究竟如何。看起来嵌套循环可能非常慢(至少对于实时应用程序而言)。

有没有人认为使用任何其他技术可以加快速度??

最佳答案

您当然可以逐行求和向量化。即 vDSP_vadd()。水平方向是vDSP_vrsum()。

如果您想编写自己的 vector 代码,水平和可能会被 psadbw 之类的东西加速,但那是英特尔。另外,看看 prefix sum algorithms ,这是著名的可并行化。

关于c++ - iOS - C/C++ - 加速积分图像计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20941037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com