通过hough变换检测直线
2009-05-19 09:44
447 查看
/*
函数功能:通过hough变换检测直线
参数说明:imgBinaryIn,表示二值图象
width,表示图象宽
height,表示图象高
houghBuf,表示hough变换需要的缓冲区指针
houghWidth,表示hough变换需要的缓冲区的宽
houghHeight,表示hough变换需要的缓冲区的高
radiusResolution,表示hough变换的极坐标半径的检测分辨率
angleResolution,表示hough变换的角度检测分辨率
radius,表示返回hough变换检测出来的最长直线的极半径
angle,表示返回hough变换检测出来的最长直线的角度
*/
void ImageAlgorithm::HoughTransForm(unsigned char * imgBinaryIn,int width,int height,int *houghBuf,int houghWidth,int houghHeight,float radiusResolution,float angleResolution,float *radius,float *angle)
{
int i,j;
for(i=0;i<houghHeight;i++)
{
for (j=0;j<houghWidth;j++)
{
*(houghBuf+i*houghWidth+j) = 0;
}
}
int r,a;
float tempR,tempA;
//遍历图象数据
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
if(*(imgBinaryIn+i*width+j)==1)
{
//a代表角度的循环变量,在变换空间累加数组的垂直方向上
for(a=0;a<houghHeight;a++)
{
//按照给定变换角度的分辨率,求取角度
tempA = (a-houghHeight/2)*angleResolution;
//根据当前遍历的角度及x,y值求取对应极坐标
tempR = (j-width/2)*cos(tempA*2*PI/360) + (i-height/2)*sin(tempA*2*PI/360);
r = tempR/radiusResolution;
//累加数组
*(houghBuf+a*houghWidth+r+houghWidth/2)+=1;
}
}
}
}
//求累加数组的极大值,并记录此时的数组坐标
int max,maxR,maxA;
max = *(houghBuf+0*houghWidth+0);
maxR = 0;
maxA = 0;
for(a=0;a<houghHeight;a++)
{
for(r=0;r<houghWidth;r++)
{
if(max<=*(houghBuf+a*houghWidth+r))
{
max = *(houghBuf+a*houghWidth+r);
maxR = r;
maxA = a;
}
}
}
//将极大值位置转换成极坐标半径和角度,并通过参数返回
*radius = (maxR-houghWidth/2)*radiusResolution;
*angle = (maxA-houghHeight/2)*angleResolution;
}
函数功能:通过hough变换检测直线
参数说明:imgBinaryIn,表示二值图象
width,表示图象宽
height,表示图象高
houghBuf,表示hough变换需要的缓冲区指针
houghWidth,表示hough变换需要的缓冲区的宽
houghHeight,表示hough变换需要的缓冲区的高
radiusResolution,表示hough变换的极坐标半径的检测分辨率
angleResolution,表示hough变换的角度检测分辨率
radius,表示返回hough变换检测出来的最长直线的极半径
angle,表示返回hough变换检测出来的最长直线的角度
*/
void ImageAlgorithm::HoughTransForm(unsigned char * imgBinaryIn,int width,int height,int *houghBuf,int houghWidth,int houghHeight,float radiusResolution,float angleResolution,float *radius,float *angle)
{
int i,j;
for(i=0;i<houghHeight;i++)
{
for (j=0;j<houghWidth;j++)
{
*(houghBuf+i*houghWidth+j) = 0;
}
}
int r,a;
float tempR,tempA;
//遍历图象数据
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
if(*(imgBinaryIn+i*width+j)==1)
{
//a代表角度的循环变量,在变换空间累加数组的垂直方向上
for(a=0;a<houghHeight;a++)
{
//按照给定变换角度的分辨率,求取角度
tempA = (a-houghHeight/2)*angleResolution;
//根据当前遍历的角度及x,y值求取对应极坐标
tempR = (j-width/2)*cos(tempA*2*PI/360) + (i-height/2)*sin(tempA*2*PI/360);
r = tempR/radiusResolution;
//累加数组
*(houghBuf+a*houghWidth+r+houghWidth/2)+=1;
}
}
}
}
//求累加数组的极大值,并记录此时的数组坐标
int max,maxR,maxA;
max = *(houghBuf+0*houghWidth+0);
maxR = 0;
maxA = 0;
for(a=0;a<houghHeight;a++)
{
for(r=0;r<houghWidth;r++)
{
if(max<=*(houghBuf+a*houghWidth+r))
{
max = *(houghBuf+a*houghWidth+r);
maxR = r;
maxA = a;
}
}
}
//将极大值位置转换成极坐标半径和角度,并通过参数返回
*radius = (maxR-houghWidth/2)*radiusResolution;
*angle = (maxA-houghHeight/2)*angleResolution;
}
相关文章推荐
- 通过hough变换检测直线
- 通过hough变换检测直线
- Hough变换检测直线的Java实现
- 利用Hough变换实现直线检测的代码
- hough变换检测直线和圆
- hough变换检测直线
- Python语言opencv使用笔记(十一)(详解hough变换检测直线与圆)
- Hough变换检测直线
- 霍夫变换直线检测houghlines及opencv的实现分析
- Hough变换直线检测
- opencv+vs2008实现canny边缘检测与hough变换检测直线并用红线在原图标出直线
- hough变换是如何检测出直线和圆的?
- hough变换检测直线
- 图像处理 C语言 hough变换 检测直线
- Hough变换检测直线和圆
- Hough变换检测直线、圆等图形的原理
- Hough变换检测直线
- 【转】利用Hough变换实现直线检测的代码
- Halcon_Hough变换检测直线,检测圆
- hough变换是如何检测出直线和圆的