如何用hough变换检测图像中的三角形?

bh2001zhh 2003-11-25 04:37:39
检测出图像中的三角形,并且算出它的顶点位置坐标。
...全文
391 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouyourich 2004-03-25
  • 打赏
  • 举报
回复
up
wqs6 2003-12-11
  • 打赏
  • 举报
回复
gz
goldcattle 2003-12-11
  • 打赏
  • 举报
回复
建议看看广义的hough变换,章鱼经的书上有。
maibishinian 2003-12-11
  • 打赏
  • 举报
回复
直线变换,得出直线方程


int CPipeiDoc::HoughLine(LINE * line,int threshold)
{
int x,y;
int r,theta;
double a,b;
int linenum = 0; //直线的条数
int h[800][181]; //统计r,theta的分布情况

//threshold = 60;
double tempcos[181],tempsin[181];
int rmax,thetamax;
double pi = 3.14159265358979323846;
int temp=0;


for(x=0;x<800;x++)
for(y=0;y<181;y++)
h[x][y] = 0;

for(x=-90;x<=90;x++)
{
tempcos[x+90] = cos((double)x/180.0*pi);
tempsin[x+90] = sin((double)x/180.0*pi);
}

for(x=10;x<310;x++)
for(y=10;y<235;y++)
{
if(bmpSource[x][y] ==0)
continue;
for(theta = -89;theta <91;theta=theta+2)
{
r=(int)(x* tempcos[theta+90] + y * tempsin[theta+90]);

h[r+400][theta+90]++;
}
}

for(int i = 0;i<8;i++)
{
for(x=0;x<800;x++)
{ for(y=0;y<181;y++)
if(temp<h[x][y])
{
temp = h[x][y];
rmax = x;
thetamax = y;
}
}

if(temp < threshold) //threshold直线像素阈值,少于此值的直线将不予考虑
break;
rmax=rmax-400;
thetamax=thetamax-90;
switch(thetamax)
{
case 0:
a = 350;
b = rmax;
break;
case 90:
a = 0;
b = rmax;
break;
case 180:
a = 350;
b = - rmax;
break;
case -90: a = 0;
b = - rmax;
break;
default:
a = -tempcos[thetamax+90]/tempsin[thetamax+90];
b = (double)rmax / tempsin[thetamax+90];
}

BOOL same = false;
int angle1,angle2;
angle1 =(int)(atan(a) /pi*180);
for(int ii = 0;ii<linenum;ii++)
{
angle2 = (int)(atan((line+ii)->a) /pi*180);

if( abs(angle1 - angle2) <=10 || 180-abs(angle1 - angle2) <=10)
{ same = true; break; }
}
if(!same)
{
(line+i)->a = a;
(line+i)->b = b;
(line+i)->c = angle1;//(int)(atan(a)/pi*180);
(line+i)->d = temp;
linenum ++;
}
else
i--;

temp = 0;
h[rmax+400][thetamax+90] = 0;
}

return linenum;
}
EvilSword 2003-12-11
  • 打赏
  • 举报
回复
直线的我做过,但是代买没有了,给你说说原理吧。

首先自己设一个极坐标系: p = f(O) (这里O指角度,p 指那个距离,也就是极坐标的两个参量啦)
根据他与直角坐标系的关系 p = x * cos(O) + y * sin(O) (式 一)

1:现在程序的输入是一列坐标 (x,y) (采样点)

2:将 角度O 从 -PI/2 到 PI/2离散话,假设为180个
将 p也从 -max到+max离散化
自己设置一个二维矩阵 O_p【O离散话个数】【p离散化个数】

3: 将 角度从最小到最大分别求 p,将O_p矩阵相应的位置 加1

4: 对1中每一个点(x,y)做一次3操作
5:求 0_p矩阵中 值大于你要求的阀值的 点,于是就得到了相应的 O和p,这就是一条直线
bh2001zhh 2003-12-10
  • 打赏
  • 举报
回复
直线的在哪儿?麻烦你发给我一下?!
bh2001zhh 2003-12-05
  • 打赏
  • 举报
回复
楼上是不是当然斑竹了?gx!!SP!!!
谁有例程?bhnew_cn@163.com
maibishinian 2003-12-05
  • 打赏
  • 举报
回复
有直线的,三角形的你改一改不知是否可行?
wqs6 2003-11-25
  • 打赏
  • 举报
回复
如何使用hough变换
http://nlpr-web.ia.ac.cn/english/rv/download/2002-4.pdf
具体如何实现
我没用过

19,469

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧