我想用霍夫變換在二值圖像中檢測一個圓。霍夫變換:通過OpenCL提高算法效率
當我使用Opencv的循環Hough變換的內置函數時,它是可以的,我可以找到圓。
現在我試着寫我自己的「內核」的代碼做Hough變換,但非常非常慢:
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的霍夫的OpenCL庫的源代碼,但它很難我提取幫助我的特定功能。
任何人都可以提供一個更好的源代碼示例,或幫助我理解爲什麼這是如此低效? 代碼的main.cpp和RAR文件http://www.files.com/set/527152684017e用於讀取和顯示圖像>
請添加指向現有源代碼的鏈接,例如OpenCL庫或其他。請同時提供您的基準,以便人們可以瞭解您已經完成了哪些工作。 –