本文主要是介绍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)
这篇关于HALCON-从入门到入门-霍夫识别直线的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!