Image primitive automatic identification method and device and storage medium

Through the combination of automated recognition algorithm and sliding window and connecting domain analysis, the automatic recognition of straight lines and arc elements in the image is realized, solving the problem of inefficiency of traditional methods and improving the recognition efficiency and accuracy.

CN119478537AActive Publication Date: 2025-02-18NANJING KAISHIMAI TECH CO LTD +2
View PDF 7 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Traditional image element recognition methods require a lot of manual operations, especially when multiple elements are included in complex images, it is less efficient, making it difficult to achieve automatic recognition and automatic measurement.

Method used

An automated recognition algorithm is used to automatically segment and fit straight lines and arc primitives in the image through the combination of sliding window and connecting domain analysis.

Benefits of technology

It significantly improves the efficiency and accuracy of image element recognition, reduces user operation burden, and especially shows efficient and stable recognition effects in complex images.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119478537A_ABST
    Figure CN119478537A_ABST
Patent Text Reader

Abstract

The invention discloses an image primitive automatic identification method and device and a storage medium, and the method comprises the following steps: firstly inputting image data containing a closed contour, and carrying out the filtering processing of the contour to remove noise; then, the contour type is judged through feature value calculation, and a single circle or a mixed primitive containing a straight line and an arc is distinguished; when a single circle is judged, circle fitting is directly carried out on the single circle, and circle parameters are output; when the primitive is a mixed primitive, a sliding window method is adopted to identify a straight line component, after the straight line component is cut off, connected domain analysis is carried out on a residual point set, and an arc region is extracted; and finally, fitting the straight line area and the arc area respectively to obtain parameters of the straight line and the circle. The method can automatically separate and recognize the straight line and arc primitives in the image, reduces manual operation, and improves the recognition precision 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 an automatic recognition method, device and storage medium for image primitives. Background Art

[0002] In machine vision applications, object measurement and geometric primitive recognition are common tasks. Traditional recognition methods usually rely on users to manually draw the region of interest and then fit the corresponding circle or line. This method is stable and reliable, but it requires a lot of time and manual operation, especially when there are multiple primitives in complex images. The efficiency is low. Specifically, in an image containing multiple basic primitives (such as arcs and lines), users need to repeatedly draw the region of interest corresponding to each primitive, which is cumbersome and time-consuming. Automatically identifying geometric primitives in images and realizing automatic measurement is an important direction to improve efficiency. Summary of the invention

[0003] Technical purpose: In view of the shortcomings of existing image primitive recognition, the present invention discloses an automatic image primitive recognition method, device and storage medium, which automatically segments and fits the straight line and arc primitives in the image through an automated recognition algorithm to improve recognition efficiency and accuracy.

[0004] Technical solution: To achieve the above technical objectives, the present invention adopts the following technical solution: A method for automatically identifying image primitives comprises the following steps: Step S1, inputting image data containing at least one closed contour, and filtering 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, fitting the arc contour is performed to obtain parameter information of the 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 a 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 recognition 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 a connected domain analysis on the remaining contour point set, and treating it as a connected area containing an arc primitive; Step S6, respectively perform fitting processing on the straight line area and arc area separated in step S5, output straight line and arc graphic elements, and complete the automatic recognition of mixed graphic elements.

[0005] 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, wherein the processor implements an automatic image primitive recognition method as described above when executing the program.

[0006] 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 identifying image primitives.

[0007] Beneficial effects: The method, device and storage medium for automatically identifying image primitives provided by the present invention have the following beneficial effects: The present invention can automatically and accurately separate and identify straight lines and arcs in an image by introducing a combination of sliding windows and connected domain analysis. Compared with the traditional method of manually drawing regions of interest and fitting them one by one, the automatic recognition method of the present invention not only reduces the user's operating burden, but also significantly improves the recognition efficiency, especially in complex images containing multiple primitives, showing efficient and stable recognition effects. At the same time, the present invention reduces the possibility of misjudgment through multi-scale sliding windows and eigenvalue determination technology, making the recognition result more accurate.

[0008] The sliding window adopted in the present invention has a multi-scale adaptive characteristic. 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 iteration 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 contour point set in the rectangular sliding window, the robustness and applicability of the recognition are ensured, and straight lines and arc areas can be stably identified when there are multiple primitives and different sizes in the image, effectively improving the adaptability of mixed primitive recognition. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below.

[0010] Figure 1 It is a flow chart of the method for automatically identifying image primitives of the present invention; Figure 2 It is a schematic diagram of the contour of an image after filtering processing in an embodiment of the present invention; Figure 3a This is a schematic diagram of the contour of a single arc image after filtering in an embodiment of the present invention; Figure 3b It 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; Figure 4 is a schematic diagram of an enlarged portion of an image region in an embodiment of the present invention; Figure 5a Schematic diagram of the minimum circumscribed rectangle formed under the small sliding window in an embodiment of the present invention; Figure 5b This is a schematic diagram of marking straight line components formed under a small sliding window in an embodiment of the present invention; Figure 6a Schematic diagram of the minimum circumscribed rectangle formed under a medium sliding window in an embodiment of the present invention; Figure 6b This is a schematic diagram of marking straight line components formed under a medium sliding window in an embodiment of the present invention; Figure 7a Schematic diagram of the minimum circumscribed rectangle formed under a large sliding window in an embodiment of the present invention; Figure 7b This is a schematic diagram of marking straight line components formed under a large sliding window in an embodiment of the present invention; Figure 8 This is a schematic diagram of a sliding window at different positions during one iteration of an embodiment of the present invention; Fig. 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; Fig.10 A partial schematic diagram of a connected domain with straight line components removed in an embodiment of the present invention; Fig.11 It is a schematic diagram of arc fitting of an arc region contour point set in an embodiment of the present invention. DETAILED DESCRIPTION

[0011] 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.

[0012] like Figure 1 As shown, the present invention provides an automatic recognition method for image primitives, which specifically includes the following steps: Step S1, inputting image data containing at least one closed contour, and filtering the contour to remove noise points and abnormal points to obtain smooth contour data; 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.

[0013] 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; 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 judged as a single arc; if the eigenvalue feature<2.8 , it is judged as 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.

[0014] Step S3: when the closed contour is determined to be a single arc, fitting the arc contour is performed to obtain parameter information of the center and radius, and the parameters of the circle are output; Here, the least square method is used to fit the prototype contour. The coordinates of the center and radius of the arc are obtained during the fitting process. These parameters are output as the final recognition result to complete the recognition of a single arc primitive. Figure 3a and Figure 3b They are respectively a schematic diagram of the contour after mean filtering of a single arc image and a schematic diagram of the contour after arc contour fitting using the least squares method.

[0015] When the contour is a mixed primitive containing an arc and a straight line, contour filtering is performed first, and then the arc component and the straight line component are distinguished. The present invention assumes that the mixed primitive only contains two components, an arc and a straight line, and does not contain other components. The arc in the present invention refers to two components, an arc and a circle. The circle is a special arc, that is, an arc with an arc of 360 degrees. The present invention prioritizes the straight line component.

[0016] The difficulty in distinguishing arcs and straight lines is that: first, when the image size is fixed, the contour of a large workpiece is larger, and the contour of a small workpiece is smaller. Using one algorithm cannot fully adapt to contours of different sizes, and parameter adjustment is required, so it is not possible to automatically and stably identify arc and straight line components; second, there are also difficulties in identification within the same contour. 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 in Figure 2, due to the different scales, the same algorithm is used without adjusting the parameters. Figure 4 The leftmost contour will be recognized as an arc. Figure 4 The rightmost contour in the image 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.

[0017] 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 a 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 recognition of the straight line component. Step S4 specifically includes the following steps: S41, setting an initial length of the sliding window, and sliding step by step along the closed contour, there is an overlapping part between two adjacent sliding windows and the shape of the sliding window is a rectangle, and the initial length of the rectangular sliding window can be set to 1 / 100 of the total length of the closed contour; S42, generating a minimum circumscribed rectangle with an angle in the rectangular sliding window at each sliding position; 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.

[0018] The method for generating the minimum enclosing rectangle with angle is as follows: S421, at each sliding position, linear fitting is performed on the contour point set in the sliding window to obtain a fitting straight line L ; S422, calculate the contour point set in the sliding window on the fitting line L Maximum distance on both sides in 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 LThe 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, whose width is d 1 +d 2 , The length is the length of the intersection segment of the straight line L and the sliding window.

[0019] S43, if the width of the minimum circumscribed rectangle is less than a preset threshold, the point set in 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, wherein the length of the sliding window is used as the key of the data dictionary, and the contour point set is used as the value of the data dictionary; 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; S45, repeatedly executing step S42 to step S44 until the exit condition is met or the preset number of iterations is reached, that is, the width of the minimum bounding rectangle exceeds the preset threshold, and the sliding ends; In one embodiment, the sliding window length is enlarged by 1.2 times, and the sliding window is enlarged once after each iteration, that is, after the sliding window slides along the closed contour for one circle. The sliding step length of the sliding window is fixed and is always 0.8 times the initial length of the sliding window.

[0020] In one embodiment, the default number of iterations is preset to 10 times, 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.

[0021] 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.

[0022] like Figure 5a-7b The following diagrams show the minimum bounding rectangles for small, medium, and large sliding windows, as well as the straight line component markers after one iteration. The large rectangle 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 all equal.

[0023] Step S5, removing the straight line area contour point set identified in step S4, treating the remaining contour data as an arc area, performing a connected domain analysis on the remaining contour point set, and treating it as a connected area containing an arc primitive; 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 the 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, such as Fig.10 The figure shows the schematic diagram of the connected domain analysis after the straight line components are removed; 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.

[0024] Step S6, respectively perform fitting processing on the straight line area and arc area separated in step S5, output straight line and arc graphic elements, and complete the automatic recognition of mixed graphic elements.

[0025] Step S6 specifically includes the following steps: S61, for each line component point identified in step S4, a minimum circumscribed rectangle with an angle is generated. If there are multiple minimum circumscribed rectangles for some line component points, a union operation is performed on these minimum circumscribed rectangles to generate one or more connected union minimum circumscribed rectangles; S62, treating each minimum bounding rectangle after taking the union as an independent fitting area, extracting all contour point sets in these areas, 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 area; S63, perform linear fitting on the contour point set in each independent fitting region to obtain the fitting straight line primitive of the region, such as Fig. 9 The figure shows a schematic diagram of the image after straight line fitting; S64, after the straight line components are removed, the remaining contour point set is a circular or arc area, and the least squares fitting is performed on these remaining contour points to complete the recognition of the circular primitive, such as Fig.11 The figure shows a schematic diagram after fitting using the least squares method; S65. Output the fitting result to complete the recognition of straight line and circular arc primitives.

[0026] The present invention also provides a storage medium storing computer executable instructions for executing any of the above-mentioned methods for automatically identifying image primitives. The storage medium includes: a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk, or an optical disk, etc., which can store program codes.

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

[0028] 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 principle 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, inputting image data containing at least one closed contour, and filtering 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, fitting the arc contour is performed to obtain parameter information of the 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 a 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 recognition 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 a connected domain analysis on the remaining contour point set, and treating it as a connected area containing an arc primitive; Step S6, respectively perform fitting processing on the straight line area and arc area separated in step S5, output straight line and arc graphic elements, and complete the automatic recognition of mixed graphic elements.

2. The method for automatically identifying 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, characterized in that: 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 judged as a single arc; if the eigenvalue feature<2.8 , it is judged as a mixed primitive containing arcs and straight lines.

4. The method for automatically identifying image primitives according to claim 1, characterized in that: Step S4 specifically includes the following steps: S41, setting the initial length of the sliding window, and sliding the sliding window step by step along the closed contour, wherein there is an overlapping part between two adjacent sliding windows and the shape of the sliding window is a rectangle; S42, generating an angled minimum circumscribed rectangle in 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 in 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 according to a preset multiple, and the sliding window continues to slide along the closed contour; S45, repeatedly executing step S42 to step S44 until the exit condition is met or the preset number of iterations is reached, and the exit condition is that the width of the minimum circumscribed rectangle exceeds the 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.

5. The method for automatically identifying image primitives according to claim 4, characterized in that: The method for generating the minimum enclosing rectangle with angle is as follows: S421, at each sliding position, linear fitting is performed on the contour point set in the sliding window to obtain a fitting straight line L ; S422, calculate the contour point set in the sliding window on the fitting line L Maximum distance on both sides in 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 of the straight line L and the sliding window.

6. The method for automatically identifying image primitives according to claim 4, characterized in that: 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 length of the sliding window 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.

7. The method for automatically recognizing image primitives according to claim 4, characterized in that: The preset threshold of the minimum bounding rectangle width is m pixels, m∈(10,20) .

8. The method for automatically identifying image primitives according to claim 1, characterized in that: 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 the 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.

9. An electronic device, characterized in that: The invention 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, an automatic image primitive recognition method as claimed in any one of claims 1 to 8 is implemented.

10. A storage medium, characterized in that: Computer executable instructions are stored, and the computer executable instructions are used to execute an automatic image primitive recognition method as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Industrial profile geometric dimension automatic detection method based on computer vision imaging

    CN109658402A

  • 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

  • Linear segment contour extraction method

    CN114612496A

  • Contour point set extraction method and device, electronic equipment and storage medium

    CN117788502A