halcon封装延长XLD轮廓函数

        这个函数主要是用于将xld轮廓进行延长,在一些显示轮廓的地方可以 用到。

1、函数原理

        主要是利用XLD的开始和结束点位,还有XLD的角度。然后根据需要延长的长度在两边分别进

行延长。

2、函数代码

内部代码: 

*对轮廓进行延长
*Contour输入轮廓,ExtendContour输出轮廓,Length延长长度
try
    *获得点位
    get_contour_xld (Contour, Row, Column)
    line_orientation (Row[0], Column[0], Row[|Row| - 1], Column[|Column| - 1], Phi)
    
    *通过角度判断
    if (Phi > rad(0) and Phi < rad(90))
        *判断起始点
        if (Row[0] < Row[|Row| - 1] and Column[0] > Column[|Column| - 1])
            RowBegin := Row[0]
            ColumnBgein := Column[0]
            RowEnd := Row[|Row| - 1]
            ColumnEnd := Column[|Column| - 1]
            
            *进行计算延长
            RowExtendBegin := RowBegin - Length * sin(Phi)
            ColumnExtendBegin := ColumnBgein + Length * cos(Phi)
            RowExtendEnd := RowEnd + Length * sin(Phi)
            ColumnExtendEnd := ColumnEnd - Length * cos(Phi)
            
            *调整方向与原有相同
            RowXldBegin := RowExtendBegin
            ColumnXldBegin := ColumnExtendBegin
            RowXldEnd := RowExtendEnd
            ColumnXldEnd := ColumnExtendEnd
            
        elseif (Row[0] > Row[|Row| - 1] and Column[0] < Column[|Column| - 1])
            RowBegin := Row[|Row| - 1]
            ColumnBgein := Column[|Column| - 1]
            RowEnd := Row[0]
            ColumnEnd := Column[0]
            
            *进行计算延长
            RowExtendBegin := RowBegin - Length * sin(Phi)
            ColumnExtendBegin := ColumnBgein + Length * cos(Phi)
            RowExtendEnd := RowEnd + Length * sin(Phi)
            ColumnExtendEnd := ColumnEnd - Length * cos(Phi)
            
            *调整方向与原有相同
            RowXldBegin := RowExtendEnd
            ColumnXldBegin := ColumnExtendEnd
            RowXldEnd := RowExtendBegin
            ColumnXldEnd := ColumnExtendBegin
            
        endif
                     
    elseif (Phi < rad(0) and Phi > rad(-90))
        *判断起始点
        if (Row[0] < Row[|Row| - 1] and Column[0] < Column[|Column| - 1])
            RowBegin := Row[0]
            ColumnBgein := Column[0]
            RowEnd := Row[|Row| - 1]
            ColumnEnd := Column[|Column| - 1]
            
            *进行计算延长
            RowExtendBegin := RowBegin + Length * sin(Phi)
            ColumnExtendBegin := ColumnBgein - Length * cos(Phi)
            RowExtendEnd := RowEnd - Length * sin(Phi)
            ColumnExtendEnd := ColumnEnd + Length * cos(Phi)
            
            *调整方向与原有相同
            RowXldBegin := RowExtendBegin
            ColumnXldBegin := ColumnExtendBegin
            RowXldEnd := RowExtendEnd
            ColumnXldEnd := ColumnExtendEnd
        elseif (Row[0] > Row[|Row| - 1] and Column[0] > Column[|Column| - 1])
            RowBegin := Row[|Row| - 1]
            ColumnBgein := Column[|Column| - 1]
            RowEnd := Row[0]
            ColumnEnd := Column[0]
            
            *进行计算延长
            RowExtendBegin := RowBegin + Length * sin(Phi)
            ColumnExtendBegin := ColumnBgein - Length * cos(Phi)
            RowExtendEnd := RowEnd - Length * sin(Phi)
            ColumnExtendEnd := ColumnEnd + Length * cos(Phi)
            
            *调整方向与原有相同
            RowXldBegin := RowExtendEnd
            ColumnXldBegin := ColumnExtendEnd
            RowXldEnd := RowExtendBegin
            ColumnXldEnd := ColumnExtendBegin
            
        endif
                        
    elseif (Phi == rad(0))
        *判断起始点
        if (Column[0] > Column[|Column| - 1])
            RowBegin := Row[0]
            ColumnBgein := Column[0]
            RowEnd := Row[|Row| - 1]
            ColumnEnd := Column[|Column| - 1]
            
            *进行计算延长
            RowExtendBegin := RowBegin - Length * sin(Phi)
            ColumnExtendBegin := ColumnBgein + Length * cos(Phi)
            RowExtendEnd := RowEnd + Length * sin(Phi)
            ColumnExtendEnd := ColumnEnd - Length * cos(Phi)
            
            *调整方向与原有相同
            RowXldBegin := RowExtendBegin
            ColumnXldBegin := ColumnExtendBegin
            RowXldEnd := RowExtendEnd
            ColumnXldEnd := ColumnExtendEnd
        elseif (Column[0] < Column[|Column| - 1])
            RowBegin := Row[|Row| - 1]
            ColumnBgein := Column[|Column| - 1]
            RowEnd := Row[0]
            ColumnEnd := Column[0]
            
            *进行计算延长
            RowExtendBegin := RowBegin - Length * sin(Phi)
            ColumnExtendBegin := ColumnBgein + Length * cos(Phi)
            RowExtendEnd := RowEnd + Length * sin(Phi)
            ColumnExtendEnd := ColumnEnd - Length * cos(Phi)
            
            *调整方向与原有相同
            RowXldBegin := RowExtendEnd
            ColumnXldBegin := ColumnExtendEnd
            RowXldEnd := RowExtendBegin
            ColumnXldEnd := ColumnExtendBegin
        endif
                      
    elseif (Phi == rad(90))
        *判断起始点
        if (Row[0] > Row[|Row| - 1])
            RowBegin := Row[0]
            ColumnBgein := Column[0]
            RowEnd := Row[|Row| - 1]
            ColumnEnd := Column[|Column| - 1]
            
            *进行计算延长
            RowExtendBegin := RowBegin - Length * sin(Phi)
            ColumnExtendBegin := ColumnBgein - Length * cos(Phi)
            RowExtendEnd := RowEnd + Length * sin(Phi)
            ColumnExtendEnd := ColumnEnd + Length * cos(Phi)
            
            *调整方向与原有相同
            RowXldBegin := RowExtendBegin
            ColumnXldBegin := ColumnExtendBegin
            RowXldEnd := RowExtendEnd
            ColumnXldEnd := ColumnExtendEnd
        elseif (Row[0] < Row[|Row| - 1])
            RowBegin := Row[|Row| - 1]
            ColumnBgein := Column[|Column| - 1]
            RowEnd := Row[0]
            ColumnEnd := Column[0]
            
            *进行计算延长
            RowExtendBegin := RowBegin - Length * sin(Phi)
            ColumnExtendBegin := ColumnBgein - Length * cos(Phi)
            RowExtendEnd := RowEnd + Length * sin(Phi)
            ColumnExtendEnd := ColumnEnd + Length * cos(Phi)
            
            *调整方向与原有相同
            RowXldBegin := RowExtendEnd
            ColumnXldBegin := ColumnExtendEnd
            RowXldEnd := RowExtendBegin
            ColumnXldEnd := ColumnExtendBegin
        endif
                      
    endif
    
    *生成轮廓
    gen_contour_polygon_xld (ExtendContour, [RowXldBegin, RowXldEnd], [ColumnXldBegin, ColumnXldEnd])

    
catch (Exception)
    gen_empty_obj (ExtendContour)
endtry
return ()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值