Method, device and storage medium for automatic recognition of image primitives

Through sliding window and connection domain analysis combined with least squares fitting, straight lines and arcs in the image are automatically identified, solving the problem of inefficiency in traditional methods and achieving efficient and accurate element recognition.

CN119478537BActive Publication Date: 2025-08-26NANJING KAISHIMAI TECH CO LTD +2
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411642668.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-08-26
Estimated Expiration
2044-11-18

AI Technical Summary

Technical Problem

Traditional image element recognition methods require a lot of manual operations, especially in complex images, which are less efficient and difficult to automatically identify and fit straight lines and arcs in images.

Method used

The combination of sliding window and connecting domain analysis is adopted to remove noise points through filtering processing, and the multi-scale sliding window and feature value judgment technology is used to automatically identify straight lines and arcs in the image, and the parameters are obtained by fitting with the least squares method.

Benefits of technology

It significantly improves the efficiency and accuracy of image element recognition, reduces user operation burden, improves the robustness and adaptability of recognition, and can be stable in multiple elements and different sizes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119478537B_ABST
    Figure CN119478537B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, and storage medium for automatic recognition of image primitives, comprising the following steps: first, inputting image data containing closed contours and filtering the contours to remove noise; then, determining the contour type through eigenvalue calculation to distinguish between single circles and mixed primitives containing lines and arcs; if a single circle is determined to be present, directly performing circle fitting on it and outputting the circle parameters; if a mixed primitive is present, using a sliding window method to identify the straight line components, removing the straight line components, performing connected domain analysis on the remaining point set, and extracting the arc regions; finally, fitting the straight line and arc regions separately to obtain the parameters of the line and circle. The method of the present invention can automatically separate and recognize straight line and arc primitives in an image, reducing manual operations and improving recognition accuracy and efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to a method, device and storage medium for automatic recognition of image primitives. Background Art

[0002] Object measurement and geometric primitive recognition are common tasks in machine vision applications. Traditional recognition methods often rely on users manually drawing a region of interest (ROI) and then fitting a corresponding circle or line. This method is stable and reliable, but requires significant time and manual effort, and is particularly inefficient when working with complex images containing multiple primitives. Specifically, in images containing multiple primitives (such as arcs and lines), users must repeatedly draw the ROI corresponding to each primitive, which is tedious and time-consuming. Automatically identifying and measuring geometric primitives in images is a key area for improving efficiency. Summary of the Invention

[0003] Technical purpose: In response to the shortcomings of existing image primitive recognition, the present invention discloses a method, device and storage medium for automatic image primitive recognition. Through an automated recognition algorithm, it automatically segments and fits straight line and arc primitives in an image, thereby improving recognition efficiency and accuracy.

[0004] Technical solution: To achieve the above technical objectives, the present invention adopts the following technical solution:

[0005] A method for automatically recognizing image primitives comprises the following steps:

[0006] Step S1: input image data containing at least one closed contour, and filter the contour to remove noise points and abnormal points to obtain smooth contour data;

[0007] Step S2: Based on the filtered contour data, determine the type of the closed contour and identify whether it is a single arc or a mixed primitive containing an arc and a straight line. If it is determined to be a single arc, proceed to step S3; if it is determined to be a mixed primitive containing an arc and a straight line, proceed to step S4.

[0008] Step S3: When the closed contour is determined to be a single arc, the arc contour is fitted to obtain parameter information of the circle center and radius, and the parameters of the circle are output;

[0009] Step S4: When a closed contour is determined to be a mixed primitive, a sliding window method is used to slide along the closed contour, and the sliding window length and contour point set information are recorded in the data dictionary. After the sliding window slides along the closed contour for one circle, its length is increased, and the sliding window continues to slide along the closed contour until the exit condition is met or the preset number of iterations is reached. The last sliding result is selected from the data dictionary as the contour point set of the straight line area to complete the identification of the straight line component.

[0010] Step S5, removing the straight line area contour point set identified in step S4, treating the remaining contour data as an arc area, performing connected domain analysis on the remaining contour point set, and treating it as a connected area containing an arc primitive;

[0011] Step S6: Fitting is performed on the straight line area and the arc area separated in step S5 respectively, and the straight line and arc graphic elements are output to complete the automatic recognition of the mixed graphic elements.

[0012] The present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method for automatically recognizing image primitives as described above is implemented.

[0013] The present invention also provides a storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to execute the above-mentioned method for automatically recognizing image primitives.

[0014] Beneficial effects: The method, device, and storage medium for automatic image primitive recognition provided by the present invention have the following beneficial effects:

[0015] By combining a sliding window with connected domain analysis, this paper can automatically and accurately separate and identify line and arc primitives in an image. Compared to the traditional method of manually drawing regions of interest and fitting them one by one, this automatic recognition method not only reduces the user's operational burden but also significantly improves recognition efficiency, demonstrating efficient and stable recognition results, especially in complex images containing multiple primitives. Furthermore, through the use of multi-scale sliding windows and eigenvalue determination technology, the paper reduces the possibility of misjudgment and makes recognition results more accurate.

[0016] The sliding window used in the present invention has multi-scale adaptive characteristics. The initial length of the sliding window can be set according to the ratio of the total length of the contour data and gradually enlarged during the iterative process, so that the present invention can adapt to the contours of primitives of different scales and complexities. In addition, by determining the width of the minimum circumscribed rectangle of the set of contour points in the rectangular sliding window, the robustness and applicability of the recognition are ensured. It can stably identify straight lines and arc areas when there are multiple primitives of different sizes in the image, effectively improving the adaptability of mixed primitive recognition. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for describing the embodiments or the prior art.

[0018] Figure 1 This is a flow chart of the method for automatically identifying image primitives according to the present invention;

[0019] Figure 2 This is a schematic diagram of the outline of an image after filtering processing in an embodiment of the present invention;

[0020] Figure 3a Schematic diagram of the contour of a single arc image after filtering in an embodiment of the present invention;

[0021] Figure 3b This is a schematic diagram of the fitting profile after least squares fitting is performed on a single arc diagram in an embodiment of the present invention;

[0022] Figure 4 is an enlarged schematic diagram of a portion of an image region in an embodiment of the present invention;

[0023] Figure 5a Schematic diagram of the minimum circumscribed rectangle formed under a small sliding window in an embodiment of the present invention;

[0024] Figure 5b Schematic diagram of marking of straight line components formed under a small sliding window in an embodiment of the present invention;

[0025] Figure 6a Schematic diagram of the minimum circumscribed rectangle formed under a medium sliding window in an embodiment of the present invention;

[0026] Figure 6b Schematic diagram of marking of straight line components formed under a medium sliding window in an embodiment of the present invention;

[0027] Figure 7a Schematic diagram of the minimum circumscribed rectangle formed under a large sliding window in an embodiment of the present invention;

[0028] Figure 7b Schematic diagram of marking of straight line components formed under a large sliding window in an embodiment of the present invention;

[0029] Figure 8 Schematic diagram of a sliding window at different positions during one iteration in an embodiment of the present invention;

[0030] Figure 9 A schematic diagram of performing straight line fitting on a set of straight line area contour points in an embodiment of the present invention;

[0031] Figure 10 A schematic diagram of a connected domain portion with straight line components removed in an embodiment of the present invention;

[0032] Figure 11 Schematic diagram of arc fitting based on a set of arc area contour points in an embodiment of the present invention. DETAILED DESCRIPTION

[0033] The present invention will be described more clearly and completely below by way of a preferred embodiment in conjunction with the accompanying drawings, but the present invention is not limited to the scope of the embodiment.

[0034] like Figure 1 As shown, the present invention provides an automatic image primitive recognition method, which specifically includes the following steps:

[0035] Step S1: input image data containing at least one closed contour, and filter the contour to remove noise points and abnormal points to obtain smooth contour data;

[0036] The primitive types of the present invention only include arcs and straight lines. The filtering process in step S1 adopts a mean filtering algorithm, specifically including taking the front and back values ​​of each point of the closed contour. n points and calculate the row and column averages to smooth the contour and reduce the impact of noise on the contour data, such as Figure 2 The image size shown is (4080, 3072). n=5 Schematic diagram of the contour after filtering, where the red line represents the fitted contour.

[0037] Step S2: Based on the filtered contour data, determine the type of the closed contour and identify whether it is a single arc or a mixed primitive containing an arc and a straight line. If it is determined to be a single arc, proceed to step S3; if it is determined to be a mixed primitive containing an arc and a straight line, proceed to step S4.

[0038] The type determination of the closed contour in step S2 includes the following steps:

[0039] S21. Calculate the minimum circumscribed circle radius of the closed contour Ra and the enclosed area Sa ;

[0040] S22. Calculate eigenvalues feature=Sa / Ra 2 , if the eigenvalue feature>2.8 , it is determined to be a single arc; if the eigenvalue feature<2.8 , it is determined to be a mixed primitive containing arcs and straight lines. Ideally feature The judgment value is 3.14, which is reserved for the accuracy of the judgment.

[0041] Step S3: When the closed contour is determined to be a single arc, the arc contour is fitted to obtain parameter information of the circle center and radius, and the parameters of the circle are output;

[0042] Here, the least square method is used to fit the prototype contour. The center coordinates and radius of the arc are obtained during the fitting process. These parameters are output as the final recognition results to complete the recognition of a single arc primitive. Figure 3aand Figure 3b These are the contour diagrams of a single arc image after mean filtering and the contour diagrams of the arc image after fitting using the least squares method.

[0043] When the contour is a mixed primitive containing arcs and straight lines, contour filtering is performed first, followed by differentiation between arc and straight line components. The present invention assumes that the mixed primitive contains only arc and straight line components, and no other components. The arc in the present invention refers to both arc and circle components. A circle is a special type of arc, i.e., one with a 360-degree arc. The present invention prioritizes the determination of the straight line component.

[0044] The difficulty in distinguishing between arcs and straight lines lies in the following: First, when the image size is fixed, the outline of a large workpiece is larger, while the outline of a small workpiece is smaller. Using one algorithm cannot fully adapt to outlines of different sizes, and parameter adjustment is required, so it cannot automatically and stably identify arc and straight line components; second, there are also difficulties in recognition within the same outline. Analogous to calculus thinking, if an arc is cut finely enough, that is, enlarged to a large enough scale, the "arc" becomes a "straight line". Figure 4 As shown, due to the different scales, using the same algorithm, without adjusting the parameters, Figure 4 The leftmost contour will be recognized as an arc. Figure 4 The rightmost contour will be recognized as a straight line, but they are the same area of ​​the image, just with different scaling. The method provided by the present invention can solve the recognition problem caused by continuous spatial scale changes.

[0045] Step S4: When a closed contour is determined to be a mixed primitive, a sliding window method is used to slide along the closed contour, and the window length and point set information are recorded in the data dictionary. After the sliding window slides along the closed contour for one circle, its length is increased, and the sliding window continues to slide along the closed contour until the exit condition is met or the preset number of iterations is reached. The last sliding result is selected from the data dictionary as the contour point set of the straight line area to complete the identification of the straight line component.

[0046] Step S4 specifically includes the following steps:

[0047] S41, setting an initial length of the sliding window, and sliding it step by step along the closed contour. There is an overlap between two adjacent sliding windows, and the shape of the sliding window is rectangular. The initial length of the rectangular sliding window can be set to 1 / 100 of the total length of the closed contour;

[0048] S42, generating an angled minimum circumscribed rectangle within the rectangular sliding window at each sliding position;

[0049] In one embodiment, the preset threshold value of the minimum bounding rectangle width is m pixels, m∈(10,20),m The value range is obtained based on experience.

[0050] The method for generating the minimum enclosing rectangle with angle is as follows:

[0051] S421, at each sliding position, perform linear fitting on the contour point set within the sliding window to obtain a fitting line L ;

[0052] S422, calculate the contour point set in the sliding window on the fitting line L Maximum distance on both sides in the length direction d 1 and d 2 The two sides here are different depending on the position of the sliding window, which may be a straight line L The left and right sides may also be straight lines L The upper and lower sides of the , and generate a minimum enclosing rectangle with an angle, the width of which is d 1 +d 2 , The length is the length of the intersection segment between the straight line L and the sliding window.

[0053] S43. If the width of the minimum bounding rectangle is less than a preset threshold, the point set within the sliding window is determined to be a straight line component, and the length of the window and the contour point set information are recorded in a data dictionary, where the length of the sliding window serves as the key of the data dictionary and the contour point set serves as the value of the data dictionary;

[0054] S44, after the sliding window slides along the closed contour for one circle, the rectangular sliding window length is increased according to a preset multiple method, and the sliding continues along the closed contour;

[0055] S45, repeating steps S42 to S44 until an exit condition is met or a preset number of iterations is reached, that is, the width of the minimum bounding rectangle exceeds a preset threshold, and the sliding ends;

[0056] In one embodiment, the sliding window length is enlarged by 1.2 times. After each iteration, that is, after the sliding window slides along the closed contour for one circle, the sliding window is enlarged once. The sliding step size of the sliding window is fixed and is always 0.8 times the initial length of the sliding window.

[0057] In one embodiment, the default number of iterations is 10, and the jump-out condition is that the width of the smallest circumscribed rectangle formed by the contour point set is less than m pixels, m∈(10,20) , but there is no set of contour points that can satisfy the requirement under a larger sliding window.

[0058] S46. Select the last sliding result from the data dictionary as the contour point set of the straight line area to complete the recognition of the straight line component.

[0059] like Figures 5a-7b The diagrams show the minimum bounding rectangles under small sliding windows, medium sliding windows, and large sliding windows, as well as the straight line component markings after one iteration. The large rectangle in the figure represents the sliding window, the small rectangle represents the minimum bounding rectangle, and the × represents the straight line component. Figure 8 The figure shows a schematic diagram of the sliding windows at different positions during an iteration. It can be seen from the figure that the sizes of the sliding windows in the same iteration are equal.

[0060] Step S5, removing the straight line area contour point set identified in step S4, treating the remaining contour data as an arc area, performing connected domain analysis on the remaining contour point set, and treating it as a connected area containing an arc primitive;

[0061] Step S5 specifically includes the following steps:

[0062] S51, cutting out the contour point set of the straight line area identified in step S4 from the filtered contour data to obtain remaining contour data;

[0063] S52, performing connected domain analysis on the remaining contour data after removing the straight line components to identify the set of contour points connected to each other, such as Figure 10 The figure shows the connected domain analysis after the straight line components are removed;

[0064] S53. In the connected domain analysis, the number of connected domains is calculated, and each connected domain is further checked to ensure that the contour data of the connected domain is complete and conforms to the arc feature;

[0065] S54: Using the connected area that meets the arc feature as the contour data of the arc component for subsequent fitting processing.

[0066] Step S6: Fitting is performed on the straight line area and the arc area separated in step S5 respectively, and the straight line and arc graphic elements are output to complete the automatic recognition of the mixed graphic elements.

[0067] Step S6 specifically includes the following steps:

[0068] S61. For each line component point identified in step S4, generate an angled minimum bounding rectangle. If there are multiple minimum bounding rectangles for some line component points, perform a union operation on these minimum bounding rectangles to generate one or more connected union minimum bounding rectangles.

[0069] S62, treating each minimum bounding rectangle after the union as an independent fitting region, and extracting all contour point sets within these regions. This operation ensures that the contour points related to each straight line component are completely extracted, and avoids missing any point set in the straight line region;

[0070] S63, perform linear fitting on the contour point set in each independent fitting area to obtain the fitting straight line primitive of the area, such as Figure 9 The figure shows a schematic diagram of the image after straight line fitting;

[0071] S64. After removing the straight line component, the remaining contour point set is a circle or arc area. Least squares fitting is performed on these remaining contour points to complete the recognition of the circular primitive, such as Figure 11 The figure shows a schematic diagram after fitting using the least squares method;

[0072] S65. Output the fitting result to complete the recognition of the straight line and arc graphics.

[0073] The present invention also provides a storage medium storing computer-executable instructions for executing any of the above-described methods for automatically recognizing image primitives. The storage medium includes any medium capable of storing program code, such as a USB flash drive, a mobile hard drive, ROM, RAM, a magnetic disk, or an optical disk.

[0074] The present invention also provides a computer program product comprising instructions, which, when executed on a computer, enable the computer to execute the above-described method for automatically recognizing image primitives, wherein the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.

[0075] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for automatically recognizing image primitives, characterized in that: The following steps are involved: Step S1: input image data containing at least one closed contour, and filter the contour to remove noise points and abnormal points to obtain smooth contour data; Step S2: Based on the filtered contour data, determine the type of the closed contour and identify whether it is a single arc or a mixed primitive containing an arc and a straight line. If it is determined to be a single arc, proceed to step S3; if it is determined to be a mixed primitive containing an arc and a straight line, proceed to step S4. Step S3: When the closed contour is determined to be a single arc, the arc contour is fitted to obtain parameter information of the circle center and radius, and the parameters of the circle are output; Step S4: When a closed contour is determined to be a mixed primitive, a sliding window method is used to slide along the closed contour, and the sliding window length and contour point set information are recorded in the data dictionary. After the sliding window slides along the closed contour for one circle, its length is increased, and the sliding window continues to slide along the closed contour until the exit condition is met or the preset number of iterations is reached. The last sliding result is selected from the data dictionary as the contour point set of the straight line area to complete the identification of the straight line component. Step S5, removing the straight line area contour point set identified in step S4, treating the remaining contour data as an arc area, performing connected domain analysis on the remaining contour point set, and treating it as a connected area containing an arc primitive; Step S6: performing fitting processing on the straight line area and the arc area separated in step S5, outputting straight line and arc primitives, and completing automatic recognition of mixed primitives; Step S4 specifically includes the following steps: S41, setting the initial length of the sliding window, and sliding it step by step along the closed contour, with overlapping parts between two adjacent sliding windows and the shape of the sliding window being a rectangle; S42, generating an angled minimum circumscribed rectangle within the sliding window at each sliding position; S43, if the width of the minimum circumscribed rectangle is less than a preset threshold, the contour point set within the sliding window is determined to be a straight line component, and the length of the sliding window and the contour point set information are recorded in the data dictionary; S44, after the sliding window slides along the closed contour for one circle, the sliding window length is enlarged by a preset multiple, and the sliding window continues to slide along the closed contour; S45, repeating steps S42 to S44 until an exit condition is met or a preset number of iterations is reached. The exit condition is that the width of the minimum bounding rectangle exceeds a preset threshold, and the sliding ends. S46. Select the last sliding result from the data dictionary as the contour point set of the straight line area to complete the recognition of the straight line component.

2. The method for automatically recognizing image primitives according to claim 1, characterized in that: The filtering process in step S1 adopts the mean filtering algorithm, which specifically includes taking the front and back values ​​of each point of the closed contour n points and calculate the row and column averages to smooth the contour and reduce the impact of noise on the contour data.

3. The method for automatically recognizing image primitives according to claim 1, wherein: The type determination of the closed contour in step S2 includes the following steps: S21. Calculate the minimum circumscribed circle radius of the closed contour Ra and the enclosed area Sa ; S22. Calculate eigenvalues feature=Sa / Ra 2 , if the eigenvalue feature>2.8 , it is determined to be a single arc; if the eigenvalue feature<2.8 , it is determined to be a mixed primitive containing arcs and straight lines.

4. The method for automatically recognizing image primitives according to claim 1, wherein: The method for generating the minimum enclosing rectangle with angle is as follows: S421, at each sliding position, perform linear fitting on the contour point set within the sliding window to obtain a fitting line L ; S422, calculate the contour point set in the sliding window on the fitting line L Maximum distance on both sides in the length direction d 1 and d 2 , and generate a minimum enclosing rectangle with an angle, whose width is d 1 +d 2 , The length is the length of the intersection segment between the straight line L and the sliding window.

5. The method for automatically recognizing image primitives according to claim 1, wherein: The initial length of the sliding window is set to 1 / 100 of the total length of the closed contour. After each sliding operation, the sliding window length is enlarged by 1.2 times, and the sliding step size of the sliding window is fixed, which is 0.8 times the initial length of the sliding window.

6. The method for automatically recognizing image primitives according to claim 1, wherein: The preset threshold for the minimum bounding rectangle width is m pixels, m∈(10,20) .

7. The method for automatically recognizing image primitives according to claim 1, wherein: Step S5 specifically includes the following steps: S51, cutting out the contour point set of the straight line area identified in step S4 from the filtered contour data to obtain remaining contour data; S52, performing connected domain analysis on the remaining contour data after the straight line components are removed to identify a set of contour points connected to each other; S53. In the connected domain analysis, the number of connected domains is calculated, and each connected domain is further checked to ensure that the contour data of the connected domain is complete and conforms to the arc feature; S54: Using the connected area that meets the arc feature as the contour data of the arc component for subsequent fitting processing.

8. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for automatically recognizing image primitives as claimed in any one of claims 1 to 7 is implemented.

9. A storage medium, characterized in that: Computer-executable instructions are stored, and the computer-executable instructions are used to execute the method for automatically recognizing image primitives according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method and device for visually detecting tolerance of large-size workpiece and computing equipment

    CN110288651A

  • Curve recognition method and system based on multi-scale operation

    CN114092910A