Halcon轮廓提取

 简介:

              对目标区域进行轮廓提取,可以用于判定形状等。

 

介绍:

boundary(获取一个区域的边界)
Region (input_object)  Regions for which the boundary is to be computed.区域
RegionBorder (output_object)Resulting boundaries.输出的边界
BoundaryType (input_control)

Boundary type.
Default value: 'inner'
List of values: 'inner', 'inner_filled', 'outer'

linner内边界。
inner_filled内边界上的孔。
outer外边界。
边界类型
gen_contour_region_xld(生成区域的XLD轮廓)
Regions (input_object)  Input regions.区域
Contours (output_object) Resulting contours.输出的边界
Mode (input_control)  

Mode of contour generation.
Default value: 'border'
List of values: 'border', 'border_holes', 'center'

border边界像素的外边界作为轮廓点。
border_holes除了输入区域的外边界,还可以得到所有孔的轮廓。
center边界像素的中心用作轮廓点。
轮廓生成方式
smallest_rectangle2_xld(任意方向的轮廓或多边形的最小外接矩形)
XLD (input_object)Contours or polygons to be examined.XLD
Row (output_control)Row coordinate of the center point of the enclosing rectangle.输出的行坐标
Column (output_control)  Column coordinate of the center point of the enclosing rectangle.输出的列坐标
Phi (output_control)  Orientation of the enclosing rectangle (arc measure).
Assertion: ((- pi / 2) < Phi) && (Phi <= (pi / 2))
弧度
Length1 (output_control)  First radius (half length) of the enclosing rectangle.
Assertion: Length1 >= 0.0
第一个边长
Length2 (output_control)  Second radius (half width) of the enclosing rectangle.
Assertion: (Length2 >= 0.0) && (Length2 <= Length1)
第二个边长
gen_rectangle2_contour_xld(创建一个矩形形状的XLD轮廓)
Rectangle (output_object)  Rectangle contour.输出的矩形轮廓
Row (input_control)  Row coordinate of the center of the rectangle.
Default value: 300.0
行坐标
Column (input_control)  Column coordinate of the center of the rectangle.
Default value: 200.0
列坐标
Phi (input_control)  Orientation of the main axis of the rectangle [rad].
Default value: 0.0
Restriction: ((- pi / 2) < Phi) && (Phi <= (pi / 2))
弧度
Length1 (input_control)  First radius (half length) of the rectangle.
Default value: 100.5
第一个边长
Length2 (input_control)Second radius (half width) of the rectangle.
Default value: 20.5
第二个边长
segment_contours_xld(将XLD分割成线段和圆弧或椭圆圆弧)
Contours (input_object) Contours to be segmented.要分割的轮廓
ContoursSplit (output_object)  Segmented contours.输出的分割轮廓
Mode (input_control) Mode for the segmentation of the contours.
Default value: 'lines_circles'
List of values: 'lines', 'lines_circles', 'lines_ellipses'
轮廓分割模式
SmoothCont (input_control)Number of points used for smoothing the contours.
Default value: 5
Suggested values: 0, 3, 5, 7, 9
Restriction: (SmoothCont == 0) || ((SmoothCont >= 3) && odd(SmoothCont))
用于平滑轮廓的点的数目
MaxLineDist1 (input_control)  Maximum distance between a contour and the approximating line (first iteration).
Default value: 4.0
Suggested values: 1.0, 1.5, 2.0, 2.5, 3.0, 3.5
Restriction: MaxLineDist1 >= 0.0
第一次迭代时轮廓线与近似线之间的最大距离
MaxLineDist2 (input_control)  

Maximum distance between a contour and the approximating line (second iteration).
Default value: 2.0
Suggested values: 1.0, 1.5, 2.0, 2.5, 3.0, 3.5
Restriction: MaxLineDist2 >= 0.0

第二次迭代时轮廓线与近似线之间的最大距离
select_contours_xld(根据特征选择XLD轮廓)
Contours (input_object) Input XLD contours.XLD轮廓
SelectedContours (output_object) Output XLD contours.输出的XDL轮廓
Feature (input_control)  

Feature to select contours with.
Default value: 'contour_length'
List of values: 'closed', 'contour_length', 'curvature', 'direction', 'maximum_extent', 'open'

closed只返回起点和终点之间的距离小于或等于Max1像素的轮廓。(Min1、Min2和Max2在这里没有影响。)
contour_length所有长度小于Min1或大于Max1的轮廓都不会返回(Min2和Max2在这里没有影响)。
curvature只返回与回归线的平均距离在Min1和Max1之间、距离的标准差在Min2和Max2之间的轮廓。
direction只返回回归线方向在Min1和Max1之间的等值线(以弧度为单位,逆时针方向)。Min1和Max1映射到[0,2*PI]的范围。(Min2和Max2在这里没有影响)。
maximum_extent轮廓中最大的长度小于Min1或大于Max1不返回(Min2和Max2在这里没有影响)。
open只返回起点和终点之间的距离大于Min1像素的轮廓线。(Max1、Min2和Max2在这里没有影响)。
特征选择
Min1 (input_control)  Lower threshold.
Default value: 0.5
最小值1
Max1 (input_control)  Upper threshold.
Default value: 200.0
最大值1
Min2 (input_control)  Lower threshold.
Default value: -0.5
最小值2
Max2 (input_control)  Upper threshold.
Default value: 0.5
最大值2
sort_contours_xld(轮廓排序)
Contours (input_object) Contours to be sorted.要排序的轮廓
SortedContours (output_object) Sorted contours.输出的排序轮廓
SortMode (input_control)  

Kind of sorting.
Default value: 'upper_left'
List of values: 'character', 'lower_left', 'lower_right', 'upper_left', 'upper_right'

character位置由周围矩形的左上角决定。与'upper_left'相反,如果轮廓线与参数RowOrCol指定的坐标方向重叠,轮廓线也会根据剩余坐标进行排序。
lower_left位置由周围矩形的左上角决定。
lower_right位置由周围矩形的右上角决定。
upper_left位置由周围矩形的左下角决定。
upper_right位置由周围矩形的右下角决定。
排序种类
Order (input_control) Increasing or decreasing sorting order.
Default value: 'true'
List of values: 'false', 'true'
减或增序
RowOrCol (input_control)  Sorting first with respect to row, then to column.
Default value: 'row'
List of values: 'column', 'row'
行或列
get_contour_global_attrib_xld(返回XLD轮廓的全局属性值)
Contour (input_object) Input XLD contour.XLD轮廓
Name (input_control)Name of the attribute.
Default value: 'regr_norm_row'
Suggested values: 'regr_norm_row', 'regr_norm_col', 'regr_mean_dist', 'regr_dev_dist', 'cont_approx', 'bright_dark', 'is_hole'
属性名
Attrib (output_control)  Attribute values.属性值
fit_line_contour_xld(用线段拟合XLD轮廓)
Contours (input_object) Input contours.XLD轮廓
Algorithm (input_control)  Algorithm for the fitting of lines.
Default value: 'tukey'
List of values: 'drop', 'gauss', 'huber', 'regression', 'tukey'
drop“最小二乘”线拟合,其中的异常值被忽略。其中,所有距轮廓线较远的轮廓点,均忽略其到回归线的平均距离乘上(ClippingFactor),计算无畸变回归线。
gauss加权“最小二乘”直线拟合,根据所有轮廓点到近似线距离的均值和标准差,减小异常值的影响。
huber加权“最小二乘”线拟合,采用Huber方法减小了异常值的影响。
regression标准最小二乘直线拟合。
tukey加权“最小二乘”线拟合,基于Tukey方法忽略异常值。
直线拟合算法
MaxNumPoints (input_control)  

Maximum number of contour points used for the computation (-1 for all points).
Default value: -1
Restriction: MaxNumPoints >= 2

用于计算的最大轮廓点数量(-1表示所有点)
ClippingEndPoints (input_control)Number of points at the beginning and at the end of the contours to be ignored for the fitting.
Default value: 0
Restriction: ClippingEndPoints >= 0
拟合时忽略轮廓开始点和结束点的个数
Iterations (input_control)  Maximum number of iterations (unused for 'regression').
Default value: 5
Restriction: Iterations >= 0
最大迭代次数(regression不使用)
ClippingFactor (input_control)Clipping factor for the elimination of outliers (typical: 1.0 for 'huber' and 'drop' and 2.0 for 'tukey').
Default value: 2.0
List of values: 1.0, 1.5, 2.0, 2.5, 3.0
Restriction: ClippingFactor > 0
裁剪因子用于消除异常值(典型的:“huber”和“drop”时使用1,“tukey”时使用2)
RowBegin (output_control)Row coordinates of the starting points of the line segments.线段起始点的行坐标
ColBegin (output_control)  Column coordinates of the starting points of the line segments.线段起始点的列坐标
RowEnd (output_control)  Row coordinates of the end points of the line segments.线段结束点的行坐标
ColEnd (output_control)  Column coordinates of the end points of the line segments.线段结束点的列坐标
Nr (output_control)Line parameter: Row coordinate of the normal vector.线参数:向量的行坐标
Nc (output_control)  Line parameter: Column coordinate of the normal vector.线参数:向量的列坐标
Dist (output_control) Line parameter: Distance of the line from the origin.线参数:直线到原点的距离
gen_contour_polygon_xld(根据多边形的参数生成XDL轮廓)
Contour (output_object)Resulting contour.输出的轮廓
Row (input_control)  Row coordinates of the polygon.
Default value: [0,1,2,2,2]
Suggested values: 0, 1, 2, 3, 4, 5, 10, 20, 50, 100, 200, 500
行坐标
Col (input_control) Column coordinates of the polygon.
Default value: [0,0,0,1,2]
Suggested values: 0, 1, 2, 3, 4, 5, 10, 20, 50, 100, 200, 500
列坐标

 

使用:

  1. 彩色图像要转成灰色图像。
  2. 通过阈值等方法获取目标区域。
  3. 获取区域的边界轮廓。
  4. 规则的形状可以使用最小外界矩形等获取形状的信息后画出形状。
  5. 不规则的可以对轮廓分段、选择、排序。获取轮廓线的属性,根据属性,获取坐标等然后拟合线(圆或椭圆)。
read_image (Image, 'E:/照片/轮廓.png')
decompose3 (Image, Image1, Image2, Image3)
trans_from_rgb (Image1, Image2, Image3, ImageResult1, ImageResult2, ImageResult3, 'hsv')
auto_threshold (ImageResult3, Regions, 2)
area_center (Regions, Area, Row, Column)
connection (Regions, ConnectedRegions)
count_obj (ConnectedRegions, Number)

dev_set_draw ('margin')
for Index := 1 to Number by 1
    select_obj (ConnectedRegions, ObjectSelected, Index)
    area_center (ObjectSelected, Area1, Row1, Column1)
    *提取感兴趣的特征
    if (Area1 > 300 and Area1 < 500)
        dev_clear_window()
        dev_display (ObjectSelected)      
        boundary (ObjectSelected, RegionBorder, 'outer')     
        gen_contour_region_xld (RegionBorder, Contours, 'border')
 
        *规则形状-矩形
        smallest_rectangle2_xld (Contours, RowRec, ColumnRec, Phi1, LengthRec1, LengthRec2)
        gen_rectangle2_contour_xld (Rectangle, RowRec, ColumnRec, Phi1, LengthRec1, LengthRec2)
        
        *不规则形状-多边形
        segment_contours_xld (Contours, ContoursSplit, 'lines', 0, 0, 0)
        select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 0.5, 200, -0.5, 0.5)       
        sort_contours_xld (SelectedContours, SortedContours, 'upper_left', 'true', 'row')
        
        count_obj (SortedContours, Number1)
        gen_empty_obj (Lines)
        for Index1 := 1 to Number1 by 1
            select_obj (SortedContours, ObjectSelected1, Index1)
            get_contour_global_attrib_xld (ObjectSelected1, 'cont_approx', Attrib)
            *-1:线 0:椭圆 1:圆
            if (Attrib == -1)
                fit_line_contour_xld (ObjectSelected1, 'tukey', 2, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
                gen_contour_polygon_xld (Polygon, [RowBegin,RowEnd], [ColBegin,ColEnd])
                concat_obj (Lines, Polygon, Lines)   
            endif
        endfor       
        break
    endif
endfor
dev_clear_window ()
dev_display (Lines)


 

轮廓.png
矩形

 

不规则

 

 

  • 4
    点赞
  • 70
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Halcon是一种图像处理软件,可以进行轮廓提取。在Halcon中,轮廓提取通常涉及以下几个步骤:分割、筛选和连接或拟合轮廓线条。 首先是轮廓的分割。在这一步骤中,Halcon会根据图像中的不同特征,如灰度值或边缘信息,将图像中的对象与背景分离开来。通过使用相关算子或其他分割算法,可以将图像中的对象轮廓提取出来。 接下来是筛选。在轮廓提取过程中,可能会存在一些杂点或背景区域被误认为是轮廓。为了得到准确的轮廓,需要进行一些筛选操作。这可以通过使用阈值、形状匹配或其他相关的筛选算法来实现。这样可以剔除掉不符合要求的区域,得到所需的完整轮廓区域。 最后是连接或拟合轮廓线条。提取出的轮廓线条可能会存在一些不连续的部分,但在实际应用中,我们通常需要得到闭合的轮廓。因此,需要对不连续的轮廓进行一些连接或填补操作,使其形成闭合的轮廓。这可以通过使用相关的连接算子或拟合算法来实现。 综上所述,在Halcon中,轮廓提取通常包括分割、筛选和连接或拟合轮廓线条这三个步骤,通过这些步骤可以得到所需的轮廓信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Halcon 第四章『图像特征和提取』◆第5.3节:XLD轮廓处理—分割、筛选、连接or拟合](https://blog.csdn.net/qq_45336030/article/details/123976623)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值