霍夫变换的累加器填充 [英] accumulator filling for Hough transform

查看:93
本文介绍了霍夫变换的累加器填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一段需要优化的代码.只是想与社区核实一下,看看该代码是否确实是最佳的.它填充霍夫变换的累加器.我实际上只是复制粘贴了 OpenCV 库中的大部分代码.谢谢!

I wrote a piece of code that needs to be optimized. Just felt like checking with community to see if that code is indeed optimal. It fills up the accumulator for the Hough transform. I actually just copy pasted most the code from the OpenCV library. Thanks!

int i,j,n,index;
for (i = 0;i<numrows;i++)
{
    for (j = 0;j<numcols;j++)
    {
            if (img[i*numcols + j] == 100)
        {
            for (n = 300;n<600;n++)
            {   
                index = cvRound(j*tabCos[n] + i * tabSin[n]) + (numrho-1)/2;
                accum[(n+1) * (numrho+2) + index+1]++;
            }
        }
    }
}

推荐答案

不,不是.用简单的指针算法替换尽可能多的 [] 用法来迭代有问题的数组.将不变表达式抽象为局部变量.

No it's not. Replace as many of the [] usages as you can by simple pointer arithmetic to iterate the arrays in question. Abstract out invariant expressions into local variables.

然而,第一个问题是,您的分析器是否表明此代码是整个应用程序上下文中的瓶颈.如果没有,为什么要对它进行微优化?

However, the first question is, does your profiler show that this code is a bottleneck in the context of your entire app. If not, why bother micro-optimizing this?

循环微优化 - 更喜欢第二个,因为不需要数组索引(多与添加)

loop micro-optimization - prefer the second as no array indexing required (mult versus add)

int ints[100];
int i;
int *pi;

for (i = 0; i < 100; ++i)
{
  printf("%d", ints[i]);
}

for (pi = ints; pi < ints + 100; ++pi)
{
  printf("%d", *pi);
}

这篇关于霍夫变换的累加器填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆