一、说明
用hough变换查找直线;hough的原理见文章: 图像处理:Hough变换原理分析
此文专门介绍halcon的具体算子实现。
二、示例代码
* Detect lines in an image with the help of the Hough transform
* and return it in HNF
*
read_image (Image, 'd:/images/reglist/patty.jpg')
* Detect edges (amplitude) using the Sobel operator
sobel_amp (Image, EdgeAmplitude, 'thin_sum_abs', 3)
dev_set_color ('red')
threshold (EdgeAmplitude, Region, 10, 255)
hough_lines (Region, 4, 100, 5, 5, Angle, Dist)
dev_set_color ('blue')
* Store input lines described in HNF
gen_region_hline (Regions, Angle, Dist)
三、相关算子
- sobel_amp (Image, EdgeAmplitude, 'thin_sum_abs', 3)
用sobel算子进行边缘提取。
- hough_lines(RegionIn : : AngleResolution, Threshold, AngleGap, DistGap : Angle, Dist)
算子 hough_lines 允许选择区域中的线状结构,因此不必连接线的各个点。该过程基于霍夫变换。这些线在 HNF 中返回,即按其法线向量的方向和长度。
参数 AngleResolution 定义了关于角度确定的精确度。它等于 1 / AngleResolution 度数。
参数Threshold决定了一条线的假设至少必须支持原始区域的多少点才能被接收到输出中。
参数 AngleGap 和 DistGap 定义霍夫图像中每个点的邻域,以确定局部最大值。这些行以 HNF 形式返回。
- gen_region_hline (:Regions: Angle, Dist:)
根据给定的角度Angle,原点矩Dist画出 一个一个的直线。
四、示例和效果
结果: