Halcon基于形状模板匹配的实战【一】

根据夹子进行基于形状模板匹配的实战

 1、打开菜单栏助手里面的Matching助手

2、点击采集助手--进入到图像采集界面--点击自动检测接口

3、点击连接--实时

4、以夹子为例,可以看到图像窗口有一个夹子

 5、点击模板感兴趣区域的旋转矩形,对夹子进行创建模板

 6、点击应用界面,切换基于形状--点击图像采集助手--点击实时图像 

 

此处可以看到无论放多少个夹子都可以根据形状进行匹配

 7、点击检测界面的执行,可以看到一些统计数据 

8、点击代码生成,可以选择生成显示代码/矫正代码

 9、可以在程序窗口看到生成的代码

* 
* Matching 01: ************************************************
* Matching 01: BEGIN of generated code for model initialization
* Matching 01: ************************************************
set_system ('border_shape_models', 'false')
* 
* Matching 01: Initialize acquisition
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] Web Camera', 0, -1, AcqHandle)
* 
* Matching 01: Obtain the model image
grab_image (Image, AcqHandle)
* 
* Matching 01: Build the ROI from basic regions
gen_rectangle2 (ModelRegion, 356.886, 1166.06, rad(-92.8126), 121.142, 84.885)
* 
* Matching 01: Reduce the model template
reduce_domain (Image, ModelRegion, TemplateImage)
* 
* Matching 01: Create the shape model
create_shape_model (TemplateImage, 6, rad(0), rad(360), rad(0.8586), ['none','no_pregeneration'], 'use_polarity', [7,31,12], 4, ModelID)
* 
* Matching 01: Get the model contour for transforming it later into the image
get_shape_model_contours (ModelContours, ModelID, 1)
* 
* Matching 01: Get the reference position
area_center (ModelRegion, ModelRegionArea, RefRow, RefColumn)
vector_angle_to_rigid (0, 0, 0, RefRow, RefColumn, 0, HomMat2D)
affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
* 
* Matching 01: Display the model contours
dev_display (Image)
dev_set_color ('green')
dev_set_draw ('margin')
dev_display (ModelRegion)
dev_display (TransContours)
stop ()
* 
* Matching 01: END of generated code for model initialization
* Matching 01:  * * * * * * * * * * * * * * * * * * * * * * *
* Matching 01: BEGIN of generated code for model application
* 
while (true)
    * 
    * Matching 01: Obtain the image
    grab_image (Image, AcqHandle)
    * 
    * Matching 01: Find the model
    find_shape_model (Image, ModelID, rad(0), rad(360), 0.5, 0, 0.5, 'least_squares', [6,1], 0.75, Row, Column, Angle, Score)
    * 
    * Matching 01: Transform the model contours into the detected positions
    dev_display (Image)
    for I := 0 to |Score| - 1 by 1
        hom_mat2d_identity (HomMat2D)
        hom_mat2d_rotate (HomMat2D, Angle[I], 0, 0, HomMat2D)
        hom_mat2d_translate (HomMat2D, Row[I], Column[I], HomMat2D)
        affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
        dev_set_color ('green')
        dev_display (TransContours)
        stop ()
    endfor
endwhile
* 
* Matching 01: Clear model when done
stop ()
clear_shape_model (ModelID)
* Matching 01: *******************************************
* Matching 01: END of generated code for model application
* Matching 01: *******************************************
* 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值