Inspect_gasket_local_deformable.hdev (网上也有相关的)相关例程学习

Index:.../Applications/Measuring-2D/inspect_gasket_local_deformable.hdev


猛一看就是一个deformable的模板匹配,但里面还有些不同。

首先就是这个变分?模型的建立

* Create variation model
sobel_amp (ModelImage, EdgeAmplitude, 'thin_max_abs', 5)
create_variation_model (425, 410, 'byte', 'direct', VariationModelID)
prepare_direct_variation_model (ModelImage, EdgeAmplitude, VariationModelID, 30, 1.5)

*

从帮助文档看到,create_variation_model一般都是训练一堆图像的,但选择 'direct'时,可以In this case, the variation model can only be trained by specifying the ideal image and the variation image directly with prepare_direct_variation_model.

并且文档最后一句说,为了减小变分模型的大小,先用sobel算子提取下边缘。

prepare_direct_variation_model 这个函数就是让模板和变分模型的句柄建立联系的函数。


然后往下是建立 deformable model。看来又是老一套

* Create locally deformable model
create_local_deformable_model (ModelImage, 'auto', rad(-10), rad(20), 'auto', 0.9, 1.1, 'auto', 0.9, 1.1, 'auto', 'none', 'use_polarity', 'auto', 'auto', [], [], ModelID)
get_deformable_model_contours (ModelContours, ModelID, 1)
area_center (ModelImage, Area, Row, Column)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, Row, Column, HomMat2DTranslate)
affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2DTranslate)

*

create_local_deformable_model 参数选择都差不多

然后下面是画出来deformable model的样子,用仿射变换。


NumImages := 7
for Index := 1 to NumImages by 1
    read_image (Image, 'gasket/gasket_' + Index$'02')
    dev_set_window (WindowHandle2)
    dev_display (Image)
    disp_message (WindowHandle2, 'Search ...', 'window', 12, 12, 'black', 'true')
    * Find the model in the search image.
    * As result, the rectified image, the respective
    * vector field, and the found contours are queried.
    count_seconds (S1)
    find_local_deformable_model (Image, ImageRectified, VectorField, DeformedContours, ModelID, rad(-10), rad(20), 1, 1, 1, 1, 0.93, 1, 0.7, 0, 0.4, ['image_rectified','vector_field','deformed_contours'], ['deformation_smoothness','expand_border','subpixel'], [Smoothness,0,1], Score, Row, Column)
    count_seconds (S2)

接下来就是检测,读取新的图片,然后find_local_deformable_model 


再往下又是老东西,gen_warped_mesh_region (VectorField, MeshRegion, Smoothness)画那个全是格的函数


        gen_region_contour_xld (DeformedContours, EdgeRegion, 'margin')
        dilation_circle (EdgeRegion, RegionDilation, 2 * Smoothness)
        intersection (RegionDilation, MeshRegion, RegionIntersection)

*

这就开始不同了,把匹配物品的XLD膨胀然后与生成的格做与运算。其实这些都是为了美观

然后        compare_variation_model (ImageRectified, Region, VariationModelID)
        connection (Region, ConnectedRegions)
        select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 30, 99999)
        count_obj (SelectedRegions, Number)

compare_variation_model 这个是用来找之前用find找到的模板匹配出来的图像与一开始创建的变分模型句柄来比较。

比较结果放在Region里面。(草草草,我忽然发现变分模型比较和一个东西很像,那个东西叫差影法,用来提取仪表刻度的,用变分模型的话,是不是也可以提取刻度呢,比如先做deformable匹配,刻度匹配上了然后把不对的地方变分消去,然后就剩下刻度了可以用来与指针做运算。以后可以试试。

比较结果做了一些形态学检测,也就是不同面积多于多少的就判定为不ok







  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值