ClassesClassesClassesClasses | | | | Operators

set_shape_model_metricT_set_shape_model_metricSetShapeModelMetricset_shape_model_metricSetShapeModelMetricSetShapeModelMetric (Operator)


set_shape_model_metricT_set_shape_model_metricSetShapeModelMetricset_shape_model_metricSetShapeModelMetricSetShapeModelMetric — Set the metric of a shape model that was created from XLD contours.


set_shape_model_metric(Image : : ModelID, HomMat2D, Metric : )

Herror T_set_shape_model_metric(const Hobject Image, const Htuple ModelID, const Htuple HomMat2D, const Htuple Metric)

Herror set_shape_model_metric(Hobject Image, const HTuple& ModelID, const HTuple& HomMat2D, const HTuple& Metric)

void HImage::SetShapeModelMetric(const HShapeModel& ModelID, const HTuple& HomMat2D, const HTuple& Metric) const

void HShapeModel::SetShapeModelMetric(const HImage& Image, const HTuple& HomMat2D, const HTuple& Metric) const

void SetShapeModelMetric(const HObject& Image, const HTuple& ModelID, const HTuple& HomMat2D, const HTuple& Metric)

void HShapeModel::SetShapeModelMetric(const HImage& Image, const HHomMat2D& HomMat2D, const HString& Metric) const

void HShapeModel::SetShapeModelMetric(const HImage& Image, const HHomMat2D& HomMat2D, const char* Metric) const

void HImage::SetShapeModelMetric(const HShapeModel& ModelID, const HHomMat2D& HomMat2D, const HString& Metric) const

void HImage::SetShapeModelMetric(const HShapeModel& ModelID, const HHomMat2D& HomMat2D, const char* Metric) const

void HOperatorSetX.SetShapeModelMetric(
[in] IHUntypedObjectX* Image, [in] VARIANT ModelID, [in] VARIANT HomMat2d, [in] VARIANT Metric)

void HShapeModelX.SetShapeModelMetric(
[in] IHImageX* Image, [in] IHHomMat2DX* HomMat2d, [in] BSTR Metric)

void HImageX.SetShapeModelMetric(
[in] IHShapeModelX* ModelID, [in] IHHomMat2DX* HomMat2d, [in] BSTR Metric)

static void HOperatorSet.SetShapeModelMetric(HObject image, HTuple modelID, HTuple homMat2D, HTuple metric)

void HShapeModel.SetShapeModelMetric(HImage image, HHomMat2D homMat2D, string metric)

void HImage.SetShapeModelMetric(HShapeModel modelID, HHomMat2D homMat2D, string metric)


set_shape_model_metricset_shape_model_metricSetShapeModelMetricset_shape_model_metricSetShapeModelMetricSetShapeModelMetric changes the value of the parameter MetricMetricMetricMetricMetricmetric that was selected during the creation of the shape model ModelIDModelIDModelIDModelIDModelIDmodelID from XLD contours. For this, the polarity of the model edges is determined based on the image ImageImageImageImageImageimage. The transformation that maps the model edges to the image position where the respective object appears is given in HomMat2DHomMat2DHomMat2DHomMat2DHomMat2DhomMat2D.

The parameter MetricMetricMetricMetricMetricmetric determines the conditions under which the model is recognized later in the search image. If MetricMetricMetricMetricMetricmetric = 'use_polarity'"use_polarity""use_polarity""use_polarity""use_polarity""use_polarity", the object in the image and the model must have the same contrast. If, for example, the model is a bright object on a dark background, the object is found only if it is also brighter than the background. If MetricMetricMetricMetricMetricmetric = 'ignore_global_polarity'"ignore_global_polarity""ignore_global_polarity""ignore_global_polarity""ignore_global_polarity""ignore_global_polarity", the object is found in the image also if the contrast reverses globally. In the above example, the object hence is also found if it is darker than the background. The runtime of find_shape_modelfind_shape_modelFindShapeModelfind_shape_modelFindShapeModelFindShapeModel will increase slightly in this case.

It must be ensured that the object edges in the ImageImageImageImageImageimage have the same (or inverse) polarity as the object edges in the image in which the object must be searched later. Especially, the object must not be occluded in the ImageImageImageImageImageimage and the background must be either brighter than the object or darker. Otherwise, the determined polarity of the model edges will not represent the polarity of the object edges during the search. Note that only the polarity of the edges is determined, not their contrast. Note also that the polarity is determined from a single-channel image, only. If a multichannel image is passed in ImageImageImageImageImageimage, only the first channel will be used (and no error message will be returned).

The transformation defined by the matrix HomMat2DHomMat2DHomMat2DHomMat2DHomMat2DhomMat2D maps the model contours to the respective position where the object appears in the ImageImageImageImageImageimage. It can be obtained by finding the object in the ImageImageImageImageImageimage, e.g., with the operator find_shape_modelfind_shape_modelFindShapeModelfind_shape_modelFindShapeModelFindShapeModel and determining the respective transformation matrix with the operator vector_angle_to_rigidvector_angle_to_rigidVectorAngleToRigidvector_angle_to_rigidVectorAngleToRigidVectorAngleToRigid.

A typical proceeding is to read the XLD contours from file. Since these XLD contours do not provide polarity information, the shape model must be created from the XLD contours by setting the parameter MetricMetricMetricMetricMetricmetric to 'ignore_local_polarity'"ignore_local_polarity""ignore_local_polarity""ignore_local_polarity""ignore_local_polarity""ignore_local_polarity". Then, in a first search image the model is recognized. The transformation that maps the model contours to the position of the object in the search image can be determined from the matching result. To verify the match interactively, the model contours can be mapped to this position. If the matching result is correct, the value of the parameter MetricMetricMetricMetricMetricmetric can be changed, e.g., to 'use_polarity'"use_polarity""use_polarity""use_polarity""use_polarity""use_polarity". This leads to a faster and more robust recognition in the following images.


set_shape_model_metricset_shape_model_metricSetShapeModelMetricset_shape_model_metricSetShapeModelMetricSetShapeModelMetric can only be used with shape models that were created from XLD contours.



ImageImageImageImageImageimage (input_object)  singlechannelimage objectHImageHImageHImageHImageXHobject (byte / uint2)

Input image used for the determination of the polarity.

ModelIDModelIDModelIDModelIDModelIDmodelID (input_control)  shape_model HShapeModel, HTupleHTupleHShapeModel, HTupleHShapeModelX, VARIANTHtuple (integer) (IntPtr) (Hlong) (Hlong) (Hlong) (Hlong)

Handle of the model.

HomMat2DHomMat2DHomMat2DHomMat2DHomMat2DhomMat2D (input_control)  hom_mat2d HHomMat2D, HTupleHTupleHTupleHHomMat2DX, VARIANTHtuple (real) (double) (double) (double) (double) (double)

Transformation matrix.

MetricMetricMetricMetricMetricmetric (input_control)  string HTupleHTupleHTupleVARIANTHtuple (string) (string) (HString) (char*) (BSTR) (char*)

Match metric.

Default value: 'use_polarity' "use_polarity" "use_polarity" "use_polarity" "use_polarity" "use_polarity"

List of values: 'ignore_global_polarity'"ignore_global_polarity""ignore_global_polarity""ignore_global_polarity""ignore_global_polarity""ignore_global_polarity", 'use_polarity'"use_polarity""use_polarity""use_polarity""use_polarity""use_polarity"

Example (HDevelop)

* Read the contours from file
read_contour_xld_dxf (Contours, 'metal-part-01', [], [], DxfStatus)
* Scale the contours such that they correspond to the image
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_scale (HomMat2DIdentity, 3.35, 3.35, 0, 0, HomMat2DScale)
affine_trans_contour_xld (Contours, ContoursAffinTrans, HomMat2DScale)
* Create the shape model with Metric='ignore_local_polarity'
create_shape_model_xld (ContoursAffinTrans, 'auto', rad(0), rad(360), \
                        'auto', 'auto', 'ignore_local_polarity', 5, ModelID)
* Get an image of the object and try to find the object in this image
read_image (Image, 'metal-parts/metal-parts-01')
find_shape_model (Image, ModelID, rad(0), rad(360), 0.5, 1, 0.5, \
                  'least_squares', 0, 0.9, Row, Column, Angle, Score)
* Visualize the match
vector_angle_to_rigid (0, 0, 0, Row, Column, Angle, HomMat2D)
get_shape_model_contours (ModelContours, ModelID, 1)
affine_trans_contour_xld (ModelContours, ModelContoursAffineTrans, HomMat2D)
* Set the matching metric to 'use_polarity', based on the position
* of the found object
set_shape_model_metric (Image, ModelID, HomMat2D, 'use_polarity')
* Use the shape model to detect the object faster and more robust
read_image (Image, 'metal-parts/metal-parts-02')
find_shape_model (Image, ModelID, rad(0), rad(360), 0.5, 0, 0.5, \
                  'least_squares', 0, 0.9, Row, Column, Angle, Score)
* Visualize the matches
for Index := 0 to |Score|-1 by 1
    vector_angle_to_rigid (0, 0, 0, Row[Index], Column[Index], Angle[Index], \
    affine_trans_contour_xld (ModelContours, ModelContoursAffineTrans, \


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

Possible Predecessors

create_shape_model_xldcreate_shape_model_xldCreateShapeModelXldcreate_shape_model_xldCreateShapeModelXldCreateShapeModelXld, create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXld, create_aniso_shape_model_xldcreate_aniso_shape_model_xldCreateAnisoShapeModelXldcreate_aniso_shape_model_xldCreateAnisoShapeModelXldCreateAnisoShapeModelXld

Possible Successors

find_shape_modelfind_shape_modelFindShapeModelfind_shape_modelFindShapeModelFindShapeModel, find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModel, find_aniso_shape_modelfind_aniso_shape_modelFindAnisoShapeModelfind_aniso_shape_modelFindAnisoShapeModelFindAnisoShapeModel

See also

create_shape_model_xldcreate_shape_model_xldCreateShapeModelXldcreate_shape_model_xldCreateShapeModelXldCreateShapeModelXld, create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXld, create_aniso_shape_model_xldcreate_aniso_shape_model_xldCreateAnisoShapeModelXldcreate_aniso_shape_model_xldCreateAnisoShapeModelXldCreateAnisoShapeModelXld



ClassesClassesClassesClasses | | | | Operators