霍夫变换:通过OpenCL提高算法效率 [英] Hough Transform: improving algorithm efficiency over OpenCL

查看:152
本文介绍了霍夫变换:通过OpenCL提高算法效率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用霍夫变换在二进制图像中检测一个圆.

I am trying to detect a circle in binary image using hough transform.

当我使用Opencv的内置函数进行圆形霍夫变换时,可以,并且可以找到圆.

When I use Opencv's built-in function for the circular hough transform, it is OK and I can find the circle.

现在,我尝试编写自己的内核"代码来进行霍夫变换,但速度非常慢:

Now I try to write my own 'kernel' code for doing hough transform but is very very slow:

 kernel void hough_circle(read_only image2d_t imageIn, global int* in,const int w_hough,__global int * circle)
 {
     sampler_t sampler=CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;
     int gid0 = get_global_id(0);
     int gid1 = get_global_id(1);
     uint4 pixel;
     int x0=0,y0=0,r;
     int maxval=0;
     pixel=read_imageui(imageIn,sampler,(int2)(gid0,gid1));
     if(pixel.x==255)
     {
     for(int r=20;r<150;r+=2)
     {
    // int r=100;

              for(int theta=0; theta<360;theta+=2)
              {

                              x0=(int) round(gid0-r*cos( (float) radians( (float) theta) ));
                            y0=(int) round(gid1-r*sin( (float) radians( (float) theta) ));
                           if((x0>0) && (x0<get_global_size(0)) && (y0>0)&&(y0<get_global_size(1)))
                            atom_inc(&in[w_hough*y0+x0]);
              }
              if(maxval<in[w_hough*y0+x0])
              {
              maxval=in[w_hough*y0+x0];
                circle[0]=gid0;
                circle[1]=gid1;
                circle[2]=r;
              }

              }

     }

 }

使用opencv的hough opencl库有一些源代码,但是很难提取出对我有帮助的特定函数.

There are source codes for the hough opencl library with opencv, but its hard to me for extract a specific function that helps me.

任何人都可以提供一个更好的源代码示例,或者帮助我理解为什么这样效率低下吗? 代码main.cpp和kernel.cl在rar文件 http://www.files.com/set/中压缩527152684017e 使用opencv lib读取和显示图像>

Can anyone offer a better source code example, or help me understand why this is so inefficient? the code main.cpp and kernel.cl compress in rar file http://www.files.com/set/527152684017e use opencv lib for read and display image >

推荐答案

重复调用sin()cos()在计算上很昂贵.由于您只能使用相同的180值theta调用这些函数,因此可以通过预先计算这些值并将它们存储在数组中来加快处理速度.

Making repeated calls to sin() and cos() is computationally expensive. Since you only ever call these functions with the same 180 values of theta, you could speed things up by precalculating these values and storing them in an array.

一种更可靠的方法是使用中点圆算法来找到这些方法的周长用简单的整数算术圈.

A more robust approach would be to use the midpoint circle algorithm to find the perimeters of these circles by simple integer arithmetic.

这篇关于霍夫变换:通过OpenCL提高算法效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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