HALCON示例程序measure_circuit_width_lines_gauss.hdev电路板线宽检测

HALCON示例程序measure_circuit_width_lines_gauss.hdev电路板线宽检测

示例程序源码(加注释)

  • 关于显示类函数解释
    dev_update_off ()
    dev_close_window ()
    read_image (Image, ‘pcb_color’)
    get_image_size (Image, Width, Height)
    dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
    set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
    dev_display (Image)
    dev_set_draw (‘margin’)
    dev_set_color (‘yellow’)
  • Define the minimum and maximum width of the pcb tracks
    MaxTrackWidth := 6.0
    MinTrackWidth := 4.0
  • Select a sub-region of the image
    Rectangle := [271,285,528,718]
    gen_rectangle1 (PcbPart, Rectangle[0], Rectangle[1], Rectangle[2], Rectangle[3])
    dev_display (Image)
    dev_display (PcbPart)
    disp_message (WindowHandle, ‘Measure the width of tracks using lines_gauss’, ‘window’, 12, 12, ‘black’, ‘true’)
    disp_continue_message (WindowHandle, ‘black’, ‘true’)
    stop ()
    dev_set_part (Rectangle[0] - 15, Rectangle[1] - 15, Rectangle[2] + 15, Rectangle[3] + 15)
    dev_display (Image)
    dev_display (PcbPart)
    disp_message (WindowHandle, ‘Exemplarily shown here for a part of the circuit board’, ‘window’, 12, 12, ‘black’, ‘true’)
    disp_continue_message (WindowHandle, ‘black’, ‘true’)
    stop ()
  • Extract the tracks
    decompose3 (Image, ImageR, ImageG, ImageB)
    reduce_domain (ImageG, PcbPart, ImageReduced)
    threshold (ImageReduced, Region, 90, 255)
    dilation_circle (Region, RegionDilation, 3.5)
    opening_rectangle1 (Region, RegionOpening, 8, 8)
    dilation_circle (RegionOpening, RegionDilation1, 3.5)
    difference (Region, RegionDilation1, RegionDifference)
    difference (RegionDilation, RegionDilation1, RegionDifference)
    connection (RegionDifference, ConnectedRegions)
    select_shape (ConnectedRegions, RegionSelected, ‘area’, ‘and’, 260, 4595)
    union1 (RegionSelected, RegionTracks)
    reduce_domain (ImageReduced, RegionTracks, ImageReducedTracks)
  • lines_gauss - 检测线条及其宽度。
  • lines_gauss(图片:输出线:高斯平滑值,滞后阈值低值,滞后阈值高值,线条是暗是亮,线条属性,找线条模式,在无法提取线条处添加交叉点:)
    lines_gauss (ImageReducedTracks, Lines, 1.5, 1, 8, ‘light’, ‘true’, ‘bar-shaped’, ‘true’)
  • 通过连续长度筛选线条
    select_shape_xld (Lines, SelectedXLD, ‘contlength’, ‘and’, 20, 99999)
    dev_display (Image)
    dev_set_color (‘yellow’)
    dev_display (PcbPart)
    dev_set_color (‘green’)
    dev_set_line_width (2)
    dev_display (Lines)
    disp_message (WindowHandle, ‘Extracted tracks’, ‘window’, 12, 12, ‘black’, ‘true’)
    disp_continue_message (WindowHandle, ‘black’, ‘true’)
    stop ()
    count_obj (SelectedXLD, NumberL)
    RowLine := []
    ColLine := []
    LineWidth := []
    for IndexL := 1 to NumberL by 1
        select_obj (SelectedXLD, Line, IndexL)
        *get_contour_xld  - 返回XLD轮廓的坐标。get_contour_xld(轮廓:::行,列)
        get_contour_xld (Line, Row, Column)
        *get_contour_attrib_xld  -  XLD轮廓的返回点属性值。get_contour_attrib_xld(轮廓::属性:值)
        get_contour_attrib_xld (Line, 'width_left', WidthL)
        get_contour_attrib_xld (Line, 'width_right', WidthR)
        RowLine := [RowLine,Row]
        ColLine := [ColLine,Column]
        LineWidth := [LineWidth,WidthR + WidthL]
    endfor

tuple_find (min2(LineWidth,MaxTrackWidth), MaxTrackWidth, IndicesTooBroad)
tuple_find (max2(LineWidth,MinTrackWidth), MinTrackWidth, IndicesTooNarrow)

if (IndicesTooBroad == -1)
    IndicesTooBroad := []
endif
if (IndicesTooNarrow == -1)
    IndicesTooNarrow := []
endif
  • 将各个点组成一个区域
    gen_region_points (RegionTooBroad, subset(RowLine,IndicesTooBroad), subset(ColLine,IndicesTooBroad))
    gen_region_points (RegionTooNarrow, subset(RowLine,IndicesTooNarrow), subset(ColLine,IndicesTooNarrow))
    connection (RegionTooBroad, RegionTooBroad)
  • 将骨架转换为XLD轮廓。
    gen_contours_skeleton_xld (RegionTooBroad, TracksTooBroad, 1, ‘filter’)
    smallest_circle (RegionTooBroad, RowTooBroad, ColumnTooBroad, RadiusTooBroad)
    gen_circle_contour_xld (CircleTooBroad, RowTooBroad, ColumnTooBroad, min2(RadiusTooBroad + 10,20), 0, 6.28318, ‘positive’, 1)
    connection (RegionTooNarrow, RegionTooNarrow)
    gen_contours_skeleton_xld (RegionTooNarrow, TracksTooNarrow, 1, ‘filter’)
    smallest_circle (RegionTooNarrow, RowTooNarrow, ColumnTooNarrow, RadiusTooNarrow)
    gen_circle_contour_xld (CircleTooNarrow, RowTooNarrow, ColumnTooNarrow, min2(RadiusTooNarrow + 10,20), 0, 6.28318, ‘positive’, 1)
    dev_clear_window ()
    dev_display (Image)
    dev_display (ImageReduced)
    dev_set_line_width (1)
    dev_set_color (‘green’)
    dev_display (Lines)
    dev_set_line_width (2)
    dev_set_color (‘red’)
    dev_display (TracksTooBroad)
    dev_display (CircleTooBroad)
    dev_set_color (‘magenta’)
    dev_display (CircleTooNarrow)
    dev_display (TracksTooNarrow)
    disp_message (WindowHandle, [‘Extracted tracks’,’ - Too broad’,’ - Too narrow’], ‘window’, 12, 12, [‘black’,‘red’,‘magenta’], ‘true’)

处理思路

这个例子是主要讲解了lines_gauss算子的应用。一个能够提取线段的算子。

后记

大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值