create_scaled_shape_model_xldT_create_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld创建缩放形状模型扩展线描述(算子)
名称
create_scaled_shape_model_xldT_create_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld — 准备一个各向同性缩放的形状模型,以便从 XLD 轮廓进行匹配。
签名
Herror T_create_scaled_shape_model_xld(const Hobject Contours, const Htuple NumLevels, const Htuple AngleStart, const Htuple AngleExtent, const Htuple AngleStep, const Htuple ScaleMin, const Htuple ScaleMax, const Htuple ScaleStep, const Htuple Optimization, const Htuple Metric, const Htuple MinContrast, Htuple* ModelID)
void CreateScaledShapeModelXld(const HObject& Contours, const HTuple& NumLevels, const HTuple& AngleStart, const HTuple& AngleExtent, const HTuple& AngleStep, const HTuple& ScaleMin, const HTuple& ScaleMax, const HTuple& ScaleStep, const HTuple& Optimization, const HTuple& Metric, const HTuple& MinContrast, HTuple* ModelID)
void HShapeModel::HShapeModel(const HXLDCont& Contours, const HTuple& NumLevels, double AngleStart, double AngleExtent, const HTuple& AngleStep, double ScaleMin, double ScaleMax, const HTuple& ScaleStep, const HTuple& Optimization, const HString& Metric, Hlong MinContrast)
void HShapeModel::HShapeModel(const HXLDCont& Contours, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const HString& Optimization, const HString& Metric, Hlong MinContrast)
void HShapeModel::HShapeModel(const HXLDCont& Contours, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const char* Optimization, const char* Metric, Hlong MinContrast)
void HShapeModel::HShapeModel(const HXLDCont& Contours, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const wchar_t* Optimization, const wchar_t* Metric, Hlong MinContrast)
(
Windows only)
void HShapeModel::CreateScaledShapeModelXld(const HXLDCont& Contours, const HTuple& NumLevels, double AngleStart, double AngleExtent, const HTuple& AngleStep, double ScaleMin, double ScaleMax, const HTuple& ScaleStep, const HTuple& Optimization, const HString& Metric, Hlong MinContrast)
void HShapeModel::CreateScaledShapeModelXld(const HXLDCont& Contours, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const HString& Optimization, const HString& Metric, Hlong MinContrast)
void HShapeModel::CreateScaledShapeModelXld(const HXLDCont& Contours, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const char* Optimization, const char* Metric, Hlong MinContrast)
void HShapeModel::CreateScaledShapeModelXld(const HXLDCont& Contours, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const wchar_t* Optimization, const wchar_t* Metric, Hlong MinContrast)
(
Windows only)
HShapeModel HXLDCont::CreateScaledShapeModelXld(const HTuple& NumLevels, double AngleStart, double AngleExtent, const HTuple& AngleStep, double ScaleMin, double ScaleMax, const HTuple& ScaleStep, const HTuple& Optimization, const HString& Metric, Hlong MinContrast) const
HShapeModel HXLDCont::CreateScaledShapeModelXld(Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const HString& Optimization, const HString& Metric, Hlong MinContrast) const
HShapeModel HXLDCont::CreateScaledShapeModelXld(Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const char* Optimization, const char* Metric, Hlong MinContrast) const
HShapeModel HXLDCont::CreateScaledShapeModelXld(Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const wchar_t* Optimization, const wchar_t* Metric, Hlong MinContrast) const
(
Windows only)
static void HOperatorSet.CreateScaledShapeModelXld(HObject contours, HTuple numLevels, HTuple angleStart, HTuple angleExtent, HTuple angleStep, HTuple scaleMin, HTuple scaleMax, HTuple scaleStep, HTuple optimization, HTuple metric, HTuple minContrast, out HTuple modelID)
public HShapeModel(HXLDCont contours, HTuple numLevels, double angleStart, double angleExtent, HTuple angleStep, double scaleMin, double scaleMax, HTuple scaleStep, HTuple optimization, string metric, int minContrast)
public HShapeModel(HXLDCont contours, int numLevels, double angleStart, double angleExtent, double angleStep, double scaleMin, double scaleMax, double scaleStep, string optimization, string metric, int minContrast)
void HShapeModel.CreateScaledShapeModelXld(HXLDCont contours, HTuple numLevels, double angleStart, double angleExtent, HTuple angleStep, double scaleMin, double scaleMax, HTuple scaleStep, HTuple optimization, string metric, int minContrast)
void HShapeModel.CreateScaledShapeModelXld(HXLDCont contours, int numLevels, double angleStart, double angleExtent, double angleStep, double scaleMin, double scaleMax, double scaleStep, string optimization, string metric, int minContrast)
HShapeModel HXLDCont.CreateScaledShapeModelXld(HTuple numLevels, double angleStart, double angleExtent, HTuple angleStep, double scaleMin, double scaleMax, HTuple scaleStep, HTuple optimization, string metric, int minContrast)
HShapeModel HXLDCont.CreateScaledShapeModelXld(int numLevels, double angleStart, double angleExtent, double angleStep, double scaleMin, double scaleMax, double scaleStep, string optimization, string metric, int minContrast)
def create_scaled_shape_model_xld(contours: HObject, num_levels: Union[int, str], angle_start: float, angle_extent: float, angle_step: Union[float, str], scale_min: float, scale_max: float, scale_step: Union[float, str], optimization: MaybeSequence[str], metric: str, min_contrast: int) -> HHandle
描述
算子 create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 根据传递到
ContoursContoursContoursContourscontourscontours 参数中的 XLD 轮廓,创建一个用于匹配的各向同性缩放形状模型。XLD 轮廓代表待搜索对象的灰度值边缘。与从模板图像创建形状模型的 create_scaled_shape_modelcreate_scaled_shape_modelCreateScaledShapeModelCreateScaledShapeModelCreateScaledShapeModelcreate_scaled_shape_model 算子不同,create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 算子是从 XLD 轮廓创建形状模型,即不使用模板图像。
输出参数 ModelIDModelIDModelIDModelIDmodelIDmodel_id 是该模型的句柄,用于后续调用 find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model。模型的原点(参考点)采用 ContoursContoursContoursContourscontourscontours 中最小的平行于坐标轴的包围矩形的重心。可通过 set_shape_model_originset_shape_model_originSetShapeModelOriginSetShapeModelOriginSetShapeModelOriginset_shape_model_origin 设置不同原点。该模型针对多个图像金字塔层级生成,并存储在内存中。如果选择了模型的完整预生成(见下文),则模型将在每个层级上以多种旋转角度和缩放比例进行生成。可通过 set_shape_model_clutterset_shape_model_clutterSetShapeModelClutterSetShapeModelClutterSetShapeModelClutterset_shape_model_clutter 添加杂波参数扩展模型。
输入参数的详细说明
NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels:
-
金字塔层数由参数 NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels 决定。该参数应尽可能取大值,因为这样能显著缩短对象搜索所需时间。另一方面,NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels 的选择必须确保模型仍可识别,且最高金字塔层包含足够数量的点(至少四个)。 若生成的模型点不足,系统将内部减少金字塔层数,直至在最高金字塔层找到足够的模型点。若此函数将导致模型无金字塔层(即最低金字塔层的模型点数已过少)create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 返回一条错误消息。
如果 NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels 设置为 'auto'"auto""auto""auto""auto""auto",
create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 将自动确定金字塔层数。计算出的金字塔层数可通过 get_shape_model_paramsget_shape_model_paramsGetShapeModelParamsGetShapeModelParamsGetShapeModelParamsget_shape_model_params 进行查询。在极少数情况下,create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 可能会将金字塔层数确定为过大或过小的值。如果金字塔层数设置过大,模型可能无法在图像中被识别,或者可能需要在 find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 中将 MinScoreMinScoreMinScoreMinScoreminScoremin_score 或
GreedinessGreedinessGreedinessGreedinessgreedinessgreediness 参数设置为非常低的值才能找到模型。如果金字塔层数设置得太少,find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 中查找模型所需的时间可能会增加。在这种情况下,应手动选择金字塔层数。
AngleStartAngleStartAngleStartAngleStartangleStartangle_start, AngleExtentAngleExtentAngleExtentAngleExtentangleExtentangle_extent 和 AngleStepAngleStepAngleStepAngleStepangleStepangle_step:
-
参数 AngleStartAngleStartAngleStartAngleStartangleStartangle_start 和 AngleExtentAngleExtentAngleExtentAngleExtentangleExtentangle_extent 确定了可能的旋转范围,在此范围内,对象在搜索过程中可能出现在图像中。请注意,find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 只能在此角度范围内找到该对象。AngleStepAngleStepAngleStepAngleStepangleStepangle_step 参数则决定了选定角度范围内的步进长度。因此,如果在
find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 中未指定亚像素精度,则该参数将指定
find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 中角度可达到的精度。AngleStepAngleStepAngleStepAngleStepangleStepangle_step 应根据对象尺寸选择。较小的模型在图像中具有较少的离散旋转状态,故应为其选择较大的 AngleStepAngleStepAngleStepAngleStepangleStepangle_step 值。若 AngleExtentAngleExtentAngleExtentAngleExtentangleExtentangle_extent 并非
AngleStepAngleStepAngleStepAngleStepangleStepangle_step 的整数倍,则AngleStepAngleStepAngleStepAngleStepangleStepangle_step 将相应调整。为确保 find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 对于没有旋转角度的模型实例返回的值为精确的 0.0,将可能的旋转范围修改如下:若不存在正整数 n 使得 AngleStartAngleStartAngleStartAngleStartangleStartangle_start 加上 n 倍
AngleStepAngleStepAngleStepAngleStepangleStepangle_step 恰为 0.0,则 AngleStartAngleStartAngleStartAngleStartangleStartangle_start 最多减去 AngleStepAngleStepAngleStepAngleStepangleStepangle_step,AngleExtentAngleExtentAngleExtentAngleExtentangleExtentangle_extent 增加
AngleStepAngleStepAngleStepAngleStepangleStepangle_step。
ScaleMinScaleMinScaleMinScaleMinscaleMinscale_min, ScaleMaxScaleMaxScaleMaxScaleMaxscaleMaxscale_max 和 ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step:
-
参数 ScaleMinScaleMinScaleMinScaleMinscaleMinscale_min 和 ScaleMaxScaleMaxScaleMaxScaleMaxscaleMaxscale_max 确定对象可能的缩放比例(尺寸)范围。缩放比例为 1 时,对应模型的原始尺寸。参数
ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step 决定选定缩放范围内的步长。因此,如果在
find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 中未指定亚像素精度,则该参数将决定
find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 中各缩放比例可达到的精度。与 AngleStepAngleStepAngleStepAngleStepangleStepangle_step 类似,ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step 应根据对象的大小进行选择。如果缩放范围不是
ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step 的整数倍,则会相应调整 ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step。为了确保对于未缩放的模型实例,find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 返回的缩放值恰好为 1.0,将按以下方式调整可能的缩放范围:如果不存在正整数 n,使得 ScaleMinScaleMinScaleMinScaleMinscaleMinscale_min 加上 n 倍的 ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step 恰好等于 1.0,则将 ScaleMinScaleMinScaleMinScaleMinscaleMinscale_min 减小至多
ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step,并将 ScaleMaxScaleMaxScaleMaxScaleMaxscaleMaxscale_max 增加,从而使可能的缩放范围扩大 ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step。
OptimizationOptimizationOptimizationOptimizationoptimizationoptimization:
-
对于特别大的模型,通过将 OptimizationOptimizationOptimizationOptimizationoptimizationoptimization 设置为不同于 'none'"none""none""none""none""none" 的值来减少模型点数可能有所帮助。当 OptimizationOptimizationOptimizationOptimizationoptimizationoptimization =
'none'"none""none""none""none""none" 时,所有模型点都会被存储。在其他所有情况下,点数会根据 OptimizationOptimizationOptimizationOptimizationoptimizationoptimization 的值进行减少。如果点数减少,可能需要在 find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 中将
GreedinessGreedinessGreedinessGreedinessgreedinessgreediness 参数设置为较小的值,例如 0.7 或 0.8。对于小型模型,减少模型点数并不会提升搜索速度,因为此时通常需要检查更多潜在模型实例。
如果 OptimizationOptimizationOptimizationOptimizationoptimizationoptimization 设置为 'auto'"auto""auto""auto""auto""auto",create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 会自动确定模型点数的减少量。
MetricMetricMetricMetricmetricmetric:
-
参数 MetricMetricMetricMetricmetricmetric 决定了模型在图像中被识别的条件。
如果 MetricMetricMetricMetricmetricmetric = 'use_polarity'"use_polarity""use_polarity""use_polarity""use_polarity""use_polarity",则图像中的对象与模型必须具有相同的对比度。例如,如果模型是暗背景上的亮色对象,则只有当该对象也比背景更亮时才能被识别。
如果 MetricMetricMetricMetricmetricmetric = 'ignore_global_polarity'"ignore_global_polarity""ignore_global_polarity""ignore_global_polarity""ignore_global_polarity""ignore_global_polarity",即使图像整体对比度发生反转,该对象仍会被识别。因此在上例中,即使对象比背景更暗,仍会被识别。在这种情况下,find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 的运行时间会略有增加。
请注意,只有当所有 ContoursContoursContoursContourscontourscontours 都提供定义边缘极性的 'edge_direction'"edge_direction""edge_direction""edge_direction""edge_direction""edge_direction" 属性时,才能选择这些指标('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")。该属性适用于通过 edges_sub_pixedges_sub_pixEdgesSubPixEdgesSubPixEdgesSubPixedges_sub_pix 等工具创建的轮廓,例如当参数 MethodMethodMethodMethodmethodmethod 设置为 'canny'"canny""canny""canny""canny""canny"。否则,可通过 set_shape_model_metricset_shape_model_metricSetShapeModelMetricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric 算子选择这两项指标,该算子能从图像中确定边缘的极性。
如果 MetricMetricMetricMetricmetricmetric = 'ignore_local_polarity'"ignore_local_polarity""ignore_local_polarity""ignore_local_polarity""ignore_local_polarity""ignore_local_polarity",即使局部对比度发生变化,模型仍会被识别。例如,当对象包含一个中等灰度值的主体剖分,其内部存在更暗或更亮的子对象时,此模式便能发挥作用。由于在此情况下
find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 的运行时间会显著增加,因此通常建议使用
create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 创建多个能够反映对象可能对比度变化的模型,并使用 find_scaled_shape_modelsfind_scaled_shape_modelsFindScaledShapeModelsFindScaledShapeModelsFindScaledShapeModelsfind_scaled_shape_models 同时进行匹配。
上述三项指标仅适用于单通道图像。若将多通道图像用作模型图像或搜索图像,则仅使用首个通道(且不会返回错误信息)。
如果 MetricMetricMetricMetricmetricmetric = 'ignore_color_polarity'"ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity",即使局部颜色对比度发生变化,模型仍能被识别。例如当对象部分区域可变色(如从红色变为绿色)时即属此类情况。该模式尤其适用于无法预先确定对象在哪些通道可见的场景。在此模式下,find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 的运行时间也会显著增加。指标 'ignore_color_polarity'"ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity"
可用于任意通道数的图像。若应用于单通道图像,其效果等同于 'ignore_local_polarity'"ignore_local_polarity""ignore_local_polarity""ignore_local_polarity""ignore_local_polarity""ignore_local_polarity"。需要注意的是,当 MetricMetricMetricMetricmetricmetric = 'ignore_color_polarity'"ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity" 时,通道无需包含光谱分层信息(如 RGB 图像)。例如,这些通道还可能包含同一对象的图像,这些图像通过从不同方向照射对象获得。
请注意,前两个指标('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")仅在所有 ContoursContoursContoursContourscontourscontours 均提供定义边极性的 'edge_direction'"edge_direction""edge_direction""edge_direction""edge_direction""edge_direction" 属性时才可选取。有关 'edge_direction'"edge_direction""edge_direction""edge_direction""edge_direction""edge_direction" 等轮廓属性的更多信息,请参阅 get_contour_attrib_xldget_contour_attrib_xldGetContourAttribXldGetContourAttribXldGetContourAttribXldget_contour_attrib_xld。否则,可通过 set_shape_model_metricset_shape_model_metricSetShapeModelMetricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric 算子选择这两项指标,该算子能从图像中确定边缘的极性。
MinContrastMinContrastMinContrastMinContrastminContrastmin_contrast:
通过 MinContrastMinContrastMinContrastMinContrastminContrastmin_contrast 参数,可以确定在
find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 执行的识别过程中,对象边缘至少需要具备的对比度。换言之,该参数用于将对象与图像中的噪声区分开来。因此,理想设置应为图像噪声引发的灰度值变化范围。例如,若灰度值波动范围在 10 个灰度级内,则应将 MinContrastMinContrastMinContrastMinContrastminContrastmin_contrast 设为 10。当模型与搜索图像均为多通道图像,且参数 MetricMetricMetricMetricmetricmetric 设为
'ignore_color_polarity'"ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity""ignore_color_polarity"(参见前文)时,需将单通道噪声乘以通道数平方根来确定 MinContrastMinContrastMinContrastMinContrastminContrastmin_contrast 值。例如:若单通道灰度值波动范围为 10 个灰度级,且图像为三通道图像,则 MinContrastMinContrastMinContrastMinContrastminContrastmin_contrast 应设为 17。若需在极低对比度图像中识别模型,则需将 MinContrastMinContrastMinContrastMinContrastminContrastmin_contrast 设置为相应较小的数值。如果希望即使模型被严重遮挡也能被识别,则应将 MinContrastMinContrastMinContrastMinContrastminContrastmin_contrast 设置为略大于噪声产生的灰度值波动范围,以确保
find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 能稳健且准确地提取模型的位置和旋转信息。
完成模型的预生成
可选地,可在 OptimizationOptimizationOptimizationOptimizationoptimizationoptimization 中传递第二个参数。该参数决定模型是否进行完全预生成。为此,需将 OptimizationOptimizationOptimizationOptimizationoptimizationoptimization 的第二个值设置为 'pregeneration'"pregeneration""pregeneration""pregeneration""pregeneration""pregeneration" 或
'no_pregeneration'"no_pregeneration""no_pregeneration""no_pregeneration""no_pregeneration""no_pregeneration"。若未使用第二个参数(即仅传递单个参数),则采用通过 set_system('pregenerate_shape_models',...)set_system("pregenerate_shape_models",...)SetSystem("pregenerate_shape_models",...)SetSystem("pregenerate_shape_models",...)SetSystem("pregenerate_shape_models",...)set_system("pregenerate_shape_models",...) 设置的模式。默认值('pregenerate_shape_models'"pregenerate_shape_models""pregenerate_shape_models""pregenerate_shape_models""pregenerate_shape_models""pregenerate_shape_models" =
'false'"false""false""false""false""false")下,模型不会进行完全预生成。模型的完整预生成通常会导致运行时间略微缩短,因为模型在运行时无需进行转换。但此模式下内存需求和模型创建时间将显著增加。需注意两种模式无法产生完全相同的结果,因为运行时转换模型必然导致转换后模型的内部数据与预生成转换模型存在差异。例如,如果模型尚未完全预生成,find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 通常会返回稍低的分数,这可能需要将
MinScoreMinScoreMinScoreMinScoreminScoremin_score 的值设置得比完全预生成的模型稍低一些。此外,两种模式下通过插值获得的姿态可能存在细微差异。若追求最高精度,应通过最小二乘法调整确定模型姿态。
若选择完全预生成模型,则模型将针对选定的角度和缩放范围进行预生成并存储在内存中。存储模型所需的内存大小与角度步长数、缩放步长数以及模型中的点数成正比。因此,如果 AngleStepAngleStepAngleStepAngleStepangleStepangle_step 或 ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step 过小,或者
AngleExtentAngleExtentAngleExtentAngleExtentangleExtentangle_extent 或缩放范围过大,可能会导致模型无法再容纳于(虚拟)内存中。在这种情况下,必须增大 AngleStepAngleStepAngleStepAngleStepangleStepangle_step 或 ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step,或者缩小 AngleExtentAngleExtentAngleExtentAngleExtentangleExtentangle_extent 或缩放范围。无论如何,模型完全容纳于主内存是理想状态,因为这可避免操作系统进行分页操作,从而大幅缩短查找对象的时间。由于 find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model能够以亚像素级分辨率确定角度,因此对于直径小于约 200 像素的模型,可以选择 AngleStepAngleStepAngleStepAngleStepangleStepangle_step >= 1° 和 ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step >= 0.02。
如果选择了 AngleStepAngleStepAngleStepAngleStepangleStepangle_step =
'auto'"auto""auto""auto""auto""auto" 或
ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step =
'auto'"auto""auto""auto""auto""auto",create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 将根据模型的大小,分别自动确定合适的角度或缩放步长。可通过 get_shape_model_paramsget_shape_model_paramsGetShapeModelParamsGetShapeModelParamsGetShapeModelParamsget_shape_model_params 查询自动计算的角度步长和缩放步长。
若未选择完整预生成模型,则模型仅在每个金字塔层级的参考姿态下创建。在这种情况下,必须在运行时通过 find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model 方法将模型转换为不同的角度和比例。因此,该模型的识别过程可能需要稍长的时间。
请注意,预生成形状模型是针对特定图像尺寸定制的。出于运行时间考虑,不支持在搜索过程中使用相同模型并行处理不同尺寸的图像。此时必须使用相同模型的副本,否则程序可能崩溃!
注意
传递至 ContoursContoursContoursContourscontourscontours 的 XLD 轮廓应缩放至与搜索图像中目标平均尺寸大致相当。这意味着该产品的 值应大致等于 1。
需注意,与
create_scaled_shape_modelcreate_scaled_shape_modelCreateScaledShapeModelCreateScaledShapeModelCreateScaledShapeModelcreate_scaled_shape_model 算子不同,本算子无法指定模型组件的最小尺寸。为避免模型中出现小模型组件,可在调用 create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld之前,使用 select_contours_xldselect_contours_xldSelectContoursXldSelectContoursXldSelectContoursXldselect_contours_xld 算子踢除短轮廓。
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
此算子返回一个句柄。请注意,即使该句柄被用作特定算子的输入参数,这些算子仍可能改变此句柄类型的实例状态。
参数
ContoursContoursContoursContourscontourscontours (输入对象) xld_cont(-array) → objectHXLDContHObjectHXLDContHobject
用于创建模型的输入轮廓。
NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels (输入控制) integer → HTupleUnion[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"
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.29, 3.14, 1.57, 0.79, 0.39
限制:
AngleExtent >= 0
AngleStepAngleStepAngleStepAngleStepangleStepangle_step (输入控制) angle.rad → HTupleUnion[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
限制:
AngleStep >= 0 && AngleStep <= pi / 2
ScaleMinScaleMinScaleMinScaleMinscaleMinscale_min (输入控制) number → HTuplefloatHTupleHtuple (real) (double) (double) (double)
模式的最小缩放。
默认值:
0.9
建议值:
0.5, 0.6, 0.7, 0.8, 0.9, 1.0
限制:
ScaleMin > 0
ScaleMaxScaleMaxScaleMaxScaleMaxscaleMaxscale_max (输入控制) number → HTuplefloatHTupleHtuple (real) (double) (double) (double)
模式的最大缩放。
默认值:
1.1
建议值:
1.0, 1.1, 1.2, 1.3, 1.4, 1.5
限制:
ScaleMax >= ScaleMin
ScaleStepScaleStepScaleStepScaleStepscaleStepscale_step (输入控制) number → HTupleUnion[float, str]HTupleHtuple (real / string) (double / string) (double / HString) (double / char*)
缩放步长(分辨率)。
默认值:
'auto'
"auto"
"auto"
"auto"
"auto"
"auto"
建议值:
'auto'"auto""auto""auto""auto""auto", 0.01, 0.02, 0.05, 0.1, 0.15, 0.2
限制:
ScaleStep >= 0
OptimizationOptimizationOptimizationOptimizationoptimizationoptimization (输入控制) string(-array) → HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
用于生成模型的优化类型及可选方法。
默认值:
'auto'
"auto"
"auto"
"auto"
"auto"
"auto"
值列表:
'auto'"auto""auto""auto""auto""auto", 'no_pregeneration'"no_pregeneration""no_pregeneration""no_pregeneration""no_pregeneration""no_pregeneration", '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", 'pregeneration'"pregeneration""pregeneration""pregeneration""pregeneration""pregeneration"
MetricMetricMetricMetricmetricmetric (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
匹配指标。
默认值:
'ignore_local_polarity'
"ignore_local_polarity"
"ignore_local_polarity"
"ignore_local_polarity"
"ignore_local_polarity"
"ignore_local_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"
MinContrastMinContrastMinContrastMinContrastminContrastmin_contrast (输入控制) number → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
搜索图像中对象的最小对比度。
默认值:
5
建议值:
1, 2, 3, 5, 7, 10, 20, 30, 40
ModelIDModelIDModelIDModelIDmodelIDmodel_id (输出控制) shape_model → HShapeModel, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
模型的句柄。
结果
如果参数有效,算子
create_scaled_shape_model_xldcreate_scaled_shape_model_xldCreateScaledShapeModelXldCreateScaledShapeModelXldCreateScaledShapeModelXldcreate_scaled_shape_model_xld 返回值 2 (H_MSG_TRUE)。如有必要,则抛出异常。如果参数 NumLevelsNumLevelsNumLevelsNumLevelsnumLevelsnum_levels 的选择导致模型包含的点过少,则会引发错误 8510。
可能的前趋
read_contour_xld_dxfread_contour_xld_dxfReadContourXldDxfReadContourXldDxfReadContourXldDxfread_contour_xld_dxf,
edges_sub_pixedges_sub_pixEdgesSubPixEdgesSubPixEdgesSubPixedges_sub_pix,
select_contours_xldselect_contours_xldSelectContoursXldSelectContoursXldSelectContoursXldselect_contours_xld
可能的后继
find_scaled_shape_modelfind_scaled_shape_modelFindScaledShapeModelFindScaledShapeModelFindScaledShapeModelfind_scaled_shape_model,
find_scaled_shape_modelsfind_scaled_shape_modelsFindScaledShapeModelsFindScaledShapeModelsFindScaledShapeModelsfind_scaled_shape_models,
get_shape_model_paramsget_shape_model_paramsGetShapeModelParamsGetShapeModelParamsGetShapeModelParamsget_shape_model_params,
clear_shape_modelclear_shape_modelClearShapeModelClearShapeModelClearShapeModelclear_shape_model,
write_shape_modelwrite_shape_modelWriteShapeModelWriteShapeModelWriteShapeModelwrite_shape_model,
set_shape_model_originset_shape_model_originSetShapeModelOriginSetShapeModelOriginSetShapeModelOriginset_shape_model_origin,
set_shape_model_paramset_shape_model_paramSetShapeModelParamSetShapeModelParamSetShapeModelParamset_shape_model_param,
set_shape_model_metricset_shape_model_metricSetShapeModelMetricSetShapeModelMetricSetShapeModelMetricset_shape_model_metric,
set_shape_model_clutterset_shape_model_clutterSetShapeModelClutterSetShapeModelClutterSetShapeModelClutterset_shape_model_clutter
替代
create_generic_shape_modelcreate_generic_shape_modelCreateGenericShapeModelCreateGenericShapeModelCreateGenericShapeModelcreate_generic_shape_model
另见
set_systemset_systemSetSystemSetSystemSetSystemset_system,
get_systemget_systemGetSystemGetSystemGetSystemget_system
模块
匹配