Halcon激光条处理并拟合直线思路整理

高斯模糊拟合激光条法:

dev_close_window ()
* 设置颜色
dev_set_color ('green')
* 读取图像
read_image (Image, 'images3/1')
* 获得图像尺寸
get_image_size (Image, Width, Height)
* 开启窗口
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* 均值滤波为了将光条处理的更加平滑
mean_image (Image, Image, 3, 3)
* 灰度化
rgb1_to_gray (Image, GrayImage)
* 二值化
threshold (GrayImage, Regions, 34, 255)
* 提取骨架
skeleton (Regions, Skeleton)
* 提取骨架点
junctions_skeleton (Skeleton, EndPoints, JuncPoints)
difference (Skeleton, JuncPoints, RegionDifference)
* 计算联通域
connection (RegionDifference, ConnectedRegions)
* 通过点计算线的区域
split_skeleton_region (ConnectedRegions, RegionLines, 9)
* 计算数量
count_obj (RegionLines, Number)
* 生成空白对象以备使用,存储最终结果
gen_empty_obj (PrintedLines)

* 循环遍历来过滤一些短的线
for Index:=1 to Number by 1
    * 按照索引取出对象
    select_obj (RegionLines, LineRegion, Index)
    * 将区域转换为线条
    gen_contour_region_xld (LineRegion, Line, 'center')
    * 计算长度
    length_xld (Line, Length)
    if (Length > 100)
        * 保存结果
        concat_obj (PrintedLines, Line, PrintedLines)
    endif
endfor
* 展示结果
dev_clear_window ()
dev_display (PrintedLines)

高斯模糊拟合激光条法:

dev_close_window ()
* 设置颜色
dev_set_color ('green')
* 读取图像
read_image (Image, 'images3/1')
* 获得图像尺寸
get_image_size (Image, Width, Height)
* 开启窗口
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
calculate_lines_gauss_parameters (8, [12,5], Sigma, Low, High)
lines_gauss (Image, Lines, Sigma, Low, High, 'light', 'true', 'parabolic', 'true')
select_contours_xld (Lines, RelLines, 'length', 5.0, 999, 0, 0)

* 计算数量
count_obj (RelLines, Number)
* 生成空白对象以备使用,存储最终结果
gen_empty_obj (PrintedLines)

* 循环遍历来过滤一些短的线
for Index:=1 to Number by 1
    * 按照索引取出对象
    select_obj (RelLines, Line, Index)
    * 计算长度
    length_xld (Line, Length)
    if (Length > 100)
        * 保存结果
        concat_obj (PrintedLines, Line, PrintedLines)
    endif
endfor
* 展示结果
dev_clear_window ()
dev_display (PrintedLines)

  

本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/yamboo/p/13712788.html