1、 基于组件的匹配
说明:
基于组件的匹配是形状匹配的扩展算法
只有一个组件会在整个ROI 区域搜索
其余组件会根据组件之间的关联关系去小范围搜索
条件:
组合物体要包含几个刚性组件
组件之间存在一定的位置关系
组件间的关系
• 全图像内搜寻 root component
• 根据root component的位置确定其它组件位置
四个主要函数
◆ 训练函数
train_model_components
◆ 创建组件模板函数
create_component_model
create_trained_component_model
◆ 搜索组件模板函数
find_component_model
1》 创建模板
.确定组件区域
.创建组件模板
read_image(ModelImage,'modules/modules_model')
/…画四个区域
gen_rectangle2(ComponentRegions,318,109,-1.62,34,19)
gen_rectangle2(Rectangle2,342,238,-1.63,32,17)
gen_rectangle2(Rectangle3,355,505,1.41,25,17)
gen_rectangle2(Rectangle4 247,448,0,14,8)
gen_rectangle2(Rectangle5,237,537,-1.57,13,10)
/…将区域合并
ComponentRegions := [ComponentRegions,Rectangle2]
ComponentRegions := [ComponentRegions,Rectangle3]
ComponentRegions := [ComponentRegions,Rectangle4]
ComponentRegions := [ComponentRegions,Rectangle5]
/…创建模板
create_component_model(ModelImage,ComponentRegions,20,20,rad(25),0,rad(360),15,40,15,10,0.8,[4,3,3,3,3],0,'none','use_polarity','true',ComponentModelID,RootRanking)
/…将模板写入地址中
write_component_model(ComponentModelID,Filename)
2》 查找模板
查找组件模板
read_component_model(Filename,ComponentModelID)
while(true)
grab_image(SearchImage,FGHandle)
/…查找模板
find_component_model(SearchImage,ComponentModelID,RootRanking[0],0,rad(360),0.5,0,0.5,'stop_search','search_from_best','none',0.8,'interpolation',0,0.8,ModelStart,ModelEnd,Score,RowComp,ColumnComp,AngleComp,ScoreComp,ModelComp)
dev_display(SearchImage)
/…显示模板轮廓
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_display(FoundComponents)
endfor
endwhile
clear_component_model(ComponentModelID)
3》 训练模板
TrainingImages:= []
/…读入四张图片
for i :=1 to 4 by 1
read_image(TrainingImage,'pipe_wrench_training_'+i)
TrainingImages := [TrainingImages,TrainingImage]
Endfor
/…训练模板
train_model_components(ModelImage,InitialComponentRegions,TrainingImages,ModelComponents,22,60,30,0.65,-1,1,rad(60),'speed','rigidity',0.2,0.4,ComponentTrainingID)
write_training_components(ComponentTrainingID,FileNameTraining)
/…通过训练结果创建模板
read_training_components(FileNameTraining,ComponentTrainingID)
create_trained_component_model(ComponentTrainingID,-rad(30),rad(60),10,0.55,4,0,'none','use_polarity','false',ComponentModelID,RootRanking)
write_component_model(ComponentModelID,FileName)
clear_training_components(ComponentTrainingID)
注释:
train_model_components(
ModelImage, // 模板图片
InitialComponents, // 根组件
TrainingImages, // 训练图片
ModelComponents, // 组件模板
ContrastLow, ContrastHigh, //同形状模板
MinSize, MinScore, // 同形状模板
SearchRowTol, SearchColumnTol, // 位置变化范围
SearchAngleTol, // 角度变化范围
TrainingEmphasis, // 速度或鲁棒性优先
AmbiguityCriterion, // 模糊匹配规则
MaxContourOverlap, // 轮廓重合
ClusterThreshold, // 根组件归类阈值
ComponentTrainingID // 模板ID
)