当前位置: 首页 > news >正文

train_model_components ——组件模型的灵感,灵感

就一句话

一个灵感:
原来可以通过两个模版匹配的角度,或者距离,去判定开关,或者距离偏差等。
这个components可能是精度会高一点,正常状态下,我觉得用两个shapemodel去一张图片里查找最简单。

components——用起来挺麻烦感觉。

train_model_components(ModelImage, InitialComponents, TrainingImages : ModelComponents : ContrastLow, ContrastHigh, MinSize, MinScore, SearchRowTol, SearchColumnTol, SearchAngleTol, TrainingEmphasis, AmbiguityCriterion, MaxContourOverlap, ClusterThreshold : ComponentTrainingID)


* ModelImage——输入:模型初始参考位置
* InitialComponents——输入:两个以上的region
* TrainingImage——输入:图集,代表了不状态下组件的关系
****ModelComponents:——输出训练好的模型组件,从示例上看是核心位置的边界区域也就是boundary-region
*/  ContrastLow——核心boundary的最低对比度
*/  ContrastHigh——最高对比度
*/  MinSize——指定模型组件的最小尺寸
*/  MinScore——最低得分0-1之间。低于MinScore的组件将被舍弃
*/  SearchRowTol,SearchColumnTol——查找过程中行,列方向的位置偏差容忍像素值
*/  TrainingEmphasis——训练的侧重点方向  shape-形状,gray_values—灰度  none—无特别强调
*/  AmbiguityCriterion—— 定义歧义性组件的标准。ignore—忽略,merge—融合
*/  MaxContourOverlap——模型组件间的最大重叠率
*/  ClusterThreshold——组件聚类,相似多少才被聚为一类。

*// ComponentTrainingID——输出。训练句柄

get_training_components( : TrainingComponents : ComponentTrainingID, Components, Image, MarkOrientation : Row, Column, Angle, Score)


**** ModelComponents——输出,train_model_components也会得到
**  ComponentTrainingID——输入,train_model_components或得的句柄
**  Components ——组件的所以  'model_components'-所有组件, 0, 1, 2, 3, 4, 5表示第几个组件
**  Image——  从哪个图片获得的组件   'model_image'模型图片, 0, 1, 2, 3, 4, 5, 6, 7, 8训练集的第几章图片
**  MarkOrientation—— 是否在输出的TrainingComponents 中标记组件的方向  

*// Row,Column,Angle——每个组件中心的坐标和每个组件的旋转角度【-3.14-3.14】
*// score —— 匹配得分

get_component_relations( : Relations : ComponentTrainingID, ReferenceComponent, Image : Row, Column, Phi, Length1, Length2, AngleStart, AngleExtent)

**** Relations ——图像化展示组件的关系
**  ComponentTrainingID——组件的句柄
**  ReferenceComponent——以第几个组件为参考组件。被参考的这个组件的row,column。phi在以后得关系结构中都是0.
**  image——需要分析组件关系的图像。这个图像必须是在训练集中的图像

*//——row,column,phi,length1,length2,anglestart,angleextent 每个组件的中心点,角度等

get_component_model_tree( : Tree, Relations : ComponentModelID, RootComponent, Image : StartNode, EndNode, Row, Column, Phi, Length1, Length2, AngleStart, AngleExtent)

****  Tree——可表示的组件轮廓结构
****  Relations——图像化展示空间关系
****  NodeType——指定要提取的节点类型 0:所有节点;1:根节点;2:子节点(非根节点)。
**** imagetype——指定提取树结构的参考图像类型。model_image':基于模型图像

*// StartNode——父节点的组件索引
*// EndNode—— 子节点的组件索引
*// Row / Column/phi --组件的位置。这里参考节点的坐标是0,角度是0,其他组件的值是相对于参考组件而定
*// AngleStart / AngleExtent——组件间相对角度起始值和范围。

* This example shows how to use the component-based matching in order
* to locate all instances of a switch that consists of two components. The
* relative movements (relations) are automatically trained by using only one
* training image. Because the model image shows the switch turned on, it is
* sufficient to use one training image that shows the switch turned off in order
* to cover all relative movements. After creating the component model all
* instances of the switch are found in a run-time image. Finally, the angle
* difference between both components can be used to decide whether the
* switches shown in the image are turned on or off.
dev_update_off ()
dev_set_draw ('margin')
dev_set_line_width (2)
read_image (ModelImage, 'bin_switch/bin_switch_model')
get_image_size (ModelImage, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
* Define the initial components
gen_rectangle1 (Region1, 78, 196, 190, 359)
gen_rectangle1 (Sub1, 150, 196, 190, 321)
difference (Region1, Sub1, InitialComponents)
gen_rectangle1 (Region2, 197, 204, 305, 339)
gen_rectangle1 (Sub2, 205, 232, 285, 314)
difference (Region2, Sub2, InitialComponent)
concat_obj (InitialComponents, InitialComponent, InitialComponents)
dev_set_colored (12)
dev_display (ModelImage)
dev_display (InitialComponents)
disp_message (WindowHandle, 'Model image and', 'window', 20, 20, 'blue', 'false')
disp_message (WindowHandle, 'input regions describing the initial components', 'window', 40, 20, 'blue', 'false')
disp_message (WindowHandle, 'Press mouse button to continue', 'window', 450, 20, 'blue', 'false')
get_mbutton (WindowHandle, Row1, Column1, Button1)
* Get the training image
read_image (TrainingImage, 'bin_switch/bin_switch_training_1')
dev_display (TrainingImage)
disp_message (WindowHandle, 'Training image', 'window', 20, 20, 'blue', 'false')
disp_message (WindowHandle, 'Press mouse button to continue', 'window', 450, 20, 'blue', 'false')
get_mbutton (WindowHandle, Row2, Column2, Button2)
* The component-based matching uses the contours of the components
* as features for the matching. In order to make sure that only significant
* features are involved in the matching the parameters ContrastLow,
* ContrastHigh, and MinSize can be passed to the training. To inspect the
* effect of different values for these three parameters, and hence to find
* the optimum values for a certain application, the following two lines of
* code can be used:
* add_channels (InitialComponents, ModelImage, ModelImageInitComp)
* gen_initial_components (ModelImageInitComp, InitialComponentsContours, 30, 30, 20, 'connection', [], [])
* Extract the model components and train the relations
dev_display (ModelImage)
disp_message (WindowHandle, 'Train the model components...', 'window', 20, 20, 'blue', 'false')
****
train_model_components (ModelImage, InitialComponents, TrainingImage, ModelComponents, \30, 30, 20, 0.7, -1, -1, rad(25), 'speed', 'rigidity', 0.2, 0.5, ComponentTrainingID)
* ModelImage——输入:模型初始参考位置
* InitialComponents——输入:两个以上的region
* TrainingImage——输入:图集,代表了不状态下组件的关系
****ModelComponents:——输出训练好的模型组件,从示例上看是核心位置的边界区域也就是boundary-region
*/  ContrastLow——核心boundary的最低对比度
*/  ContrastHigh——最高对比度
*/  MinSize——指定模型组件的最小尺寸
*/  MinScore——最低得分0-1之间。低于MinScore的组件将被舍弃
*/  SearchRowTol,SearchColumnTol——查找过程中行,列方向的位置偏差容忍像素值
*/  TrainingEmphasis——训练的侧重点方向  shape-形状,gray_values—灰度  none—无特别强调
*/  AmbiguityCriterion—— 定义歧义性组件的标准。ignore—忽略,merge—融合
*/  MaxContourOverlap——模型组件间的最大重叠率
*/  ClusterThreshold——组件聚类,相似多少才被聚为一类。*// ComponentTrainingID——输出。训练句柄dev_set_color ('blue')
dev_display (ModelImage)
disp_message (WindowHandle, 'Result of the training:', 'window', 20, 20, 'blue', 'false')
disp_message (WindowHandle, '  1) Final model components', 'window', 40, 20, 'blue', 'false')
dev_set_colored (12)
****获取训练组件
get_training_components (ModelComponents, ComponentTrainingID, 'model_components', 'model_image', 'true', RowRef, ColumnRef, AngleRef, ScoreRef)
**** ModelComponents——输出,train_model_components也会得到
**  ComponentTrainingID——输入,train_model_components或得的句柄
**  Components ——组件的所以  'model_components'-所有组件, 0, 1, 2, 3, 4, 5表示第几个组件
**  Image——  从哪个图片获得的组件   'model_image'模型图片, 0, 1, 2, 3, 4, 5, 6, 7, 8训练集的第几章图片
**  MarkOrientation—— 是否在输出的TrainingComponents 中标记组件的方向  *// Row,Column,Angle——每个组件中心的坐标和每个组件的旋转角度【-3.14-3.14】
*// score —— 匹配得分dev_display (ModelComponents)
disp_message (WindowHandle, 'Press mouse button to continue', 'window', 450, 20, 'blue', 'false')
count_obj (ModelComponents, NumComp)
dev_set_line_width (1)
for I := 0 to NumComp - 1 by 1dev_set_color ('blue')dev_display (ModelImage)set_tposition (WindowHandle, 20, 20)write_string (WindowHandle, 'Result of the training:')set_tposition (WindowHandle, 40, 20)write_string (WindowHandle, '  1) Final model components')set_tposition (WindowHandle, 60, 20)write_string (WindowHandle, '  2) Relations with respect to component ' + I)dev_set_colored (12)get_component_relations (Relations, ComponentTrainingID, I, 'model_image', Row, Column, Phi, Length1, Length2, AngleStart, AngleExtent)
**** Relations ——图像化展示组件的关系
**  ComponentTrainingID——组件的句柄
**  ReferenceComponent——以第几个组件为参考组件。被参考的这个组件的row,column。phi在以后得关系结构中都是0.
**  image——需要分析组件关系的图像。这个图像必须是在训练集中的图像*//——row,column,phi,length1,length2,anglestart,angleextent 每个组件的中心点,角度等dev_display (Relations)disp_message (WindowHandle, 'Press mouse button to continue', 'window', 450, 20, 'blue', 'false')*get_mbutton (WindowHandle, Row4, Column4, Button4)
endfor
* Add small tolerances to the automatically derived relations in order
* to receive a higher robustness.
***添加容差,以便或得稳定性
modify_component_relations (ComponentTrainingID, 'all', 'all', 1, rad(1))
* Create the component model based on the training result.
dev_set_color ('blue')
dev_display (ModelImage)
disp_message (WindowHandle, 'Create the component model...', 'window', 20, 20, 'blue', 'false')****创建一个组件模型句柄
** 基于 train_model_components训练好的组件句柄,创建一个组件模型
create_trained_component_model (ComponentTrainingID, 0, rad(360), 10, 0.7, 'auto', 'auto', 'none', 'use_polarity', 'false', ComponentModelID, RootRanking)
** 提取组件关系结构
get_component_model_tree (Tree, Relations, ComponentModelID, 1, 'model_image', StartNode, EndNode, Row, Column, Phi, Length1, Length2, AngleStart, AngleExtent)
****  Tree——可表示的组件轮廓结构
****  Relations——图像化展示空间关系
****  NodeType——指定要提取的节点类型 0:所有节点;1:根节点;2:子节点(非根节点)。
**** imagetype——指定提取树结构的参考图像类型。model_image':基于模型图像*// StartNode——父节点的组件索引
*// EndNode—— 子节点的组件索引
*// Row / Column/phi --组件的位置。这里参考节点的坐标是0,角度是0,其他组件的值是相对于参考组件而定
*// AngleStart / AngleExtent——组件间相对角度起始值和范围。***这里这个案例关注的是phidev_display (ModelImage)
disp_message (WindowHandle, 'Component model', 'window', 20, 20, 'blue', 'false')
dev_set_colored (12)
dev_display (Tree)
dev_display (Relations)
disp_message (WindowHandle, 'Press mouse button to continue', 'window', 450, 20, 'blue', 'false')
*get_mbutton (WindowHandle, Row5, Column5, Button5)
wait_seconds (0.5)
* Find the component model in a run-time image
dev_set_line_width (2)
Button := 0
ImgNo := 1
while (Button != 1)read_image (SearchImage, 'bin_switch/bin_switch_' + ImgNo)find_component_model (SearchImage, ComponentModelID, 1, 0, rad(360), 0, 0, 1, 'stop_search', 'prune_branch', 'none', 0.6, 'least_squares', 0, 0.85, ModelStart, ModelEnd, Score, RowComp, ColumnComp, AngleComp, ScoreComp, ModelComp)count_seconds (Seconds2)dev_display (SearchImage)NumFound := |ModelStart|for Match := 0 to |ModelStart| - 1 by 1get_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_bin_switch_match (AngleCompInst, Match, WindowHandle)endfordisp_message (WindowHandle, 'Press mouse button to stop', 'window', 450, 20, 'blue', 'false')ImgNo := ImgNo + 1if (ImgNo > 9)ImgNo := 1endifdev_error_var (Error, 1)dev_set_check ('~give_error')get_mposition (WindowHandle, R, C, Button)dev_error_var (Error, 0)dev_set_check ('give_error')if (Error != H_MSG_TRUE)Button := 0endif
*     stop ()
endwhile

http://www.dtcms.com/a/298984.html

相关文章:

  • PYTHON从入门到实践-15数据可视化
  • 震网(Stuxnet):打开潘多拉魔盒的数字幽灵
  • Android ADB命令之内存统计与分析
  • C++对象模型
  • CH341 Linux驱动 没有 /dev/ttyCH341USB0
  • 前端模块化开发实战指南
  • kafka中生产者的数据分发策略
  • starrocks官网docker部署mysql无法连接
  • 影刀RPA_Temu关键词取数_源码解读
  • RK3568笔记九十三:基于RKNN Lite的YOLOv5目标检测
  • 高性能网络DPDK、RDMA、XDP初探
  • VTK交互——ClientData
  • Java程序员学从0学AI(六)
  • Baumer工业相机堡盟工业相机如何通过YoloV8深度学习模型实现轮船检测识别(C#代码UI界面版)
  • 热传导问题Matlab有限元编程 :工业级热仿真核心技术-搭建热传导求解器【含案例源码】
  • CSS3知识补充
  • 【企业架构】TOGAF概念之二
  • 基于深度学习的图像分类:使用Capsule Networks实现高效分类
  • 【Linux手册】操作系统如何管理存储在外设上的文件
  • 用 FFmpeg 把视频输出为图片序列
  • 创建 Vue 项目的 4 种主流方式
  • 小程序的客服咨询(与企业微信建立沟通)
  • [论文阅读] 人工智能 + 软件工程 | NoCode-bench:评估LLM无代码功能添加能力的新基准
  • 使用Python实现单词记忆软件
  • Day 22: 复习
  • Datawhale AI 夏令营—科大讯飞AI大赛(大模型技术)—让大模型理解表格数据(列车信息表)
  • 【影刀RPA_初级课程_我的第一个机器人】
  • .bat 打开方式恢复
  • 秋招Day20 - 微服务 - 概念
  • 大模型应用班-第2课 DeepSeek使用与提示词工程课程重点 学习ollama 安装 用deepseek-r1:1.5b 分析PDF 内容