Skip to content

create_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_modelT_create_trained_component_model🔗

Short description🔗

create_trained_component_modelCreateTrainedComponentModelCreateTrainedComponentModelcreate_trained_component_modelT_create_trained_component_model — Prepare a component model for matching based on trained components.

Warning🔗

create_trained_component_modelCreateTrainedComponentModel is obsolete and is only provided for reasons of backward compatibility. The operator will be removed with HALCON 26.11.

Signature🔗

create_trained_component_model( component_training ComponentTrainingID, angle.rad AngleStart, angle.rad AngleExtent, integer MinContrastComp, real MinScoreComp, integer NumLevelsComp, angle.rad AngleStepComp, string OptimizationComp, string MetricComp, string PregenerationComp, out component_model ComponentModelID, out integer 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 )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 )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]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 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)

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 )

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)

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)

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 )

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 )

Description🔗

create_trained_component_modelCreateTrainedComponentModel prepares the training result, which is passed in ComponentTrainingIDcomponentTrainingIDcomponent_training_id, as a component model for matching. The output parameter ComponentModelIDcomponentModelIDcomponent_model_id is a handle for this model, which is used in subsequent calls to find_component_modelFindComponentModel. In contrast to create_component_modelCreateComponentModel, the model components must have been previously trained using train_model_componentsTrainModelComponents before calling create_trained_component_modelCreateTrainedComponentModel.

The parameters AngleStartangleStartangle_start and AngleExtentangleExtentangle_extent determine the range of possible rotations of the component model in an image.

Internally, a separate shape model is built for each model component (see create_shape_modelCreateShapeModel). Therefore, the parameters MinContrastCompminContrastCompmin_contrast_comp, MinScoreCompminScoreCompmin_score_comp, NumLevelsCompnumLevelsCompnum_levels_comp, AngleStepCompangleStepCompangle_step_comp, OptimizationCompoptimizationCompoptimization_comp, MetricCompmetricCompmetric_comp, and PregenerationComppregenerationComppregeneration_comp correspond to the parameters of create_shape_modelCreateShapeModel, with the following differences: First, the parameter Optimizationoptimizationoptimization of create_shape_modelCreateShapeModel provides the possibility to reduce the number of model points as well as the possibility to completely pregenerate the shape model. In contrast, the operator create_trained_component_modelCreateTrainedComponentModel uses a separate parameter PregenerationComppregenerationComppregeneration_comp in order to decide whether the shape models should be completely pregenerated or not. A second difference concerning the parameter MinScoreCompminScoreCompmin_score_comp should be noted. When using the shape-based matching, this parameter needs not be passed when preparing the shape model using create_shape_modelCreateShapeModel but only during the search using find_shape_modelFindShapeModel. In contrast, when preparing the component model it is favorable to analyze rotational symmetries of the model components and similarities between the model components. However, this analysis only leads to meaningful results if the value for MinScoreCompminScoreCompmin_score_comp that is used during the search (see find_component_modelFindComponentModel) is already approximately known. After the search with find_component_modelFindComponentModel the pose parameters of the components in a search image are returned. Note that the pose parameters refer to the reference points of the components. The reference point of a component is the center of gravity of its associated region that is returned in ModelComponentsmodelComponentsmodel_components of train_model_componentsTrainModelComponents.

The parameters MinContrastCompminContrastCompmin_contrast_comp, NumLevelsCompnumLevelsCompnum_levels_comp, AngleStepCompangleStepCompangle_step_comp, and OptimizationCompoptimizationCompoptimization_comp can be automatically determined by passing 'auto'"auto" for the respective parameters.

All component-specific input parameters (parameter names terminate with the suffix Comp) must either contain one element, in which case the parameter is used for all model components, or must contain the same number of elements as the number of model components contained in ComponentTrainingIDcomponentTrainingIDcomponent_training_id, in which case each parameter element refers to the corresponding component in ComponentTrainingIDcomponentTrainingIDcomponent_training_id.

In addition to the individual shape models, the component model also contains information about the way the single model components must be searched relative to each other using find_component_modelFindComponentModel in order to minimize the computation time of the search. For this, the components are represented in a tree structure. First, the component that stands at the root of this search tree (root component) is searched. Then, the remaining components are searched relative to the pose of their predecessor in the search tree.

The root component can be passed as an input parameter of find_component_modelFindComponentModel during the search. To what extent a model component is suited to act as root component depends on several factors. In principle, a model component that can be found in the image with a high probability should be chosen. Therefore, a component that is sometimes occluded to a high degree or that is missing in some cases is not well suited to act as root component. Additionally, the computation time that is associated with the root component during the search can serve as a criterion. A ranking of the model components that is based on the latter criterion is returned in RootRankingrootRankingroot_ranking. In this parameter the indices of the model components are sorted in descending order according to their associated computation time, i.e., RootRankingrootRankingroot_ranking[0] contains the index of the model component that, chosen as root component, allows the fastest search. Note that the ranking returned in RootRankingrootRankingroot_ranking represents only a coarse estimation. Furthermore, the calculation of the root ranking assumes that the image size as well as the value of the system parameter 'border_shape_models'"border_shape_models" are identical when calling create_trained_component_modelCreateTrainedComponentModel and find_component_modelFindComponentModel.

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.

Parameters🔗

ComponentTrainingIDcomponentTrainingIDcomponent_training_id (input_control) component_training → (handle)HTuple (HHandle)HComponentTraining, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the training result.

AngleStartangleStartangle_start (input_control) angle.rad → (real)HTuple (double)HTuple (double)floatHtuple (double)

Smallest rotation of the component model.

Default: -0.39-0.39
Suggested values: -3.14, -1.57, -0.79, -0.39, -0.20, 0.0-3.14, -1.57, -0.79, -0.39, -0.20, 0.0

AngleExtentangleExtentangle_extent (input_control) angle.rad → (real)HTuple (double)HTuple (double)floatHtuple (double)

Extent of the rotation of the component model.

Default: 0.790.79
Suggested values: 6.28, 3.14, 1.57, 0.79, 0.396.28, 3.14, 1.57, 0.79, 0.39
Restriction: AngleExtent >= 0

MinContrastCompminContrastCompmin_contrast_comp (input_control) integer(-array) → (integer / string)HTuple (Hlong / HString)HTuple (int / long / string)MaybeSequence[Union[int, str]]Htuple (Hlong / char*)

Minimum contrast of the components in the search images.

Default: 'auto'"auto"
Suggested values: 'auto', 10, 20, 20, 40"auto", 10, 20, 20, 40
Restriction: MinContrastComp >= 0

MinScoreCompminScoreCompmin_score_comp (input_control) real(-array) → (real)HTuple (double)HTuple (double)MaybeSequence[float]Htuple (double)

Minimum score of the instances of the components to be found.

Default: 0.50.5
Suggested values: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.00.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0
Minimum increment: 0.01
Recommended increment: 0.05
Restriction: 0 <= MinScoreComp && MinScoreComp <= 1

NumLevelsCompnumLevelsCompnum_levels_comp (input_control) integer(-array) → (integer / string)HTuple (Hlong / HString)HTuple (int / long / string)MaybeSequence[Union[int, str]]Htuple (Hlong / char*)

Maximum number of pyramid levels for the components.

Default: 'auto'"auto"
List of values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'auto'1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "auto"

AngleStepCompangleStepCompangle_step_comp (input_control) angle.rad(-array) → (real / string)HTuple (double / HString)HTuple (double / string)MaybeSequence[Union[float, str]]Htuple (double / char*)

Step length of the angles (resolution) for the components.

Default: 'auto'"auto"
Suggested values: 'auto', 0.0175, 0.0349, 0.0524, 0.0698, 0.0873"auto", 0.0175, 0.0349, 0.0524, 0.0698, 0.0873
Restriction: AngleStepComp >= 0

OptimizationCompoptimizationCompoptimization_comp (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Kind of optimization for the components.

Default: 'auto'"auto"
List of values: 'auto', 'none', 'point_reduction_high', 'point_reduction_low', 'point_reduction_medium'"auto", "none", "point_reduction_high", "point_reduction_low", "point_reduction_medium"

MetricCompmetricCompmetric_comp (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Match metric used for the components.

Default: 'use_polarity'"use_polarity"
List of values: 'ignore_color_polarity', 'ignore_global_polarity', 'ignore_local_polarity', 'use_polarity'"ignore_color_polarity", "ignore_global_polarity", "ignore_local_polarity", "use_polarity"

PregenerationComppregenerationComppregeneration_comp (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Complete pregeneration of the shape models for the components if equal to 'true'"true".

Default: 'false'"false"
List of values: 'false', 'true'"false", "true"

ComponentModelIDcomponentModelIDcomponent_model_id (output_control) component_model → (handle)HTuple (HHandle)HComponentModel, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the component model.

RootRankingrootRankingroot_ranking (output_control) integer(-array) → (integer)HTuple (Hlong)HTuple (int / long)Sequence[int]Htuple (Hlong)

Ranking of the model components expressing the suitability to act as the root component.

Result🔗

If the parameters are valid, the operator create_trained_component_modelCreateTrainedComponentModel returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Module🔗

Matching