Circle detection method and device, and computer readable storage medium
By performing edge detection and circle fitting of the image to be detected, combined with contrast screening, the problem of unstable edge contrast detection in the prior art is solved, and higher edge contrast and detection accuracy are achieved.
Patent Information
- Application Number
- CN202011414992.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-04
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2040-12-04
AI Technical Summary
The prior art cannot guarantee the edge contrast of circle detection, especially in the case of interference or noise, and the circle and edge are prone to be inconsistent.
By performing edge detection on the image to be detected, multiple edge points are obtained, and then these edge points are combined into multiple edge point sets, and circle fitting is performed based on each edge point set to obtain multiple fitted circles. Edge points are filtered according to the contrast of the fitted circle, retain edge points with high stability, and finally, circle fitting is performed based on these edge points to obtain the circle to be detected in the image to be detected.
Through this method, the edge contrast and accuracy of circle detection can be significantly improved, and the resistance to noise and interference can be enhanced.
Smart Images

Figure CN112489024B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of robot vision technology, and in particular to a circle detection method and device, and a computer-readable storage medium. Background Art
[0002] In actual production applications, it is necessary to use a machine vision system to extract information about circular features (referring to circular structures on the surface of workpieces / objects, such as circular holes, cylinders, etc.) to guide production testing and realize the automation and intelligence of production operations.
[0003] The inventors of the present application have discovered that the methods in the prior art cannot guarantee the edge contrast of the found circle, and when there is interference or noise, it is easy for the found circle to not fit the edge. Summary of the invention
[0004] The main technical problem solved by the present application is to provide a circle detection method and device thereof, and a computer-readable storage medium, which can ensure the accuracy of the detected circle.
[0005] In order to solve the above technical problems, a technical solution adopted in the present application is: to provide a circle detection method, the method comprising: performing edge detection on an image to be detected to obtain multiple edge points; combining any at least three edge points among the multiple edge points to obtain multiple edge point sets, and performing circle fitting based on each edge point set to obtain multiple fitted circles; screening the multiple edge points according to the contrast of the multiple fitted circles; performing circle fitting based on the combination formed by the retained edge points to obtain the circle to be detected in the image to be detected.
[0006] To solve the above technical problems, another technical solution adopted in the present application is: to provide a circle detection device, including a processor and a memory, the processor is coupled to the memory, the memory stores program data, and the processor implements the steps in the above method by executing the program data in the memory.
[0007] In order to solve the above technical problem, another technical solution adopted by the present application is: providing a computer-readable storage medium, wherein the computer storage medium stores a computer program, and the computer program can be executed by a processor to implement the steps in the above method.
[0008] The beneficial effect of the present application is: the method in the present application first combines any at least three edge points among multiple edge points to obtain multiple edge point sets, and performs circle fitting based on each edge point set to obtain multiple fitting circles, and then screens the multiple edge points according to the contrast of the multiple fitting circles, retaining edge points with higher stability, so that the circle obtained by performing circle fitting based on the combination formed by the retained edge points can have higher edge contrast and accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0010] Figure 1 It is a flow chart of an implementation method of a circle detection method of the present application;
[0011] Figure 2 yes Figure 1 Schematic diagram of the process of step S130;
[0012] Figure 3 yes Figure 2 Schematic diagram of the process of step S131;
[0013] Figure 4 It is a schematic diagram of an area of interest in an application scenario;
[0014] Figure 5 yes Figure 1 Schematic diagram of the process of step S140;
[0015] Figure 6 yes Figure 1 Schematic diagram of the process of step S110;
[0016] Figure 7 is a schematic diagram of the region of interest in another application scenario;
[0017] Figure 8 is a schematic diagram of the region of interest in another application scenario;
[0018] Fig. 9 It is a structural schematic diagram of an implementation method of a circle detection device of the present application;
[0019] Fig.10 It is a structural schematic diagram of an implementation method of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0021] See also Figure 1 , Figure 1 : is a flow chart of an implementation method of a circle detection method of the present application, the method comprising:
[0022] S110: Perform edge detection on the image to be detected to obtain a plurality of edge points.
[0023] Specifically, the image to be detected can be a grayscale image, a color image or a depth image. For the convenience of processing, if the image to be detected is a color image or a depth image, it is first converted into a grayscale image before edge detection, and then subsequent steps are performed based on the grayscale image.
[0024] An edge is a geometric feature of a group of connected pixels, which are usually located where the grayscale of pixels changes between two different areas. By using an edge detection algorithm to perform edge detection on the image to be detected, multiple edge points of the image to be detected can be obtained, including the positions of the multiple edge points and the corresponding pixel values.
[0025] In this embodiment, in order to reduce the processing amount, calculation time and increase accuracy, before edge detection is performed on the image to be detected, a region of interest (ROI) in the image to be detected is extracted, and then edge detection is performed based on the region of interest to obtain multiple edge points. The shape of the region of interest is a circular ring or a fan ring.
[0026] S120: Combining any at least three edge points among the plurality of edge points to obtain a plurality of edge point sets, and performing circle fitting based on each edge point set to obtain a plurality of fitting circles.
[0027] Specifically, since at least three points determine a circle, any at least three edge points among the plurality of edge points are combined to obtain a plurality of edge point sets each including at least three edge points.
[0028] Algorithms such as the average method, the weighted average method or the least square method can be used to fit multiple edge point sets respectively to obtain multiple fitting circles.
[0029] In an application scenario, in order to ensure that all possible results are not missed, step S120 specifically includes: grouping multiple edge points so that each group contains the same number of edge points and each group contains at least three edge points, thereby obtaining multiple edge point sets, and performing circle fitting based on each edge point set to obtain multiple fitting circles. That is, the multiple edge point sets finally obtained include the same number of edge points, and assuming that there are M edge points, the number of edge point sets obtained is Where N is the number of edge points in the edge point set.
[0030] In a specific example, N is 3, that is, at this time, all three edge points in the plurality of edge points are combined to obtain a plurality of edge point sets. For example, there are 7 edge points, and any 3 edge points are combined to obtain A set of edge points.
[0031] Of course, in other application scenarios, the number of edge points in multiple edge point sets may not be equal, and N may also be 4, 5 or even more, which is not limited in this application.
[0032] S130: Screening multiple edge points according to the contrast of multiple fitting circles.
[0033] Specifically, after obtaining multiple fitting circles, the contrast of the multiple fitting circles is calculated respectively, wherein the higher the contrast of the fitting circles is, the more stable the edge points corresponding to the fitting circles are. Therefore, some unstable edge points can be discarded according to the contrast of the multiple fitting circles. That is to say, step S130 can discard the edge points that may cause fluctuations in the final detection results.
[0034] S140: performing circle fitting based on the combination formed by the retained edge points to obtain the circle to be detected in the image to be detected.
[0035] Specifically, after the above steps, the retained edge points have high stability, so the circle obtained by performing circle fitting based on the combination formed by the retained edge points has strong stability, high edge contrast and more robust ability to resist movement of the region of interest.
[0036] From the above content, it can be seen that the method in this embodiment first combines any at least three edge points among the multiple edge points to obtain multiple edge point sets, and performs circle fitting based on each edge point set to obtain multiple fitting circles, and then screens the multiple edge points according to the contrast of the multiple fitting circles, retaining edge points with higher stability, so that the circle obtained by performing circle fitting based on the combination formed by the retained edge points can have higher edge contrast and accuracy.
[0037] See also Figure 2 , Figure 2 yes Figure 1 Schematic diagram of the process of step S130, step S130 specifically includes:
[0038] S131: screening the multiple fitting circles according to their contrasts.
[0039] Specifically, some fitting circles that do not meet the preset requirements are discarded according to the contrast, so as to further ensure the stability of the edge points that are finally retained.
[0040] See also Figure 3 In one application scenario, step S131 specifically includes:
[0041] S1311: Calculate the global contrast and local contrast of multiple fitted circles respectively.
[0042] S1312: retain the fitted circles whose global contrast is greater than the first preset threshold and whose local contrast is greater than the second preset threshold.
[0043] Specifically, the global contrast of the fitting circle refers to the contrast of the entire fitting circle, and the local contrast of the fitting circle refers to the contrast of a specific arc on the fitting circle.
[0044] Combination Figure 4 , the calculation method of the global contrast and local contrast of the fitted circle is introduced below:
[0045] Extract the area Q to be calculated including the fitting circle S from the image to be detected ( Figure 4 The filled part in the middle), and then the contrast of the area to be calculated Q is calculated, so that the calculated contrast is the global contrast of the fitting circle S.
[0046] A region ABCD to be calculated including a specific arc on the fitting circle S is extracted from the image to be detected, and then the contrast of the region ABCD to be calculated is calculated, so that the calculated contrast is the local contrast of the fitting circle S.
[0047] How to calculate the contrast between the to-be-calculated area Q and the to-be-calculated area ABCD belongs to the prior art and will not be described in detail here.
[0048] In this application scenario, only when both the global contrast and the local contrast meet the requirements will the corresponding fitting circle be retained, otherwise the corresponding fitting circle will be discarded.
[0049] In other application scenarios, step S131 may specifically be to retain a fitting circle whose local contrast meets the requirements, which is not limited here.
[0050] S132: sorting the retained multiple fitting circles in descending order of contrast.
[0051] Specifically, the multiple retained fitting circles may be sorted in descending order according to global contrast, or may be sorted in descending order according to local contrast, which is not limited here.
[0052] In an application scenario, in order to improve the calculation speed, step S132 may specifically be:
[0053] S1321: performing normalization processing on the contrasts of the retained multiple fitting circles to obtain scores of the multiple fitting circles.
[0054] S1322: Sort the retained multiple fitting circles in descending order of scores.
[0055] Specifically, when performing the normalization process, the contrasts of the multiple fitted circles may be divided by a preset value (eg, 255) respectively, or the contrasts of the multiple fitted circles may be divided by the maximum value of all contrasts respectively, and there is no limitation here.
[0056] S133: retaining edge points corresponding to a plurality of fitted circles arranged in front.
[0057] Specifically, the edge points corresponding to the fitting circles arranged in the first fixed positions (such as the first 10 positions) may be retained, or the edge points corresponding to the fitting circles whose difference with the fitting circle arranged in the first position is within a preset range may be retained.
[0058] In the above implementation, the fitted circles are first screened, some fitted circles that do not meet the requirements are discarded, and then the retained fitted circles are sorted, and finally the edge points corresponding to the first several fitted circles are retained to ensure the stability of the edge points finally retained.
[0059] It should be noted that, in other implementations, multiple fitted circles may not be screened before being sorted, but all the fitted circles may be sorted directly in descending order of contrast, and then the edge points corresponding to the first several fitted circles are retained.
[0060] See also Figure 5 , Figure 5 yes Figure 1 Schematic diagram of the process of step S140, step S140 specifically includes:
[0061] S141: Perform circle fitting based on the combination formed by the retained edge points to obtain a fitting circle.
[0062] Specifically, all the retained edge points are formed into a combination, and then based on the combination, an algorithm such as an average method, a weighted average method or a least square method is used for fitting to obtain a fitting circle.
[0063] S142: Determine whether the contrast of the fitted circle meets a preset requirement.
[0064] If the determination result is yes, then go to step S143 , and if the determination result is no, then go to step S144 .
[0065] Specifically, it may be determined whether the global contrast of the fitted circle obtained in step S141 meets the preset requirements, or it may be determined whether the local contrast of the fitted circle obtained in step S141 meets the preset requirements, or it may be determined whether both the global contrast and the local contrast of the fitted circle obtained in step S141 meet the preset requirements.
[0066] For example, in an application scenario, it is determined whether the global contrast of the fitted circle reaches a preset threshold. If so, it is determined that the contrast of the fitted circle meets the preset requirement. Otherwise, it is determined that the contrast of the fitted circle does not meet the preset requirement.
[0067] S143: Determine the fitted circle as the circle to be detected in the image to be detected.
[0068] S144: Determine that the detection fails.
[0069] Specifically, if the contrast of the fitted circle meets the preset requirement, the detection is determined to be successful, and the fitted circle is determined as the circle to be detected in the image to be detected, that is, the circle to be found; otherwise, the detection is determined to be a failure.
[0070] In this embodiment, after a fitting circle is obtained by performing circle fitting based on the combination formed by the retained edge points, the contrast of the fitting circle is also determined to further ensure the edge contrast and accuracy of the found circle.
[0071] Of course, in other implementations, after the fitting circle is obtained in step S141, the contrast of the fitting circle may not be judged, but the fitting circle may be directly determined as the circle to be detected in the image to be detected.
[0072] See also Figure 6 , Figure 6 yes Figure 1 Schematic diagram of the process of step S110, step S110 specifically includes:
[0073] S111: extracting a region of interest in the image to be detected.
[0074] S112: radiating outwards from a point outside the region of interest as an end point to form a plurality of scan lines passing through the region of interest.
[0075] S113: In the region of interest, a difference between pixel values of a pixel point on the scan line and an adjacent pixel point is calculated, wherein the adjacent pixel point is a pixel point on the scan line, and a pixel point on the scan line whose difference exceeds a preset threshold is determined as an edge point.
[0076] Specifically, for each pixel in the area of interest, the difference between its pixel value and that of the adjacent pixel (the adjacent pixel is also located on the scan line) is calculated, and then after the calculation is completed, the pixel corresponding to the difference exceeding the preset threshold is determined as the edge point (in an application scenario, the pixel corresponding to the largest difference can also be determined as the edge point).
[0077] Combination Figure 7 , Figure 7 The middle fan annular area is the region of interest extracted from the image to be detected. Eight scan lines OA to OH are formed by radiating outward from a point O outside the region of interest as the endpoint, wherein the angles between two adjacent scan lines are equal (or unequal). Then, pixel values on multiple scan lines are extracted in the region of interest, that is, pixel values on line segments OA' to OH' are extracted respectively, and then based on the extracted pixel values, points on line segments OA' to OH' whose pixel values differ from those of adjacent pixel points (the adjacent pixel points are also located on the scan lines) exceeding a preset threshold value are determined respectively (or the pixel points with the largest difference), and then the determined pixel points are determined as edge points.
[0078] In this embodiment, before step S120, the following steps are also included:
[0079] S150: grouping the plurality of edge points according to at least one of polarities of the plurality of edge points and position sequence of the plurality of edge points on the scan line to obtain a plurality of groups of edge points, so as to perform subsequent steps based on the plurality of groups of edge points respectively.
[0080] Specifically, the polarity of edge points is divided into positive and negative: along the same direction, the pixel value of the edge point close to the positive pole and the pixel value of the edge point close to the negative pole change in the opposite direction, specifically, one becomes larger and the other becomes smaller.
[0081] The position order of multiple edge points on the scan line refers to the order of the edge point on the scan line in the direction close to or away from the endpoint. For example, Figure 8 As shown, in the direction away from the end point O, A1, B1, and C1 are all the first points on the scan line, A2, B2, and C2 are all the second points on the scan line, and A3, B3, and C3 are all the third points on the scan line.
[0082] It can be understood that edge points with the same position order on the scan line correspond to the same object to be detected. For example, A1, B1, and C1 correspond to the same circle to be detected, and A2, B2, and C2 correspond to the same circle to be detected.
[0083] When the plurality of edge points are grouped according to their polarities, the edge points with positive polarities are grouped into one group, and the edge points with negative polarities are grouped into another group.
[0084] When the plurality of edge points are grouped according to the position sequence of the plurality of edge points on the scan line, the edge points having the same position sequence on the scan line are grouped into one group.
[0085] When the edge points are grouped according to their polarities and the position order of the edge points on the scan line, the edge points may be first divided into two groups according to the polarities, and then further grouped according to the position order of the edge points on the scan line for each group.
[0086] Meanwhile, after the grouping is completed, the subsequent steps may be performed for the edge points of all groups respectively, that is, steps S120 to S140 may be performed for each group of edge points respectively, or the subsequent steps may be performed for only the edge points of one group.
[0087] Of course, in other implementations, step S120 may be directly executed after step S110 without executing step S150.
[0088] In order to better understand the circle detection method of the present application, the above method is further explained below in conjunction with specific examples.
[0089] Combination Figure 8 , Figure 8 There are 3 circles to be detected. First, the region of interest is extracted from the image to be detected ( Figure 8 The filling part in the middle), then radiate outward from a point O outside the area of interest to form 8 scan lines OA~OH passing through the area of interest, and then in the area of interest, the pixel point with the largest difference in pixel value with the adjacent pixel point on the 8 scan lines is determined as the edge point, so that a total of 24 edge points are obtained.
[0090] Then the 24 edge points are grouped according to the order of their positions on the scan line, and a total of 3 groups are obtained, namely the first group: edge point A1, edge point B1, edge point C1, edge point D1, edge point E1, edge point F1, edge point G1, edge point H1; the second group: edge point A2, edge point B2, edge point C2, edge point D2, edge point E2, edge point F2, edge point G2, edge point H2; the third group: edge point A3, edge point B3, edge point C3, edge point D3, edge point E3, edge point F3, edge point G3 and edge point H3.
[0091] Then, the same steps are performed on the above three groups respectively, wherein the first group is used for illustration.
[0092] Combine any three edge points in the first group to get 56 edge point sets are used, and circle fitting is performed based on the 56 edge point sets respectively, so as to obtain 56 fitting circles.
[0093] Assume that after screening (the specific screening process can be found in the above-mentioned related content), only 20 fitting circles are left, and then the edge points corresponding to the 20 fitting circles are retained, and then a fitting circle is obtained by performing circle fitting based on the combination formed by the remaining edge points.
[0094] Then, it is determined whether the contrast of the fitted circle meets the requirement. If so, the fitted circle is the final detected circle. If not, the detection is determined to have failed.
[0095] See also Fig. 9 , Fig. 9 It is a structural diagram of an embodiment of a circle detection device of the present application. The circle detection device 200 includes a processor 210 and a memory 220. The processor 210 is coupled to the memory 220. When working, the processor 210 controls itself and the memory 220 to implement the steps in any of the above methods. The detailed steps can be found in the above embodiments and will not be repeated here.
[0096] See also Fig.10 , Fig.10 The computer-readable storage medium 300 stores a computer program 310, which can be executed by a processor to implement the steps in any of the above methods.
[0097] Among them, the computer-readable storage medium 300 can specifically be a device that can store the computer program 310, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, or it can also be a server that stores the computer program 310. The server can send the stored computer program 310 to other devices for execution, or it can also execute the stored computer program 310 by itself.
[0098] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A circle detection method, characterized in that: The method comprises: Perform edge detection on the image to be detected to obtain multiple edge points; Combining any at least three edge points among the plurality of edge points to obtain a plurality of edge point sets, and performing circle fitting based on each of the edge point sets to obtain a plurality of fitting circles; Screening the plurality of edge points according to the contrasts of the plurality of fitting circles to remove the edge points on the fitting circles whose contrasts do not meet preset requirements; Performing circle fitting based on the combination formed by the retained edge points to obtain the circle to be detected in the image to be detected; The step of screening the plurality of edge points according to the contrast of the plurality of fitting circles comprises: The plurality of fitted circles are sorted in descending order of contrast; wherein the step of sorting the plurality of fitted circles in descending order of contrast comprises: normalizing the contrast of the plurality of retained fitted circles to obtain scores of the plurality of fitted circles; and sorting the plurality of retained fitted circles in descending order of the scores; retaining the edge points corresponding to the plurality of fitting circles arranged in front; The step of performing circle fitting based on the combination formed by the retained edge points to obtain the circle to be detected in the image to be detected comprises: Performing circle fitting based on the combination formed by the retained edge points to obtain a fitting circle; judging whether the contrast of the fitting circle meets the preset requirements; if so, determining the fitting circle as the circle to be detected in the image to be detected; otherwise, judging that the detection fails; Before sorting the plurality of fitting circles in descending order of contrast, the method further includes: screening the plurality of fitted circles according to their contrasts, so as to perform subsequent steps based on the retained fitted circles; The step of screening the plurality of fitting circles according to the contrast of the plurality of fitting circles comprises: respectively calculating the global contrast and the local contrast of the plurality of fitted circles; retaining the fitted circle whose global contrast is greater than a first preset threshold and whose local contrast is greater than a second preset threshold; Wherein, the step of calculating the global contrast of the plurality of fitting circles comprises: Extracting a region to be calculated including the fitted circle from the image to be detected, calculating the contrast of the region to be calculated of the fitted circle, and using the obtained contrast as the global contrast of the plurality of fitted circles; The step of calculating the local contrast of the plurality of fitting circles comprises: A region to be calculated including a specific arc on the fitting circle is extracted from the image to be detected, a contrast of the region to be calculated including the specific arc on the fitting circle is calculated, and the obtained contrast is used as a local contrast of the plurality of fitting circles.
2. The method according to claim 1, characterized in that The step of combining any at least three edge points among the plurality of edge points to obtain a plurality of edge point sets, and performing circle fitting based on each edge point set to obtain a plurality of fitting circles comprises: The plurality of edge points are grouped so that each group contains the same number of edge points and each group contains at least three edge points, thereby obtaining a plurality of edge point sets, and a circle fitting is performed based on each edge point set to obtain a plurality of fitting circles.
3. The method according to claim 1, characterized in that The step of performing edge detection on the image to be detected to obtain a plurality of edge points comprises: Extracting a region of interest in the image to be detected; Taking a point outside the region of interest as an endpoint, radiating outwards to form a plurality of scan lines passing through the region of interest; In the region of interest, the difference between the pixel values of the pixel point on the scan line and the adjacent pixel point is calculated, wherein the adjacent pixel point is the pixel point on the scan line, and the pixel point on the scan line whose difference exceeds a preset threshold is determined as the edge point.
4. The method according to claim 3, characterized in that Before combining any at least three edge points among the plurality of edge points to obtain a plurality of edge point sets, and performing circle fitting based on each edge point set to obtain a plurality of fitting circles, the method further includes: The plurality of edge points are grouped according to at least one of polarities of the plurality of edge points and position sequence of the plurality of edge points on the scan line to obtain a plurality of groups of edge points, so as to perform subsequent steps based on the plurality of groups of edge points respectively.
5. A circle detection device, characterized in that: The method comprises a processor and a memory, wherein the processor is coupled to the memory, program data is stored in the memory, and the processor implements the steps in the method according to any one of claims 1 to 4 by executing the program data in the memory.
6. A computer-readable storage medium, characterized in that: The computer storage medium stores a computer program, and the computer program can be executed by a processor to implement the steps in the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Image-based straight line detection method and apparatus, and electronic device
CN111047615A