Circle fitting and detection method and device, electronic equipment and readable storage medium

By eliminating outliers during the circle fitting process and using the distance difference between the reference circle and other edge points to determine the candidate circle, the problem of outliers affecting existing circle fitting algorithms is solved, achieving higher accuracy and convenience.

CN117011278BActive Publication Date: 2025-12-26AINNOVATION (HEFEI) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311018443.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-10
Publication Date
2025-12-26
Estimated Expiration
2043-08-10

AI Technical Summary

Technical Problem

Existing circle fitting algorithms, such as least squares and Hough transform, are easily affected by outliers, resulting in poor circle fitting accuracy.

Method used

By acquiring multiple edge points in the target image, fitting a reference circle, and calculating the distance difference between other edge points outside the reference circle and the reference circle, outliers are eliminated. The candidate circle is determined using a preset number and distance threshold, and finally the fitted circle is determined.

Benefits of technology

This method improves the accuracy of circle fitting, reduces the need for manual parameter adjustments, enhances the versatility and convenience of the method, and improves the accuracy of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117011278B_ABST
    Figure CN117011278B_ABST
Patent Text Reader

Abstract

The application provides a circle fitting and detection method and device, electronic equipment and readable storage medium, wherein the method comprises: collecting a plurality of edge points of a target object to be fitted in a target image; fitting a preset number of edge points in the plurality of edge points as a reference circle; calculating a distance difference between other edge points outside the fitted reference circle and the reference circle; fitting the edge points with a distance difference not higher than a distance threshold as a candidate circle; and determining a fitting circle of the target object to be fitted according to the candidate circle. After the reference circle is determined, the application determines outliers according to the distance difference between other edge points outside the fitted reference circle and the reference circle, and the outliers are excluded when the target object to be fitted is fitted, so that the interference of the outliers on the circle fitting result is eliminated, and the circle fitting accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of quality detection, in particular to a circle fitting and detection method and device, electronic equipment and readable storage medium. BACKGROUND

[0002] Circle fitting is a common detection form in image processing and a common application scenario in industry. The common circle fitting algorithms, such as least square method and Hough transform, have no ability to solve abnormal points and are easily affected by outliers, and have poor accuracy. SUMMARY

[0003] Therefore, the embodiments of the present application aim to provide a circle fitting and detection method and device, electronic equipment and readable storage medium, which can improve the accuracy of circle fitting.

[0004] In a first aspect, the embodiments of the present application provide a circle fitting method, which comprises: collecting a plurality of edge points of a to-be-fitted object in a target image; fitting a preset number of edge points in the plurality of edge points as a reference circle; calculating distance differences between other edge points outside the reference circle and the reference circle; fitting the edge points with distance differences not higher than a distance threshold as candidate circles; and determining a fitting circle of the to-be-fitted object according to the candidate circles.

[0005] In the above implementation process, after the reference circle is determined, the outliers are determined according to the distance differences between the other edge points outside the reference circle and the reference circle, and the outliers are excluded when the to-be-fitted object is fitted, which can exclude the interference of outliers on the circle fitting result and improve the accuracy of circle fitting. In addition, in the whole process, fewer parameters are used, and only the number of edge points and the distance threshold need to be manually input at the first time, and the manual adjustment is less in other processes, which is very convenient to use and has strong versatility.

[0006] In one embodiment, after the plurality of edge points of the to-be-fitted object in the target image are collected, the method further comprises: sorting the plurality of edge points; taking a first edge point as a starting edge point; determining a preset number of edge points according to the starting edge point and a preset step; fitting the preset number of edge points in the plurality of edge points as a reference circle; calculating distance differences between other edge points outside the reference circle and the reference circle; fitting the edge points with distance differences not higher than a distance threshold as candidate circles; taking a next edge point as a starting edge point to update the preset number of edge points, and obtaining the candidate circles according to the updated preset number of edge points, until the preset number of edge points includes a last edge point.

[0007] In the implementation process, different edge points in the plurality of edge points are taken as starting edges, and a plurality of reference circles are fitted according to the preset step length. Then, according to the distance difference between the other edge points corresponding to each reference circle and the reference circle, a plurality of candidate circles can be fitted. The problem that the accuracy of the candidate circle directly calculated according to the selected edge point as an outlier and the reference circle fitted according to the outlier is reduced can be avoided. Since the plurality of candidate circles are calculated according to the reference circle fitted according to each edge point as a starting edge point in turn, when the fitting circle of the object to be fitted is determined, the candidate circle closest to the object to be fitted can be selected as the fitting circle of the object to be fitted, and the accuracy of the fitting circle is improved.

[0008] In one embodiment, the method further comprises: updating the preset step length according to a set increment, and updating the preset number of edge points according to the updated preset step length and the starting edge point, so as to obtain the candidate circle according to the updated preset number of edge points, until the preset step length is n / m, wherein n is the number of edge points, m is the number of edge points of the fitted reference circle, and n / m is rounded down.

[0009] In the implementation process, by further increasing the update of the preset step length, more candidate circles can be obtained on the basis of updating the starting edge point, the range of the fitting circle selection is increased, and the accuracy of the fitting circle is further improved.

[0010] In one embodiment, the candidate circles are a plurality of, and the determination of the fitting circle of the object to be fitted according to the candidate circles comprises: calculating the distance mean of the edge points used to fit each candidate circle to the corresponding candidate circle respectively; and determining the fitting circle of the object to be fitted according to the distance mean and the number of edge points whose distance difference is not higher than the distance threshold.

[0011] In the implementation process, when the fitting circle of the object to be fitted is determined according to the candidate circle, the fitting circle is determined based on the number of edge points whose distance difference is not higher than the distance threshold and the distance mean, which can reduce the possibility that the accuracy of the candidate circle fitted by fewer edge points is directly higher than the accuracy of the candidate circle fitted by more edge points when only the distance threshold is used for judgment, and thus the accuracy of the determined fitting circle is improved.

[0012] In one embodiment, the distance difference comprises a standard deviation, and the calculating the distance difference between the other edge points outside the reference circle and the reference circle comprises: determining a difference value between a distance of each other edge point to a center of the reference circle and a radius of the reference circle as a distance between each other edge point and the reference circle; calculating a mean value of distances between the other edge points and the reference circle according to the distances between the other edge points and the reference circle; and calculating a standard deviation between the other edge points and the reference circle according to the mean value of distances.

[0013] In the implementation process, since the standard deviation can reflect the dispersion degree of a data set, by taking the standard deviation between the other edge points and the reference circle as the distance difference between the other edge points and the reference circle to determine whether each edge point used for fitting the reference circle is a dispersion point, the accuracy of screening the dispersion points can be improved.

[0014] In one embodiment, the acquiring the plurality of edge points of the object to be fitted in the target image comprises: determining a number of sub-circumferential calipers according to a number of edge points to be acquired; and detecting the edge points of the object to be fitted in each sub-circumferential caliper according to a one-dimensional edge detection technology to obtain the plurality of edge points of the object to be fitted.

[0015] In the implementation process, since the number of circumferential calipers can be adjusted, the number of circumferential calipers can be adjusted according to the number of edge points to be acquired, so that the number of edge points used for circle fitting can be changed, and the application scenarios of circle fitting are increased. In addition, since the one-dimensional edge detection technology is simple and easy to implement, when detecting the edge points in each sub-circumferential caliper, the difficulty of edge point detection can be reduced by using the one-dimensional edge detection technology.

[0016] In a second aspect, the embodiments of the present application further provide a detection method, comprising: acquiring a target image of an object to be detected; performing circle fitting on the object to be detected in the target image according to the circle fitting method in the first aspect or any possible implementation manner of the first aspect to obtain a fitting circle corresponding to the object to be detected; and determining a detection result of the object to be detected according to the fitting circle.

[0017] In the implementation process, since the circle fitting method of the present application can eliminate the outlier when performing circle fitting on the object to be fitted, the interference of the outlier on the circle fitting result can be eliminated, the circle fitting accuracy is improved, and the detection accuracy of the object to be detected is improved.

[0018] In a third aspect, the embodiments of the present application further provide a circle fitting device, comprising: a collection module configured to collect a plurality of edge points of a to-be-fitted object in a target image; a first fitting module configured to fit a preset number of edge points in the plurality of edge points into a reference circle; a calculation module configured to calculate a distance difference between other edge points outside the reference circle and the reference circle; a second fitting module configured to fit the edge points with the distance difference not higher than a distance threshold into a to-be-selected circle; and a determination module configured to determine a fitting circle of the to-be-fitted object according to the to-be-selected circle.

[0019] In a fourth aspect, the embodiments of the present application further provide a detection device, comprising: an acquisition module configured to acquire a target image of a to-be-detected object; a circle fitting module configured to perform circle fitting on the to-be-detected object in the target image according to the circle fitting method in the first aspect or any possible implementation manner of the first aspect, to obtain a fitting circle corresponding to the to-be-detected object; and a second determination module configured to determine a detection result of the to-be-detected object according to the fitting circle.

[0020] In a fifth aspect, the embodiments of the present application further provide an electronic device, comprising: a processor and a memory, wherein the memory stores machine readable instructions executable by the processor, and when the electronic device is running, the machine readable instructions are executed by the processor to perform the steps of the method in the first aspect or any possible implementation manner of the first aspect.

[0021] In a sixth aspect, the embodiments of the present application further provide a computer readable storage medium, which stores a computer program, and when the computer program is run by a processor, the steps in the first aspect or any possible implementation manner of the first aspect are executed.

[0022] In order to make the above objectives, characteristics and advantages of the present application more apparent and easy to understand, the following embodiments are specifically described below, and the accompanying drawings are described in detail as follows. BRIEF DESCRIPTION OF DRAWINGS

[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments, and it should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation on the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0024] Figure 1 Flowchart of the circle fitting method provided by the embodiments of the present application;

[0025] Figure 2 Schematic diagram of the circumference caliper provided by the embodiments of the present application;

[0026] Figure 3 A flow chart of a detection method provided by an embodiment of the present application is shown in FIG. 1.

[0027] Figure 4 A functional module schematic diagram of a circle fitting device provided by an embodiment of the present application is shown in FIG. 2.

[0028] Figure 5 A functional module schematic diagram of a detection device provided by an embodiment of the present application is shown in FIG. 3.

[0029] Figure 6 A block schematic diagram of an electronic device provided by an embodiment of the present application is shown in FIG. 4. DETAILED DESCRIPTION

[0030] The technical solutions in the embodiments of the present application will be described below with reference to the accompanying drawings.

[0031] It should be noted that similar reference numerals and letters refer to similar items throughout the accompanying drawings, and thus, once an item is defined in one drawing, it need not be further defined and explained in subsequent drawings. Meanwhile, in the description of the present application, the terms "first", "second", and the like are merely used to distinguish descriptions, and cannot be understood as indicating or implying relative importance.

[0032] For a spatial circular object, there are differences between design and production or deformation after long-term use, which will affect its use, and thus it is necessary to detect the spatial circular object to determine whether it meets the engineering requirements. Since these spatial circular objects are all spatial circles, they can be detected by the method of circle fitting.

[0033] The present inventor has found through long-term research that the common circle fitting methods, such as the least square method and the Hough transform, do not have the ability to solve abnormal points, and the existence of abnormal points will affect the accuracy of circle fitting. For abnormal points, RANSAC can exclude the interference of abnormal points on the circle fitting result to a certain extent, but the RANSAC method needs to define many parameters such as the number of iterations, the number of sampling points, and the fitting threshold. It is necessary to manually adjust the parameters repeatedly, which is relatively troublesome to use, and defining too many parameters also means that the universality of the RANSAC method is not strong, i.e., different parameters need to be set to achieve a better effect when fitting different data.

[0034] Therefore, the present application provides a circle fitting method. The reference circle is fitted by selecting a preset number of edge points. The outlier is determined based on the distance difference between the other edge points outside the fitted reference circle and the reference circle. The outlier is removed when fitting the object to be fitted, which can eliminate the interference of the outlier on the circle fitting result and improve the circle fitting accuracy. In addition, the parameters used in the whole process are less, and only the number of edge points and the distance threshold need to be manually input at the first time. Other processes do not need manual adjustment, which is very convenient to use and has strong versatility.

[0035] Please refer to Figure 1 is a flowchart of the circle fitting method provided by the embodiment of the present application. The specific process shown in Figure 1 will be described in detail below.

[0036] Step S201, a plurality of edge points of an object to be fitted in a target image are collected.

[0037] The object to be fitted here can be a circular object such as a screw, a gear, a gasket, etc. Of course, it can also be a circular pipe, a wire, etc. with a circular cross section. The object to be fitted can be selected according to actual conditions, and the present application does not make specific limitations.

[0038] The target image described above can be an original image of the object to be fitted, or a grayscale image obtained by performing grayscale processing on the original image. The target image can be selected according to actual conditions, and the present application does not make specific limitations.

[0039] Optionally, the edge points of the object to be fitted can be obtained based on gradient, local features, and deep learning, etc. The method for obtaining the edge points of the object to be fitted can be selected according to actual conditions.

[0040] Step S202, a preset number of edge points in the plurality of edge points are fitted as a reference circle.

[0041] The preset number here can be three, four, five, etc. The preset number can be selected according to actual needs.

[0042] Generally, three points can be used to fit a circle, so at least three edge points need to be selected when fitting the reference circle.

[0043] Optionally, the edge points used to fit the reference circle can be random edge points, or edge points selected according to certain rules. For example, selected according to the arrangement order of the edge points, or selected according to the average distance between the edge points, etc. The selection of the edge points used to fit the reference circle can be adjusted according to actual conditions.

[0044] Step S203, calculate the distance difference between the other edge points outside the fitting reference circle and the reference circle.

[0045] It can be understood that when fitting the reference circle, only part of the edge points of the object to be fitted are selected, and the remaining edge points are not used to fit the reference circle, i.e. the other edge points outside the fitting reference circle. For example, 15 edge points of the object to be fitted are collected in step S201, and 3 edge points are selected for fitting when fitting the reference circle, then the remaining 12 edge points are the other edge points outside the fitting reference circle.

[0046] The distance difference here can be the distance from the other edge points to the circumference of the reference circle, or the distance from the other edge points to the center of the reference circle. The distance difference can be a standard deviation, a variance or a difference value, etc. The distance difference can be determined according to actual conditions.

[0047] Optionally, the above-mentioned reference circle can be one or multiple. When the reference circle is multiple, the distance difference between the other edge points outside each reference circle and the reference circle is calculated.

[0048] Step S204, fit the edge points with a distance difference not higher than the distance threshold as a candidate circle.

[0049] It should be understood that when collecting the edge points of the object to be fitted, not all the collected edge points are cluster points, i.e. there can be some outliers. These outliers can affect the fitting result of the finally fitted circle, thus leading to poor accuracy of the fitted circle of the object to be fitted.

[0050] Therefore, after the reference circle is determined, whether each edge point is an outlier can be determined according to the relationship between the distance between the edge point and the reference circle and the distance threshold, if the edge point is an outlier, the edge point can be removed first, and then the circle fitting of the object to be fitted is performed.

[0051] In one embodiment, the edge point with a distance difference greater than the distance threshold is an outlier. The edge point with a distance difference less than or equal to the distance threshold is a cluster point.

[0052] The candidate circle here includes the fitted circle of the object to be fitted.

[0053] It can be understood that the above-mentioned candidate circle can be one or multiple. When the candidate circle is multiple, one candidate circle can be fitted for each candidate circle according to step S203 and step S204.

[0054] Optionally, the edge points with distance difference not higher than the distance threshold value are fitted into the candidate circle by using a least mean square method, a least square method, a weighted average method, a Hall transformation, an average value method, etc. The method for fitting the candidate circle can be adjusted according to actual conditions, and the application does not make specific limitations.

[0055] In step S205, the fitting circle of the object to be fitted is determined according to the candidate circle.

[0056] It should be understood that when there are multiple candidate circles, the fitting circle of the object to be fitted needs to be selected from the multiple candidate circles.

[0057] Optionally, the fitting circle of the object to be fitted can be determined according to the mean distance between the edge points used to fit the candidate circle and the candidate circle, or can be determined according to the variance of the distance between the edge points used to fit the candidate circle and the candidate circle, or can be determined according to the standard deviation of the distance between the edge points used to fit the candidate circle and the candidate circle, etc. The method for determining the fitting circle of the object to be fitted according to the candidate circle can be selected according to actual conditions.

[0058] In the above implementation process, after the reference circle is determined, the outlier points are determined according to the distance difference between the other edge points outside the fitting reference circle and the reference circle, and the outlier points are excluded when the object to be fitted is fitted by a circle, which can exclude the interference of the outlier points on the fitting result of the circle and improve the fitting accuracy of the circle. In addition, in the whole process, fewer parameters are used, and only the number of edge points and the distance threshold value need to be manually input at the first time, and other processes need less human intervention and adjustment, which is very convenient to use and has strong universality.

[0059] In a possible implementation, after step S201, the method further includes: sorting the multiple edge points; taking the first edge point as a starting edge point; determining a preset number of edge points according to the starting edge point and a preset step length; fitting the preset number of edge points in the multiple edge points into a reference circle; calculating the distance difference between the other edge points outside the fitting reference circle and the reference circle; fitting the edge points with distance difference not higher than the distance threshold value into a candidate circle; updating the preset number of edge points by taking the next edge point as the starting edge point, and obtaining the candidate circle according to the updated preset number of edge points, until the preset number of edge points includes the last edge point.

[0060] It can be understood that when the multiple edge points are sorted, the first edge point can be determined randomly according to actual conditions. For example, the first edge point can be a special point of the object to be fitted, can be any edge point in the multiple edge points, or can be a specified edge point, etc. After the first edge point is determined, the multiple edge points can be sorted according to the actual sorting of the object to be fitted.

[0061] The preset step length is a specified step length value. For example, the preset step length can be step length 1, step length 2, step length 3, and the like. The preset step length can be adjusted according to actual conditions, and the present application does not make specific limitations.

[0062] For example, if the preset number of edge points is 3 edge points and the preset step length is 1, the first edge point can be selected as the starting edge point, and 3 edge points are selected according to the step length 1 to fit the reference circle, that is, the edge points used to fit the reference circle are the first edge point, the second edge point, and the third edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circle. Then, the second edge point is selected as the starting edge point, and 3 edge points are selected according to the step length 1 to fit the reference circle, that is, the edge points used to fit the reference circle are the second edge point, the third edge point, and the fourth edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circle. Then, the third edge point is selected as the starting edge point, and 3 edge points are selected according to the step length 1 to fit the reference circle, that is, the edge points used to fit the reference circle are the third edge point, the fourth edge point, and the fifth edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circle. The above process is repeated until the last edge point is included in the edge points used to fit the reference circle.

[0063] In the above implementation process, different edge points in the plurality of edge points are selected as the starting edge, and a plurality of reference circles are fitted according to the preset step length. Then, according to the distance difference between the other edge points corresponding to each reference circle and the reference circle, a plurality of candidate circles can be fitted. The problem that the accuracy of the candidate circle obtained by directly fitting the reference circle according to the selected edge point as an outlier is reduced can be avoided. Since the plurality of candidate circles are calculated by fitting the reference circle according to each edge point as the starting edge point in turn, when the fitted circle of the object to be fitted is determined, the candidate circle closest to the object to be fitted can be selected as the fitted circle of the object to be fitted, thereby improving the accuracy of the fitted circle.

[0064] In a possible implementation, the method further includes updating the preset step length according to a set increment, and updating the preset number of edge points according to the updated preset step length and the starting edge point, so as to obtain the candidate circle according to the updated preset number of edge points, until the preset step length is n / m, where n is the number of edge points, m is the number of edge points used to fit the reference circle, and n / m is rounded down.

[0065] The setting increment value herein is a pre-specified step increment value. For example, the setting increment value can be 1, 2, 3, 4, and the like. The setting increment value can be adjusted according to actual conditions, and the present application does not make specific limitations.

[0066] It should be understood that different edge point fitting reference points can be selected to obtain as many candidate circles as possible to further improve the accuracy of the fitted circle. Therefore, not only can the number of reference circles be increased by updating the starting edge point, but also the number of reference circles can be increased by updating the step.

[0067] Optionally, the pre-set step increment value and the starting edge point can have multiple updating methods, for example:

[0068] The first method is: if the preset number of edge points is 3, the preset step is 1, and the set increment is 1. Then, the first edge point is taken as the starting edge point, and 3 edge points are selected according to the step 1 to fit the reference circle, that is, the edge points used to fit the reference circle are the first edge point, the second edge point, and the third edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circles. Then, the second edge point is taken as the starting edge point, and 3 edge points are selected according to the step 1 to fit the reference circle, that is, the edge points used to fit the reference circle are the second edge point, the third edge point, and the fourth edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circles. Then, the third edge point is taken as the starting edge point, and 3 edge points are selected according to the step 1 to fit the reference circle, that is, the edge points used to fit the reference circle are the third edge point, the fourth edge point, and the fifth edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circles. The above steps are repeated until the edge point used to fit the reference circle includes the last edge point. Then, the preset step is updated, that is, the updated preset step is 2, and the above steps are continued to be repeated, that is, the first edge point is taken as the starting edge point, and 3 edge points are selected according to the step 2 to fit the reference circle, that is, the edge points used to fit the reference circle are the first edge point, the third edge point, and the fifth edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circles. Then, the second edge point is taken as the starting edge point, and 3 edge points are selected according to the step 2 to fit the reference circle, that is, the edge points used to fit the reference circle are the second edge point, the fourth edge point, and the sixth edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circles. Then, the third edge point is taken as the starting edge point, and 3 edge points are selected according to the step 2 to fit the reference circle, that is, the edge points used to fit the reference circle are the fifth edge point, the seventh edge point, and the ninth edge point. Further, the distance difference between the other edge points outside the fitted reference circle and the reference circle is calculated, and the edge points with a distance difference not higher than the distance threshold are fitted as the candidate circles. The above steps are repeated until the edge point used to fit the reference circle includes the last edge point. Then, the preset step is updated again, that is, the updated preset step is 3, and the above steps are continued to be repeated until the preset step is n / m.

[0069] The second way: if the preset number of edge points is 3, the preset step is 1, and the preset increment is 1. Then, the first edge point is taken as the starting edge point, and 3 edge points are selected according to the step 1 to fit the reference circle, that is, the edge points used to fit the reference circle are the first edge point, the second edge point, and the third edge point. Further, the distance difference between the other edge points outside the reference circle and the reference circle is calculated, and the edge points with the distance difference not higher than the distance threshold are fitted as the candidate circles. Then, the preset step is updated, that is, the updated preset step is 2, and the first edge point is taken as the starting edge point, and 3 edge points are selected according to the step 2 to fit the reference circle, that is, the edge points used to fit the reference circle are the first edge point, the third edge point, and the fifth edge point. Further, the distance difference between the other edge points outside the reference circle and the reference circle is calculated, and the edge points with the distance difference not higher than the distance threshold are fitted as the candidate circles. Then, the preset step is updated again, that is, the updated preset step is 3, and the first edge point is taken as the starting edge point, and the above steps are repeated until the preset step is n / m.

[0070] The second way: if the preset number of edge points is 3, the preset step is 1, and the preset increment is 1. Then, the first edge point is taken as the starting edge point, and 3 edge points are selected according to the step 1 to fit the reference circle, that is, the edge points used to fit the reference circle are the first edge point, the second edge point, and the third edge point. Further, the distance difference between the other edge points outside the reference circle and the reference circle is calculated, and the edge points with the distance difference not higher than the distance threshold are fitted as the candidate circles. Then, the preset step is updated, that is, the updated preset step is 2, and the first edge point is taken as the starting edge point, and 3 edge points are selected according to the step 2 to fit the reference circle, that is, the edge points used to fit the reference circle are the first edge point, the third edge point, and the fifth edge point. Further, the distance difference between the other edge points outside the reference circle and the reference circle is calculated, and the edge points with the distance difference not higher than the distance threshold are fitted as the candidate circles. Then, the preset step is updated again, that is, the updated preset step is 3, and the first edge point is taken as the starting edge point, and the above steps are repeated until the preset step is n / m.

[0071] Then, the third edge point is taken as a starting edge point, three edge points are selected according to the preset step length to fit a reference circle, the edge points used to fit the reference circle are the third edge point, the fourth edge point and the fifth edge point, the distance differences between the other edge points outside the reference circle and the reference circle are further calculated, and the edge points with the distance differences not higher than the distance threshold are fitted as candidate circles. Then, the preset step length is updated, and the updated preset step length is 2. Then, the third edge point is taken as a starting edge point, three edge points are selected according to the updated preset step length to fit a reference circle, the edge points used to fit the reference circle are the third edge point, the fifth edge point and the seventh edge point, the distance differences between the other edge points outside the reference circle and the reference circle are further calculated, and the edge points with the distance differences not higher than the distance threshold are fitted as candidate circles. Then, the preset step length is updated again, and the updated preset step length is 3. Then, the third edge point is taken as a starting edge point, and the above steps are repeated until the preset step length is n / m. Each edge point is taken as a starting edge point, and the above steps are repeated until the edge points used to fit the reference circle include the last edge point and the preset step length is n / m.

[0072] The updating manner of the preset step length and the starting edge point is only exemplary, and the updating manner of the preset step length and the starting edge point can also include other manners.

[0073] In the implementation process, by further updating the preset step length, more candidate circles can be obtained on the basis of updating the starting edge point, the range of the fitted circle selection is increased, and the accuracy of the fitted circle is further improved.

[0074] In a possible implementation, the step S205 includes: calculating a distance mean of the edge points used to fit each candidate circle to the corresponding candidate circle respectively; and determining the fitted circle of the object to be fitted according to the number of the edge points with the distance differences not higher than the distance threshold and the distance mean.

[0075] The distance mean includes a distance standard deviation mean of all the edge points used to fit each candidate circle to the corresponding candidate circle, a distance variance mean of all the edge points used to fit each candidate circle to the corresponding candidate circle, a distance average of all the edge points used to fit each candidate circle to the corresponding candidate circle, and the like. The distance mean can be selected according to actual conditions.

[0076] The determination of the fitted circle of the object to be fitted is determined according to the accuracy of the candidate circle, that is, the candidate circle with the highest accuracy is the fitted circle of the object to be fitted.

[0077] It can be understood that only part of the edge points or none of the edge points used to fit the candidate circle are on the candidate circle, and thus the accuracy of the corresponding candidate circle fitting can be determined according to the distance mean of the edge points used to fit the candidate circle.

[0078] In some embodiments, the smaller the average distance between the edge points used to fit the candidate circle and the candidate circle, the higher the accuracy of the candidate circle fitting.

[0079] It should be understood that in some cases, if some candidate circles select more edge points when fitting, and some candidate circles select less edge points when fitting, then only judging the accuracy of the candidate circle by the average distance between the edge points used to fit the candidate circle and the candidate circle may affect the accuracy of the judgment. For example, in an extreme case, if there are only 3 edge points used to fit the first candidate circle, even if all 3 edge points are outliers, it is highly likely that all 3 edge points are on the first candidate circle, i.e. the average distance between the edge points used to fit the first candidate circle and the candidate circle is 0. Compared with the first candidate circle, the second candidate circle may use more edge points (e.g. 10) when fitting, and it is possible that all 10 edge points used to fit the second candidate circle are not on the second candidate circle, or only part of them are on the second candidate circle. At this time, the average distance between the edge points used to fit the second candidate circle and the second candidate circle is usually greater than 0. Then, it may be determined that the accuracy of the first candidate circle fitted by 3 edge points is higher than the accuracy of the second candidate circle fitted by 10 edge points, which may cause misjudgment.

[0080] Therefore, the number of edge points used to fit the candidate circle can also be added as a constraint condition on the basis of the average distance to determine the fitting circle of the object to be fitted.

[0081] In some embodiments, the priority of the number of edge points with a distance difference not higher than the distance threshold can be set to be higher than the average distance. That is, when determining the fitting circle of the object to be fitted, first determine the number of edge points with a distance difference not higher than the distance threshold to determine the candidate circle with the most number of edge points with a distance difference not higher than the distance threshold. Then determine the candidate circle with the smallest average distance in the candidate circle with the most number of edge points to be the fitting circle of the object to be fitted.

[0082] In the above implementation process, when determining the fitting circle of the object to be fitted based on the candidate circle, both the number of edge points with a distance difference not higher than the distance threshold and the average distance are used for determination, which can reduce the case that the accuracy of the candidate circle fitted by fewer edge points may be directly higher than the accuracy of the candidate circle fitted by more edge points when only using the distance threshold for judgment, thereby improving the accuracy of the determined fitting circle.

[0083] In a possible implementation, the step S203 comprises: determining a difference between a distance of each other edge point to a center of the reference circle and a radius of the reference circle as a distance between each other edge point and the reference circle; calculating a mean value of distances between the other edge points and the reference circle according to the distances between the other edge points and the reference circle; and calculating a standard deviation of distances between the other edge points and the reference circle according to the mean value.

[0084] The formula of the distance between each other edge point and the reference circle can be as follows:

[0085] d ki = D ki - R k ;

[0086] wherein D ki is a distance of an i th edge point of a k th reference circle to a center of the k th reference circle, R k is a radius of the k th reference circle, d ki is a distance between the i th edge point of the k th reference circle and the reference circle, and k and i are both non-zero natural numbers.

[0087] The formula of the mean value of distances between the other edge points and the reference circle can be as follows:

[0088]

[0089] wherein d k1 is a distance between a 1 st edge point of a k th reference circle and the reference circle, d k2 is a distance between a 2 nd edge point of the k th reference circle and the reference circle, d kn is a distance between an n th edge point of the k th reference circle and the reference circle, N is a total number of edge points of the k th reference circle, v is the mean value of distances between the other edge points and the reference circle, and n is a non-zero natural number.

[0090] It should be understood that after the mean value of distances between the other edge points and the reference circle is determined, a variance of distances between the other edge points and the reference circle can be calculated according to the mean value, and a standard deviation of distances between the other edge points and the reference circle can be calculated according to the variance. The standard deviation of distances between the other edge points and the reference circle is the distance difference between the other edge point and the reference circle.

[0091] In the implementation process, since the standard deviation can reflect the dispersion degree of a data set, by taking the standard deviation of distances between the other edge points and the reference circle as the distance difference between the other edge point and the reference circle to determine whether each edge point used to fit the reference circle is a dispersion point, the accuracy of screening the dispersion points can be improved.

[0092] In a possible implementation, the step S201 comprises: determining the number of sub-circumferential calipers according to the number of edge points to be collected; and detecting the edge points of the object to be fitted in each sub-circumferential caliper according to a one-dimensional edge detection technique to obtain a plurality of edge points of the object to be fitted.

[0093] The circumferential caliper herein is a tool for positioning edges. The principle is to set a plurality of small rectangles (i.e., sub-circumferential calipers) in the region of interest of the image, and position the places of gray value mutation in each small rectangle, which can be defined as an edge point. The number, width, length, etc. of the sub-circumferential calipers in the circumferential caliper can be adjusted according to actual conditions.

[0094] It should be understood that when collecting a plurality of edge points of the object to be fitted in the target image, the region of interest of each sub-circumferential caliper is traversed, and the points of gray value mutation in each sub-circumferential caliper are found respectively, and the points of gray value mutation are determined as the edge points of the sub-circumferential caliper.

[0095] Exemplarily, as shown in the figure, Figure 2 the number of sub-circumferential calipers of the circumferential caliper is 7, for each sub-circumferential caliper, the gray value of the white part in the sub-circumferential caliper is 255, and the gray value of the black part is 0, so there are two mutation points of gray value in each sub-circumferential caliper, i.e., 255 and -255. If the outer diameter circle of the object to be fitted needs to be fitted, the point of gray value mutation of 255 can be selected. If the outer diameter circle of the object to be fitted needs to be fitted, the point of gray value mutation of -255 can be selected.

[0096] In the above implementation process, since the number of circumferential calipers can be adjusted, the number of circumferential calipers can be adjusted according to the number of edge points to be collected, so that the number of edge points for circle fitting can be changed, increasing the application scenarios of circle fitting. In addition, since the one-dimensional edge detection technique is simple and easy to implement, when detecting the edge points in each sub-circumferential caliper, the detection difficulty of the edge points can be reduced by using the one-dimensional edge detection technique.

[0097] Please refer to Figure 3 , which is a flowchart of the detection method provided by the embodiment of the present application. The specific process shown in Figure 3 will be described in detail below.

[0098] In step S301, a target image of an object to be detected is obtained.

[0099] The object to be detected herein can be a circular object such as a gear, a screw, a gasket, etc., and of course can also be a circular pipe, a wire, etc. with a circular cross section. The object to be detected can be selected according to actual conditions, and the present application does not make specific limitations.

[0100] Optionally, the target image of the object to be detected can be acquired by a camera, a camera, or the like image acquisition device.

[0101] In step S302, the object to be detected in the target image is fitted into a circle according to the circle fitting method in the above embodiment, so as to obtain a fitting circle corresponding to the object to be detected.

[0102] In step S303, the detection result of the object to be detected is determined according to the fitting circle.

[0103] It can be understood that the spatial circular objects such as gears and screws need to be quality detected before leaving the factory. Among them, the deformation condition, the size condition, by adopting the circle fitting method to fit the fitting circle corresponding to the spatial circular object, and according to the relationship between the fitting circle and the standard circle, whether the object to be detected is deformed, whether the size is too large or too small, etc. is determined, so as to realize the quality detection of the object to be detected.

[0104] In the above implementation process, since the circle fitting method of the present application eliminates the outliers when fitting the object to be fitted, the interference of the outliers on the circle fitting result can be excluded, the circle fitting accuracy is improved, and the detection accuracy of the object to be detected is improved.

[0105] Based on the same application concept, the present application embodiment also provides a circle fitting device corresponding to the circle fitting method. Since the principle of solving the problem of the device in the present application embodiment is similar to the above-mentioned circle fitting method embodiment, the implementation of the device in the present embodiment can be referred to the description of the above-mentioned method embodiment, and the repeated parts will not be described here.

[0106] Please refer to Figure 4 is a functional module schematic diagram of the circle fitting device provided by the present application embodiment. Each module in the circle fitting device in the present embodiment is used to execute each step in the above-mentioned method embodiment. The circle fitting device comprises a collection module 301, a first fitting module 302, a calculation module 303, a second fitting module 304, and a determination module 305; wherein,

[0107] The collection module 301 is used to collect a plurality of edge points of the object to be fitted in the target image.

[0108] The first fitting module 302 is used to fit a preset number of edge points in the plurality of edge points into a reference circle.

[0109] The calculation module 303 is used to calculate the distance difference between the other edge points outside the reference circle and the reference circle.

[0110] The second fitting module 304 is used to fit the edge points with the distance difference not higher than the distance threshold value into a candidate circle.

[0111] The determining module 305 is configured to determine a fitting circle of the object to be fitted according to the candidate circle.

[0112] In a possible implementation, the first fitting module 302 is further configured to sort the plurality of edge points, take a first edge point as a starting edge point, determine a preset number of edge points according to the starting edge point and a preset step length, and fit the preset number of edge points as a reference circle.

[0113] In a possible implementation, the circle fitting apparatus further includes an updating module configured to update the preset number of edge points by taking a next edge point as a starting edge point, and obtain the candidate circle according to the updated preset number of edge points, until the preset number of edge points includes a last edge point.

[0114] In a possible implementation, the updating module is further configured to update the preset step length by a preset increment, and update the preset number of edge points according to the updated preset step length and the starting edge point, to obtain the candidate circle according to the updated preset number of edge points, until the preset step length is n / m, where n is the number of edge points, m is the number of edge points of the reference circle to be fitted, and n / m is rounded down.

[0115] In a possible implementation, the determining module 305 is further configured to: calculate a distance mean of edge points used to fit each candidate circle to the corresponding candidate circle respectively, and determine the fitting circle of the object to be fitted according to the distance mean and the number of edge points whose distance difference is not higher than a distance threshold.

[0116] In a possible implementation, the calculating module 303 is specifically configured to: determine a difference between a distance of each other edge point to a center of the reference circle and a radius of the reference circle as a distance between the other edge point and the reference circle, calculate a distance mean between the other edge points and the reference circle according to a plurality of distances between a plurality of other edge points and the reference circle, and calculate a standard deviation between the other edge points and the reference circle according to the distance mean.

[0117] In a possible implementation, the collecting module 301 is specifically configured to: determine a number of sub-calipers of a circumference caliper according to a number of edge points to be collected, and detect edge points of the object to be fitted in each sub-caliper according to a one-dimensional edge detection technology, to obtain a plurality of edge points of the object to be fitted.

[0118] In a possible implementation, the second fitting module 304 is specifically configured to: fit the edge points whose distance difference is not higher than a distance threshold as a candidate circle by a least mean square method.

[0119] Based on the same application concept, this application also provides a detection device corresponding to the detection method. Since the principle of the device in this application is similar to that of the aforementioned detection method, the implementation of the device in this application can refer to the description in the above-mentioned method embodiments, and the repeated parts will not be described again.

[0120] Please see Figure 5 This is a functional module diagram of the detection device provided in this application embodiment. Each module in the detection device in this embodiment is used to execute the steps in the above method embodiments. The detection device includes an acquisition module 401, a circle fitting module 402, and a second determination module 403; wherein,

[0121] The acquisition module 401 is used to acquire the target image of the object to be detected.

[0122] The circle fitting module 402 is used to perform circle fitting on the object to be detected in the target image according to the circle fitting method described above, so as to obtain the fitted circle corresponding to the object to be detected.

[0123] The second determining module 403 is used to determine the detection result of the object to be detected based on the fitted circle.

[0124] To facilitate understanding of this embodiment, the electronic device that performs the circle fitting method and / or detection method disclosed in the embodiments of this application will be described in detail below.

[0125] like Figure 6 The diagram shown is a block illustration of an electronic device. The electronic device 100 may include a memory 111 and a processor 113. Those skilled in the art will understand that... Figure 6 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device 100. For example, the electronic device 100 may also include components that are more... Figure 6 The more or fewer components shown, or having the same Figure 6 The different configurations shown.

[0126] The aforementioned memory 111 and processor 113 are electrically connected to each other directly or indirectly to enable data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses or signal lines. The aforementioned processor 113 is used to execute executable modules stored in the memory.

[0127] The memory 111 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), and the like. The memory 111 is configured to store a program. After receiving an execution instruction, the processor 113 executes the program. The method performed by the electronic device 100 defined in the process disclosed in any of the embodiments of the present application can be applied to the processor 113 or implemented by the processor 113.

[0128] The processor 113 can be an integrated circuit chip with a signal processing capability. The processor 113 can be a general purpose processor, including a central processing unit (CPU), a network processor (NP), and the like. The processor 113 can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The processor 113 can implement or execute the methods, steps, and logical block diagrams disclosed in the embodiments of the present application. The general purpose processor can be a microprocessor or the processor can also be any conventional processor.

[0129] The electronic device 100 in the embodiments of the present application can be configured to execute each step in each method provided in the embodiments of the present application.

[0130] In addition, the embodiments of the present application further provide a computer readable storage medium, and the computer readable storage medium stores a computer program. When the computer program is run by a processor, the steps of the circle fitting method and / or the detection method described in the method embodiments are executed.

[0131] The computer program product of the circle fitting method and / or the detection method provided in the embodiments of the present application includes a computer readable storage medium storing program codes, and the program codes include instructions for executing the steps of the circle fitting method and / or the detection method described in the method embodiments. For details, refer to the method embodiments, which will not be repeated here.

[0132] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can also be implemented by other manners. The apparatus embodiments described above are only schematic, for example, the flow charts and block diagrams in the drawings show the possible implementation architectures, functions and operations of the apparatus, method and computer program product according to the embodiments of the present application. In this regard, each block in the flow charts or block diagrams can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logical functions. It should also be noted that, in some alternative implementations, the functions noted in the blocks can occur in different orders from those noted in the drawings. For example, two consecutive blocks can actually be executed in parallel, and sometimes they can be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flow charts, and the combination of blocks in the block diagrams and / or flow charts, can be implemented by a dedicated hardware-based system for executing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

[0133] In addition, each functional module in the embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0134] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application can be embodied in the form of a software product in essence or in the part that contributes to the prior art, or part of the technical solutions. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes. It should be noted that in this paper, relationship terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between the entities or operations. Moreover, the terms "include", "contain" or any other variants are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to the process, method, article or device. Without more limitations, the elements defined by the statement "include" do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0135] The above is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.

[0136] The above is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. The above is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.

Claims

1. A circle fitting method characterized by, The method comprises: collecting a plurality of edge points of a target object in a target image; sorting the plurality of edge points; taking a first edge point as a starting edge point; determining a preset number of edge points according to the starting edge point and a preset step length; fitting the preset number of edge points in the plurality of edge points as a reference circle; calculating a distance difference between other edge points outside the reference circle and the reference circle; fitting the edge points with a distance difference not higher than a distance threshold as a candidate circle; updating the preset number of edge points by taking a next edge point as a starting edge point, and obtaining the candidate circle according to the updated preset number of edge points, until the preset number of edge points includes a last edge point; determining a fitting circle of the target object according to the candidate circle; wherein the candidate circle is a plurality of candidate circles, and the determining of the fitting circle of the target object according to the candidate circle comprises: respectively calculating a distance mean of edge points used to fit each candidate circle to the corresponding candidate circle; determining the fitting circle of the target object according to the number of edge points with a distance difference not higher than a distance threshold and the distance mean.

2. The method of claim 1, wherein, The method further comprises: updating the preset step length according to a set increment, and updating the preset number of edge points according to the updated preset step length and the starting edge point, to obtain the candidate circle according to the updated preset number of edge points, until the preset step length is n / m, wherein n is the number of edge points, and m is the number of edge points used to fit the reference circle, and n / m is rounded down.

3. The method of claim 1, wherein, The distance difference comprises a standard deviation, and the calculating of the distance difference between other edge points outside the reference circle and the reference circle comprises: determining a difference between the distance of each other edge point to the center of the reference circle and the radius of the reference circle as the distance between each other edge point and the reference circle; calculating a distance mean between the other edge points and the reference circle according to a plurality of distances between a plurality of other edge points and the reference circle; calculating a standard deviation between the other edge points and the reference circle according to the distance mean.

4. The method of claim 1, wherein, The collecting of the plurality of edge points of the target object in the target image comprises: determining a number of sub-circumferential calipers according to the number of edge points to be collected; detecting edge points of the target object in each sub-caliper according to a one-dimensional edge detection technique, to obtain a plurality of edge points of the target object.

5. A method of detection, characterized in that The method comprises: obtaining a target image of an object to be detected; performing circle fitting on the object to be detected in the target image according to the circle fitting method of any one of claims 1-4, to obtain a fitting circle corresponding to the object to be detected; determining a detection result of the object to be detected according to the fitting circle.

6. A circle fitting apparatus characterized by comprising: The method comprises: a collecting module configured to collect a plurality of edge points of a target object in a target image; a first fitting module configured to sort the plurality of edge points; taking a first edge point as a starting edge point; determining a preset number of edge points according to the starting edge point and a preset step length; fitting the preset number of edge points in the plurality of edge points as a reference circle; a calculating module configured to calculate a distance difference between other edge points outside the reference circle and the reference circle. The second fitting module is configured to fit the edge points with the distance difference not higher than the distance threshold as candidate circles; The updating module is configured to update the preset number of edge points with one edge point as a starting edge point, and obtain the candidate circles according to the updated preset number of edge points until the preset number of edge points includes a last edge point. The determining module is configured to: calculate a distance mean of the edge points used to fit each of the candidate circles to the corresponding candidate circle respectively; and determine a fitting circle of the object to be fitted according to the number of the edge points with the distance difference not higher than the distance threshold and the distance mean.

7. A detection device, characterized in that The method comprises the following steps: The acquisition module is configured to acquire a target image of an object to be detected. The circle fitting module is configured to perform circle fitting on the object to be detected in the target image according to the circle fitting method of any one of claims 1-5 to obtain a fitting circle corresponding to the object to be detected. The second determining module is configured to determine a detection result of the object to be detected according to the fitting circle.

8. An electronic device, comprising: The processor, the memory, the memory stores machine readable instructions executable by the processor, when the electronic equipment runs, the machine readable instructions are executed by the processor to execute the steps of the method in any one of claims 1 to 5. The computer program is stored on the computer readable storage medium, and the computer program is executed by the processor to execute the steps of the method in any one of claims 1 to 5.

9. A computer-readable storage medium, characterized in that, ​

Citation Information

Patent Citations

  • A fast iterative line-circle optimal fitting method

    CN109035363A

  • Circular detection method and device and computer readable storage medium

    CN112489024A