create_trained_component_modelT_create_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_model创建训练组件模型(算子)
名称
create_trained_component_modelT_create_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_model — 基于训练好的组件准备组件模型进行匹配。
签名
create_trained_component_model( : : ComponentTrainingID, AngleStart, AngleExtent, MinContrastComp, MinScoreComp, NumLevelsComp, AngleStepComp, OptimizationComp, MetricComp, PregenerationComp : ComponentModelID, RootRanking)
Herror T_create_trained_component_model(const Htuple ComponentTrainingID, const Htuple AngleStart, const Htuple AngleExtent, const Htuple MinContrastComp, const Htuple MinScoreComp, const Htuple NumLevelsComp, const Htuple AngleStepComp, const Htuple OptimizationComp, const Htuple MetricComp, const Htuple PregenerationComp, Htuple* ComponentModelID, Htuple* RootRanking)
void CreateTrainedComponentModel(const HTuple& ComponentTrainingID, const HTuple& AngleStart, const HTuple& AngleExtent, const HTuple& MinContrastComp, const HTuple& MinScoreComp, const HTuple& NumLevelsComp, const HTuple& AngleStepComp, const HTuple& OptimizationComp, const HTuple& MetricComp, const HTuple& PregenerationComp, HTuple* ComponentModelID, HTuple* RootRanking)
HComponentModel HComponentTraining::CreateTrainedComponentModel(double AngleStart, double AngleExtent, const HTuple& MinContrastComp, const HTuple& MinScoreComp, const HTuple& NumLevelsComp, const HTuple& AngleStepComp, const HString& OptimizationComp, const HTuple& MetricComp, const HTuple& PregenerationComp, HTuple* RootRanking) const
HComponentModel HComponentTraining::CreateTrainedComponentModel(double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const HString& OptimizationComp, const HString& MetricComp, const HString& PregenerationComp, Hlong* RootRanking) const
HComponentModel HComponentTraining::CreateTrainedComponentModel(double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const char* OptimizationComp, const char* MetricComp, const char* PregenerationComp, Hlong* RootRanking) const
HComponentModel HComponentTraining::CreateTrainedComponentModel(double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const wchar_t* OptimizationComp, const wchar_t* MetricComp, const wchar_t* PregenerationComp, Hlong* RootRanking) const
(
Windows only)
void HComponentModel::HComponentModel(const HComponentTraining& ComponentTrainingID, double AngleStart, double AngleExtent, const HTuple& MinContrastComp, const HTuple& MinScoreComp, const HTuple& NumLevelsComp, const HTuple& AngleStepComp, const HString& OptimizationComp, const HTuple& MetricComp, const HTuple& PregenerationComp, HTuple* RootRanking)
void HComponentModel::HComponentModel(const HComponentTraining& ComponentTrainingID, double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const HString& OptimizationComp, const HString& MetricComp, const HString& PregenerationComp, Hlong* RootRanking)
void HComponentModel::HComponentModel(const HComponentTraining& ComponentTrainingID, double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const char* OptimizationComp, const char* MetricComp, const char* PregenerationComp, Hlong* RootRanking)
void HComponentModel::HComponentModel(const HComponentTraining& ComponentTrainingID, double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const wchar_t* OptimizationComp, const wchar_t* MetricComp, const wchar_t* PregenerationComp, Hlong* RootRanking)
(
Windows only)
HTuple HComponentModel::CreateTrainedComponentModel(const HComponentTraining& ComponentTrainingID, double AngleStart, double AngleExtent, const HTuple& MinContrastComp, const HTuple& MinScoreComp, const HTuple& NumLevelsComp, const HTuple& AngleStepComp, const HString& OptimizationComp, const HTuple& MetricComp, const HTuple& PregenerationComp)
Hlong HComponentModel::CreateTrainedComponentModel(const HComponentTraining& ComponentTrainingID, double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const HString& OptimizationComp, const HString& MetricComp, const HString& PregenerationComp)
Hlong HComponentModel::CreateTrainedComponentModel(const HComponentTraining& ComponentTrainingID, double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const char* OptimizationComp, const char* MetricComp, const char* PregenerationComp)
Hlong HComponentModel::CreateTrainedComponentModel(const HComponentTraining& ComponentTrainingID, double AngleStart, double AngleExtent, Hlong MinContrastComp, double MinScoreComp, Hlong NumLevelsComp, double AngleStepComp, const wchar_t* OptimizationComp, const wchar_t* MetricComp, const wchar_t* PregenerationComp)
(
Windows only)
static void HOperatorSet.CreateTrainedComponentModel(HTuple componentTrainingID, HTuple angleStart, HTuple angleExtent, HTuple minContrastComp, HTuple minScoreComp, HTuple numLevelsComp, HTuple angleStepComp, HTuple optimizationComp, HTuple metricComp, HTuple pregenerationComp, out HTuple componentModelID, out HTuple rootRanking)
HComponentModel HComponentTraining.CreateTrainedComponentModel(double angleStart, double angleExtent, HTuple minContrastComp, HTuple minScoreComp, HTuple numLevelsComp, HTuple angleStepComp, string optimizationComp, HTuple metricComp, HTuple pregenerationComp, out HTuple rootRanking)
HComponentModel HComponentTraining.CreateTrainedComponentModel(double angleStart, double angleExtent, int minContrastComp, double minScoreComp, int numLevelsComp, double angleStepComp, string optimizationComp, string metricComp, string pregenerationComp, out int rootRanking)
public HComponentModel(HComponentTraining componentTrainingID, double angleStart, double angleExtent, HTuple minContrastComp, HTuple minScoreComp, HTuple numLevelsComp, HTuple angleStepComp, string optimizationComp, HTuple metricComp, HTuple pregenerationComp, out HTuple rootRanking)
public HComponentModel(HComponentTraining componentTrainingID, double angleStart, double angleExtent, int minContrastComp, double minScoreComp, int numLevelsComp, double angleStepComp, string optimizationComp, string metricComp, string pregenerationComp, out int rootRanking)
HTuple HComponentModel.CreateTrainedComponentModel(HComponentTraining componentTrainingID, double angleStart, double angleExtent, HTuple minContrastComp, HTuple minScoreComp, HTuple numLevelsComp, HTuple angleStepComp, string optimizationComp, HTuple metricComp, HTuple pregenerationComp)
int HComponentModel.CreateTrainedComponentModel(HComponentTraining componentTrainingID, double angleStart, double angleExtent, int minContrastComp, double minScoreComp, int numLevelsComp, double angleStepComp, string optimizationComp, string metricComp, string pregenerationComp)
def create_trained_component_model(component_training_id: HHandle, angle_start: float, angle_extent: float, min_contrast_comp: MaybeSequence[Union[int, str]], min_score_comp: MaybeSequence[float], num_levels_comp: MaybeSequence[Union[int, str]], angle_step_comp: MaybeSequence[Union[float, str]], optimization_comp: str, metric_comp: MaybeSequence[str], pregeneration_comp: MaybeSequence[str]) -> Tuple[HHandle, Sequence[int]]
def create_trained_component_model_s(component_training_id: HHandle, angle_start: float, angle_extent: float, min_contrast_comp: MaybeSequence[Union[int, str]], min_score_comp: MaybeSequence[float], num_levels_comp: MaybeSequence[Union[int, str]], angle_step_comp: MaybeSequence[Union[float, str]], optimization_comp: str, metric_comp: MaybeSequence[str], pregeneration_comp: MaybeSequence[str]) -> Tuple[HHandle, int]
描述
create_trained_component_modelcreate_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_model 将通过 ComponentTrainingIDComponentTrainingIDComponentTrainingIDComponentTrainingIDcomponentTrainingIDcomponent_training_id 传入的训练结果准备为用于匹配的组件模型。输出参数 ComponentModelIDComponentModelIDComponentModelIDComponentModelIDcomponentModelIDcomponent_model_id
是该模型的句柄,用于后续对
find_component_modelfind_component_modelFindComponentModelFindComponentModelFindComponentModelfind_component_model 的调用。与
create_component_modelcreate_component_modelCreateComponentModelCreateComponentModelCreateComponentModelcreate_component_model 不同,在调用 create_trained_component_modelcreate_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_model 之前,必须先使用 train_model_componentstrain_model_componentsTrainModelComponentsTrainModelComponentsTrainModelComponentstrain_model_components 对模型组件进行训练。
参数 AngleStartAngleStartAngleStartAngleStartangleStartangle_start 和 AngleExtentAngleExtentAngleExtentAngleExtentangleExtentangle_extent
用于确定组件模型在图像中可能的旋转范围。
在内部,每个模型组件都会构建一个独立的形状模型(参见 create_shape_modelcreate_shape_modelCreateShapeModelCreateShapeModelCreateShapeModelcreate_shape_model)。因此,参数 MinContrastCompMinContrastCompMinContrastCompMinContrastCompminContrastCompmin_contrast_comp、MinScoreCompMinScoreCompMinScoreCompMinScoreCompminScoreCompmin_score_comp、NumLevelsCompNumLevelsCompNumLevelsCompNumLevelsCompnumLevelsCompnum_levels_comp、AngleStepCompAngleStepCompAngleStepCompAngleStepCompangleStepCompangle_step_comp、OptimizationCompOptimizationCompOptimizationCompOptimizationCompoptimizationCompoptimization_comp, MetricCompMetricCompMetricCompMetricCompmetricCompmetric_comp 和 PregenerationCompPregenerationCompPregenerationCompPregenerationComppregenerationComppregeneration_comp 对应于
create_shape_modelcreate_shape_modelCreateShapeModelCreateShapeModelCreateShapeModelcreate_shape_model 的参数,但存在以下区别: 首先,create_shape_modelcreate_shape_modelCreateShapeModelCreateShapeModelCreateShapeModelcreate_shape_model 的 OptimizationOptimizationOptimizationOptimizationoptimizationoptimization 参数既提供了减少模型点数量的功能,也提供了完全预生成形状模型的功能。相比之下,
create_trained_component_modelcreate_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_model 算子使用独立的
PregenerationCompPregenerationCompPregenerationCompPregenerationComppregenerationComppregeneration_comp 参数来决定是否应完全预生成形状模型。此外,还应注意关于 MinScoreCompMinScoreCompMinScoreCompMinScoreCompminScoreCompmin_score_comp 参数的第二个区别。在形状匹配过程中,使用
create_shape_modelcreate_shape_modelCreateShapeModelCreateShapeModelCreateShapeModelcreate_shape_model 准备形状模型时无需传递此参数,仅在
find_shape_modelfind_shape_modelFindShapeModelFindShapeModelFindShapeModelfind_shape_model 搜索阶段需要。而准备组件模型时,分析模型组件的旋转对称性及组件间相似性更为有利。但该分析仅在搜索阶段(参见 find_component_modelfind_component_modelFindComponentModelFindComponentModelFindComponentModelfind_component_model)使用的
MinScoreCompMinScoreCompMinScoreCompMinScoreCompminScoreCompmin_score_comp 值已大致确定时,才能产生有效结果。使用
find_component_modelfind_component_modelFindComponentModelFindComponentModelFindComponentModelfind_component_model 进行搜索后,将返回搜索图像中各组件的姿态参数。请注意,这些姿态参数指的是组件的参考点。组件的参考点即其关联区域的重心,该区域在 train_model_componentstrain_model_componentsTrainModelComponentsTrainModelComponentsTrainModelComponentstrain_model_components 的 ModelComponentsModelComponentsModelComponentsModelComponentsmodelComponentsmodel_components 中返回。
参数 MinContrastCompMinContrastCompMinContrastCompMinContrastCompminContrastCompmin_contrast_comp、NumLevelsCompNumLevelsCompNumLevelsCompNumLevelsCompnumLevelsCompnum_levels_comp、AngleStepCompAngleStepCompAngleStepCompAngleStepCompangleStepCompangle_step_comp 和 OptimizationCompOptimizationCompOptimizationCompOptimizationCompoptimizationCompoptimization_comp 可以通过将相应参数的值设为 'auto'"auto""auto""auto""auto""auto" 来自动确定。
所有组件特有的输入参数(参数名称以后缀 Comp 结尾)必须包含一个元素(此时该参数将用于所有模型组件),或者必须包含与 ComponentTrainingIDComponentTrainingIDComponentTrainingIDComponentTrainingIDcomponentTrainingIDcomponent_training_id 中模型组件数量相同的元素(此时每个参数元素对应
ComponentTrainingIDComponentTrainingIDComponentTrainingIDComponentTrainingIDcomponentTrainingIDcomponent_training_id 中的相应组件)。
除了各个形状模型外,组件模型还包含关于如何使用
find_component_modelfind_component_modelFindComponentModelFindComponentModelFindComponentModelfind_component_model 搜索单个模型组件之间相对位置的信息,以最大限度地减少搜索的计算时间。为此,组件以树形结构表示。首先搜索位于搜索树根部的组件(根组件)。随后,其余组件将根据其在搜索树中前驱组件的姿态进行相对搜索。
在搜索过程中,根组件可作为
find_component_modelfind_component_modelFindComponentModelFindComponentModelFindComponentModelfind_component_model 的输入参数传递。模型组件适合作为根组件的程度取决于多个因素。原则上应选择在图像中具有较高检出概率的模型组件。因此,那些有时会被高度遮挡或在某些情况下缺失的组件,并不适合作为根组件。此外,搜索过程中与根组件相关的计算时间也可作为评估标准。基于该标准对模型组件进行排序的结果存储于 RootRankingRootRankingRootRankingRootRankingrootRankingroot_ranking 参数中。在此参数中,模型组件的索引会根据其关联的计算时间按降序排列,即 RootRankingRootRankingRootRankingRootRankingrootRankingroot_ranking[0] 包含作为根组件时能实现最快搜索速度的模型组件的索引。需注意 RootRankingRootRankingRootRankingRootRankingrootRankingroot_ranking 返回的排序仅为粗略估算。此外,根排名的计算假设在调用 create_trained_component_modelcreate_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_model 和 find_component_modelfind_component_modelFindComponentModelFindComponentModelFindComponentModelfind_component_model 时,图像大小以及系统参数
'border_shape_models'"border_shape_models""border_shape_models""border_shape_models""border_shape_models""border_shape_models" 的值是相同的。
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
此算子返回一个句柄。请注意,即使该句柄被用作特定算子的输入参数,这些算子仍可能改变此句柄类型的实例状态。
参数
ComponentTrainingIDComponentTrainingIDComponentTrainingIDComponentTrainingIDcomponentTrainingIDcomponent_training_id (输入控制) component_training → HComponentTraining, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
训练结果的句柄。
AngleStartAngleStartAngleStartAngleStartangleStartangle_start (输入控制) angle.rad → HTuplefloatHTupleHtuple (real) (double) (double) (double)
组件模型的最小旋转。
默认值:
-0.39
建议值:
-3.14, -1.57, -0.79, -0.39, -0.20, 0.0
AngleExtentAngleExtentAngleExtentAngleExtentangleExtentangle_extent (输入控制) angle.rad → HTuplefloatHTupleHtuple (real) (double) (double) (double)
组件模型的旋转幅度。
默认值:
0.79
建议值:
6.28, 3.14, 1.57, 0.79, 0.39
限制:
AngleExtent >= 0
MinContrastCompMinContrastCompMinContrastCompMinContrastCompminContrastCompmin_contrast_comp (输入控制) integer(-array) → HTupleMaybeSequence[Union[int, str]]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)
搜索图像中组件的最小对比度。
默认值:
'auto'
"auto"
"auto"
"auto"
"auto"
"auto"
建议值:
'auto'"auto""auto""auto""auto""auto", 10, 20, 20, 40
限制:
MinContrastComp >= 0
MinScoreCompMinScoreCompMinScoreCompMinScoreCompminScoreCompmin_score_comp (输入控制) real(-array) → HTupleMaybeSequence[float]HTupleHtuple (real) (double) (double) (double)
要查找的组件实例的最低分数。
默认值:
0.5
建议值:
0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0
最小增量:
0.01
建议增量:
0.05
限制:
0 <= MinScoreComp && MinScoreComp <= 1
NumLevelsCompNumLevelsCompNumLevelsCompNumLevelsCompnumLevelsCompnum_levels_comp (输入控制) integer(-array) → HTupleMaybeSequence[Union[int, str]]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)
组件的金字塔层级最大数量。
默认值:
'auto'
"auto"
"auto"
"auto"
"auto"
"auto"
值列表:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'auto'"auto""auto""auto""auto""auto"
AngleStepCompAngleStepCompAngleStepCompAngleStepCompangleStepCompangle_step_comp (输入控制) angle.rad(-array) → HTupleMaybeSequence[Union[float, str]]HTupleHtuple (real / string) (double / string) (double / HString) (double / char*)
组件角度的步长(分辨率)。
默认值:
'auto'
"auto"
"auto"
"auto"
"auto"
"auto"
建议值:
'auto'"auto""auto""auto""auto""auto", 0.0175, 0.0349, 0.0524, 0.0698, 0.0873
限制:
AngleStepComp >= 0
OptimizationCompOptimizationCompOptimizationCompOptimizationCompoptimizationCompoptimization_comp (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
对组件进行某种优化。
默认值:
'auto'
"auto"
"auto"
"auto"
"auto"
"auto"
值列表:
'auto'"auto""auto""auto""auto""auto", 'none'"none""none""none""none""none", 'point_reduction_high'"point_reduction_high""point_reduction_high""point_reduction_high""point_reduction_high""point_reduction_high", 'point_reduction_low'"point_reduction_low""point_reduction_low""point_reduction_low""point_reduction_low""point_reduction_low", 'point_reduction_medium'"point_reduction_medium""point_reduction_medium""point_reduction_medium""point_reduction_medium""point_reduction_medium"
MetricCompMetricCompMetricCompMetricCompmetricCompmetric_comp (输入控制) string(-array) → HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
用于组件的匹配度量标准。
默认值:
'use_polarity'
"use_polarity"
"use_polarity"
"use_polarity"
"use_polarity"
"use_polarity"
值列表:
'ignore_color_polarity'"ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity", 'ignore_global_polarity'"ignore_global_polarity""ignore_global_polarity""ignore_global_polarity""ignore_global_polarity""ignore_global_polarity", 'ignore_local_polarity'"ignore_local_polarity""ignore_local_polarity""ignore_local_polarity""ignore_local_polarity""ignore_local_polarity", 'use_polarity'"use_polarity""use_polarity""use_polarity""use_polarity""use_polarity"
PregenerationCompPregenerationCompPregenerationCompPregenerationComppregenerationComppregeneration_comp (输入控制) string(-array) → HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
若等于 'true'"true""true""true""true""true",则完成部件形状模型的预生成。
默认值:
'false'
"false"
"false"
"false"
"false"
"false"
值列表:
'false'"false""false""false""false""false", 'true'"true""true""true""true""true"
ComponentModelIDComponentModelIDComponentModelIDComponentModelIDcomponentModelIDcomponent_model_id (输出控制) component_model → HComponentModel, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
组件模型的句柄。
RootRankingRootRankingRootRankingRootRankingrootRankingroot_ranking (输出控制) integer(-array) → HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)
模型组件适合作为根组件的适配性排名。
示例(HDevelop)
* Get the model image.
read_image (ModelImage, 'model_image.tif')
* Define the regions for the initial components.
gen_rectangle2 (InitialComponentRegions, 212, 233, 0.62, 167, 29)
gen_rectangle2 (Rectangle2, 298, 363, 1.17, 162, 34)
gen_rectangle2 (Rectangle3, 63, 444, -0.26, 50, 27)
gen_rectangle2 (Rectangle4, 120, 473, 0, 33, 20)
concat_obj (InitialComponentRegions, Rectangle2, InitialComponentRegions)
concat_obj (InitialComponentRegions, Rectangle3, InitialComponentRegions)
concat_obj (InitialComponentRegions, Rectangle4, InitialComponentRegions)
* Get the training images.
gen_empty_obj (TrainingImages)
for i := 1 to 4 by 1
read_image (TrainingImage, 'training_image-'+i+'.tif')
concat_obj (TrainingImages, TrainingImage, TrainingImages)
endfor
* Extract the model components and train the relations.
train_model_components (ModelImage, InitialComponentRegions, \
TrainingImages, ModelComponents, 22, 60, 30, 0.65, \
0, 0, rad(60), 'speed', 'rigidity', 0.2, 0.4, \
ComponentTrainingID)
* Create the component model based on the training result.
create_trained_component_model (ComponentTrainingID, -rad(30), rad(60), 10, \
0.5, 'auto', 'auto', 'none', \
'use_polarity', 'false', ComponentModelID, \
RootRanking)
* Find the component model in a run-time image.
read_image (SearchImage, 'search_image.tif')
find_component_model (SearchImage, ComponentModelID, RootRanking, -rad(30), \
rad(60), 0.5, 0, 0.5, 'stop_search', 'prune_branch', \
'none', 0.55, 'least_squares', 0, 0.9, ModelStart, \
ModelEnd, Score, RowComp, ColumnComp, AngleComp, \
ScoreComp, ModelComp)
结果
如果参数有效,算子
create_trained_component_modelcreate_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_model 返回值 2 (H_MSG_TRUE)。如有必要,则抛出异常。
可能的前趋
train_model_componentstrain_model_componentsTrainModelComponentsTrainModelComponentsTrainModelComponentstrain_model_components,
read_training_componentsread_training_componentsReadTrainingComponentsReadTrainingComponentsReadTrainingComponentsread_training_components
可能的后继
find_component_modelfind_component_modelFindComponentModelFindComponentModelFindComponentModelfind_component_model
替代
create_component_modelcreate_component_modelCreateComponentModelCreateComponentModelCreateComponentModelcreate_component_model
模块
匹配