#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define pi 3.1415926
struct circle{
int cx;
int cy;
float cr;
};
const int m = 70;
const int n = 50;
//这里阈值就取1因为就一个圆,不存在概率问题
struct circle HoughCircle(int edge[m][n],float step_r,float step_angle,int r_min,int r_max)
{
struct circle result;
printf("%d\n",edge[0][0]);
long int i=0,j=0,k=0,r=0,num_x = 0,num_y = 0;
int a=0,b=0;
int max_para=0;
int size_r = round((r_max - r_min) / step_r) + 1;
int size_angle = round(2 * pi / step_angle);
int hough_space[m][n][size_r]; //m,n为二值图像的大小
int no_zero_x[800000];
int no_zero_y[800000];
long int index[1000];
long int count = 0;
long int length = 0;
int par1=0,par2=0,par3=0;
int circleParaXYR[1000][3];
long int num = 1;
memset(hough_space,0,sizeof(hough_space));
memset(no_zero_x,0,sizeof(no_zero_x));
memset(no_zero_y,0,sizeof(no_zero_y));
memset(index,0,sizeof(index));
memset(circleParaXYR,0,sizeof(circleParaXYR));
printf("hello\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(edge[i][j])
{
no_zero_x[num_x] = i;
no_zero_y[num_y] = j;
num_x ++;
num_y ++;
}
}
}
printf("hello1\n");
for(i=0;i<num_x;i++)
{
for(r=0;r<size_r;r++)
{
for(k=0;k<size_angle;k++)
{
a = round(no_zero_x[i] - (r_min + (r - 1) * step_r) * cos(k * step_angle));
b = round(no_zero_y[i] - (r_min + (r - 1) * step_r) * sin(k * step_angle));
if(a > 0 && a < m && b > 0 && b < n)
{
hough_space[a][b][r] += 1;
}
}
}
}
printf("hello2\n");
max_para = hough_space[0][0][0];
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<size_r;k++)
{
if(max_para < hough_space[i][j][k])
{
max_para = hough_space[i][j][k];
}
}
}
}
printf("hello5\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<size_r;k++)
{
count ++;
if(max_para == hough_space[i][j][k])
{
index[length] = count;
length ++;
}
}
}
}
printf("test\n");
j=0;
for(k=0;k<length;k++)
{
printf("what\n");
par3 = floor(index[k]/(m*n))+1;
par2 = floor((index[k]-(par3-1)*(m*n))/m)+1;
par1 = index[k] - (par3-1)*(m*n)-(par2-1)*m;
circleParaXYR[j][0] = par1;
circleParaXYR[j][1] = par2;
circleParaXYR[j][2] = par3;
}
printf("hello213\n");
if(length>=1)
{
int temp1 = circleParaXYR[0][0];
int temp2 = circleParaXYR[0][1];
float temp3 = circleParaXYR[0][2];
int c1 = temp1;
int c2 = temp2;
float c3 = temp3;
temp3 = r_min + (temp3-1)*step_r;
if(length>1)
{
for(k=1;k<length;k++)
{
c1 += circleParaXYR[k][0];
c2 += circleParaXYR[k][1];
c3 += circleParaXYR[k][2];
num ++;
}
}
c1 = round(c1/num);
c2 = round(c2/num);
c3 = round(c3/num);
c3 = r_min + (c3-1)*step_r;
result.cx = c1;
result.cy = c2;
result.cr = c3;
printf("圆心x坐标:%d,圆心y坐标:%d,圆半径:%f\n",c1,c2,c3);
}
return result;
}
int main()
{
int i,j;
int test[m][n];
memset(test,0,sizeof(test));
long long int count=0;
float step_r = 0.5;
float step_angle = 0.1;
int r_min = 20;
int r_max = 30;
/* for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
test[j][i] = c[count];
count++;
}
}*/
struct circle t = HoughCircle(test,step_r,step_angle,r_min,r_max);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 7 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/2241f086a97c494bbe8bb61a420ea8a8_qq_34717531.jpg!1)
学术菜鸟小晨
- 粉丝: 1w+
- 资源: 5001
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)