HALCON-从入门到入门-霍夫识别直线

1.废话

霍夫变换是一种特征检测,被广泛应用在图像分析、计算机视觉以及数位影像处理。霍夫变换是用来辨别找出物件中的特征,例如:线条。他的算法流程大致如下,给定一个物件、要辨别的形状的种类,算法会在参数空间中执行投票来决定物体的形状,而这是由累加空间里的局部最大值来决定。

  现在广泛使用的霍夫变换是由RichardDuda和PeterHart在公元1972年发明,并称之为广义霍夫变换,广义霍夫变换和更早前1962年的PaulHough的专利有关。经典的霍夫变换是侦测图片中的直线,之后,霍夫变换不仅能识别直线,也能够识别任何形状,常见的有圆形、椭圆形。1981年,因为DanaH.Ballard的一篇期刊论文“Generalizing the Hough transform to detect arbitrary shapes”,让霍夫变换开始流行于计算机视觉界。

2.实现效果

3.代码解析

1.读取图片

read_image (Image, 'fabrik')

2.裁剪出白色部分

rectangle1_domain (Image, ImageReduced, 170, 280, 310, 360)

3.执行索贝尔滤波

sobel_dir (ImageReduced, EdgeAmplitude, EdgeDirection, 'sum_abs', 3)

4.二值化出区域

threshold (EdgeAmplitude, Region, 55, 255)

5.裁剪出二值化的区域内的像素

reduce_domain (EdgeDirection, Region, EdgeDirectionReduced)

6.执行霍夫直线检测

hough_lines_dir (EdgeDirectionReduced, HoughImage, Lines, 4, 2, 'mean', 3, 25, 5, 5, 'true', Angle, Dist)

7.生成直线

gen_region_hline (LinesHNF, Angle, Dist)

4.文件

* Detect lines in an image with the help of the Hough transform
* using the edge direction as additional information and return it both
* in HNF and as regions
* 
read_image (Image, 'fabrik')
rectangle1_domain (Image, ImageReduced, 170, 280, 310, 360)
* Detect edges (amplitude and direction) using the Sobel operator
sobel_dir (ImageReduced, EdgeAmplitude, EdgeDirection, 'sum_abs', 3)
dev_set_color ('red')
threshold (EdgeAmplitude, Region, 55, 255)
* Reduce the direction image to the edge region
reduce_domain (EdgeDirection, Region, EdgeDirectionReduced)
* Start the Hough transform using the edge direction information
hough_lines_dir (EdgeDirectionReduced, HoughImage, Lines, 4, 2, 'mean', 3, 25, 5, 5, 'true', Angle, Dist)
* Store input lines described in HNF
gen_region_hline (LinesHNF, Angle, Dist)
dev_display (Image)
dev_set_colored (12)
* Display the lines
dev_set_draw ('margin')
dev_display (LinesHNF)
* Display the edge pixels that contributed to the corresponding lines
dev_set_draw ('fill')
dev_display (Lines)

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄晓魚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值