• 模板匹配二 行远


    XLD模板匹配实例

    解读对于这个图片,会出现重复查找,后续解决!

    dev_update_off()
    dev_close_window()
    read_image(Image, 'E:/学习/Halcon/模板匹配/XLD/modules_01.png')
    get_image_size(Image, Width, Height)
    
    dev_open_window(0, 0, Width, Height, 'black', WindowHandle)
    dev_display(Image)
    
    *获取灰度图
    rgb1_to_gray(Image, GrayImage)
    *获取感兴趣的区域
    draw_rectangle2(WindowHandle, Row, Column, Phi, Length1, Length2)
    gen_rectangle2(Rectangle1, Row, Column, Phi, Length1, Length2)
    
    
    
    
    *创建模板
    reduce_domain(GrayImage, Rectangle1, ImageReduced)
    
    
    edges_sub_pix(ImageReduced, Edges, 'canny', 1, 20, 40)
    *create_shape_model(ImageReduced, 'auto', rad(0), rad(360), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
    create_shape_model_xld(Edges, 'auto', rad(0), rad(360), 'auto', 'auto', 'ignore_local_polarity', 50, ModelID)
    
    get_shape_model_contours(ModelContours, ModelID, 1)
    find_shape_model(GrayImage, ModelID, rad(0), rad(360), 0.9, 1, 0.9, 'least_squares', 0, 0.9, Row1, Column1, Angle1, Score1)
    
    
    vector_angle_to_rigid(0, 0, 0,Row1, Column1, 0, HomMat2D)
    affine_trans_contour_xld(ModelContours, ContoursAffinTrans, HomMat2D)
    dev_clear_window()
    dev_display(Image)
    dev_display(ContoursAffinTrans)
    
    find_shape_models(GrayImage, ModelID, rad(0), rad(360), 0.86, 0, 0.9, 'least_squares', 0, 0.9, Row4, Column4, Angle4, Score4, Model)
    dev_clear_window()
    dev_display(Image)
    for I:=0 to |Score4|-1 by 1
        
       hom_mat2d_identity(HomMat2DIdentity)
       hom_mat2d_translate(HomMat2DIdentity, Row4[I],Column4[I], HomMat2DTranslate)
       hom_mat2d_rotate(HomMat2DTranslate, Angle4[I], Row4[I],Column4[I], HomMat2DRotate)
        affine_trans_contour_xld(ModelContours, ContoursAffinTrans1, HomMat2DRotate)
        dev_display(ContoursAffinTrans1)
        
    endfor

    查了几次。

    解决上述问题:

    采用了这种方式实现ROI获取XLD:

    1 *获取感兴趣的区域
    2 draw_rectangle2(WindowHandle, Row, Column, Phi, Length1, Length2)
    3 gen_rectangle2(Rectangle1, Row, Column, Phi, Length1, Length2)
    4 smallest_rectangle2(Rectangle1, Row3, Column3, Phi2, Length12, Length22)
    5 gen_rectangle2_contour_xld(Rectangle, Row3, Column3, Phi2, Length12, Length22)

    可以解决上述问题,但不知道第一种方式出现这种问题的根源在哪里。

  • 相关阅读:
    一个例子讲明爬虫请求库requests
    SpringBoot【六】 Shiro
    SpringBoot【五】 Spring Security
    SpringBoot【四】 任务
    Swagger
    SpringBoot【三】 整合 JDBC、Druid、MyBatis
    SpringBoot【二】 SpringBoot 配置
    SpringBoot【一】入门程序及原理分析
    SpingBoot 相关问题:启动 web 项目之后出现 java.lang.UnsatisfiedLinkError: D:Tomcatapache-tomcat-9.0.36in cnative-1.dll
    SpringBoot 相关问题:IDEA 创建 SpringBoot 项目时出现 Initialization failed for 'https://start.spring.io' 问题
  • 原文地址:https://www.cnblogs.com/xingyuanzier/p/16016799.html
Copyright © 2020-2023  润新知