halcon封装measure_pos为测量园函数

        与测量直线的相同,也是为了有些时候加入自己的规则而封装。

函数封装:

函数使用: 

NumDistance(矩形之间间距离)

RecHeight(矩形半高)

RecWidth(矩形半宽),

Sigma(平滑系数)
Threshold(灰度值)

ransition(极性)

Select(线选择)

Direction(找线朝向)

        上述参数基本都是找线卡尺常规参数,只有最后这个Direction(找线朝向)是单加的。这个是控制卡尺找线方向的,可以直接更人性的使用从里往外,从外往里这样,更加简单直接。

函数代码: 


* 参数设置
* Direction(找线朝向),NumDistance(矩形之间间距),RecHeight(矩形半高),RecWidth(矩形半宽),Sigma(平滑系数)
* Threshold(灰度值),Transition(极性),Select(线选择)
gen_empty_obj (RecContour)
RowEdges := []
ColumnEdges := []

try
    *获取图像宽高
    fit_circle_contour_xld (FindCircle, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi1, EndPhi1, PointOrder1)
    get_image_size (Image, Width, Height)
    
    *判断起始点
    if (StartPhi <= EndPhi)
        for Index := StartPhi to EndPhi by NumDistance
            if (Direction == 'ItoO')//从里到外
                RectangleRow := Row - Radius * sin(rad(Index))
                RectangleColumn := Column + Radius * cos(rad(Index))
                gen_rectangle2 (Rectangle, RectangleRow, RectangleColumn, rad(Index), RecHeight, RecWidth)
                gen_measure_rectangle2 (RectangleRow, RectangleColumn, rad(Index), RecHeight, RecWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
                measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
                gen_contour_region_xld (Rectangle, Contours, 'border')
                concat_obj (RecContour, Contours, RecContour)
                RowEdges := [RowEdges, RowEdge]
                ColumnEdges := [ColumnEdges, ColumnEdge]       
            elseif (Direction == 'OtoI')//从外到里
                RectangleRow := Row - Radius * sin(rad(Index))
                RectangleColumn := Column + Radius * cos(rad(Index))
                gen_rectangle2 (Rectangle, RectangleRow, RectangleColumn, rad(Index) + rad(180), RecHeight, RecWidth)
                gen_measure_rectangle2 (RectangleRow, RectangleColumn, rad(Index) + rad(180), RecHeight, RecWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
                measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
                gen_contour_region_xld (Rectangle, Contours, 'border')
                concat_obj (RecContour, Contours, RecContour)
                RowEdges := [RowEdges, RowEdge]
                ColumnEdges := [ColumnEdges, ColumnEdge]       
            endif
        endfor
    elseif (StartPhi >= EndPhi)
        for Index := StartPhi to EndPhi by -NumDistance
            if (Direction == 'ItoO')//从里到外
                RectangleRow := Row - Radius * sin(rad(Index))
                RectangleColumn := Column + Radius * cos(rad(Index))
                gen_rectangle2 (Rectangle, RectangleRow, RectangleColumn, rad(Index), RecHeight, RecWidth)
                gen_measure_rectangle2 (RectangleRow, RectangleColumn, rad(Index), RecHeight, RecWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
                measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
                gen_contour_region_xld (Rectangle, Contours, 'border')
                concat_obj (RecContour, Contours, RecContour)
                RowEdges := [RowEdges, RowEdge]
                ColumnEdges := [ColumnEdges, ColumnEdge]       
            elseif (Direction == 'OtoI')//从外到里
                RectangleRow := Row - Radius * sin(rad(Index))
                RectangleColumn := Column + Radius * cos(rad(Index))
                gen_rectangle2 (Rectangle, RectangleRow, RectangleColumn, rad(Index) + rad(180), RecHeight, RecWidth)
                gen_measure_rectangle2 (RectangleRow, RectangleColumn, rad(Index) + rad(180), RecHeight, RecWidth, Width, Height, 'nearest_neighbor', MeasureHandle)
                measure_pos (Image, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdge, ColumnEdge, Amplitude, Distance)
                gen_contour_region_xld (Rectangle, Contours, 'border')
                concat_obj (RecContour, Contours, RecContour)
                RowEdges := [RowEdges, RowEdge]
                ColumnEdges := [ColumnEdges, ColumnEdge]       
            endif
        endfor
    endif
    * 显示点位
    gen_cross_contour_xld (Cross, RowEdges, ColumnEdges, 6, rad(45))
    concat_obj (RecContour, Cross, RecContour)
    
    * 拟合园
    gen_contour_polygon_xld (Contour, RowEdges, ColumnEdges)
    fit_circle_contour_xld (Contour, 'geotukey', -1, 0, 0, 3, 2, CircleRow, CircleColumn, CircleRadius, CircleStartPhi, CircleEndPhi, PointOrder)
    
    *判断起始点
    if (StartPhi <= EndPhi)
        gen_circle_contour_xld (Circle, CircleRow, CircleColumn, CircleRadius, CircleStartPhi, CircleEndPhi, 'positive', 1)
    elseif (StartPhi >= EndPhi)
        gen_circle_contour_xld (Circle, CircleRow, CircleColumn, CircleRadius, CircleEndPhi, CircleStartPhi, 'positive', 1)
    endif
    
    
catch (Exception)
    RowEdges := []
    ColumnEdges := []
endtry

return ()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值