摘要
缺陷检测有多种方式:blob剖析、特点模板匹配、差分信号、亮度立体式等。它们各有特点,像一群不同的战士,各自拥有强大的武器。让我们一起探索它们的精彩之处吧!
正文
halcon——缺陷检测常见方式汇总(特点训炼)
前言
机器视觉技术中缺陷检测分成一下几类:
-
blob剖析 特点
-
模板匹配(精准定位) 差分信号:halcon——缺陷检测常见方式汇总(模板匹配(精准定位) 差分信号) – 只有自身强劲 – 博客园 (cnblogs.com)
-
亮度立体式:halcon——缺陷检测常见方式汇总(亮度立体式) – 只有自身强劲 – 博客园 (cnblogs.com)
-
特点训炼
-
精确测量线性拟合:halcon——缺陷检测常见方式汇总(精确测量线性拟合) – 只有自身强劲 – 博客园 (cnblogs.com)
-
时域 室内空间域融合:halcon——缺陷检测常见方式汇总(时域室内空间域融合) – 只有自身强劲 – 博客园 (cnblogs.com)
-
深度神经网络
这篇博闻主要是对缺点图象的纹路特点训炼开展深入分析。
特点训炼
在纹路中找缺陷。根据高斯函数混和实体模型(GMM)支持向量机的纹路查验实体模型,适用图像金字塔,能够剖析纹路的好几个頻率范畴。
规定:训练样本务必完美无瑕疵。
总体流程:
-
建立实体模型create_texture_inspection_model或载入实体模型read_texture_inspection_model
-
加上训练样本add_texture_inspection_model_image
-
查询样版get_texture_inspection_model_image
-
训炼实体模型train_texture_inspection_model
各层金字塔式都是会训炼一个GMM实体模型,并明确该层的’novelty_threshold’(区别有没有缺陷的阀值)。
主要参数获得:get_texture_inspection_model_param
主要参数设置:set_texture_inspection_model_param
主要参数剖析:’patch_normalization’:’weber’对色度鲁棒性,‘none’必须色度做为评定(默认设置)
‘patch_rotational_robustness’:’true’对转动鲁棒性,’false’必须转动做为评定(默认设置)
‘levels’:设定实际的金字塔式层参加训炼,纹路越不光滑,则较低的金字塔式等级越可省去。默认设置auto。
‘sensitivity’:敏感度,危害’novelty_threshold’的数值。负数会造成 高些的阀值,进而越来越少的发觉缺点。默认设置0。
‘novelty_threshold’,阀值,全自动测算获得,若結果不理想化,能够手动式调整。
-
开展检验apply_texture_inspection_model
-
实体模型储存与释放出来write_texture_inspection_model
若实体模型不会再必须,则释放出来clear_texture_inspection_model
halcon经典案例(apply_texture_inspection_model.hdev)
一,建立实体模型,加上训练样本(完好无缺的图象)
TrainingImageIndices := [1,2] TextureModelFilename := 'texture_model_carpet'dev_open_window_fit_size (0, 0, Width, Height, -1, -1, WindowHandle1) dev_display (Image)*建立实体模型 create_texture_inspection_model ('basic', TextureInspectionModel) for Index := 0 to |TrainingImageIndices| - 1 by 1read_image (Image, 'carpet/carpet_' TrainingImageIndices[Index]$'02') dev_display (Image) Message := '插入图片 ' (Index 1) ' of ' |TrainingImageIndices| '训炼提前准备'dev_disp_text (Message, 'window', 12, 12, 'black', [], []) *载入训练样本(二张) add_texture_inspection_model_image (Image, TextureInspectionModel, Indices) endfor
二,基本设定主要参数后,逐渐训炼
*主要参数设置'patch_normalization':'weber'对色度鲁棒性,‘none’必须色度做为评定(默认设置)set_texture_inspection_model_param (TextureInspectionModel, 'patch_normalization', 'weber') Levels := [2,3,4]* 'levels':设定实际的金字塔式层参加训炼,纹路越不光滑,则较低的金字塔式等级越可省去。默认设置auto。set_texture_inspection_model_param (TextureInspectionModel, 'levels', Levels)* 逐渐训炼train_texture_inspection_model (TextureInspectionModel)*查询样版主要参数'novelty_threshold',阀值,全自动测算获得,若結果不理想化,能够手动式调整。get_texture_inspection_model_param (TextureInspectionModel, 'novelty_threshold', NoveltyThreshold)* 查询每个金字塔式级别的独创性评分图象和独创性地区,能够把'gen_result_handle'设定为'true', *以后get_texture_inspection_result_object载入'novelty_score_image'和'novelty_region'。set_texture_inspection_model_param (TextureInspectionModel, 'gen_result_handle', 'true')
三,对缺点图象初检测,表明检测結果
*设定对话框,用以表明每个金字塔式层图象WindowWidth := 320WindowHeight := 280dev_open_window (0, 0, WindowWidth, WindowHeight, 'black', WindowHandle1) set_display_font (WindowHandle1, 16, 'mono', 'true', 'false') dev_open_window (0, WindowWidth 8, WindowWidth, WindowHeight, 'black', WindowHandle2) set_display_font (WindowHandle2, 16, 'mono', 'true', 'false') dev_open_window (0, 2 * WindowWidth 16, WindowWidth, WindowHeight, 'black', WindowHandle3) set_display_font (WindowHandle3, 16, 'mono', 'true', 'false') dev_open_window (WindowHeight 50, WindowWidth / 2 8, 2 * WindowWidth, 2 * WindowHeight, 'black', WindowHandle4) set_display_font (WindowHandle4, 16, 'mono', 'true', 'false') WindowHandles := [WindowHandle1,WindowHandle2,WindowHandle3] ** 检验第一张训炼图象上的纹路缺点以调整主要参数。 for Index := 1 to 3 by 1ImageIndex := 5read_image (TestImage, 'carpet/carpet_' ImageIndex$'02')*检测当今图象apply_texture_inspection_model (TestImage, NoveltyRegion, TextureInspectionModel, TextureInspectionResultID)* 查验调试信息。 *查询每个金字塔式级别的独创性评分图象(NovScoreImage)和独创性地区(NovRegionL) * 独创性得分图象可用以独立调整独创性阀值。get_texture_inspection_result_object (NovScoreImage, TextureInspectionResultID, 'novelty_score_image') get_texture_inspection_result_object (NovRegion, TextureInspectionResultID, 'novelty_region')* 表明各层(金字塔式)的結果count_obj (NovScoreImage, Number) for Level := 1 to Number by 1 CurrentWindow := WindowHandles[Level - 1] dev_set_window (CurrentWindow) dev_clear_window () select_obj (NovScoreImage, NovScoreImageL, Level) select_obj (NovRegion, NovRegionL, Level) get_image_size (NovScoreImageL, Width, Height) dev_set_part (0, 0, Height - 1, Width - 1) dev_display (NovScoreImageL) Legend := 'Novelty region (level ' Levels[Level - 1] ')'dev_set_color ('red') dev_set_line_width (2)* dev_display (NovRegionL) dev_disp_text (['Novelty score image (level ' Levels[Level - 1] ')','Novelty threshold: ' NoveltyThreshold[Level - 1]$'.1f'], 'window', 12, 12, 'black', [], []) dev_disp_text (Legend, 'window', WindowHeight - 30, 12, 'white', ['box_color','shadow'], ['black','false']) endfor *表明結果dev_set_window (WindowHandle4) dev_display (TestImage) dev_set_line_width (2) dev_set_color ('red') dev_display (NoveltyRegion) area_center (NoveltyRegion, Area, Row, Column)if (Index < 3) dev_disp_text ('Result', 'window', 12, 12, 'black', [], [])elsedev_disp_text ('Final result', 'window', 12, 12, 'black', [], []) endif
四,依据检测結果开展调整主要参数
* 奇特阀值的调整。 if (Index == 1) Message[0] := '图象中有很多小不正确.'Message[1] := '能够根据更改 novelty thresholds的值来调节敏感度(sensitivity—)'Message[2] := '比如降低敏感度主要参数的值'dev_disp_text (Message, 'window', 12, 12, 'black', [], []) * 设定阀值测算的敏感度。 负数造成 高些的阀值,因而检验到的缺点更少。 * 'sensitivity':敏感度,危害'novelty_threshold'的数值。负数会造成 高些的阀值,进而越来越少的发觉缺点。默认设置0。 set_texture_inspection_model_param (TextureInspectionModel, 'sensitivity', -10) get_texture_inspection_model_param (TextureInspectionModel, 'novelty_threshold', NoveltyThreshold) endif if (Index == 2) Message := '还可以根据立即控制独创性界限来独立调节单独等级的敏感性'dev_disp_text (Message, 'window', 12, 12, 'black', [], [])* 奇特阀值的调整。 * * 从纹路中获得(全自动明确的)奇特阀值 * 查验实体模型并将适度改动的值设定为新的独创性阀值。 * *如果我们确立设定独创性界限,则忽视敏感度。 * 大家在这儿将其再次设定为 0 以防止搞混set_texture_inspection_model_param (TextureInspectionModel, 'sensitivity', 0)* Offset := [25,10,30] get_texture_inspection_model_param (TextureInspectionModel, 'novelty_threshold', NoveltyThreshold) set_texture_inspection_model_param (TextureInspectionModel, 'novelty_threshold', Offset NoveltyThreshold) get_texture_inspection_model_param (TextureInspectionModel, 'novelty_threshold', NoveltyThreshold) endif endforfor Level := 1 to |WindowHandles| by 1dev_set_window (WindowHandles[Level - 1]) dev_clear_window () endfor dev_set_window (WindowHandle4) dev_clear_window ()
五,到此,实体模型提前准备结束,将所有图象开展缺陷检测并表明
*检验全部检测图象上的纹路缺点。NumImages := 7for Index := 1 to NumImages by 1read_image (TestImage, 'carpet/carpet_' Index$'02')* *检验当今图象apply_texture_inspection_model (TestImage, NoveltyRegion, TextureInspectionModel, TextureInspectionResultID)*获得独创性图象和地区get_texture_inspection_result_object (NovScoreImage, TextureInspectionResultID, 'novelty_score_image') get_texture_inspection_result_object (NovRegion, TextureInspectionResultID, 'novelty_region')* 表明单独金字塔式叠加层数的結果count_obj (NovScoreImage, Number)for Level := 1 to Number by 1CurrentWindow := WindowHandles[Level - 1] dev_set_window (CurrentWindow) dev_clear_window () select_obj (NovScoreImage, NovScoreImageL, Level) select_obj (NovRegion, NovRegionL, Level) get_image_size (NovScoreImageL, Width, Height) dev_set_part (0, 0, Height - 1, Width - 1) dev_display (NovScoreImageL) Legend := 'Novelty region (level ' Levels[Level - 1] ')'dev_set_color ('red') dev_set_line_width (2)* dev_display (NovRegionL) dev_disp_text (['Novelty score image (level ' Levels[Level - 1] ')','Novelty threshold: ' NoveltyThreshold[Level - 1]$'.1f'], 'window', 12, 12, 'black', [], []) dev_disp_text (Legend, 'window', WindowHeight - 50, 12, ['red','white'], ['box_color','shadow'], ['black','false']) endfor* 表明結果 dev_set_window (WindowHandle4) dev_display (TestImage) dev_set_line_width (2) dev_set_color ('red') dev_display (NoveltyRegion) area_center (NoveltyRegion, Area, Row, Column)if (Area > 100) dev_disp_text ('Not OK', 'window', 12, 12, 'white', 'box_color', 'red')elsedev_disp_text ('OK', 'window', 12, 12, 'white', 'box_color', 'forest green') endif if (Index < NumImages) dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], []) stop () endif endfor
【专业术语表述】
-
Patch:邻近清晰度的结合。
-
Novelty Score:在检测全过程中,将检测图象的纹路特点与纹路查验实体模型开展较为,并测算他们的’novelty score’。 该值越大,单独纹路特点越不宜纹路查验实体模型的概率越大。
-
Novelty Threshold:Novelty Score高过该阀值,则纹路有缺陷。
-
“ novelty_region”是根据组成不一样金字塔式级别的独创性地区而转化成的,即不一样等级金字塔式构成的相交地区。假如仅有单面金字塔式,那麼该层的独创性地区立即便是novelty_region。
若要查询每个金字塔式级别的独创性评分图象和独创性地区,能够把’gen_result_handle’设定为’true’,以后get_texture_inspection_result_object载入’novelty_score_image’和’novelty_region’。
关注不迷路
扫码下方二维码,关注宇凡盒子公众号,免费获取最新技术内幕!
评论0