set_shape_model_metricT_set_shape_model_metricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric (算子)

名称

set_shape_model_metricT_set_shape_model_metricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric — 设置从 XLD 轮廓创建的形状模型的度量。

签名

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)

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 HShapeModel::SetShapeModelMetric(const HImage& Image, const HHomMat2D& HomMat2D, const wchar_t* Metric) const   ( Windows only)

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 HImage::SetShapeModelMetric(const HShapeModel& ModelID, const HHomMat2D& HomMat2D, const wchar_t* Metric) const   ( Windows only)

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)

def set_shape_model_metric(image: HObject, model_id: HHandle, hom_mat_2d: Sequence[float], metric: str) -> None

描述

set_shape_model_metricset_shape_model_metricSetShapeModelMetricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric changes the value of the parameter MetricMetricMetricMetricmetricmetric that was selected during the creation of the shape model ModelIDModelIDModelIDModelIDmodelIDmodel_id 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 HomMat2DHomMat2DHomMat2DHomMat2DhomMat2Dhom_mat_2d

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_generic_shape_modelfind_generic_shape_modelFindGenericShapeModelFindGenericShapeModelFindGenericShapeModelfind_generic_shape_model 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 HomMat2DHomMat2DHomMat2DHomMat2DhomMat2Dhom_mat_2d 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_generic_shape_modelfind_generic_shape_modelFindGenericShapeModelFindGenericShapeModelFindGenericShapeModelfind_generic_shape_model and determining the respective transformation matrix with the procedure get_hom_mat2d_from_matching_result. The operator set_shape_model_metricset_shape_model_metricSetShapeModelMetricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric ignores an origin that was set by set_shape_model_originset_shape_model_originSetShapeModelOriginSetShapeModelOriginSetShapeModelOriginset_shape_model_origin and always assumes (0,0) as the origin. Hence, when finding the object in the ImageImageImageImageimageimage, all other operators must have the origin at the point (0,0). Therefore, set_shape_model_originset_shape_model_originSetShapeModelOriginSetShapeModelOriginSetShapeModelOriginset_shape_model_origin must be called with (0,0) as the origin.

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_metricSetShapeModelMetricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric can only be used with shape models that were created from XLD contours.

执行信息

此算子修改后续输入参数的状态:

在执行此算子时,若该参数值需在多个线程间使用,则必须对其访问进行同步。

参数

ImageImageImageImageimageimage (输入对象)  singlechannelimage objectHImageHObjectHImageHobject (byte / uint2)

Input image used for the determination of the polarity.

ModelIDModelIDModelIDModelIDmodelIDmodel_id (输入控制,状态被修改)  shape_model HShapeModel, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Handle of the model.

HomMat2DHomMat2DHomMat2DHomMat2DhomMat2Dhom_mat_2d (输入控制)  hom_mat2d HHomMat2D, HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

Transformation matrix.

MetricMetricMetricMetricmetricmetric (输入控制)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Match metric.

默认值: 'use_polarity' "use_polarity" "use_polarity" "use_polarity" "use_polarity" "use_polarity"

值列表: '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"

示例(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, ContoursAffineTrans, HomMat2DScale)
*
* Create the shape model with Metric='ignore_local_polarity'
create_generic_shape_model (ModelID)
train_generic_shape_model (ContoursAffineTrans, 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_generic_shape_model (Image, ModelID, MatchResultID, NumMatchResult)
*
* Visualize the match
get_generic_shape_model_result_object (Objects, MatchResultID, 'all', \
                                       'contours')
stop()
get_generic_shape_model_result (MatchResultID, 'all', 'hom_mat_2d', \
                                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_generic_shape_model (Image, ModelID, MatchResultID, NumMatchResult)
*
* Visualize the matches
get_generic_shape_model_result_object (Objects, MatchResultID, 'all', \
                                       'contours')

结果

如果参数有效,算子 set_shape_model_metricset_shape_model_metricSetShapeModelMetricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric 返回值 2 ( H_MSG_TRUE )。如有必要,则抛出异常。

可能的前趋

create_generic_shape_modelcreate_generic_shape_modelCreateGenericShapeModelCreateGenericShapeModelCreateGenericShapeModelcreate_generic_shape_model

可能的后继

find_generic_shape_modelfind_generic_shape_modelFindGenericShapeModelFindGenericShapeModelFindGenericShapeModelfind_generic_shape_model

另见

set_generic_shape_model_paramset_generic_shape_model_paramSetGenericShapeModelParamSetGenericShapeModelParamSetGenericShapeModelParamset_generic_shape_model_param

模块

匹配