首页 > 其他分享 >Halcon 创建变异模型

Halcon 创建变异模型

时间:2024-10-20 14:17:18浏览次数:3  
标签:get 变异 创建 variation Halcon dev 图像 model gen

*create_variation_model( : : Width, Height, Type, Mode : ModelID)

说明:创建一个ID为ModelID,宽为Width,高为Height,类型为Type的Variation Model,参数Mode决定了创建标准图像和相应的variation图像的方法。'standard'表示标准的训练方法,标准图像的位置是各训练图像位置的平均,'robust'表示鲁棒的训练方法,标准图像的位置是各训练图像的中值,此模式在训练图像中可能存在ERROR时使用,'direct'表示标准图像由单张图像经过处理得到,由此方法得到的标准图像只能应用prepare_direct_variation_model算子得到variation model。

*prepare_variation_model( : : ModelID, AbsThreshold, VarThreshold : )

说明:设置variation model的绝对阈值和相对阈值。绝对阈值即待检测图像与标准图像的差值,相对阈值即待检测图像与variation model与VarThreshold乘绩的差值。

Smoothness := 25
read_image (ModelImage, 'E:/项目/电芯上料现场/江苏11拉/20230703/11标定图/泡沫横1/1.bmp')
gen_rectangle1 (ROI_0, 510.681, 2581.9, 1171.39, 3286.78)
reduce_domain (ModelImage, ROI_0, ImageReduced)
crop_domain (ImageReduced, ImagePart)
get_image_size (ImagePart, Width, Height)
dev_get_window (WindowHandle)

*提取对比图像

sobel_amp (ImagePart, EdgeAmplitude, 'thin_sum_abs_binomial', 7)
threshold (EdgeAmplitude, Region1, 100, 255)
connection (Region1, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 20, 99999)
region_to_mean (SelectedRegions1, EdgeAmplitude, EdgeAmplitude)

//创建模板

create_variation_model (Width, Height, 'byte', 'direct', VariationModelID)
prepare_direct_variation_model (ImagePart, EdgeAmplitude, VariationModelID, 40, 2.5)
create_local_deformable_model (ImagePart, 'auto', [], [], 'auto', 0.9, [], 'auto', 0.9, [], 'auto', 'none', 'use_polarity', 'auto', 'auto', [], [], ModelID)
get_deformable_model_contours (ModelContours, ModelID, 1)
area_center (ImagePart, Area, Row, Column)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, Row, Column, HomMat2DTranslate)
affine_trans_contour_xld (ModelContours, ContoursAffineTrans, HomMat2DTranslate)
dev_set_window (WindowHandle)
dev_set_line_width (2)
dev_set_color ('yellow')
dev_display (ImagePart)
dev_display (ContoursAffineTrans)

//查找模板,标记缺陷位置

list_files ('E:/项目/电芯上料现场/标定图/泡沫横1', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
    read_image (Image, ImageFiles[Index])

    count_seconds (S1)
    find_local_deformable_model (Image, ImageRectified, VectorField, DeformedContours, ModelID, rad(-10), rad(20), 1, 1, 1, 1, 0.7, 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)
    Time := S2 - S1
    if (|Score| > 0)
        gen_empty_obj (MeshRegion)
        count_obj (VectorField, Number)
        for IndexI := 1 to Number by 1
            select_obj (VectorField, ObjectSelected, IndexI)
            vector_field_to_real (ObjectSelected, DRow, DCol)
            get_image_size (VectorField, Width1, Height1)
            for ContR := 0.5 to Height1[0] - 1 by Smoothness
                Col1 := [0.5:Width[0] - 1]
                tuple_gen_const (Width[0] - 1, ContR, Row1)
                *get_grayval_interpolated— 返回图像在元组给定位置的灰度值 行和列。
                get_grayval_interpolated (DRow, Row1, Col1, 'bilinear', GrayRow)
                get_grayval_interpolated (DCol, Row1, Col1, 'bilinear', GrayCol)
                gen_region_points (Region, GrayRow, GrayCol)
                concat_obj (MeshRegion, Region, MeshRegion)
            endfor
             for ContC := 0.5 to Width1[0] - 1 by Smoothness
                Row1 := [0.5:Height[0] - 1]
                tuple_gen_const (Height[0] - 1, ContC, Col1)
                get_grayval_interpolated (DRow, Row1, Col1, 'bilinear', GrayRow)
                get_grayval_interpolated (DCol, Row1, Col1, 'bilinear', GrayCol)
                gen_region_points (Region, GrayRow, GrayCol)
                concat_obj (MeshRegion, Region, MeshRegion)
             endfor
        endfor
        gen_region_contour_xld (DeformedContours, EdgeRegion, 'margin')
        dilation_circle (EdgeRegion, RegionDilation, 2 * Smoothness)
        intersection (RegionDilation, MeshRegion, RegionIntersection)
        dev_set_line_width (1)
        dev_set_color ('yellow')
        dev_display (RegionIntersection)
        Found[Index] := |Score|
        dev_set_line_width (2)
        dev_set_color ('green')
        dev_display (DeformedContours)
        dev_set_window (WindowHandle)
        dev_display (ImageRectified)
        disp_message (WindowHandle, ['模板时间 ' + Time$'1.2f' + ' s','模板分数: ' + Score$'.2f'], 'window', 12, 12, 'black', 'true')
        disp_message (WindowHandle, Index, 'window', 60, 12, 'forest green', 'true')
       
        wait_seconds (2)
        *标记缺陷位
        *compare_variation_model- 将图像与变体模型进行比较。
        compare_variation_model (ImageRectified, Region, VariationModelID)
        connection (Region, ConnectedRegions)
        select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 100, 299)
        count_obj (SelectedRegions, Number)
        if (Number > 0)
            area_center (SelectedRegions, Area, Row1, Column1)
            elliptic_axis (SelectedRegions, Ra, Rb, Phi)
            tuple_gen_const (Number, 1, Ones)
            PointOrder := []
            for Idx := 0 to Number - 1 by 1
                PointOrder := [PointOrder,'positive']
            endfor
            gen_ellipse_contour_xld (ContEllipse, Row1, Column1, Phi, Ra + 10, Rb + 10, 0 * Ones, 6.28318 * Ones, PointOrder, 1.5)
            dev_set_color ('red')
            dev_display (ContEllipse)
            disp_message (WindowHandle, '模板NG', 'window', 80, 12, 'red', 'true')
        else
            disp_message (WindowHandle, '模板OK', 'window', 80, 12, 'forest green', 'true')
        endif
    else
        disp_message (WindowHandle, '未找到模板', 'window', 80, 12, 'black', 'true')
    endif
    wait_seconds (2)
endfor

标签:get,变异,创建,variation,Halcon,dev,图像,model,gen
From: https://blog.csdn.net/2202_75557553/article/details/143088043

相关文章

  • DJ混音创作 DJ Mix Pads 2 激活版 虚拟乐器和音效创建混音软件
    DJMixPads2是一款功能强大的音乐制作软件,它允许用户通过虚拟乐器和音效创建自己的音乐混音和曲目。该软件具有用户友好的界面,提供多种预加载样本和循环,支持电子、流行、摇滚等多种音乐风格。用户可以通过点击不同的打击垫和循环来实时创作音乐,并添加混响、延迟等效果。此外,DJ......
  • Vue CLI 与 Vite:构建工具的选择及其在 Vue 项目中的应用(如何在 Vue 2 中使用 Vue CLI
    文章目录1.引言2.VueCLI与Vite的基本概念2.1VueCLI概述2.2Vite概述3.如何在Vue2中使用VueCLI进行项目创建3.1安装VueCLI3.2创建Vue2项目3.3启动开发服务器4.Vue3项目中如何使用Vite实现快速开发4.1使用Vite初始化Vue3项目4.2启......
  • 【YOLO】Anaconda安装以及修改环境创建的默认路径
    Anaconda可以用来管理多python环境由于每个py项目所依赖的软件包版本不一致,可能导致兼容性问题Anaconda通过创建虚拟环境,来区分各个项目,避免项目间软件包互相污染 Anaconda下载地址:官网:https://www.anaconda.com/download/success(官网下载比较慢)清华源:https://mirr......
  • Golang 常用的五种创建型设计模式
    Golang常用的五种创建型设计模式原创GoOfficialBlogGoOfficialBlog 2024年10月18日19:10中国香港听全文在Go中,创建设计模式有助于管理对象的创建,并控制对象的实例化方式。这些模式在对象创建过程复杂或需要特殊处理时特别有用。以下是Go中常用的主要创建模式: ......
  • 我在创建表时,建表语句中不同数据类型字段的排列顺序对性能有影响吗?
    在MySQL或其他数据库管理系统(DBMS)中,字段的排列顺序对表的性能影响并不是非常显著或直接的,但在某些特定情况下,优化字段排列可以带来一些性能或存储效率上的好处。以下是一些需要考虑的因素,尤其是当涉及大量数据和性能优化时。1.数据类型的对齐和存储效率MySQL在存储数据时,试......
  • Race Track Generator Ultimate:Race Track Generator(赛车场赛道看台场景创建工具)
    下载:​​Unity资源商店链接资源下载链接效果图:......
  • 如何创建Electron + Vue3项目, 并调用C# dll
    依赖环境当前系统环境为win11,真正上手才知道环境问题才是最大的问题,希望本文能帮你节约时间。本文参考以下资料https://www.electronforge.io/guides/framework-integration/vue-3perplexity.ai和kimi.ai提供其他相关资料nodejs在开发前需要确定你要调用的dll是32位还是64位......
  • SAP:关于创建销售订单-交货/拣配-审批信贷-过账的接口
    关于本来要分几步做的接口业务强制要求集成到一步的那些抽象需求已知该接口要有几次调用中间出错要保存错误消息,不然哪一步出错都不知道。所以要建一个消息表,组件接口调用的唯一标识销售订单号交货单号过账状态标记(E/W/S或者整个1-9记录哪一步出错)消息点击查看代码D......
  • Create-react-app创建的项目打包后页面空白的解决方法
    当我们使用create-react-app脚手架创建一个react项目之后,等到项目开发完成想要打包部署时会发现,通过npmrunbuild命令打包后的项目在浏览器端访问时会出现页面空白的情况。解决方法:此类问题一般有两种解决方法,其中第一种也是最常见的,当我们打开浏览器控制台时会发现,当首页空白......
  • 通过github创建自己网页链接的方法
    文章目录要使用GitHub创建静态网页链接,可以按照以下详细步骤进行操作:一、准备阶段二、创建仓库并配置三、准备并上传静态网站文件四、配置GitHubPages五、访问和更新你的静态网页要使用GitHub创建静态网页链接,可以按照以下详细步骤进行操作:一、准备阶段注册GitHu......