基于halcon的ncc分类识别

原图

建模图

在这里插入图片描述
在这里插入图片描述

识别图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

代码

封装函数

*****  dev_display_ncc_matching_results (ModelIds, ClassColors, Row, Column, Angle, Model)
* 
NumMatches := |Row|
if (NumMatches > 0)
    if (|Model| == 0)
        tuple_gen_const (NumMatches, 0, Model)
    elseif (|Model| == 1)
        tuple_gen_const (NumMatches, Model, Model)
    endif
    for Index := 0 to |ModelID| - 1 by 1
        get_ncc_model_region (ModelRegion, ModelID[Index])
        gen_contour_region_xld (ModelRegion, ModelContours, 'border_holes')
        dev_set_color (Color[Index % |Color|])
        for Match := 0 to NumMatches - 1 by 1
            if (Index == Model[Match])
                hom_mat2d_identity (HomMat2DIdentity)
                hom_mat2d_rotate (HomMat2DIdentity, Angle[Match], 0, 0, HomMat2DRotate)
                hom_mat2d_translate (HomMat2DRotate, Row[Match], Column[Match], HomMat2DTranslate)
                affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2DTranslate)
                dev_display (ContoursAffinTrans)
                affine_trans_pixel (HomMat2DTranslate, 0, 0, RowTrans, ColTrans)
                gen_cross_contour_xld (Cross, RowTrans, ColTrans, 6, Angle[Match])
                dev_display (Cross)
            endif
        endfor
    endfor
endif
return ()
***analyze_result (ModelIds, Model, ClassLabels, Text, TextColors)
CableTypeFound := false
for I := 0 to |ModelIds| - 1 by 1
    *  类型12确定
    if (I < 2)
        if (CableTypeFound)
            continue
        endif
        if (find(Model,I) != -1)
            Text := 'Cable is of ' + ClassLabels[I]
            TextColors := 'black'
            CableTypeFound := true
        else     
            Text := '没找到此类型'
            TextColors := 'red'
        endif
        
    else
    *标签1234确定
        if (find(Model,I) == -1)
            Text := [Text,ClassLabels[I] + ' 标签没有 ']
            TextColors := [TextColors,'red']
        else
            Text := [Text,ClassLabels[I] + ' 标签存在']
            TextColors := [TextColors,'black']
        endif
    endif
endfor
return (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值