| 
 | 
 
基于组件建模的匹配定位方法,具体代码如下: 
- * 基于组件之间的相对关系进行匹配component-based matching
 
 - * 本程序展示了如何创建输入和输出的关系,训练,测试
 
 - dev_update_off ()
 
 - dev_set_draw ('margin')
 
 - read_image (ModelImage, 'dip_switch/dip_switch_model')
 
 - get_image_size (ModelImage, Width, Height)
 
 - dev_close_window ()
 
 - dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
 
 - * 初始化组件,可手动框出目标的位置Define the initial components
 
 - * 不变的两部分
 
 - 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
 
 - stop()
 
 - * 获取需要训练的样本图库,同一个物件(最好包含全部的不同状态),背景单一Get the training images
 
 - gen_empty_obj (TrainingImages)
 
 - for I := 1 to 12 by 1
 
 -     read_image (TrainingImage, 'dip_switch/dip_switch_training_' + I02')
 
 -     concat_obj (TrainingImages, TrainingImage, TrainingImages)
 
 -     dev_display (TrainingImage)
 
 - endfor
 
 - stop()
 
 - * 以下两句代码可以辅助我们找到最佳的参数:ContrastLow, ContrastHigh, and MinSize
 
 - * add_channels (InitialComponents, ModelImage, ModelImageInitComp)
 
 - * gen_initial_components (ModelImageInitComp, InitialComponentEdges, 45, 45, 30, 'connection', [], [])
 
 - * 训练模型,并保存相应的模型方便下次直接读取 Extract the model components and train the relations
 
 - * read_training_components ('train_dip_switch.ct', ComponentTrainingID)
 
 - 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')
 
 - get_training_components (ModelComponents, ComponentTrainingID, 'model_components', 'model_image', 'false', RowRef, ColumnRef, AngleRef, ScoreRef)
 
 - dev_display (ModelComponents)
 
 - stop()
 
 - * 显示训练样本的组件相对关系
 
 - count_obj (ModelComponents, NumComp)
 
 - for I := 0 to NumComp - 1 by 1
 
 -     dev_display (ModelImage)
 
 -     get_component_relations (Relations, ComponentTrainingID, I, 'model_image', Row, Column, Phi, Length1, Length2, AngleStart, AngleExtent)
 
 -     dev_display (Relations)
 
 - endfor
 
 - stop()
 
 - * 增加训练模型的鲁棒性 to receive a higher robustness.
 
 - modify_component_relations (ComponentTrainingID, 'all', 'all', 0, rad(4))
 
 - ******** 测试
 
 - MinScoreComp := gen_tuple_const(13,0.8)
 
 - MinScoreComp[0] := 0.4
 
 - NumLevelsComp := gen_tuple_const(13,0)
 
 - NumLevelsComp[0] := 4
 
 - dev_display (ModelImage)
 
 - 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)
 
 - dev_display (ModelImage)
 
 - dev_set_colored (12)
 
 - dev_display (Tree)
 
 - dev_display (Relations)
 
 - clear_training_components (ComponentTrainingID)
 
 - * 实时测试,采用已经创建好的模型ComponentModelID, RootRanking
 
 - ImgNo := 1
 
 - for i:=0 to 100 by 1
 
 -     read_image (SearchImage, 'dip_switch/dip_switch_' + ImgNo02d')
 
 -     count_seconds (Seconds1)
 
 -     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)
 
 -     count_seconds (Seconds2)
 
 -     dev_display (SearchImage)
 
 -     NumFound := |ModelStart|
 
 -     Time := (Seconds2 - Seconds1) * 1000
 
 -     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
 
 - endfor
 
 - clear_component_model (ComponentModelID)
 
  复制代码 
 
 
 
 |   
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册  
 
x
 
 
 
 
 |