康耐德智能

 有光必有源,康耐德视觉光源!

 服务热线:0769-28680919    手机:15322933971

图片展示
搜索

更多资讯

分类标题

关注康耐德智能

        

电话:0769-28680919

传真:0769-28680910

邮箱:csray@csray.com

地址:东莞市南城区天安数码城C2栋507室


基于Halcon像素精度的边缘提取学习

作 者:康耐德智能 关注:1068 发表时间:2019-05-16 09:00:35 来源:原创

本文主要围绕Halcon的边缘提取中的一个算子get_region_contour展开学习


1. get_region_contour

该算子检测图像中线条及其宽度被广泛应用;

Signature

get_region_contour(Region : : : Rows, Columns)

 

Region: (input_object) 输入图像的感兴趣区域

Rows: (output_control)  轮廓的Y的坐标点

Columns: (output_control)  轮廓的X坐标点

 

Halcon例程1:

提取前图片:




dev_close_window ()

read_image (Image, 'mreut')

dev_open_window (0, 0, 512, 512, 'white', WindowID)

dev_display (Image)

dev_set_color ('black')

threshold (Image, Region, 180, 255)

dev_clear_window ()

dev_display (Region)

connection (Region, ConnectedRegions)

select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10000, 100000000)

get_region_contour (SelectedRegions, Rows, Columns)

RowLine1 := 5

ColLine1 := 300

RowLine2 := 300

ColLine2 := 400

NumberTuple := |Rows|

dev_set_color ('red')

disp_line (WindowID, RowLine1, ColLine1, RowLine2, ColLine2)

dev_set_color ('green')

* Calculate the distance between points of the contour

* of the selected region and the displayed line

for i := 1 to NumberTuple by 20

disp_line (WindowID, Rows[i], Columns[i] - 2, Rows[i], Columns[i] + 2)

disp_line (WindowID, Rows[i] - 2, Columns[i], Rows[i] + 2, Columns[i])

distance_pl (Rows[i], Columns[i], RowLine1, ColLine1, RowLine2, ColLine2, Distance)

endfor

 

提取后的图片(放大后轮廓点更加清晰):



Halcon例程2:

1. get_region_contour

该算子检测图像中线条及其宽度被广泛应用;

Signature

get_region_polygon(Region : : Tolerance : Rows, Columns)

 

Region: (input_object) 输入图像的感兴趣区域

Tolerance(intput_object)所提取的轮廓与region误差距离

Rows: (output_control)  轮廓的Y的坐标点

Columns: (output_control)  轮廓的X坐标点

 

提取前图片:


read_image (Image, 'rings_and_nuts')

dev_close_window ()

dev_open_window_fit_image (Image, 0, 0, 640, 640, WindowHandle)

set_display_font (WindowHandle, 14, 'mono', 'true', 'false')

get_image_size (Image, Width, Height)

*

* Extract the rings.

binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)

connection (Region, ConnectedRegions)

fill_up (ConnectedRegions, RegionFillUp)

compactness (RegionFillUp, Compactness)

for i := 0 to |Compactness| - 1 by 1

    if (Compactness[i] > 1.5 and Compactness[i] < 2.5)

        select_obj (RegionFillUp, ObjectSelected, i + 1)

        *

        * Determine the size and position of the rings.

        smallest_circle (ObjectSelected, Row, Column, RadiusMax)

        inner_circle (ObjectSelected, CenterRow, CenterCol, RadiusMin)

        Radius := (RadiusMax + RadiusMin) / 2.0

        AnnulusRadius := (RadiusMax - RadiusMin) / 4.0

        *

        * Determine the position between two cogs.

        * This position is then used as the start angle for the circular ROI.

        get_region_polygon (ObjectSelected, AnnulusRadius, RowsBorder, ColumnsBorder)

        SqrDistanceBorder := (RowsBorder - CenterRow) * (RowsBorder - CenterRow) + (ColumnsBorder - CenterCol) * (ColumnsBorder - CenterCol)

        tuple_sort_index (SqrDistanceBorder, Indices)

        line_orientation (CenterRow, CenterCol, RowsBorder[Indices[0]], ColumnsBorder[Indices[0]], AngleStart)

        AngleExtent := rad(360)

        *

        * Create the measure for a circular ROI.

        Interpolation := 'bilinear'

        gen_measure_arc (CenterRow, CenterCol, Radius, AngleStart, AngleExtent, AnnulusRadius, Width, Height, Interpolation, MeasureHandle)

        *

        * Determine all edge pairs that have a negative transition, i.e., edge pairs

        * that enclose dark regions.

        * Note that the output parameters IntraDistance and InterDistance are given as arc lengths.

        Sigma := 1.0

        Threshold := 30

        Transition := 'negative'

        Select := 'all'

        measure_pairs (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)

        *

        * Determine the number of cogs.

        NumCogs := |RowEdgeFirst|

        *

        * Determine the linear distance between the two edges of each edge pair ('Linear cog size')

        * as well as the angular distance of the edge pairs ('Angular cog size').

        distance_pp (RowEdgeFirst, ColumnEdgeFirst, RowEdgeSecond, ColumnEdgeSecond, LinearDistance)

        AngularDistance := deg(IntraDistance / Radius)

        *

        * Visualize the determined edges

        gen_empty_obj (Crosses)

        for J := 0 to |RowEdgeFirst| - 1 by 1

            gen_cross_contour_xld (Cross1, RowEdgeFirst[J], ColumnEdgeFirst[J], 12, atan2(CenterRow - RowEdgeFirst[J],ColumnEdgeFirst[J] - CenterCol))

            gen_cross_contour_xld (Cross2, RowEdgeSecond[J], ColumnEdgeSecond[J], 12, atan2(CenterRow - RowEdgeSecond[J],ColumnEdgeSecond[J] - CenterCol))

            concat_obj (Crosses, Cross1, Crosses)

            concat_obj (Crosses, Cross2, Crosses)

        endfor

        dev_display (Image)

        dev_set_line_width (2)

        dev_set_color ('green')

        dev_display (Crosses)

        *

        * Display the measured size of the cogs

        Message := 'Number of cogs: ' + |RowEdgeFirst|

        Message[1] := 'Mean cog size:'

        Message[2] := '- Arc length: ' + mean(IntraDistance)$'.2f' + ' +/- ' + deviation(IntraDistance)$'.2f' + ' pixel'

        Message[3] := '- Linear:     ' + mean(LinearDistance)$'.2f' + ' +/- ' + deviation(LinearDistance)$'.2f' + ' pixel'

        Message[4] := '- Angular:    ' + mean(AngularDistance)$'.2f' + ' +/- ' + deviation(AngularDistance)$'.2f' + ' deg'

        disp_message (WindowHandle, Message, 'window', 260, 10, 'black', 'true')

        *

        * Close the measure

        close_measure (MeasureHandle)

        disp_continue_message (WindowHandle, 'black', 'true')

        stop ()

    endif

endfor

提取后的图片:


广东省东莞市南城区黄金路1号天安数码城C2-507

电话:0769-28680919

手机:15322933971

邮箱:csray@csray.com

版权所有:东莞康耐德智能控制有限公司

粤ICP备18080826号-1

在线客服
联系方式
热线电话
0769-28680919
手机服务
15322933971
上班时间
周一到周五
二维码
二维码
在线客服