首页 > 其他分享 >分类器——高斯混合模型之缺陷检测(纹理缺陷检测)

分类器——高斯混合模型之缺陷检测(纹理缺陷检测)

时间:2024-03-07 15:44:51浏览次数:20  
标签:10 false GMM 检测 image dev 分类器 mesh 缺陷

* This example program shows you how to use the GMM classifier for novelty
* detection to perform a web inspection task.  To perform the novelty detection,
* all pixels belonging to the single trained class are computed, and are then
* subtracted from the classification ROI to extract the erroneous pixels.  For
* the web inspection task, the GMM can consequently be used to detect
* textures that do not correspond to the texture of the trained good objects.

* 此示例程序向您展示如何使用 GMM 分类器进行新颖性检测以执行 网状检测任务。 
*为了执行新颖性检测,将计算属于单个训练类的所有像素,然后从分类 ROI 中减去以提取错误像素。 
*因此,对于卷材检测任务,GMM 可用于检测与训练好的物体的纹理不对应的纹理。
* 
dev_update_off ()
* 
ReadPretrainedClassifier := false
* 取消注释以下行以从磁盘读取预训练的分类器。训练可能持续长达半分钟。
* ReadPretrainedClassifier := true
SaveClassifier := false
* 取消注释将 GMM训练样本后将分类器保存到磁盘
* SaveClassifier := true
* 
read_image (Image, 'plastic_mesh/plastic_mesh_01')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_color ('red')
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
get_system ('example_dir', HalconExamples)
* The texture filters used for the classification will return artifacts at the image
* borders because the images of the plastic mesh to be inspected do not
* contain an integer number of mesh cells.  Because this would lead to wrongly
* detected errors at the image borders, we must exclude the area close to the
* image border from the training and classification.  This is done with the following
* rectangle.  Note that the image is later scaled down by a factor of two.
* 用于分类的纹理过滤器将在图像边框处返回伪影,因为要检查的塑料网格的图像不包含整数个网格单元。
*由于这会导致在图像边界处错误检测到错误,因此我们必须从训练和分类中排除靠近图像边界的区域。 
*这是通过以下矩形完成的。 请注意,图像稍后会缩小两倍。
gen_rectangle1 (Rectangle, 10, 10, Height / 2 - 11, Width / 2 - 11)
if (ReadPretrainedClassifier)
    * 从磁盘读取先前训练的GMM模型
    dev_display (Image)
    disp_message (WindowHandle, 'Reading classifier from disk...', 'window', 10, 10, 'cyan', 'false')
    read_class_gmm (HalconExamples + '/hdevelop/Segmentation/Classification/novelty_detection.gmm', GMMHandle)
    wait_seconds (1.5)
else
    * 创建GMM模型分类器
    create_class_gmm (5, 1, [1,5], 'spherical', 'normalization', 5, 42, GMMHandle)
    * 以5件完好样品来训练模型
    for J := 1 to 5 by 1
        read_image (Image, 'plastic_mesh/plastic_mesh_' + J$'02')
        * The images are zoomed down because the resolution of the mesh is very
        * high.  This saves a large amount of processing time.
        *由于网格的分辨率非常高,因此图像被缩小。 这节省了大量的处理时间。
        zoom_image_factor (Image, ImageZoomed, 0.5, 0.5, 'constant')
        dev_display (ImageZoomed)
        disp_message (WindowHandle, '训练样本添加中...', 'window', 10, 10, 'cyan', 'false')
        * Generate the texture image.
        *生成纹理图像
        gen_texture_image (ImageZoomed, ImageTexture)
        * 纹理图像添加至分类器
        add_samples_image_class_gmm (ImageTexture, Rectangle, GMMHandle, 2.0)
    endfor
    dev_display (ImageZoomed)
    disp_message (WindowHandle, 'Training GMM...', 'window', 10, 10, 'cyan', 'false')
    * 训练模型.
    train_class_gmm (GMMHandle, 100, 0.1, 'training', 0.0001, Centers, Iter)
    if (SaveClassifier)
        write_class_gmm (GMMHandle, HalconExamples + '/hdevelop/Segmentation/Classification/novelty_detection.gmm')
    endif
endif
* 检测塑料网中的异常
dev_set_draw ('margin')
dev_set_line_width (3)
for J := 1 to 14 by 1
    read_image (Image, 'plastic_mesh/plastic_mesh_' + J$'02')
    zoom_image_factor (Image, ImageZoomed, 0.5, 0.5, 'constant')
    dev_display (ImageZoomed)
    dev_set_color ('white')
    dev_display (Rectangle)
    gen_texture_image (ImageZoomed, ImageTexture)
    reduce_domain (ImageTexture, Rectangle, ImageTextureReduced)
    * Classify samples belonging to the trained class with the GMM.
    *使用 GMM 对属于训练类的样本进行分类。
    classify_image_class_gmm (ImageTextureReduced, Correct, GMMHandle, 0.000002)
    * Subtract them from the ROI to obtain the texture errors.
    *从 ROI 中减去它们以获得纹理误差。
    difference (Rectangle, Correct, Errors)
    * Postprocess the returned raw errors to remove insignificant parts of the
    * detected errors.
    * 对返回的原始错误进行后处理,以删除检测到的错误中无关紧要的部分。
    opening_circle (Errors, ErrorsOpening, 3.5)
    closing_circle (ErrorsOpening, ErrorsClosing, 10.5)
    connection (ErrorsClosing, ErrorsConnected)
    select_shape (ErrorsConnected, FinalErrors, 'area', 'and', 300, 1000000)
    count_obj (FinalErrors, NumErrors)
    dev_set_color ('red')
    dev_display (FinalErrors)
    if (NumErrors > 0)
        disp_message (WindowHandle, 'Mesh not OK', 'window', 10, 10, 'red', 'false')
    else
        disp_message (WindowHandle, 'Mesh OK', 'window', 10, 10, 'forest green', 'false')
    endif
    if (J < 14)
        disp_continue_message (WindowHandle,'cyan', 'false')
    endif
    stop ()
endfor

 

 

 

标签:10,false,GMM,检测,image,dev,分类器,mesh,缺陷
From: https://www.cnblogs.com/echo-efun/p/18059032

相关文章

  • 分类器——高斯混合模型之水果分类
    *此示例程序演示如何应用通用GMM*使用“面积”和“圆度”特征区分柑橘类水果的分类。此外,还对提取的水果的2D特征空间进行了可视化。*read_image(Image,'color/citrus_fruits_01')get_image_pointer1(Image,Pointer,Type,Width,Height)dev_close_window()dev......
  • 分类器——高斯混合模型/Gaussian-Mixture-Models(GMM)之图像分割
    图像分割之高斯混合模型使用GMM的步骤如下:首先,GMM由create_class_gmm创建。然后,通过add_sample_class_gmm添加训练向量,然后可以使用write_samples_class_gmm将它们写入磁盘。通过train_class_gmm确定分类器中心参数(如上定义)。此外,它们可以与write_class_gmm一起保存,以便以后......
  • 【教程】HBuilderX开发实践:隐私合规检测问题解决方案
    文章目录摘要引言正文1、违规收集个人信息2、APP强制、频繁、过度索取权限知识点补充总结 摘要本篇博客介绍了在使用HBuilderX进行开发过程中,常遇到的隐私合规问题,并提供了相应的解决方案。主要包括违规收集个人信息和APP强制、频繁、过度索取权限两方面。......
  • 2. 寄存器(内存) | 检测点3.1
          TRANSLATEwithxEnglishArabicHebrewPolishBulgarianHindiPortugueseCatalanHmongDawRomanianChineseSimplifiedHungarianRussianChineseTraditionalIndonesianSlovakCzechItalianSlovenianDanishJapanese......
  • 目标检测两种常用的数据集COCO和VOC
    背景:今天跟着我们算法工程师学了几分钟的算法模型训练,她讲到目标检测常用的数据集是COCO和VOC,我不知道啥是数据集,更加不知道这两个是什么,它们有什么用,于是我简单了解了一下子~要解决的问题: 什么是数据集?COCO和VOC是什么?它们分别是什么格式?问题1:什么是数据集?数据集,其字......
  • 老年人姿态检测
    【跌倒检测传感信号方案】【方案1】该方案设计为:陀螺仪+心率传感器方案优点:陀螺仪数据经tinyML数据处理后,输出姿态信息改变数据;平稳姿态转为跌倒姿态,人体效率骤升。双通道数据结合判断是否跌倒。方案缺点:跌倒检测装置需设置为腕表状(通过腕部心率传感器监测心率)或胸表......
  • 1-8高灵敏度电容式水位检测芯片VK36W系列 电容式触摸IC原厂【FAE技术支持】
     产品型号:VK36W1D产品品牌:VINKA/永嘉微电封装形式:SOT23-6产品年份:新年份深圳市永嘉微电科技有限公司,原厂直销,原装现货更有优势!工程服务,技术支持,让您的生产高枕无忧!量大价优,保证原装正品。您有量,我有价!概述VK36W1D具有1个触摸检测通道,可用来检测水从无到有和水从有到无的......
  • 使用纹理对比度检测检测AI生成的图像
    在本篇文章中我们将介绍如何开发一个深度学习模型来检测人工智能生成的图像大多数用于检测人工智能生成图像的深度学习方法取决于生成图像的方法,或者取决于图像的性质/语义,其中模型只能检测人工智能生成的人、脸、汽车等特定对象。但是这篇论文“RichandPoorTextureContrast......
  • Git无法正常工作,因为检测到XXX存储库可能不安全(unsafe repository)的解决方法
    背景前两天因为对硬盘进行了误操作,导致系统无法进入,只能重新安装。待系统安装完毕后第一时间将VS下了回来。在VS开发环境部署完毕后,我打开了自己的解决方案,结果在“Git更改”选项卡内遇到了如下图的提示(分别是VS2022和VS2019): 过程在点击“将其标记为安全”后该存储库可以正......
  • 闭眼检测
    配置参数--shape-predictorshape_predictor_68_face_landmarks.dat--videotest.mp4代码案例#导入工具包fromscipy.spatialimportdistanceasdistfromcollectionsimportOrderedDictimportnumpyasnpimportargparseimporttimeimportdlibimportcv2......