halcon组件匹配

组件匹配需要创建多个ROI来分别对应每个组件,同时需要比较多的训练图片尽可能识别组件间不同的相对位置关系。

 

*创建多个ROI生成组件

gen_rectangle2 (InitialComponents, 265, 138, -0.02, 23, 13)

gen_rectangle2 (InitialComponent, 342, 286, -0.02, 168, 13)

concat_obj (InitialComponents, InitialComponent, InitialComponents)

for I := 0 to 11 by 1

gen_rectangle2 (InitialComponent, 311 + I * 0.5, 128 + I * 28.2, 0, 10, 12)

concat_obj (InitialComponents, InitialComponent, InitialComponents)

endfor

*创建多个图片训练集

gen_empty_obj (TrainingImages)

for I := 1 to 12 by 1

read_image (TrainingImage, 'dip_switch/dip_switch_training_' + I$'02')

concat_obj (TrainingImages, TrainingImage, TrainingImages)

dev_display (TrainingImage)

endfor

*创建组件模型

train_model_components (ModelImage, InitialComponents, TrainingImages, ModelComponents, 45, 45, 30, 0.95, -1, -1, rad(20), 'speed', 'rigidity', 0.2, 0.5, ComponentTrainingID)

write_training_components (ComponentTrainingID, 'train_dip_switch.ct')

*获取组件间相对关系

count_obj (ModelComponents, NumComp)

for I := 0 to NumComp - 1 by 1

dev_display (ModelImage)

dev_set_colored (12)

get_component_relations (Relations, ComponentTrainingID, I, 'model_image', Row, Column, Phi, Length1, Length2, AngleStart, AngleExtent)

dev_display (Relations)

endfor

*优化模型并获取关系树

create_trained_component_model (ComponentTrainingID, 0, rad(360), 10, MinScoreComp, NumLevelsComp, 'auto', 'none', 'use_polarity', 'false', ComponentModelID, RootRanking)

get_component_model_tree (Tree, Relations, ComponentModelID, RootRanking, 'model_image', StartNode, EndNode, Row, Column, Phi, Length1, Length2, AngleStart, AngleExtent)

*模型搜索并可视化每个组件匹配结果

find_component_model (SearchImage, ComponentModelID, RootRanking, 0, rad(360), 0, 0, 0.5, 'stop_search', 'prune_branch', 'none', MinScoreComp, 'least_squares', 0, 0.9, ModelStart, ModelEnd, Score, RowComp, ColumnComp, AngleComp, ScoreComp, ModelComp)

dev_display (SearchImage)

NumFound := |ModelStart|

disp_message (WindowHandle, NumFound + ' object(s) found in ' + Time$'4.2f' + ' ms', 'image', 20, 20, 'yellow', 'false')

for Match := 0 to |ModelStart| - 1 by 1

get_found_component_model (FoundComponents, ComponentModelID, ModelStart, ModelEnd, RowComp, ColumnComp, AngleComp, ScoreComp, ModelComp, Match, 'false', RowCompInst, ColumnCompInst, AngleCompInst, ScoreCompInst)

dev_set_colored (12)

dev_display (FoundComponents)

visualize_dip_switch_match (RowCompInst, ColumnCompInst, AngleCompInst, RowRef, ColumnRef, AngleRef, WindowHandle, Match)

endfor

 

 图6 创建多个ROI对应不同的component

图7 训练不同位置的图片

 

图8 生成组件模型

 

 图9 生成模型组件

 图10 获取组件相对位置关系

图11 优化组件模型并获取关系树

 

 图12 搜索组件模型并可视化每一个组件匹配结果

posted @   QuincyYi  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示