Ellipse detection method and system fusing deep feature localization and geometric constraint optimization
By integrating deep feature localization and geometric constraint optimization, an ellipse detection method is developed. This method combines deep learning and geometric optimization to solve the robustness and accuracy problems of ellipse detection in complex scenes, and achieves efficient and reliable ellipse parameter estimation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ZHEJIANG UNIV OF WATER RESOURCES & ELECTRIC POWER
- Filing Date
- 2026-03-30
- Publication Date
- 2026-07-14
AI Technical Summary
Existing ellipse detection techniques struggle to achieve robust localization and high-precision, geometrically consistent parameter estimation in complex scenarios. Geometric model-based methods are susceptible to interference, while deep learning-based methods lack explicit geometric constraints.
An ellipse detection method combining deep feature localization and geometric constraint optimization is proposed. The elliptical target is initially located through a feature pyramid network and a region proposal network. The parameters are fitted using the least squares method and the Levenberg-Marquardt nonlinear iterative optimization algorithm. Combined with geometric rationality verification, abnormal estimation results are eliminated.
It achieves highly robust positioning and high-precision ellipse parameter estimation in complex scenarios, significantly improving the anti-interference ability and geometric consistency of detection, and is suitable for practical applications such as industrial vision inspection.
Smart Images

Figure CN122391275A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of ellipse detection technology, and in particular to an ellipse detection method and system that integrates depth feature localization and geometric constraint optimization. Background Technology
[0002] Existing ellipse detection techniques are mainly divided into two categories: geometric model-based methods and deep learning-based regression methods. Geometric model-based methods (such as edge detection combined with least squares fitting) are effective in simple scenes, but in complex backgrounds, with occlusion, or with incomplete edges, they are easily affected by a large number of non-target contour points, leading to computational complexity and insufficient stability. While deep learning-based methods have strong localization capabilities in complex backgrounds, they lack explicit geometric constraints due to end-to-end parametric regression, resulting in potential geometric inconsistencies and poor interpretability in the estimated ellipse parameters, and they are also highly sensitive to the distribution of training data. Some existing fusion schemes still fail to effectively decouple the two key aspects of target localization and geometric parameter estimation, making it difficult to simultaneously achieve highly robust localization and high-precision, geometrically consistent parameter estimation in complex scenes. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this application aims to provide an ellipse detection method and system that integrates deep feature localization and geometric constraint optimization. This method can overcome the shortcomings of geometric model-based methods, such as poor robustness and susceptibility to interference, as well as the shortcomings of deep learning-based regression methods, such as insufficient geometric consistency and unreasonable parameters, in complex scenarios. This enables highly robust localization and high-precision, geometrically consistent parameter estimation.
[0004] To achieve the above objectives, this application adopts the following technical solution:
[0005] This application provides an ellipse detection method that integrates deep feature localization and geometric constraint optimization. The method includes the following steps:
[0006] S101, Obtain the input image to be detected;
[0007] S102, the input image is input into a pre-trained target detection network, the target detection network includes a feature pyramid network and a region proposal network, the feature pyramid network extracts multi-scale depth features of the input image, and the region proposal network generates one or more axis-aligned candidate regions based on the multi-scale depth features, each candidate region is used to cover a potential elliptical target;
[0008] S103, for each candidate region, extract the corresponding local image from the input image;
[0009] S104, preprocess the local image, including sequentially performing Gaussian filtering for noise reduction, grayscale processing, and adaptive threshold segmentation to enhance the elliptical edges and suppress background interference.
[0010] S105, perform contour extraction on the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target;
[0011] S106. Based on the set of contour points, the least squares method is used to fit the elliptical geometric model to obtain the initial estimated values of the ellipse parameters, which include the center coordinates, the length of the major axis, the length of the minor axis, and the rotation angle.
[0012] S107, Perform geometric rationality verification on the initial estimated value and eliminate abnormal estimation results that do not meet the preset elliptical convexity constraint or axis length ratio range;
[0013] S108. For the verified initial estimate, the Levenberg-Marquardt nonlinear iterative optimization algorithm is used to fit the contour point set with the ellipse geometric equation as a constraint, and the ellipse parameters are optimized and updated until the preset convergence condition is met, and the final ellipse detection and parameter estimation results are output.
[0014] As a preferred technical solution, step S101 involves acquiring the input image to be detected, including:
[0015] The system acquires raw images containing elliptical targets in real time from an industrial camera or webcam; or reads pre-stored image files containing elliptical targets from a storage device; performs format verification and integrity checks on the raw images or image files to ensure they conform to preset image encoding formats and data integrity requirements; converts the verified images into a unified color space and pixel bit depth, and scales them to the fixed input size required by the target detection network to generate the input image to be detected.
[0016] As a preferred technical solution, in step S102, the input image is input into a pre-trained target detection network, including:
[0017] The input image is fed into the feature pyramid network, and basic feature maps are extracted through the backbone network of the feature pyramid network. By fusing features from different levels from top to bottom and through horizontal connection paths, a multi-scale feature pyramid with rich semantic information is constructed.
[0018] In the region proposal network, anchor boxes of various scales and aspect ratios are preset for each level of the multi-scale feature pyramid; a corresponding region proposal is generated at each anchor box position; for each generated region proposal, a classification branch is used to predict the confidence score of the region proposal containing elliptical targets; for each generated region proposal, a regression branch is used to predict the positional offset of the region proposal relative to the corresponding preset anchor box, so as to perform preliminary screening and position fine-tuning of candidate regions; for the preliminary candidate regions generated at all levels, a non-maximum suppression operation is applied to remove highly overlapping redundant regions based on the overlap area between the confidence scores of the region proposals and the region proposals.
[0019] Output a set of axis-aligned candidate regions, each of which is used to cover a potential elliptical target.
[0020] As a preferred technical solution, in step S103, for each candidate region, a corresponding local image is extracted from the input image, including:
[0021] The coordinates of each candidate region output by the object detection network are obtained, including the coordinates of the top-left vertex, width, and height of the candidate region in the input image. The coordinate values of the candidate regions are converted from floating-point numbers to integers to ensure the validity of the pixel coordinates. It is determined whether the converted integer coordinates exceed the boundary of the input image. If any side of the candidate region exceeds the image boundary, the coordinates of that boundary are adjusted to within the effective pixel range of the image. Based on the adjusted integer coordinates, a corresponding rectangular image block is cropped from the input image as the initial local image. The resolution of the cropped initial local image is adjusted to a preset fixed size using a bilinear interpolation algorithm to standardize the input for subsequent processing. The local image after resolution adjustment is converted from the original RGB color space to a grayscale color space or HSV color space to adapt to subsequent image preprocessing and contour extraction operations.
[0022] As a preferred technical solution, step S104 involves preprocessing the local image, including:
[0023] Gaussian filtering is applied to the local image for noise reduction. The size and standard deviation of the Gaussian kernel are adaptively determined based on the size of the local image and the noise level, so as to smooth the image noise while preserving the elliptical edge information.
[0024] The denoised local image is converted from color space to single-channel grayscale image, and the grayscale value is calculated using a weighted method, giving the green channel a higher weight to conform to the visual characteristics of the human eye and the color response of common sensors;
[0025] The grayscale image is processed using a Gaussian weighted adaptive thresholding segmentation algorithm. The adaptive thresholding segmentation algorithm dynamically calculates the segmentation threshold for each pixel in the image based on the Gaussian weighted grayscale values of its neighboring pixels. During the adaptive thresholding segmentation process, the size of the neighborhood block is set to an odd value that is not less than the estimated ellipse edge width, and a positive constant parameter is set to fine-tune the segmentation sensitivity.
[0026] A morphological closing operation is performed on the binary image generated after threshold segmentation to close any minor breaks or holes that may exist at the edge of the ellipse. The connected components of the morphologically processed binary image are calculated, and the area and contour integrity of the connected components are used to filter the images, retaining only the candidate elliptical regions that meet the preset conditions for subsequent contour extraction.
[0027] As a preferred technical solution, step S105 involves extracting contours from the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target, including:
[0028] For the binary image after preprocessing and morphological operations, the Suzuki85 chain code tracing algorithm is used to traverse the image pixels, detect and extract the outer contours of all connected components and possible internal hole contours in the image; during the contour extraction process, a minimum contour length threshold is set to filter out small or discontinuous false contour fragments caused by noise.
[0029] For each extracted candidate contour, calculate the convex hull of the candidate contour and evaluate the convexity of the contour. Prioritize retaining contours with convexity close to 1 as candidates for elliptical boundaries.
[0030] For each of the filtered contours, the Douglas-Peucker algorithm based on curve arc length is used to simplify the contour point set, reducing the number of contour points while retaining the key features of the elliptical geometry.
[0031] The simplified contour point set is smoothed, and a Gaussian filter is applied to filter the coordinate sequence of the contour points to eliminate the jagged fluctuations that may be caused by pixel-level extraction.
[0032] From the smoothed contour point sequence, uniform resampling is performed according to the principle of fixed step size or equal arc length to generate a discrete contour point set for subsequent fitting of elliptical geometric model.
[0033] As a preferred technical solution, in step S106, based on the contour point set, the least squares method is used to fit the elliptical geometric model to obtain initial estimates of the ellipse parameters, including:
[0034] The contour point set is preprocessed by coordinate centering, the centroid coordinates of the point set are calculated, and all contour points are translated so that the center of the point set is located at the origin of the temporary coordinate system.
[0035] Weights are assigned to the translated contour points. The weights are determined based on the estimated local edge gradient magnitude at each contour point, with points having larger gradient magnitudes being assigned higher weights.
[0036] Based on the weighted contour point set, an overdetermined linear equation system is constructed with the coefficients of the general quadratic curve equation of an ellipse as unknowns.
[0037] By employing algebraic distance least squares fitting, and solving a generalized eigenvalue problem constrained by positive definiteness, the coefficients of the general quadratic curve equation of the ellipse that minimize the sum of the squares of the algebraic distances from all contour points to the ellipse are obtained.
[0038] The coefficients of the general quadratic equation of the ellipse are converted into standard ellipse geometric parameters, which include the center coordinates, major axis length, minor axis length, and rotation angle.
[0039] The initial geometric parameters obtained from the transformation are verified for rationality to ensure that the length of the major axis is greater than the length of the minor axis and that the rotation angle is normalized to the preset range of 0 to π radians.
[0040] As a preferred technical solution, in step S107, the initial estimated value is geometrically validated to eliminate abnormal estimation results that do not meet the preset elliptical convexity constraint or axis length ratio range, including:
[0041] The ellipse equation is reconstructed based on the initially estimated ellipse parameters, and the algebraic distances from all contour points to the reconstructed ellipse are calculated to generate a distance set.
[0042] Calculate the mean and standard deviation of the distance set, set a dynamic threshold based on the standard deviation, remove contour points whose algebraic distance exceeds the dynamic threshold as outliers, and recalculate the initial estimate based on the remaining contour points to improve data consistency.
[0043] Based on the recalculated initial estimate, the convexity constraint of the ellipse is verified by calculating the ratio of the minimum convex hull area of the contour point set to the theoretical area of the ellipse. If the ratio of the minimum convex hull area to the theoretical area of the ellipse exceeds the preset ratio range, it is determined that the initial estimate does not satisfy the convexity constraint.
[0044] Verify the ellipse's axis length ratio by calculating the ratio of the minor axis length to the major axis length. If the ratio is less than the preset minimum axis length ratio threshold or greater than the preset maximum axis length ratio threshold, the ellipse is determined to be too flat or too close to a circle, and is considered an abnormal geometric shape.
[0045] Calculate the sum of Euclidean distances from all points in the contour point set to the edge of the initially estimated ellipse. If the sum of Euclidean distances exceeds the adaptive threshold calculated based on the size of the contour point set and the image size, the initial estimate is deemed to have a low fit to the original contour.
[0046] For the initial estimate that satisfies all the above verification conditions, a comprehensive score is given based on the size of its contour point set, goodness of fit, and geometric consistency with the estimation results of neighboring candidate regions.
[0047] Only initial estimates with a comprehensive score higher than a preset threshold are retained and marked as valid estimates. These initial estimates are then passed to subsequent nonlinear optimization steps, while all abnormal estimates that fail validation or have low scores are removed.
[0048] As a preferred technical solution, in step S108, for the verified initial estimate, using the elliptic geometric equation as a constraint, the Levenberg-Marquardt nonlinear iterative optimization algorithm is used to fit the contour point set, including:
[0049] The ellipse center coordinates, major axis length, minor axis length, and rotation angle in the initial estimated values are used as the initial parameter vector for nonlinear optimization iteration;
[0050] The initial parameter vector is preprocessed by normalization, which involves dividing the center coordinates by the size of the local image and dividing the axis length parameter by the length of the image diagonal, in order to improve the numerical stability of the optimization algorithm.
[0051] A parameterized model based on the standard geometric equation of an ellipse is constructed, and a loss function based on geometric distance is defined. This loss function is the sum of the squares of the shortest geometric distances from each point in the contour point set to the edge of the current parameter ellipse. In each iteration, the Jacobian matrix of the loss function with respect to the current parameter vector is calculated, and an incremental regularization equation is constructed based on the Jacobian matrix and the current residual. The damping factor of the Levenberg-Marquardt algorithm is dynamically adjusted according to the decrease in the loss function; when the loss decreases significantly, the damping factor is reduced to approximate a Gaussian-Marquardt algorithm. Newton's method accelerates convergence. When the loss decreases significantly, the damping factor is increased to approximate the gradient descent method to ensure stability. During iterative optimization, a Cauchy kernel function is introduced to weight the distance residuals of each contour point to reduce the negative impact of possible outliers on the optimization process and enhance the robustness of the fit. Multiple convergence conditions are set, including: the change in the loss function value is less than the first threshold, the change norm of the parameter vector is less than the second threshold, or the number of iterations reaches a preset maximum value. When any convergence condition is met, the iteration stops, and the parameter vector updated in the last iteration is denormalized to restore the final elliptical geometric parameters in the image coordinate system.
[0052] For the final geometric parameters obtained through optimization, calculate the goodness-of-fit index between the final geometric parameters and the contour point set, and output the final geometric parameters and the goodness-of-fit index together as the ellipse detection and parameter estimation results.
[0053] This application also provides an ellipse detection system that integrates depth feature localization and geometric constraint optimization, the system comprising:
[0054] The image acquisition module is used to acquire the input image to be detected;
[0055] The target localization module, connected to the image acquisition module, is used to input the input image into a pre-trained target detection network. The target detection network includes a feature pyramid network and a region proposal network. The feature pyramid network extracts multi-scale depth features of the input image, and the region proposal network generates one or more axis-aligned candidate regions based on the multi-scale depth features. Each candidate region is used to cover a potential elliptical target.
[0056] The local image processing module, connected to the target localization module, is used to extract the corresponding local image from the input image for each candidate region and preprocess the local image. The preprocessing includes sequentially performing Gaussian filtering for noise reduction, grayscale processing, and adaptive threshold segmentation to enhance the elliptical edges and suppress background interference.
[0057] The contour extraction module, connected to the local image processing module, is used to extract contours from the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target.
[0058] The parameter initial estimation and verification module is connected to the contour extraction module. It is used to fit the elliptical geometric model based on the contour point set using the least squares method to obtain the initial estimated values of the elliptical parameters, and to verify the geometric rationality of the initial estimated values, eliminating abnormal estimation results that do not meet the preset elliptical convexity constraints or axis length ratio range. The elliptical parameters include the center coordinates, major axis length, minor axis length, and rotation angle.
[0059] The parameter optimization output module is connected to the parameter initial estimation and verification module. It is used to fit the contour point set with the ellipse geometric equation as a constraint and the Levenberg-Marquardt nonlinear iterative optimization algorithm to the verified initial estimate value, optimize and update the ellipse parameters until the preset convergence condition is met, and output the final ellipse detection and parameter estimation results.
[0060] Compared with the prior art, the beneficial effects of this application are as follows:
[0061] 1. Significantly improves detection robustness and anti-interference capability in complex scenes. In step S102, a deep learning object detection network (including FPN and RPN) is used for initial localization in the entire image. The generated candidate regions effectively frame elliptical targets from complex backgrounds. This allows all subsequent fine-tuning processes (S103-S108) to be performed only within the candidate regions, fundamentally avoiding interference from numerous non-target edges and noise across the entire image, thus solving the main problem of traditional pure geometric methods failing in complex scenes.
[0062] 2. High-precision and geometrically consistent parameter estimation was achieved. This application does not stop at coarse regression using deep networks, but instead uses the localization results (candidate regions) as input for subsequent professional geometric analysis. Steps S104-S105 perform enhancement and contour extraction within the local region, obtaining a cleaner set of elliptical boundary points. Step S106 uses the least squares method for initialization, and step S108 uses the elliptical geometric equation as a constraint, employing the LM algorithm for nonlinear optimization. This two-step strategy of "geometric initialization + constraint optimization" ensures that the final output elliptical parameters (center, axis length, angle) not only have the smallest mathematical fitting error to the point set, but also strictly satisfy the geometric definition of an ellipse, solving the problem of poor geometric consistency of parameters in pure deep learning regression methods.
[0063] 3. The reliability of the results is ensured through a multi-verification mechanism. The geometric rationality verification introduced in step S107 is a key innovation. It actively eliminates initial estimation results that do not meet the convexity constraint or have abnormal axis length ratios. This step effectively filters out erroneous fittings caused by contour extraction errors, target occlusion, or non-elliptical interference, ensuring that only candidates with reasonable shapes enter the final optimization stage, significantly improving the overall credibility of the final output results.
[0064] 4. A good balance is achieved between efficiency and accuracy. This application avoids time-consuming global contour extraction and Hough transform operations across the entire image, and also avoids the difficult training of deep networks for high-precision geometric parameter regression. Its computational overhead is mainly concentrated on the forward propagation of the object detection network and the fast local processing of multiple candidate regions. The structure is clear, easier to deploy in engineering, and suitable for practical application scenarios that require both real-time performance and accuracy (such as industrial vision inspection).
[0065] In summary, this application combines the powerful target localization capability of deep learning with the accurate and interpretable modeling capability of traditional geometric vision. Through decoupled design and specific verification and optimization steps, the method achieves high robustness, high accuracy, strong geometric consistency and good practicality in complex scenarios, overcoming the inherent defects of existing single technical routes. Attached Figure Description
[0066] Figure 1 This is a schematic diagram of the ellipse detection method that integrates deep feature localization and geometric constraint optimization according to this application;
[0067] Figure 2 This is a process diagram for application scenario one of this application;
[0068] Figure 3 This is a process diagram for application scenario two of this application;
[0069] Figure 4 This is a process diagram for application scenario three of this application. Detailed Implementation
[0070] To enable those skilled in the art to better understand the present application, the technical solutions in specific embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0071] like Figure 1 As shown, this application provides an ellipse detection method that integrates deep feature localization and geometric constraint optimization. The method includes the following steps:
[0072] S101, Obtain the input image to be detected.
[0073] S102, the input image is fed into a pre-trained object detection network, which includes a feature pyramid network and a region proposal network. The feature pyramid network extracts multi-scale depth features of the input image, and the region proposal network generates one or more axis-aligned candidate regions based on the multi-scale depth features. Each candidate region is used to cover a potential elliptical object.
[0074] S103, for each candidate region, extract the corresponding local image from the input image.
[0075] S104, preprocesses the local image, including sequentially performing Gaussian filtering for noise reduction, grayscale processing, and adaptive threshold segmentation to enhance the elliptical edges and suppress background interference.
[0076] S105, perform contour extraction on the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target.
[0077] S106. Based on the contour point set, the least squares method is used to fit the elliptical geometric model to obtain the initial estimated values of the ellipse parameters, including the center coordinates, major axis length, minor axis length, and rotation angle.
[0078] S107, Perform geometric rationality verification on the initial estimate and eliminate abnormal estimate results that do not meet the preset elliptic convexity constraint or axis length ratio range.
[0079] S108. Based on the validated initial estimate, the Levenberg-Marquardt nonlinear iterative optimization algorithm is used to fit the contour point set with the ellipse geometric equation as a constraint, and the ellipse parameters are optimized and updated until the preset convergence condition is met, and the final ellipse detection and parameter estimation results are output.
[0080] Further, in step S101, acquiring the input image to be detected includes:
[0081] The system acquires raw images containing elliptical targets in real time from industrial cameras or webcams, or reads pre-stored image files containing elliptical targets from storage devices. The raw images or image files undergo format and integrity verification to ensure they conform to preset image encoding formats and data integrity requirements. The verified images are then converted to a uniform color space and pixel depth and scaled to the fixed input size required by the target detection network to generate the input image to be detected.
[0082] Specifically, step S101 is an image input and preprocessing pipeline, which includes the following three sub-steps:
[0083] Image Source Acquisition: The system supports image acquisition from two sources. One is real-time acquisition from industrial cameras or webcams, suitable for real-time applications such as online inspection and production line monitoring; the other is reading pre-stored image files from storage devices, suitable for offline analysis and dataset processing. This design provides a flexible data input interface.
[0084] Data Validation: After acquiring the raw image data, the system immediately performs format and integrity verification. Format verification ensures that the image file conforms to the system's supported encoding formats (such as JPEG, PNG, BMP, etc.), while integrity verification ensures that the image data has not been corrupted during transmission or storage. This step is the first line of defense to ensure the stability of subsequent processing flows.
[0085] Image Standardization: After verification, the image enters the standardization process. First, it is converted to a uniform color space and pixel depth (e.g., uniformly converted to RGB color space and 8-bit pixel depth) to eliminate differences from different acquisition devices or storage formats and ensure consistency in algorithm processing conditions. Next, the image is scaled to a fixed input size (e.g., 640x640 pixels) required by the object detection network. This scaling operation typically employs image transformation algorithms such as aspect ratio-preserving padding or direct resizing to meet the fixed input tensor size requirements of deep learning models.
[0086] The above technical solution has the following beneficial effects:
[0087] Enhanced system robustness and applicability: By supporting both real-time acquisition and file reading modes, and adding format and integrity checks, this method can adapt to the real-time online detection needs on industrial production lines and the analysis needs of batch historical data in laboratory environments. At the same time, it effectively avoids system crashes or detection failures caused by data errors, thereby improving the engineering practicality and reliability of the entire system.
[0088] Ensuring consistent processing and detection accuracy: A unified color space and pixel-level depth transformation eliminate color and brightness differences in the original image caused by different sources, providing standardized input for subsequent deep feature extraction and image processing, and reducing errors introduced by inconsistent input. Scaling to a fixed size ensures that the pre-trained object detection network can operate at its optimal design, maintaining the stability of feature extraction capabilities and laying a reliable foundation for subsequent high-precision candidate region generation.
[0089] Improving overall processing efficiency: Fixed-size scaling during the input phase avoids dynamic and potentially more time-consuming size adjustments during subsequent network inference. This pre-processing standardization ensures that data is ready before entering the core detection module, which optimizes the computation process and improves the overall system throughput.
[0090] Further, in step S102, the input image is fed into the pre-trained object detection network, including:
[0091] The input image is fed into a feature pyramid network, and basic feature maps are extracted through the backbone network of the feature pyramid network. By fusing features from different levels through top-down and lateral connection paths, a multi-scale feature pyramid with rich semantic information is constructed.
[0092] In the region proposal network, anchor boxes of various scales and aspect ratios are pre-defined for each level of the multi-scale feature pyramid. A corresponding region proposal is generated at each anchor box location. For each generated region proposal, a classification branch predicts the confidence score of whether the region proposal contains elliptical targets. For each generated region proposal, a regression branch predicts the positional offset of the region proposal relative to the corresponding pre-defined anchor box, performing initial screening and fine-tuning of candidate regions. For all preliminary candidate regions generated at all levels, non-maximum suppression is applied, removing highly overlapping redundant regions based on the overlap area between the region proposal's confidence score and the region proposal.
[0093] Output a set of axis-aligned candidate regions, each of which is used to cover a potential elliptical target.
[0094] Specifically, step S102 is an end-to-end deep network inference and selection process based on the idea of a two-stage object detector (such as Faster R-CNN), which is broken down as follows:
[0095] 1. Multi-scale deep feature extraction:
[0096] Backbone network feature extraction: The input image is first passed through a pre-trained convolutional neural network backbone (such as ResNet or VGG) for forward propagation. This backbone network performs convolution and downsampling layer by layer, outputting a set of basic feature maps with different spatial resolutions but high-level semantic information.
[0097] Feature Pyramid Construction: Subsequently, these feature maps from different levels are fed into the Feature Pyramid Network (FPN) for processing. The FPN uses a top-down upsampling path to element-wise fuse semantically rich high-level features (low resolution) with laterally connected, detail-rich low-level features (high resolution). This process constructs a multi-scale feature pyramid, where each layer possesses both strong semantic information and an appropriate spatial resolution suitable for detecting targets at different scales.
[0098] 2. Region proposal generation based on anchor frames:
[0099] In the region proposal network, for each layer of the aforementioned feature pyramid, a set of anchor boxes with various scales and aspect ratios are predefined. These anchor boxes serve as prior reference boxes for elliptical targets of different sizes and shapes, and are densely tiled at each spatial location of the feature map.
[0100] For each anchor box, the RPN computes two outputs: a classification score (the probability that the anchor box is either "foreground" (i.e., contains the elliptical target) or "background") and a bounding box regression offset (the prediction of the fine-tuning that the anchor box needs to be to more tightly enclose the potential target). This step generates a large number of preliminary "region proposals" in parallel at each location on the feature map.
[0101] 3. Selection and refinement of proposals:
[0102] Preliminary screening: Based on the confidence scores predicted by the classification branches, all preliminary region proposals are sorted and the highest-scoring subset (e.g., the top-N) is retained, thereby quickly filtering out a large number of obvious background regions.
[0103] Position fine-tuning: For each retained region proposal, the position offset predicted by the regression branch is used to finely adjust the corresponding anchor frame coordinates to obtain candidate regions with more accurate positions.
[0104] Redundancy Removal: Due to the dense and overlapping anchor frames, the above steps will generate a large number of highly overlapping candidate regions. At this point, a non-maximum suppression algorithm is applied: all candidate regions are sorted according to their confidence scores, and the region with the highest score is selected sequentially. All other regions whose overlap area exceeds a set threshold (e.g., IoU > 0.7) are then suppressed (deleted). This operation ensures that each candidate region in the final output corresponds to an independent, highly probable target location.
[0105] The beneficial effects of the above technical solution are as follows:
[0106] 1. Robust and efficient initial localization of elliptical targets: Utilizing the powerful feature learning capabilities of deep convolutional networks, it can understand and locate the semantic target of "ellipse" from pixel-level information. Even in cluttered, low-contrast, or partially occluded backgrounds, it can effectively distinguish the target from the background, overcoming the shortcomings of traditional methods that rely entirely on low-level gradients or edge information and are prone to failure.
[0107] 2. Significantly reduces the search space for subsequent geometric processing, improving overall efficiency: Traditional geometric methods (such as Hough transform) require a global search across all edge points in the entire image, resulting in extremely high computational complexity. This step uses a deep network to quickly filter out a few (usually tens to hundreds) highly suspicious candidate regions, allowing all subsequent time-consuming image preprocessing, contour extraction, and iterative fitting operations to be performed only within these small local windows. This reduces the computational load by orders of magnitude, greatly enhancing the method's real-time performance potential.
[0108] 3. It solves the problem of detecting ellipses at multiple scales and unknown scales: By combining a feature pyramid network with multi-scale anchor boxes, the network can simultaneously detect large ellipses on low-resolution (large receptive field) feature maps and small ellipses on high-resolution (rich detail) feature maps. This design allows the method to adaptively detect targets of different sizes in images without prior knowledge of the ellipse's scale range, enhancing the method's versatility.
[0109] 4. It provides high-quality regions of interest for high-precision geometric fitting: The axis-aligned candidate regions generated by RPN not only provide the possible locations of the target, but also perform preliminary position fine-tuning through regression. This ensures that the extracted local image (S103) can more completely and centrally contain the target ellipse, creating optimal conditions for the subsequent extraction of a clean set of contour points, which is an important foundation for high-precision parameter estimation.
[0110] Furthermore, in step S103, for each candidate region, a corresponding local image is extracted from the input image, including:
[0111] The coordinates of each candidate region output by the object detection network are obtained, including the coordinates of the top-left vertex, width, and height of the candidate region in the input image. The coordinate values of the candidate regions are converted from floating-point numbers to integers to ensure the validity of the pixel coordinates. It is determined whether the converted integer coordinates exceed the boundaries of the input image. If any side of the candidate region exceeds the image boundary, the coordinates of that boundary are adjusted to within the effective pixel range of the image. Based on the adjusted integer coordinates, a corresponding rectangular image patch is cropped from the input image as the initial local image. For the cropped initial local image, a bilinear interpolation algorithm is used to adjust the resolution of the image patch to a preset fixed size to standardize the input for subsequent processing. The resolution-adjusted local image is converted from the original RGB color space to a grayscale color space or HSV color space to adapt to subsequent image preprocessing and contour extraction operations.
[0112] Specifically, step S103 is a data preprocessing procedure that accurately extracts and standardizes the local regions of the target from the entire image. It transforms the abstract "boundary coordinates" output by the target detection network into regularized image data that can be directly manipulated by subsequent image processing algorithms. Its implementation can be decomposed into the following six ordered steps:
[0113] 1. Coordinate Acquisition: Receive information on each candidate region from the output of step S102 (object detection network). Each region is typically represented by a vector or tuple containing four elements, in the format (x, y, width, height). Here, x and y represent the pixel coordinates of the top-left corner of the candidate region in the input image coordinate system, and width and height represent the width and height of the region (in pixels), respectively. These coordinate values are usually floating-point numbers because they are predicted by the network's regression layers.
[0114] 2. Coordinate Integerization: Since image pixel indices must be integers, floating-point coordinates (x, y, width, height) need to be converted to integer coordinates (x_int, y_int, w_int, h_int). This is typically done using floor or rounding. This step ensures that the coordinates subsequently used to index the image array are valid and unambiguous.
[0115] 3. Boundary Checking and Correction: The converted integer coordinates may exceed the boundaries of the original input image (e.g., x_int may be negative, or x_int + w_int may be greater than the image width). To prevent array out-of-bounds errors during cropping, boundary constraints must be implemented. The specific steps are:
[0116] The values of x_int and y_int are restricted to the range of [0, image width - 1] and [0, image height - 1].
[0117] Limit the values of w_int and h_int to ensure that x_int + w_int <= image width and y_int + h_int <= image height.
[0118] This is typically achieved using the max() and min() functions to ensure that the rectangular area ultimately used for the screenshot is completely inside the original image.
[0119] 4. Image Patch Cropping: Using the boundary-corrected integer coordinates (x_final, y_final, w_final, h_final), a rectangular region is cropped from the original input image (a three-dimensional array, e.g., [height, width, 3] corresponding to RGB channels) through array slicing operations. The resulting "initial local image" has dimensions (h_final, w_final, 3).
[0120] 5. Resolution Standardization: Due to the varying sizes of different candidate regions, the initial local images extracted vary in size, making subsequent batch or fixed-parameter processing (such as convolution kernel size, threshold block size, etc.) inconvenient. Therefore, it is necessary to scale them to a preset fixed size (e.g., 128x128 pixels). Bilinear interpolation is a commonly used method in this step. It calculates the color value of the target pixel based on a weighted average of the distances to the four original image pixels surrounding it, providing better smoothness and visual quality during scaling and avoiding the jagged edges that may occur with nearest-neighbor interpolation.
[0121] 6. Color Space Conversion: To accommodate subsequent preprocessing operations such as grayscale conversion and thresholding, the resolution-normalized RGB image is typically converted to a single-channel grayscale image. A commonly used conversion formula is a weighted average: Gray = 0.299*R + 0.587*G + 0.114*B. In certain specific scenarios (such as when selecting targets based on color), conversion to the HSV color space may also be necessary. This space separates brightness, hue, and saturation, making it more robust to changes in lighting conditions.
[0122] For example, consider an input image (input_img) with dimensions of 800 pixels (width) x 600 pixels (height). The object detection network outputs a candidate region with coordinates: [x=150.7,y=80.3,width=120.5,height=110.8].
[0123] Coordinates obtained: bbox = [150.7,80.3,120.5,110.8].
[0124] Coordinate integerization: Rounding is used to obtain integer coordinates: bbox_int = [151,80,121,111].
[0125] Boundary checks and corrections:
[0126] Checking x_int=151, it is within [0,799], so it is valid.
[0127] Checking y_int=80, it is within [0,599], so it is valid.
[0128] Check the right boundary: x_int + w_int = 151 + 121 = 272, which is less than the image width of 800, so it is valid.
[0129] Check the lower boundary: y_int + h_int = 80 + 111 = 191, which is less than the image height of 600, so it is valid.
[0130] No correction is needed; the final coordinates are bbox_final = [151,80,121,111].
[0131] Image patching: Perform array slicing on input_img: local_patch = input_img[80:191,151:272, :]. The resulting local_patch is an RGB image patch with shape (111,121,3).
[0132] Resolution normalization: The default fixed size is 128x128. Image patches of (111,121,3) are scaled to (128,128,3) using bilinear interpolation. Image content is uniformly stretched / compressed to the new size.
[0133] Color space conversion: The scaled 128x128x3 RGB image is converted into a 128x128 single-channel grayscale image using a grayscale conversion formula, ready for the next step of preprocessing.
[0134] The beneficial effects of the above technical solution are as follows:
[0135] 1. Improved system robustness and stability: By converting floating-point coordinates to integers and performing rigorous boundary checks and corrections, the method ensures that cropping operations from any image (including cases where the target is located at the image edge) will not fail due to invalid or out-of-bounds coordinates. This enables the method to stably handle any coordinates that the object detection network may output, enhancing the fault tolerance and engineering practicality of the entire process and avoiding system anomalies caused by boundary conditions.
[0136] 2. Significantly Improved Computational Efficiency of Subsequent Processing: Traditional methods typically perform edge detection and contour analysis on the entire image, resulting in high computational costs. This step, by extracting only rectangular image patches corresponding to candidate regions, strictly limits all subsequent time-consuming image preprocessing, contour extraction, and geometric fitting operations to a few small local windows. This achieves a significant reduction in computational complexity from the global image scale (O(total number of pixels)) to the local target scale (O(sum of pixels in the candidate region)), providing a foundation for real-time or high-performance ellipse detection.
[0137] 3. Standardize input to ensure consistency and accuracy in geometric processing:
[0138] Size standardization: Image patches are adjusted to a preset fixed size using bilinear interpolation, eliminating scale differences between different candidate regions caused by variations in target size and distance. This ensures that all subsequent image processing operators (such as Gaussian filter kernel size and morphological operation structuring element size) and contour analysis algorithms can operate at a uniform scale, avoiding the need for dynamic parameter adjustments due to varying input scales. This simplifies the process and improves the stability and comparability of the results.
[0139] Color space adaptation: Converting to grayscale or HSV color space provides the most suitable input for subsequent preprocessing steps. Grayscale conversion significantly reduces data dimensionality, focusing on brightness information and improving the efficiency of edge extraction and thresholding; while conversion to HSV space is more effective in scenarios where color information (such as ellipses with specific hues) is needed to enhance the separation of the target from the background. This flexibility optimizes the representation of image data, creating conditions for extracting cleaner and more accurate elliptical boundary contour point sets.
[0140] 4. Providing high-quality input data for high-precision geometric fitting: High-quality geometric fitting heavily relies on clear edge information. This step is a crucial preprocessing step to ensure this. Boundary correction avoids truncating invalid black-filled areas; bilinear interpolation in size normalization smoothly scales the image, preserving edge continuity to the greatest extent; color space conversion enhances the contrast between the target and the background. The ultimate goal of these operations is to provide a high-quality local image with a complete target, minimal background interference, and uniform size for the next step (S104) of image enhancement and contour extraction, thus directly contributing to the high accuracy of the final ellipse parameter estimation.
[0141] Furthermore, in step S104, the local image is preprocessed, including:
[0142] Gaussian filtering is applied to local images for noise reduction. The size and standard deviation of the Gaussian kernel are adaptively determined based on the size of the local image and the noise level, so as to smooth the image noise while preserving the elliptical edge information.
[0143] Specifically, the noise level of the local image is first assessed, which can be estimated by calculating the gray-level variance of the smoothed region or using a predefined noise model. Based on the assessed noise level and the size of the local image itself, the size (e.g., 3x3, 5x5, 7x7, etc.) and standard deviation (σ) of the Gaussian kernel are dynamically determined by looking up a table or by using a formula. When the noise is high and the image size is large, a slightly larger kernel and σ may be used; conversely, a smaller parameter is used. Subsequently, this adaptively determined Gaussian kernel is used to perform a convolution operation on the local image to smooth Gaussian noise and fine textures, while taking advantage of the good edge-preserving properties of Gaussian filtering to maximize the preservation of the sharpness of elliptical edges.
[0144] The denoised local image is converted from color space to single-channel grayscale image, and grayscale values are calculated using a weighted method, with higher weights given to the green channel to conform to the visual characteristics of the human eye and the color response of common sensors.
[0145] It should be noted that the color conversion can be performed in step S103 or step S104. If the color conversion has already been performed in step S103, then the color conversion step is not required in step S104.
[0146] Specifically, the denoised color (usually RGB) image is converted to a single-channel grayscale image. The conversion does not use a simple averaging method ((R+G+B) / 3), but rather a weighted method: Gray = 0.299 * R + 0.587 * G + 0.114 * B. This formula originates from the ITU-R BT.601 standard, giving the green channel the highest weight (0.587). This is based on two facts: first, human visual cells are most sensitive to green light; second, in most color image sensors (such as Bayer arrays), the number of green pixels is twice that of red or blue, resulting in a generally higher signal-to-noise ratio. This weighting method produces a grayscale image that better matches human visual perception and has superior contrast, helping to more accurately distinguish ellipses from the background in subsequent processing.
[0147] The grayscale image is processed using a Gaussian-weighted adaptive thresholding algorithm. This algorithm dynamically calculates the segmentation threshold for each pixel based on the Gaussian-weighted grayscale values of its neighboring pixels. During the adaptive thresholding process, the neighborhood block size is set to an odd value that is not less than the estimated ellipse edge width, and a positive constant parameter is set to fine-tune the segmentation sensitivity.
[0148] Specifically, a Gaussian-weighted adaptive thresholding algorithm (such as cv2.ADAPTIVE_THRESH_GAUSSIAN_C in OpenCV) is applied to grayscale images. This algorithm calculates a threshold T(x,y) for each pixel (x,y) in the image individually. The calculation method is as follows: a square neighborhood with a side length of blockSize (an odd number) is taken centered on the pixel. The grayscale values of all pixels within this neighborhood are then Gaussian-weighted averaged. This average is subtracted from a constant C to obtain the local threshold T(x,y). The setting of blockSize is crucial; its value should not be less than the estimated width of the ellipse edge (for example, it can be set to 5, 7, 9, etc., based on prior knowledge or image resolution) to ensure that the neighborhood can cover the bright and dark areas on both sides of the edge, thus calculating a reasonable local threshold. The constant C is used to fine-tune the segmentation sensitivity. A positive value of C will lower the threshold, and the segmentation result will be more biased towards the foreground (white), often used to suppress background noise.
[0149] A morphological closing operation is performed on the binary image generated after thresholding to close any tiny breaks or holes that may exist at the edge of the ellipse.
[0150] Specifically, a morphological closing operation is performed on the binary image obtained in the previous step (white foreground, black background). The closing operation is a combination of dilation and erosion, using a predefined structuring element (usually a circle or square). The dilation operation bridges minor breaks at the edges caused by noise or insufficient contrast, while the subsequent erosion operation restores the object's approximate original shape while avoiding over-dilation. This step effectively connects adjacent edge fragments and fills in tiny holes within the elliptical boundaries caused by texture or uneven lighting, resulting in a more continuous and fuller candidate elliptical region.
[0151] Calculate the connected components of the morphologically processed binary image, and filter them based on the area and contour integrity of the connected components, retaining only candidate elliptical regions that meet the preset conditions for subsequent contour extraction.
[0152] Specifically, connected component labeling and analysis are performed on the binary image repaired by closing operations. First, the image is scanned to identify all interconnected foreground (white) pixel groups, each group constituting a connected component. Then, the geometric and shape properties of each connected component are calculated, mainly including: Area: Filtering out connected components with areas that are too small (potentially noise points) or too large (potentially background blocks). Contour integrity / compactness: For example, calculating the ratio of the area of the connected component to the area of its bounding rectangle, or analyzing the convexity of its contour, to filter out relatively regular, closed regions and eliminate obvious linear or fragmented noise. Only connected components with areas within a preset range and relatively complete contours are retained and marked as candidate elliptical regions. These filtered regions will be used for subsequent contour extraction (S105), thereby effectively reducing invalid calculations and false detections.
[0153] The beneficial effects of the above technical solution are as follows:
[0154] 1. Significantly improves edge signal-to-noise ratio and enhances method robustness: Adaptive Gaussian filtering intelligently denoises based on different image qualities and region sizes, smoothing noise while maximizing the preservation of realistic elliptical edges, providing a "clean" input for subsequent processing. Weighted grayscale enhances the visual contrast between the ellipse and the background by optimizing brightness conversion. The combination of these two significantly improves the image's signal-to-noise ratio, making the method more stable when facing unavoidable noise and complex textures in real-world scenes.
[0155] 2. Effectively overcomes the effects of uneven illumination and local contrast variations: This is one of the core contributions of this step. Traditional global thresholding segmentation completely fails on images with uneven illumination. Gaussian-weighted adaptive thresholding segmentation calculates a dynamic threshold for each pixel based on its local neighborhood, accurately following changes in local image brightness. This allows for reliable segmentation of elliptical targets from the background even in areas with uneven illumination, shadows, or reflections. The neighborhood block size is set to be related to the width of the ellipse edge, ensuring that the threshold calculation accurately reflects the local contrast characteristics of the edge.
[0156] 3. Ensuring the continuity and integrity of the extracted contour lays the foundation for high-precision fitting: Morphological closing operations specifically address the common problems of edge breaks and internal holes after binary segmentation. It can "stitch" broken edge fragments and fill small holes, thereby outputting a continuous, complete, and full elliptical region binary mask. This is a prerequisite for subsequently extracting a coherent and closed contour point set (S105), directly determining the initial quality of least squares fitting (S106).
[0157] 4. Efficiently filtering interference in the early stages to improve overall process efficiency and accuracy: Connected component analysis and screening, as an early verification step, can quickly eliminate noise blocks, texture blocks, or other small objects that clearly do not conform to elliptical features based on simple geometric features (area, shape). This avoids sending a large number of invalid regions into the subsequent time-consuming contour extraction and iterative fitting steps, significantly reducing unnecessary computational overhead and effectively reducing the possibility of misdetecting noise as ellipses, thus improving the accuracy and reliability of the final output results.
[0158] Further, in step S105, contour extraction is performed on the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target, including:
[0159] For the preprocessed and morphologically manipulated binary image, the Suzuki85 chain code tracing algorithm is used to traverse the image pixels, detecting and extracting the external contours of all connected components and possible internal hole contours. During contour extraction, a minimum contour length threshold is set to filter out small or discontinuous false contour fragments caused by noise.
[0160] The Suzuki85 chaincode tracing algorithm is based on the principle commonly used in OpenCV's cv2.findContours algorithm. This algorithm scans image pixels, identifies the boundary between the foreground (white) and background (black), traverses and records the outer contours (outer boundaries) of all connected regions (i.e., candidate elliptical regions) and the contours of any potential internal holes (black holes within the region). The algorithm outputs a series of contours, each composed of an ordered set of boundary pixel coordinates. During this process, a minimum contour length threshold is set; any contour with fewer pixels than this threshold is discarded. This effectively filters out small or discontinuous false contour fragments formed by residual noise points.
[0161] For each extracted candidate contour, the convex hull of the contour (i.e., the smallest convex polygon containing all points of the contour) is calculated, and the convexity of the contour is evaluated. Contours with a convexity close to 1 are preferentially retained as candidates for elliptical boundaries. The convexity (Solidity) of the contour can be calculated by comparing the ratio of the area of the original contour to the area of its convex hull; its value is between 0 and 1. An ellipse itself is a convex shape, and its contour convexity should be very close to 1. Therefore, a high convexity threshold (e.g., 0.9) is set to preferentially retain contours with a convexity close to 1 as strong candidate elliptical boundaries, while contours with low convexity (indicating concave or irregular shapes) are initially excluded.
[0162] For each selected contour, the Douglas-Peucker algorithm, based on curve arc length, is used to simplify the contour point set, reducing the number of contour points while preserving key features of the ellipse's geometry. The Douglas-Peucker algorithm approximates the original contour with a polyline defined by key points, ensuring that the maximum distance from any point on the approximate polyline to the original contour does not exceed a set tolerance (epsilon). By setting an appropriate tolerance value, this algorithm can eliminate a large number of collinear points or points with gentle curvature changes on the contour, retaining only key points that define the inflection points of the ellipse shape (such as near the endpoints of the major and minor axes). This significantly reduces the number of contour points without significantly altering the ellipse's geometry, thereby reducing the amount of data required for subsequent fitting calculations.
[0163] The simplified contour point set is smoothed by applying a Gaussian filter to the coordinate sequence of the contour points to eliminate jagged fluctuations that may be caused by pixel-level extraction. Since contour extraction is based on a pixel grid, the simplified point sequence may still exhibit pixel-level jagged fluctuations in coordinates. To eliminate these fluctuations, a one-dimensional Gaussian filter is applied to the simplified contour point sequence (a series of (x,y) coordinates), smoothing both the x-coordinate and y-coordinate sequences separately. This is equivalent to performing a local weighted average on the contour curve, making the contour points smoother, more continuous, and closer to the ideal smooth elliptical curve, reducing the negative impact of high-frequency noise caused by pixel discretization on high-precision geometric fitting.
[0164] From the smoothed contour point sequence, uniform resampling is performed according to a fixed step size or equal arc length principle to generate a discrete contour point set for subsequent fitting of the ellipse's geometric model. The spacing between points in the smoothed contour point sequence may still be uneven. To ensure a uniform distribution of data points for fitting, uniform resampling is performed on the smoothed contour. Two common methods are: the fixed step size method (taking a point every fixed arc length along the contour curve) or the equal arc length principle (dividing the total arc length of the entire contour curve into N equal segments and taking points at the endpoints of each segment). Through resampling, a discrete contour point set with a controllable number of points and uniform spacing is generated. This point set can more evenly reflect the geometry of the entire ellipse, avoiding overly dense areas and sparse areas, which is beneficial for improving the stability and accuracy of least squares fitting algorithms.
[0165] The beneficial effects of the above technical solution are as follows:
[0166] 1. Achieving precise conversion from pixel regions to geometric data: The Suzuki85 algorithm accurately converts binary image regions into vector contours described by a sequence of coordinate points, which is a necessary prerequisite for ellipse fitting. Minimum contour length filtering removes obviously invalid noise segments at the data entry point.
[0167] 2. Early validation at the geometric level improves data reliability: Convexity calculation and screening is a powerful prior validation of geometric shapes. It utilizes the fundamental geometric property that "an ellipse is convex" to filter out a large number of irregular, concave non-elliptical contours (such as two joined circles, other polygonal objects, etc.) at the contour level, significantly improving the data quality passed to subsequent fitting steps and reducing the risk of false detections from the source.
[0168] 3. Significantly optimize data scale and quality, improving overall efficiency and accuracy:
[0169] Improved efficiency: The Douglas-Peucker simplification reduces the number of contour points by an order of magnitude without losing key shape information. This directly reduces the size of the equations that need to be constructed and solved in the subsequent least squares fitting (S106), significantly reducing computational complexity and improving the processing speed of the method.
[0170] Improving accuracy: Gaussian smoothing eliminates pixel-level jagged noise, resulting in smoother contours that more closely approximate the true boundaries of a continuous ellipse. Uniform resampling ensures that the data points used for fitting are evenly distributed across the ellipse circumference, avoiding fitting bias caused by uneven point distribution (e.g., densely populated regions receiving unreasonably higher weights in the fitting). These two steps together improve the "purity" and "fairness" of the original data used for fitting, laying a solid data foundation for obtaining high-precision, unbiased ellipse parameter estimates.
[0171] Furthermore, in step S106, based on the contour point set, the least squares method is used to fit the elliptical geometric model to obtain initial estimates of the elliptical parameters, including:
[0172] The contour point set is preprocessed by coordinate centering, the centroid coordinates of the point set are calculated, and all contour points are translated so that the center of the point set is located at the origin of the temporary coordinate system.
[0173] Weights are assigned to the translated contour points. The weights are determined based on the estimated local edge gradient magnitude at each contour point, with points having larger gradient magnitudes being assigned higher weights.
[0174] Based on the weighted contour point set, an overdetermined linear equation system is constructed with the coefficients of the general quadratic curve equation of an ellipse as unknowns.
[0175] By employing algebraic distance least squares fitting, and solving a generalized eigenvalue problem constrained by positive definiteness, the coefficients of the general quadratic curve equation of the ellipse that minimize the sum of the squares of the algebraic distances from all contour points to the ellipse are obtained.
[0176] The coefficients of the general quadratic equation of an ellipse are converted into standard elliptic geometric parameters, including the center coordinates, major axis length, minor axis length, and rotation angle.
[0177] The initial geometric parameters obtained from the transformation are verified for rationality to ensure that the length of the major axis is greater than the length of the minor axis and that the rotation angle is normalized to the preset range of 0 to π radians.
[0178] Specifically, step S106 aims to transform the discrete set of contour points into a preliminary parametric model that conforms to the geometric definition of an ellipse. Its implementation is a rigorous mathematical computation process, comprising the following six sub-steps:
[0179] 1. Coordinate Centering Preprocessing: First, calculate the centroid coordinates (x̄, ȳ) of the contour point set. Then, translate all contour points (xi, yi) so that the new point coordinates are (xi - x̄, yi - ȳ). This operation moves the center of the point set to the origin of the temporary coordinate system. The purpose is to eliminate the potential problem of excessively large values in subsequent calculations, improve numerical stability, and ensure that the translation operation does not affect the shape parameters (axis length, angle) of the ellipse.
[0180] 2. Gradient-Magnitude-Based Weighting: For the translated point set, a weight wi is calculated for each point. The weight is determined by the edge gradient magnitude at the point's corresponding location in the original local image. A larger gradient magnitude indicates a higher probability that the point is on an edge and a more precise location. A common method is to pre-compute the gradient map using operators such as Sobel. Assigning higher gradient points higher weights allows points with more reliable locations and a greater likelihood of being "true edges" to have a greater influence on the results during the fitting process.
[0181] 3. Constructing an overdetermined linear system of equations: An ellipse on a two-dimensional plane can be represented by a general quadratic curve equation: Ax² + Bxy + Cy² + Dx + Ey + F = 0. Substituting each weighted contour point (xi, yi) into this equation yields a linear equation concerning the coefficients A, B, C, D, E, and F. Since the number of contour points N is much greater than 6 (the number of unknown coefficients), an overdetermined linear system of equations is formed, which can be formally written as M * v = 0, where M is an Nx6 matrix (elements are calculated from point coordinates), and v = [A,B,C,D,E,F]^T is the vector of coefficients to be determined.
[0182] 4. Solving the Constrained Generalized Eigenvalue Problem: To obtain a meaningful ellipse (rather than a parabola or hyperbola), the constraint B² - 4AC < 0 (ellipse condition) must be imposed. Using algebraic distance least squares fitting (direct linear transformation, DLT), this problem can be transformed into solving a generalized eigenvalue problem with positive definite constraints: S * v = λ * C * v. Here, S is the divergence matrix (M^T * W * M, where W is the diagonal weight matrix) composed of weighted point sets, and C is a constant matrix representing the constraint B² - 4AC = 1 (or other equivalent forms). Solving this generalized eigenvalue problem corresponds to minimizing the weighted sum of squares of the algebraic distances from all points to the ellipse, and its solution vector v is the best estimate of the coefficients of the general quadratic curve of the ellipse.
[0183] 5. Conversion of coefficients to standard geometric parameters: After obtaining the coefficient vector v, it can be converted into intuitive standard geometric parameters through a series of defined mathematical formulas. The conversion process includes calculating the center coordinates (xc, yc) of the ellipse (considering the translation in step 1 and performing an inverse coordinate transformation), the length of the major semi-axis a, the length of the minor semi-axis b, and the rotation angle θ (the angle between the major axis of the ellipse and the horizontal axis). These parameters have clear physical / geometric meanings and form the basis for subsequent processing and output.
[0184] 6. Parameter Rationality Verification and Normalization: Perform basic verification on the initial parameters obtained from the transformation. First, ensure that the major axis length 'a' is greater than the minor axis length 'b'. If this is not satisfied, swap 'a' and 'b' and adjust the angle 'θ'. Second, normalize the rotation angle 'θ' to a preset range (usually 0 to π radians or -π / 2 to π / 2) to avoid ambiguity in angle representation. This step ensures that the initial parameters are geometrically consistent and normalized.
[0185] The beneficial effects of the above technical solution are as follows:
[0186] 1. Provides high-precision, unbiased initial parameter estimation: Algebraic distance least squares fitting provides mathematically optimal statistical estimation, minimizing the overall algebraic error between the contour points and the elliptical model. Combined with the numerical stability improved by coordinate centering, this step can extract the elliptical parameters most likely representing the overall geometric trend from the potentially noisy set of contour points, laying a high-precision foundation for the entire method.
[0187] 2. Enhancing the robustness of the fit by using edge confidence weighting: The gradient magnitude-based weighting mechanism is one of the key innovations of this step. It no longer operates on a "one point, one vote" basis, but rather gives greater "vote" to points with stronger edges and more accurate positioning. This effectively suppresses the influence of outliers (such as noise or non-edge points) or poorly fitted local areas on the overall model, making the fitting results more faithful to the true elliptical boundary and improving robustness under non-ideal contour conditions.
[0188] 3. Ensure the solution conforms to the elliptic geometric constraints, providing a high-quality starting point for subsequent optimization: By solving the generalized eigenvalue problem constrained by positive definiteness, this step forces the fitted quadratic curve to satisfy the elliptic condition (B² - 4AC < 0), thus fundamentally avoiding invalid solutions such as parabolas or hyperbolas. This ensures that the initial estimate of the output is geometrically reasonable as an ellipse. This geometrically reasonable initial value is crucial for the nonlinear optimization in the subsequent step S108, enabling it to converge to the global optimum more quickly and stably, avoiding getting trapped in local optima or diverging due to inappropriate initial values.
[0189] 4. Achieve standardized and interpretable output from data points to parameter models: Transform abstract quadratic curve coefficients into standard geometric parameters, giving the results intuitive physical meaning (center, magnitude, direction), facilitating subsequent application, verification, and visualization. Parameter rationality verification and normalization further ensure output consistency, eliminate ambiguity caused by mathematical ambiguity, and provide clean and regular intermediate results for the entire system.
[0190] Furthermore, in step S107, the initial estimate is geometrically validated, and abnormal estimation results that do not meet the preset elliptic convexity constraint or axis length ratio range are eliminated, including:
[0191] The ellipse equation is reconstructed based on the initially estimated ellipse parameters, and the algebraic distance from all contour points to the reconstructed ellipse is calculated to generate a distance set. The mean and standard deviation of the distance set are calculated, a dynamic threshold based on the standard deviation is set, contour points whose algebraic distance exceeds the dynamic threshold are removed as outliers, and the initial estimate is recalculated based on the remaining contour points to improve data consistency.
[0192] Specifically, the elliptic curve is reconstructed using the initial estimated parameters. The algebraic distance from each original contour point to the ellipse is calculated, forming a distance set. The mean μ and standard deviation σ of this set are calculated. A dynamic threshold is set, for example, μ + k*σ (k is a constant, such as 2.0 or 3.0). All contour points with distances exceeding this threshold are considered outliers and are removed. Subsequently, only the remaining, more consistent inliers are used to perform a final least-squares fit, yielding the cleaned-up initial estimate. This step improves the quality of the baseline model used for all subsequent validations at the data level.
[0193] Based on the recalculated initial estimate, the convexity constraint of the ellipse is verified by calculating the ratio of the minimum convex hull area of the contour point set to the theoretical area of the ellipse. If the ratio of the minimum convex hull area to the theoretical area of the ellipse exceeds the preset ratio range, it is determined that the initial estimate does not satisfy the convexity constraint.
[0194] Specifically, the minimum convex hull of the contour point set and its area, Area_convexhull, are calculated. Simultaneously, the theoretical area of the ellipse, Area_ellipse = π * a * b, is calculated using the purified ellipse parameters (center, major semi-axis a, minor semi-axis b). The ratio of these two areas, Ratio_convex = Area_convexhull / Area_ellipse, is calculated. Since the convex hull area is always greater than or equal to the area of the ellipse's inscribed point set, this ratio should be slightly greater than 1 for a perfectly fitted convex contour. An upper and lower bound close to 1 is set (e.g., [0.95, 1.1]). If the ratio exceeds this range, it indicates that the contour shape has significant concavity or differs too much from the ellipse model, failing to meet the convexity constraint, and is therefore discarded.
[0195] Verify the ellipse's axis length ratio by calculating the ratio of the minor axis length to the major axis length. If this ratio is less than a preset minimum axis length ratio threshold or greater than a preset maximum axis length ratio threshold, the ellipse is determined to be too flat or too close to a circle, and is considered an abnormal geometric shape.
[0196] Specifically, calculate the ellipse's aspect ratio Ratio_aspect = b / a (minor axis / major axis, with a value between 0 and 1). Set an acceptable range of ellipse shapes based on the application scenario. For example, set a minimum aspect ratio threshold min_ratio (e.g., 0.1) to exclude falsely detected, excessively elongated line-segment-like contours; set a maximum aspect ratio threshold max_ratio (e.g., 0.95) to exclude shapes that are too close to circles (necessary in some applications that strictly distinguish between circles and ellipses). If Ratio_aspect is outside this range, it is considered an abnormal geometry.
[0197] Calculate the sum of Euclidean distances from all points in the contour point set to the edge of the initially estimated ellipse. If the sum of Euclidean distances exceeds the adaptive threshold calculated based on the size of the contour point set and the image size, the initial estimate is deemed to have a low fit to the original contour.
[0198] Specifically, a more precise error metric is calculated—the sum (or average) of the Euclidean distances from all points in the contour point set to the edge of the ellipse. This distance is the shortest geometric distance from a point to the ellipse, and it has more geometric significance than the algebraic distance. An adaptive error threshold is set based on the number of contour points (scale) and the image size (scale). For example, the threshold can be proportional to the sqrt(number of contour points) or the percentage of the image diagonal length. If the total error exceeds this threshold, it indicates that even if the geometry is roughly correct, the fitting accuracy is too low, the model is unreliable, and it is discarded.
[0199] For initial estimates that meet all the above validation conditions, a comprehensive score is given based on the size of their contour point set, goodness of fit, and geometric consistency with the estimation results of neighboring candidate regions. Only initial estimates with a comprehensive score higher than a preset threshold are retained and marked as valid estimates. These initial estimates are then passed to subsequent nonlinear optimization steps, while all outlier estimates that fail validation or have low scores are removed.
[0200] Specifically, the scoring function considers: data support: the size of the contour point set (more points generally mean greater reliability); goodness of fit: the reciprocal of the sum of Euclidean distances calculated in the previous step (smaller error, higher score); geometric consistency: compatibility with other neighboring candidate ellipse estimates in the image (e.g., whether the center position and size conflict with other surrounding ellipses, applicable in scenarios requiring the detection of multiple similar targets). A final comprehensive scoring threshold is set. Only candidates with scores higher than this threshold are retained and formally marked as valid estimates. All candidates that fail any hard validation step or have excessively low scores are permanently removed as outlier estimates.
[0201] The beneficial effects of the above technical solution are as follows:
[0202] 1. Significantly improves the reliability and accuracy of the final output results. By establishing a "quality control station" in the middle of the process, abnormal estimates caused by noise contours, occlusion, target adhesion, and mismatches of non-elliptical objects are actively and rigorously filtered out. This ensures that only high-quality candidates that have undergone multiple geometric and logical checks flow into the final optimization and output stages, thereby greatly reducing the false detection rate and false alarm rate from the root, making the final detection result set highly reliable.
[0203] 2. Significantly enhances the system's robustness in complex scenes: Traditional fitting methods are sensitive to outliers and noise. The outlier removal and re-estimation mechanism in this step gives the method the ability to "self-repair" data. Convexity constraints and axis-to-length ratio verification utilize the strong prior geometric knowledge of ellipses, effectively distinguishing ellipses from a large number of irregular objects. This allows the method to maintain stable detection performance even when facing complex real-world images containing interference.
[0204] 3. Optimize computational resource allocation and improve overall process efficiency: The subsequent S108 step (nonlinear optimization) is the most computationally expensive step. This step acts as a highly efficient pre-filter, eliminating a large number of obviously invalid and low-quality candidates in advance. This avoids wasting valuable computational resources on useless optimization of these "garbage" candidates, ensuring that system resources are concentrated on processing truly promising candidates, thereby significantly improving overall processing efficiency.
[0205] 4. Providing high-quality initial values for subsequent optimization, ensuring convergence and accuracy: The initial estimate passed to S108 is a "high-quality seed" that has undergone data purification (outlier removal) and multiple verifications. This allows the nonlinear optimization process to start from an initial point very close to the true solution, greatly reducing the number of iterations required for convergence, lowering the risk of getting trapped in local optima, and ensuring that the final optimization result achieves higher accuracy.
[0206] 5. The output results have clear geometric meaning and interpretability: The comprehensive scoring mechanism can quantify the credibility of each detection result. The final output not only includes the ellipse parameters but also their scores, providing downstream applications (such as robot decision-making and measurement systems) with an intuitive basis for judging the reliability of the detection results, increasing the practicality and interpretability of the entire system.
[0207] Furthermore, in step S108, for the validated initial estimate, the Levenberg-Marquardt nonlinear iterative optimization algorithm is used to fit the contour point set under the constraint of the elliptical geometric equation, including:
[0208] The ellipse center coordinates, major axis length, minor axis length, and rotation angle from the initial estimates are used as the initial parameter vector for the nonlinear optimization iteration. The initial parameter vector is preprocessed by normalization, dividing the center coordinates by the size of the local image and dividing the axis lengths by the length of the image diagonal, to improve the numerical stability of the optimization algorithm.
[0209] Specifically, the verified initial estimates (center (x_c, y_c), major axis a, minor axis b, rotation angle θ) are constructed into a 5-dimensional parameter vector p = [x_c, y_c, a, b, θ]^T. To improve the stability of subsequent numerical calculations, this vector is normalized: the center coordinates x_c and y_c are divided by the width and height of the local image, respectively, and the axis lengths a and b are divided by the diagonal length of the local image. This makes the magnitude of all parameters roughly uniform to the range of O(1), avoiding the ill-conditioned problem of the optimization algorithm caused by excessive differences in coordinate and axis length values.
[0210] A parameterized model based on the standard geometric equation of an ellipse is constructed, and a loss function based on geometric distance is defined. The loss function is the sum of squares of the shortest geometric distances from each point in the contour point set to the edge of the current parameter ellipse. In each iteration, the Jacobian matrix of the loss function with respect to the current parameter vector is calculated, and an incremental regularization equation is constructed based on the Jacobian matrix and the current residual.
[0211] Specifically, the loss function L(p) is defined as the sum of squares of the shortest geometric distances from all contour points (x_i, y_i) to the current elliptical model (defined by parameter p), i.e., L(p) = Σ_i d_i(p)^2, where d_i(p) is the Euclidean distance from point (x_i, y_i) to ellipse E(p). This has a more explicit geometric meaning than the algebraic distance used in S106. In each iteration, the Jacobian matrix J of the loss function with respect to the current parameter vector p (containing the partial derivatives of each distance with respect to each parameter) and the residual vector r (containing each d_i(p)) need to be calculated.
[0212] The damping factor of the Levenberg-Marquardt algorithm is dynamically adjusted based on the decrease in the loss function. When the loss decreases significantly, the damping factor is decreased to approximate the Gauss-Newton method and accelerate convergence; when the loss decreases only slightly, the damping factor is increased to approximate the gradient descent method and ensure stability. During iterative optimization, a Cauchy kernel function is introduced to weight the distance residuals of each contour point to reduce the negative impact of potential outliers on the optimization process and enhance the robustness of the fit.
[0213] Specifically, the LM algorithm calculates the parameter update δ by solving the incremental equation (J^TJ + λI)δ = -J^Tr, where λ is the damping factor.
[0214] Dynamic adjustment of the damping factor: λ is adaptively adjusted according to the proportion of loss reduction in the current iteration. If the loss reduction is significant (e.g., exceeding a threshold), λ is decreased to make the algorithm closer to the Gauss-Newton method, enabling rapid convergence within the optimization basin; if the loss reduction is not significant or increases, λ is increased to make the algorithm closer to the gradient descent method, enhancing stability and helping to escape local minima or pass through flat regions.
[0215] Robust kernel weighting: To enhance robustness to potential outliers, a Cauchy kernel function is introduced to weight the distance residual d_i for each point during residual calculation: w_i = 1 / (1 + (d_i / c)^2), where c is the scaling parameter. The weighted residuals are used to construct J^Tr and J^TJ, automatically reducing the weight of points far from the model and minimizing their misleading influence on the optimization direction.
[0216] Multiple convergence conditions are set, including: the change in the loss function value is less than a first threshold, the norm of the parameter vector change is less than a second threshold, or the number of iterations reaches a preset maximum value. When any convergence condition is met, the iteration stops, and the parameter vector updated in the last iteration is denormalized to restore the final elliptical geometric parameters in the image coordinate system.
[0217] Specifically, a triple stopping condition is set, and iteration stops when any one of them is met: Loss change condition: The change in the loss function value between two consecutive iterations, |L_{k} - L_{k-1}|, is less than a preset first threshold ε 1, indicating that the optimization objective has basically stabilized. Parameter change condition: The norm of the parameter update, ||δ||, is less than a preset second threshold ε 2, indicating that the parameters themselves have almost stopped changing. Maximum number of iterations limit: The number of iterations k reaches a preset maximum value K_max to prevent infinite loops or slow convergence.
[0218] For the final geometric parameters obtained through optimization, calculate the goodness-of-fit index between the final geometric parameters and the contour point set, and output the final geometric parameters and the goodness-of-fit index together as the ellipse detection and parameter estimation results.
[0219] Specifically, after the iteration converges, the final normalized parameter vector p_final is denormalized (i.e., the center coordinates are multiplied by the image size, and the axis length is multiplied by the diagonal length) to restore it to the original image pixel coordinate system, thus obtaining the final ellipse geometric parameters. Using the final parameters, the root mean square geometric error or other goodness-of-fit indices from all contour points to the ellipse are recalculated. The final ellipse geometric parameters and the calculated goodness-of-fit indices are then output as the detection and parameter estimation results for the elliptical target.
[0220] The beneficial effects of the above technical solution are as follows:
[0221] 1. High parameter estimation accuracy: By minimizing the sum of squares of geometric distances (rather than algebraic distance), this step directly optimizes the most fundamental geometric error between the elliptical model and the contour point set. This makes the final solved parameters the optimal estimate in the maximum likelihood sense, mathematically providing higher absolute accuracy than the initial estimate (S106) and any method based solely on algebraic distance, fully releasing the potential of the geometric information contained in the contour point set.
[0222] 2. Excellent numerical stability and convergence reliability: Parameter normalization preprocessing effectively solves the numerical scaling problem in optimization, providing favorable numerical conditions for the LM algorithm. The dynamically adjusted damping factor enables the algorithm to intelligently switch between fast convergence (Gauss-Newton) and robust progression (gradient descent), accelerating under favorable conditions while maintaining stability in difficult regions, significantly improving the reliability of the optimization process in successfully converging to a meaningful local optimum (usually the global optimum).
[0223] 3. Strong resistance to outlier interference: The introduction of the Cauchy kernel function to weight the residuals is key to achieving robust fitting in this step. It automatically identifies and weakens the influence of points that deviate significantly from the model (which may be outliers not completely filtered out by S107, or defects in contour extraction), allowing the optimization process to focus on data points with consistent characteristics. This ensures that even with imperfect data quality, the final result will not be "biased" by a few bad points, significantly enhancing the robustness of the method.
[0224] 4. A clear and efficient iteration termination mechanism: Multiple convergence conditions provide flexible and reliable stopping criteria. Thresholds for changes in loss and parameters ensure that optimization stops promptly when the required accuracy is reached, avoiding unnecessary computation; the upper limit on the number of iterations prevents infinite loops in divergent or oscillating situations. This ensures that the optimization steps always produce a definite result within a finite time, improving the efficiency and controllability of the overall process.
[0225] 5. Provide standardized output with confidence metrics: Outputting goodness-of-fit metrics (such as RMSE) is a highly valuable engineering step. This metric quantifies the degree of fit between the final elliptic model and the original image data, providing an objective confidence measure for downstream systems (such as quality inspection and robot grasping). Users can use this metric to filter high-precision results or to grade the reliability of the results, greatly enhancing the interpretability and engineering applicability of the entire method's output.
[0226] This application also provides an ellipse detection system that integrates depth feature localization and geometric constraint optimization, the system comprising:
[0227] The image acquisition module is used to acquire the input image to be detected.
[0228] The target localization module, connected to the image acquisition module, is used to input the input image into a pre-trained target detection network. The target detection network includes a feature pyramid network and a region proposal network. The feature pyramid network extracts multi-scale depth features from the input image, and the region proposal network generates one or more axis-aligned candidate regions based on the multi-scale depth features. Each candidate region is used to cover a potential elliptical target.
[0229] The local image processing module, connected to the target localization module, is used to extract the corresponding local image from the input image for each candidate region and preprocess the local image. The preprocessing includes sequentially performing Gaussian filtering for noise reduction, grayscale processing, and adaptive threshold segmentation to enhance the elliptical edges and suppress background interference.
[0230] The contour extraction module, connected to the local image processing module, is used to extract contours from the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target.
[0231] The parameter initial estimation and verification module is connected to the contour extraction module. It is used to fit the elliptical geometric model based on the contour point set using the least squares method to obtain the initial estimated values of the ellipse parameters, and to verify the geometric rationality of the initial estimated values. Abnormal estimation results that do not meet the preset elliptical convexity constraints or axis length ratio range are eliminated. The ellipse parameters include the center coordinates, major axis length, minor axis length, and rotation angle.
[0232] The parameter optimization output module connects to the parameter initial estimation and verification module. It is used to fit the contour point set with the ellipse geometric equation as a constraint, and optimize and update the ellipse parameters for the verified initial estimate, until the preset convergence condition is met, and output the final ellipse detection and parameter estimation results.
[0233] The following are three practical application scenarios for the above methods:
[0234] Scenario 1: Red blood cell recognition, such as Figure 2 As shown.
[0235] Scenario 2: Camera recognition, such as Figure 3 As shown.
[0236] Scenario 3: Egg recognition, such as Figure 4 As shown.
[0237] It should be noted that the terms "first," "second," and similar terms used in this application specification and claims do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, "an" or "a" and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. "A plurality" or "several" indicates at least two. Unless otherwise stated, terms such as "front," "back," "left," "right," "lower," and / or "upper" are for illustrative purposes only and are not limited to a location or spatial orientation. Terms such as "comprising" or "including" indicate that the elements or objects preceding "comprising" encompass the elements or objects listed following "comprising" or "including" and their equivalents, and do not exclude other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect.
[0238] The singular forms “a,” “the,” and “the” used in this application specification and appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.
[0239] It should be understood that those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.
Claims
1. An ellipse detection method integrating deep feature localization and geometric constraint optimization, characterized in that, Includes the following steps: S101, Obtain the input image to be detected; S102, the input image is input into a pre-trained target detection network, the target detection network includes a feature pyramid network and a region proposal network, the feature pyramid network extracts multi-scale depth features of the input image, and the region proposal network generates one or more axis-aligned candidate regions based on the multi-scale depth features, each candidate region is used to cover a potential elliptical target; S103, for each candidate region, extract the corresponding local image from the input image; S104, preprocess the local image, including sequentially performing Gaussian filtering for noise reduction, grayscale processing, and adaptive threshold segmentation to enhance the elliptical edges and suppress background interference. S105, perform contour extraction on the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target; S106. Based on the set of contour points, the least squares method is used to fit the elliptical geometric model to obtain the initial estimated values of the ellipse parameters, which include the center coordinates, the length of the major axis, the length of the minor axis, and the rotation angle. S107, Perform geometric rationality verification on the initial estimated value and eliminate abnormal estimation results that do not meet the preset elliptical convexity constraint or axis length ratio range; S108. For the verified initial estimate, the Levenberg-Marquardt nonlinear iterative optimization algorithm is used to fit the contour point set with the ellipse geometric equation as a constraint, and the ellipse parameters are optimized and updated until the preset convergence condition is met, and the final ellipse detection and parameter estimation results are output.
2. The ellipse detection method integrating depth feature localization and geometric constraint optimization according to claim 1, characterized in that, In step S101, the input image to be detected is obtained, including: The system acquires raw images containing elliptical targets in real time from an industrial camera or webcam; or reads pre-stored image files containing elliptical targets from a storage device; performs format verification and integrity checks on the raw images or image files to ensure they conform to preset image encoding formats and data integrity requirements; converts the verified images into a unified color space and pixel bit depth, and scales them to the fixed input size required by the target detection network to generate the input image to be detected.
3. The ellipse detection method according to claim 1, which integrates depth feature localization and geometric constraint optimization, is characterized in that... In step S102, the input image is input into a pre-trained target detection network, including: The input image is fed into the feature pyramid network, and basic feature maps are extracted through the backbone network of the feature pyramid network. By fusing features from different levels from top to bottom and through horizontal connection paths, a multi-scale feature pyramid with rich semantic information is constructed. In the region proposal network, anchor boxes of various scales and aspect ratios are preset for each level of the multi-scale feature pyramid; a corresponding region proposal is generated at each anchor box position; for each generated region proposal, a classification branch is used to predict the confidence score of the region proposal containing elliptical targets; for each generated region proposal, a regression branch is used to predict the positional offset of the region proposal relative to the corresponding preset anchor box, so as to perform preliminary screening and position fine-tuning of candidate regions; for the preliminary candidate regions generated at all levels, a non-maximum suppression operation is applied to remove highly overlapping redundant regions based on the overlap area between the confidence scores of the region proposals and the region proposals. Output a set of axis-aligned candidate regions, each of which is used to cover a potential elliptical target.
4. The ellipse detection method integrating depth feature localization and geometric constraint optimization according to claim 1, characterized in that, In step S103, for each candidate region, a corresponding local image is extracted from the input image, including: The coordinates of each candidate region output by the object detection network are obtained, including the coordinates of the top-left vertex, width, and height of the candidate region in the input image. The coordinate values of the candidate regions are converted from floating-point numbers to integers to ensure the validity of the pixel coordinates. It is determined whether the converted integer coordinates exceed the boundary of the input image. If any side of the candidate region exceeds the image boundary, the coordinates of that boundary are adjusted to within the effective pixel range of the image. Based on the adjusted integer coordinates, a corresponding rectangular image block is cropped from the input image as the initial local image. The resolution of the cropped initial local image is adjusted to a preset fixed size using a bilinear interpolation algorithm to standardize the input for subsequent processing. The local image after resolution adjustment is converted from the original RGB color space to a grayscale color space or HSV color space to adapt to subsequent image preprocessing and contour extraction operations.
5. An ellipse detection method integrating depth feature localization and geometric constraint optimization according to claim 1 or 4, characterized in that, In step S104, the local image is preprocessed, including: Gaussian filtering is applied to the local image for noise reduction. The size and standard deviation of the Gaussian kernel are adaptively determined based on the size of the local image and the noise level, so as to smooth the image noise while preserving the elliptical edge information. The denoised local image is converted from color space to single-channel grayscale image, and the grayscale value is calculated using a weighted method, giving the green channel a higher weight to conform to the visual characteristics of the human eye and the color response of common sensors; The grayscale image is processed using a Gaussian weighted adaptive thresholding segmentation algorithm. The adaptive thresholding segmentation algorithm dynamically calculates the segmentation threshold for each pixel in the image based on the Gaussian weighted grayscale values of its neighboring pixels. During the adaptive thresholding segmentation process, the size of the neighborhood block is set to an odd value that is not less than the estimated ellipse edge width, and a positive constant parameter is set to fine-tune the segmentation sensitivity. A morphological closing operation is performed on the binary image generated after threshold segmentation to close any minor breaks or holes that may exist at the edge of the ellipse. The connected components of the morphologically processed binary image are calculated, and the area and contour integrity of the connected components are used to filter the images, retaining only the candidate elliptical regions that meet the preset conditions for subsequent contour extraction.
6. The ellipse detection method according to claim 5, which integrates depth feature localization and geometric constraint optimization, is characterized in that... Step S105: Extract contours from the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target, including: For the binary image after preprocessing and morphological operations, the Suzuki85 chain code tracing algorithm is used to traverse the image pixels, detect and extract the outer contours of all connected components and possible internal hole contours in the image; during the contour extraction process, a minimum contour length threshold is set to filter out small or discontinuous false contour fragments caused by noise. For each extracted candidate contour, calculate the convex hull of the candidate contour and evaluate the convexity of the contour. Prioritize retaining contours with convexity close to 1 as candidates for elliptical boundaries. For each of the filtered contours, the Douglas-Peucker algorithm based on curve arc length is used to simplify the contour point set, reducing the number of contour points while retaining the key features of the elliptical geometry. The simplified contour point set is smoothed, and a Gaussian filter is applied to filter the coordinate sequence of the contour points to eliminate the jagged fluctuations that may be caused by pixel-level extraction. From the smoothed contour point sequence, uniform resampling is performed according to the principle of fixed step size or equal arc length to generate a discrete contour point set for subsequent fitting of elliptical geometric model.
7. The ellipse detection method according to claim 1, which integrates depth feature localization and geometric constraint optimization, is characterized in that... In step S106, based on the contour point set, the least squares method is used to fit the elliptical geometric model to obtain initial estimates of the ellipse parameters, including: The contour point set is preprocessed by coordinate centering, the centroid coordinates of the point set are calculated, and all contour points are translated so that the center of the point set is located at the origin of the temporary coordinate system. Weights are assigned to the translated contour points. The weights are determined based on the estimated local edge gradient magnitude at each contour point, with points having larger gradient magnitudes being assigned higher weights. Based on the weighted contour point set, an overdetermined linear equation system is constructed with the coefficients of the general quadratic curve equation of an ellipse as unknowns. By employing algebraic distance least squares fitting, and solving a generalized eigenvalue problem constrained by positive definiteness, the coefficients of the general quadratic curve equation of the ellipse that minimize the sum of the squares of the algebraic distances from all contour points to the ellipse are obtained. The coefficients of the general quadratic equation of the ellipse are converted into standard ellipse geometric parameters, which include the center coordinates, major axis length, minor axis length, and rotation angle. The initial geometric parameters obtained from the transformation are verified for rationality to ensure that the length of the major axis is greater than the length of the minor axis and that the rotation angle is normalized to the preset range of 0 to π radians.
8. The ellipse detection method according to claim 1, which integrates depth feature localization and geometric constraint optimization, is characterized in that... In step S107, the initial estimated value is geometrically validated, and abnormal estimation results that do not meet the preset elliptic convexity constraint or axis length ratio range are eliminated, including: The ellipse equation is reconstructed based on the initially estimated ellipse parameters, and the algebraic distances from all contour points to the reconstructed ellipse are calculated to generate a distance set. Calculate the mean and standard deviation of the distance set, set a dynamic threshold based on the standard deviation, remove contour points whose algebraic distance exceeds the dynamic threshold as outliers, and recalculate the initial estimate based on the remaining contour points to improve data consistency. Based on the recalculated initial estimate, the convexity constraint of the ellipse is verified by calculating the ratio of the minimum convex hull area of the contour point set to the theoretical area of the ellipse. If the ratio of the minimum convex hull area to the theoretical area of the ellipse exceeds the preset ratio range, it is determined that the initial estimate does not satisfy the convexity constraint. Verify the ellipse's axis length ratio by calculating the ratio of the minor axis length to the major axis length. If the ratio is less than the preset minimum axis length ratio threshold or greater than the preset maximum axis length ratio threshold, the ellipse is determined to be too flat or too close to a circle, and is considered an abnormal geometric shape. Calculate the sum of Euclidean distances from all points in the contour point set to the edge of the initially estimated ellipse. If the sum of Euclidean distances exceeds the adaptive threshold calculated based on the size of the contour point set and the image size, the initial estimate is deemed to have a low fit to the original contour. For the initial estimate that satisfies all the above verification conditions, a comprehensive score is given based on the size of its contour point set, goodness of fit, and geometric consistency with the estimation results of neighboring candidate regions. Only initial estimates with a comprehensive score higher than a preset threshold are retained and marked as valid estimates. These initial estimates are then passed to subsequent nonlinear optimization steps, while all abnormal estimates that fail validation or have low scores are removed.
9. The ellipse detection method according to claim 1, which integrates depth feature localization and geometric constraint optimization, is characterized in that... In step S108, for the verified initial estimate, the Levenberg-Marquardt nonlinear iterative optimization algorithm is used to fit the contour point set under the constraint of the elliptical geometric equation, including: The ellipse center coordinates, major axis length, minor axis length, and rotation angle in the initial estimated values are used as the initial parameter vector for nonlinear optimization iteration; The initial parameter vector is preprocessed by normalization, which involves dividing the center coordinates by the size of the local image and dividing the axis length parameter by the length of the image diagonal, in order to improve the numerical stability of the optimization algorithm. A parameterized model based on the standard geometric equation of an ellipse is constructed, and a loss function based on geometric distance is defined. This loss function is the sum of the squares of the shortest geometric distances from each point in the contour point set to the edge of the current parameter ellipse. In each iteration, the Jacobian matrix of the loss function with respect to the current parameter vector is calculated, and an incremental regularization equation is constructed based on the Jacobian matrix and the current residual. The damping factor of the Levenberg-Marquardt algorithm is dynamically adjusted according to the decrease in the loss function. When the loss decreases significantly, the damping factor is reduced to approximate the Gauss-Newton method and accelerate convergence; when the loss decrease is unclear... To ensure stability, the damping factor is increased to approximate gradient descent. During iterative optimization, a Cauchy kernel function is introduced to weight the distance residuals of each contour point to reduce the negative impact of potential outliers on the optimization process and enhance the robustness of the fit. Multiple convergence conditions are set, including: the change in the loss function value is less than a first threshold, the change norm of the parameter vector is less than a second threshold, or the number of iterations reaches a preset maximum value. When any convergence condition is met, the iteration stops, and the parameter vector updated in the last iteration is denormalized to restore the final elliptical geometric parameters in the image coordinate system. For the final geometric parameters obtained through optimization, calculate the goodness-of-fit index between the final geometric parameters and the contour point set, and output the final geometric parameters and the goodness-of-fit index together as the ellipse detection and parameter estimation results.
10. An ellipse detection system integrating depth feature localization and geometric constraint optimization, characterized in that, include: The image acquisition module is used to acquire the input image to be detected; The target localization module, connected to the image acquisition module, is used to input the input image into a pre-trained target detection network. The target detection network includes a feature pyramid network and a region proposal network. The feature pyramid network extracts multi-scale depth features of the input image, and the region proposal network generates one or more axis-aligned candidate regions based on the multi-scale depth features. Each candidate region is used to cover a potential elliptical target. The local image processing module, connected to the target localization module, is used to extract the corresponding local image from the input image for each candidate region and preprocess the local image. The preprocessing includes sequentially performing Gaussian filtering for noise reduction, grayscale processing, and adaptive threshold segmentation to enhance the elliptical edges and suppress background interference. The contour extraction module, connected to the local image processing module, is used to extract contours from the preprocessed local image to obtain a set of contour points representing the boundary of the elliptical target. The parameter initial estimation and verification module is connected to the contour extraction module. It is used to fit the elliptical geometric model based on the contour point set using the least squares method to obtain the initial estimated values of the elliptical parameters, and to verify the geometric rationality of the initial estimated values, eliminating abnormal estimation results that do not meet the preset elliptical convexity constraints or axis length ratio range. The elliptical parameters include the center coordinates, major axis length, minor axis length, and rotation angle. The parameter optimization output module is connected to the parameter initial estimation and verification module. It is used to fit the contour point set with the ellipse geometric equation as a constraint and the Levenberg-Marquardt nonlinear iterative optimization algorithm to the verified initial estimate value, optimize and update the ellipse parameters until the preset convergence condition is met, and output the final ellipse detection and parameter estimation results.