fit_rectangle2_contour_xldfit_rectangle2_contour_xldFitRectangle2ContourXldFitRectangle2ContourXldfit_rectangle2_contour_xld (算子)
名称
fit_rectangle2_contour_xldfit_rectangle2_contour_xldFitRectangle2ContourXldFitRectangle2ContourXldfit_rectangle2_contour_xld — 将矩形拟合到 XLD 轮廓。
签名
fit_rectangle2_contour_xld(Contours : : Algorithm, MaxNumPoints, MaxClosureDist, ClippingEndPoints, Iterations, ClippingFactor : Row, Column, Phi, Length1, Length2, PointOrder)
Herror fit_rectangle2_contour_xld(const Hobject Contours, const char* Algorithm, const Hlong MaxNumPoints, double MaxClosureDist, const Hlong ClippingEndPoints, const Hlong Iterations, double ClippingFactor, double* Row, double* Column, double* Phi, double* Length1, double* Length2, char* PointOrder)
Herror T_fit_rectangle2_contour_xld(const Hobject Contours, const Htuple Algorithm, const Htuple MaxNumPoints, const Htuple MaxClosureDist, const Htuple ClippingEndPoints, const Htuple Iterations, const Htuple ClippingFactor, Htuple* Row, Htuple* Column, Htuple* Phi, Htuple* Length1, Htuple* Length2, Htuple* PointOrder)
void FitRectangle2ContourXld(const HObject& Contours, const HTuple& Algorithm, const HTuple& MaxNumPoints, const HTuple& MaxClosureDist, const HTuple& ClippingEndPoints, const HTuple& Iterations, const HTuple& ClippingFactor, HTuple* Row, HTuple* Column, HTuple* Phi, HTuple* Length1, HTuple* Length2, HTuple* PointOrder)
void HXLDCont::FitRectangle2ContourXld(const HString& Algorithm, Hlong MaxNumPoints, double MaxClosureDist, Hlong ClippingEndPoints, Hlong Iterations, double ClippingFactor, HTuple* Row, HTuple* Column, HTuple* Phi, HTuple* Length1, HTuple* Length2, HTuple* PointOrder) const
void HXLDCont::FitRectangle2ContourXld(const HString& Algorithm, Hlong MaxNumPoints, double MaxClosureDist, Hlong ClippingEndPoints, Hlong Iterations, double ClippingFactor, double* Row, double* Column, double* Phi, double* Length1, double* Length2, HString* PointOrder) const
void HXLDCont::FitRectangle2ContourXld(const char* Algorithm, Hlong MaxNumPoints, double MaxClosureDist, Hlong ClippingEndPoints, Hlong Iterations, double ClippingFactor, double* Row, double* Column, double* Phi, double* Length1, double* Length2, HString* PointOrder) const
void HXLDCont::FitRectangle2ContourXld(const wchar_t* Algorithm, Hlong MaxNumPoints, double MaxClosureDist, Hlong ClippingEndPoints, Hlong Iterations, double ClippingFactor, double* Row, double* Column, double* Phi, double* Length1, double* Length2, HString* PointOrder) const
(
Windows only)
static void HOperatorSet.FitRectangle2ContourXld(HObject contours, HTuple algorithm, HTuple maxNumPoints, HTuple maxClosureDist, HTuple clippingEndPoints, HTuple iterations, HTuple clippingFactor, out HTuple row, out HTuple column, out HTuple phi, out HTuple length1, out HTuple length2, out HTuple pointOrder)
void HXLDCont.FitRectangle2ContourXld(string algorithm, int maxNumPoints, double maxClosureDist, int clippingEndPoints, int iterations, double clippingFactor, out HTuple row, out HTuple column, out HTuple phi, out HTuple length1, out HTuple length2, out HTuple pointOrder)
void HXLDCont.FitRectangle2ContourXld(string algorithm, int maxNumPoints, double maxClosureDist, int clippingEndPoints, int iterations, double clippingFactor, out double row, out double column, out double phi, out double length1, out double length2, out string pointOrder)
def fit_rectangle2_contour_xld(contours: HObject, algorithm: str, max_num_points: int, max_closure_dist: float, clipping_end_points: int, iterations: int, clipping_factor: float) -> Tuple[Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[float], Sequence[str]]
def fit_rectangle2_contour_xld_s(contours: HObject, algorithm: str, max_num_points: int, max_closure_dist: float, clipping_end_points: int, iterations: int, clipping_factor: float) -> Tuple[float, float, float, float, float, str]
描述
fit_rectangle2_contour_xldfit_rectangle2_contour_xldFitRectangle2ContourXldFitRectangle2ContourXldFitRectangle2ContourXldfit_rectangle2_contour_xld fits rectangles to the
rectangular XLD contours given by ContoursContoursContoursContourscontourscontours and returns the
parameters of the rectangles in RowRowRowRowrowrow, ColumnColumnColumnColumncolumncolumn
(center), PhiPhiPhiPhiphiphi (orientation), as well as Length1Length1Length1Length1length1length_1
and Length2Length2Length2Length2length2length_2 (half edge lengths). The angle PhiPhiPhiPhiphiphi is
returned in radians and specifies the angle between the horizontal
axis and the edge with the half length Length1Length1Length1Length1length1length_1 in the
mathematically positive direction (counterclockwise). In addition,
the point order of the contour is returned in PointOrderPointOrderPointOrderPointOrderpointOrderpoint_order.
PointOrderPointOrderPointOrderPointOrderpointOrderpoint_order = 'positive'"positive""positive""positive""positive""positive" means that the contour
is traversed in the mathematically positive direction
(counterclockwise).
The algorithm used for the fitting of the rectangles can be selected
via AlgorithmAlgorithmAlgorithmAlgorithmalgorithmalgorithm:
- 'regression'"regression""regression""regression""regression""regression"
-
Standard least-squares line fitting.
- 'huber'"huber""huber""huber""huber""huber"
-
Weighted least-squares line fitting, where the impact of outliers
is decreased based on the approach of Huber (see below).
- 'tukey'"tukey""tukey""tukey""tukey""tukey"
Weighted least-squares line fitting, where
outliers are ignored based on the approach of Tukey(see below).
For 'huber'"huber""huber""huber""huber""huber" and 'tukey'"tukey""tukey""tukey""tukey""tukey", a robust error statistics is used
to estimate the standard deviation of the distances of the contour points
from the approximating sides of the rectangle while ignoring outliers. The
standard deviation is computed separately for each side of the rectangle to
allow the processing of rectangles whose sides are not exactly perpendicular
to each other. The parameter ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactorclipping_factor (a scaling factor
relative to the standard deviation) controls the amount of outliers:
The smaller the value chosen for ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactorclipping_factor the more outliers
are detected. The detection of outliers is iterated. The parameter
IterationsIterationsIterationsIterationsiterationsiterations specifies the number of iterations. For
AlgorithmAlgorithmAlgorithmAlgorithmalgorithmalgorithm = 'regression'"regression""regression""regression""regression""regression", the values of the last two
parameters are ignored. Note that in the approach of Tukey ('tukey'"tukey""tukey""tukey""tukey""tukey"),
the outliers are removed before performing the approximation and all other
points are weighted, whereas in the approach of Huber ('huber'"huber""huber""huber""huber""huber"),
the outliers still have a small influence. Particularly, for outliers the
optimization is influenced linearly and for points with a smaller distance it
is influenced to the square. For the algebraic approach, all distances of the
points influence the optimization to the square and thus are not robust
against outliers. In practice, the approach of Tukey is recommended.
To reduce the computational load, the fitting of rectangles can be
restricted to a subset of the contour points: If a value other than
-1 is assigned to MaxNumPointsMaxNumPointsMaxNumPointsMaxNumPointsmaxNumPointsmax_num_points, only up to
MaxNumPointsMaxNumPointsMaxNumPointsMaxNumPointsmaxNumPointsmax_num_points points, uniformly distributed across the
contour, are used.
Depending on the processing used to create ContoursContoursContoursContourscontourscontours, the
start and end points of a contour may contain positional errors.
Therefore, it is possible to exclude ClippingEndPointsClippingEndPointsClippingEndPointsClippingEndPointsclippingEndPointsclipping_end_points
points at the beginning and at the end of a contour from the
rectangle fitting.
Contours, for which the distance between their start points and
their end points is <= MaxClosureDistMaxClosureDistMaxClosureDistMaxClosureDistmaxClosureDistmax_closure_dist are
considered to be closed. For closed contours, the end point of the
contour is not used for the rectangle fitting because it would
receive twice the weight of the remaining points in the fit.
The fitting of the rectangle to the contour is based on finding the
correspondence between the contour points and the four sides of the
rectangle. To enable a successful fit, there must be at least one
point that lies in the interior of the line segment that represents
the respective rectangle side, i.e., the point must not lie at the
ends of the line segment. Because of this, at least eight contour
points are necessary to fit the rectangle. A point is internally
assigned to the side of the rectangle to which it has the minimum
distance. For this, the currently optimal rectangle parameters,
i.e., the parameters used for the current iteration step, are used
internally. If no corresponding points are found for at least one
side of the rectangle, the rectangle parameters cannot be determined
uniquely. In this case, the error 3266 is returned. Because of
this, the caller of fit_rectangle2_contour_xldfit_rectangle2_contour_xldFitRectangle2ContourXldFitRectangle2ContourXldFitRectangle2ContourXldfit_rectangle2_contour_xld must ensure
that the input contours sufficiently resemble a rectangle. In
particular, none of the interior angles of the contour, if the
contour was approximated by four lines, should be smaller than 45
degrees or larger than 135 degrees. Because of the assignment of
contour points to the closest side of the rectangle this would mean
that at least one side of the rectangle would have no corresponding
points. Furthermore, ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactorclipping_factor should not be chosen
too small to avoid that the outlier suppression creates rectangle
sides without corresponding contour points. This can only happen
for AlgorithmAlgorithmAlgorithmAlgorithmalgorithmalgorithm = 'tukey'"tukey""tukey""tukey""tukey""tukey". If the above
conditions are observed, fit_rectangle2_contour_xldfit_rectangle2_contour_xldFitRectangle2ContourXldFitRectangle2ContourXldFitRectangle2ContourXldfit_rectangle2_contour_xld returns
highly accurate rectangle parameters. If the outlier suppression
according to Tukey is used, fit_rectangle2_contour_xldfit_rectangle2_contour_xldFitRectangle2ContourXldFitRectangle2ContourXldFitRectangle2ContourXldfit_rectangle2_contour_xld can
be used to robustly fit rectangles, e.g., to rectangular contours
with rounded corners.
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 在元组级别上自动并行化。
参数
ContoursContoursContoursContourscontourscontours (输入对象) xld_cont(-array) → objectHXLDContHObjectHXLDContHobject
Input contours.
AlgorithmAlgorithmAlgorithmAlgorithmalgorithmalgorithm (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
Algorithm for fitting the rectangles.
默认值:
'regression'
"regression"
"regression"
"regression"
"regression"
"regression"
值列表:
'huber'"huber""huber""huber""huber""huber", 'regression'"regression""regression""regression""regression""regression", 'tukey'"tukey""tukey""tukey""tukey""tukey"
MaxNumPointsMaxNumPointsMaxNumPointsMaxNumPointsmaxNumPointsmax_num_points (输入控制) integer → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
Maximum number of contour points used for the
computation (-1 for all points).
默认值:
-1
限制:
MaxNumPoints == -1 || MaxNumPoints >= 8
MaxClosureDistMaxClosureDistMaxClosureDistMaxClosureDistmaxClosureDistmax_closure_dist (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
Maximum distance between the end points of a
contour to be considered as closed.
默认值:
0.0
限制:
MaxClosureDist >= 0.0
ClippingEndPointsClippingEndPointsClippingEndPointsClippingEndPointsclippingEndPointsclipping_end_points (输入控制) integer → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
Number of points at the beginning and at the end of the
contours to be ignored for the fitting.
默认值:
0
建议值:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
限制:
ClippingEndPoints >= 0
IterationsIterationsIterationsIterationsiterationsiterations (输入控制) integer → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
Maximum number of iterations
(not used for 'regression'"regression""regression""regression""regression""regression").
默认值:
3
限制:
Iterations >= 0
ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactorclipping_factor (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
Clipping factor for the elimination of outliers
(typical values: 1.0 for 'huber'"huber""huber""huber""huber""huber" and
2.0 for 'tukey'"tukey""tukey""tukey""tukey""tukey").
默认值:
2.0
建议值:
1.0, 1.5, 2.0, 2.5, 3.0
限制:
ClippingFactor > 0
RowRowRowRowrowrow (输出控制) rectangle2.center.y(-array) → HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)
Row coordinate of the center of the rectangle.
ColumnColumnColumnColumncolumncolumn (输出控制) rectangle2.center.x(-array) → HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)
Column coordinate of the center of the rectangle.
PhiPhiPhiPhiphiphi (输出控制) rectangle2.angle.rad(-array) → HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)
Orientation of the main axis of the rectangle [rad].
Length1Length1Length1Length1length1length_1 (输出控制) rectangle2.hwidth(-array) → HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)
First radius (half length) of the rectangle.
Length2Length2Length2Length2length2length_2 (输出控制) rectangle2.hheight(-array) → HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)
Second radius (half width) of the rectangle.
PointOrderPointOrderPointOrderPointOrderpointOrderpoint_order (输出控制) string(-array) → HTupleSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Point order of the contour.
值列表:
'negative'"negative""negative""negative""negative""negative", 'positive'"positive""positive""positive""positive""positive"
结果
fit_rectangle2_contour_xldfit_rectangle2_contour_xldFitRectangle2ContourXldFitRectangle2ContourXldFitRectangle2ContourXldfit_rectangle2_contour_xld returns 2 (
H_MSG_TRUE)
if all parameter
values are correct, and rectangles could be fitted to the input
contours. 如果输入为空则可设置行为通过 set_system('no_object_result',<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>)set_system("no_object_result",<Result>)。如有必要,则抛出异常。 If the parameter ClippingFactorClippingFactorClippingFactorClippingFactorclippingFactorclipping_factor is
chosen too small, i.e., all points are classified as outliers, the
error 3266 is raised. If no points could be found for at least one
side of the rectangle, the error 3266 is raised as well.
可能的前趋
gen_contours_skeleton_xldgen_contours_skeleton_xldGenContoursSkeletonXldGenContoursSkeletonXldGenContoursSkeletonXldgen_contours_skeleton_xld,
lines_gausslines_gaussLinesGaussLinesGaussLinesGausslines_gauss,
lines_facetlines_facetLinesFacetLinesFacetLinesFacetlines_facet,
edges_sub_pixedges_sub_pixEdgesSubPixEdgesSubPixEdgesSubPixedges_sub_pix,
smooth_contours_xldsmooth_contours_xldSmoothContoursXldSmoothContoursXldSmoothContoursXldsmooth_contours_xld,
union_collinear_contours_xldunion_collinear_contours_xldUnionCollinearContoursXldUnionCollinearContoursXldUnionCollinearContoursXldunion_collinear_contours_xld,
union_collinear_contours_ext_xldunion_collinear_contours_ext_xldUnionCollinearContoursExtXldUnionCollinearContoursExtXldUnionCollinearContoursExtXldunion_collinear_contours_ext_xld,
union_adjacent_contours_xldunion_adjacent_contours_xldUnionAdjacentContoursXldUnionAdjacentContoursXldUnionAdjacentContoursXldunion_adjacent_contours_xld
可能的后继
dist_rectangle2_contour_points_xlddist_rectangle2_contour_points_xldDistRectangle2ContourPointsXldDistRectangle2ContourPointsXldDistRectangle2ContourPointsXlddist_rectangle2_contour_points_xld,
gen_rectangle2_contour_xldgen_rectangle2_contour_xldGenRectangle2ContourXldGenRectangle2ContourXldGenRectangle2ContourXldgen_rectangle2_contour_xld
替代
smallest_rectangle2_xldsmallest_rectangle2_xldSmallestRectangle2XldSmallestRectangle2XldSmallestRectangle2Xldsmallest_rectangle2_xld
另见
fit_line_contour_xldfit_line_contour_xldFitLineContourXldFitLineContourXldFitLineContourXldfit_line_contour_xld,
fit_circle_contour_xldfit_circle_contour_xldFitCircleContourXldFitCircleContourXldFitCircleContourXldfit_circle_contour_xld,
fit_ellipse_contour_xldfit_ellipse_contour_xldFitEllipseContourXldFitEllipseContourXldFitEllipseContourXldfit_ellipse_contour_xld
模块
基础