Legend recognition method, device and electronic equipment
By identifying the shape categories and topological relationships of the primitives, the problem of low legend recognition accuracy is solved, and efficient recognition is achieved even when legends are scaled or deformed.
Patent Information
- Application Number
- CN202210458927.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-27
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-04-27
AI Technical Summary
In existing technologies, the accuracy of legend recognition is relatively low, especially after legends are scaled or combined, which makes accurate recognition difficult and affects recognition efficiency.
By identifying the shape categories of the primitives, the target topological relationship is established, and the topological relationship to be identified is determined by using the bounding rectangle and text content, and then matching is performed to determine the legend recognition result.
It improves the accuracy and efficiency of legend recognition, and can adapt to legends that are rotated, mirrored, or deformed, thus reducing the amount of data processing.
Smart Images

Figure CN117011358B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer-aided design technology, and more specifically to a method, apparatus, and electronic device for legend recognition. Background Technology
[0002] With the continuous development and popularization of computer technology, more and more computer technologies are gradually being integrated into daily production and life. As an early and relatively mature computer technology, CAD drafting is increasingly widely used in the construction field. Architectural design drawings serve as the design prototypes of buildings. Reviewing these drawings before construction can effectively avoid some problems or safety hazards after construction is completed and put into use, thus effectively ensuring the overall quality of the building. Therefore, intelligent CAD drawing review has emerged. At the same time, the drawing review industry has placed higher demands on the computer's ability to quickly and accurately interpret drawings. In the process of computer-aided drawing interpretation, legend recognition is particularly important, especially in the electromechanical field, where legends are diverse and their attributes and meanings are particularly important.
[0003] Current technologies for legend recognition often employ block reference (blocks are composed of basic elements such as lines, fills, and text) and strict reference to feature element size information. However, in actual drawings, most legends are presented in block reference form, meaning all elements belonging to a legend are grouped into a set. During subsequent editing, these originally grouped elements are broken up. If the legend is then searched for based on the element set, the corresponding set cannot be found, leading to recognition failure and affecting accuracy. Furthermore, if the legend is scaled, searching for elements based on the scaled dimensions will not yield related elements. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a legend recognition method, apparatus, and electronic device to solve the problem of low legend recognition accuracy.
[0005] According to a first aspect, embodiments of the present invention provide a legend recognition method, including:
[0006] Obtain the target topological relationship of the target legend and the legend to be identified. The target topological relationship is the positional relationship between the first target shape category composed of target elements in the target legend and other elements in the target legend.
[0007] The shape categories composed of each graphic element in the image to be identified are identified to determine all shape categories in the image to be identified.
[0008] Search among all shape categories for a second target shape category that is the same as the first target shape category;
[0009] Based on the second target shape category and the positional relationships of other elements in the legend to be identified, the topological relationship to be identified is determined;
[0010] The target topological relationship is matched with the topological relationship to be identified to determine the legend recognition result.
[0011] The legend recognition method provided in this embodiment of the invention identifies each graphic element during drawing recognition and then uses the shape category composed of the graphic elements as the basis for legend recognition, which ensures the accuracy of legend recognition. Furthermore, by using the shape category to narrow the matching range, the amount of data processing is reduced, and the efficiency of legend recognition is improved.
[0012] In conjunction with the first aspect, in the first embodiment of the first aspect, determining the topological relationship to be identified based on the shape category of the second target graphic element and the positional relationships of other graphic elements in the graphic element to be identified includes:
[0013] Obtain the first bounding rectangle of the second target shape category and the second bounding rectangles of other shape categories in the illustration to be identified;
[0014] The topological relationship to be identified is determined based on the positional relationship between the first circumscribed rectangle and each of the second circumscribed rectangles.
[0015] The legend recognition method provided in this embodiment of the invention can accurately determine the position of each shape category by using the circumscribed rectangle method, since there may be irregular shapes in other shape categories of the legend to be recognized, and their position points are difficult to determine accurately.
[0016] In conjunction with the first embodiment of the first aspect, in the second embodiment of the first aspect, determining the topological relationship to be identified based on the positional relationship between the first circumscribed rectangle and each of the second circumscribed rectangles includes:
[0017] Based on the positional relationship between the first bounding rectangle and each of the second bounding rectangles, the distance and included angle between the first bounding rectangle and each of the second bounding rectangles are determined;
[0018] When there are filled primitives in the other shape categories, calculate the area ratio of the corresponding second bounding rectangle to the first bounding rectangle;
[0019] When a text element exists in one of the other shape categories, the text content of the text element is obtained.
[0020] The topological relationship to be identified is formed based on the distance, included angle, area ratio, and text content.
[0021] The legend recognition method provided in this invention includes included angles in the topological relationship to be recognized, which enables the identification of deformations such as rotation and mirroring during subsequent topological relationship matching, thereby improving the accuracy of legend recognition; and by combining text content and fill area ratio, the accuracy of legend recognition is further guaranteed.
[0022] In conjunction with the second embodiment of the first aspect, in the third embodiment of the first aspect, the step of forming the topological relationship to be identified based on the distance, included angle, area ratio, and text content includes:
[0023] Using the distance, included angle, area ratio, and text content, topological units of other corresponding shape categories are formed;
[0024] The topological units are classified based on their corresponding shape categories to determine the topological relationships to be identified.
[0025] The legend recognition method provided in this invention obtains the corresponding topological units for each shape category, and constructs the topological relationship to be recognized as a whole, which simplifies the topological relationship to be recognized; at the same time, classifying the topological units reduces the amount of data processing for subsequent matching and improves the efficiency of legend recognition.
[0026] In conjunction with the first aspect, in the fourth embodiment of the first aspect, the step of matching the target topological relationship with the topological relationship to be identified to determine the legend recognition result includes:
[0027] Obtain the second category of shape categories in the topological relationship to be identified, and the second quantity under each category;
[0028] The second category and the second quantity are matched with the corresponding first category and the first quantity in the target topology relationship to determine the legend recognition result.
[0029] The legend recognition method provided in this invention uses type and quantity for matching, which can quickly filter out the topological relationships to be identified that do not match the target topological relationship, thus improving the efficiency of legend recognition.
[0030] In conjunction with the fourth embodiment of the first aspect, in the fifth embodiment of the first aspect, the target topological relationship includes the included angle, area ratio, and text content between the first bounding rectangle of the second target shape category and the second bounding rectangle of the other shape categories. The step of matching the second type and the second quantity with the corresponding first type and first quantity in the target topological relationship to determine the legend recognition result includes:
[0031] When the first type matches the second type and the first quantity matches the second quantity, compare whether the included angle in the topological relationship to be identified is consistent with the included angle in the target topological relationship.
[0032] When there is a discrepancy, calculate the deviation between the included angle in the topological relationship to be determined and the corresponding included angle in the target topological relationship, and determine whether the deviation is within a preset range;
[0033] When the deviation is within the preset range, and the area ratio and text content in the topological relationship to be identified are consistent with the corresponding area ratio and text content in the target topological relationship, it is determined that the legend to be identified matches the target legend.
[0034] The legend recognition method provided in this embodiment of the invention combines angle deviation with angle matching, making the recognition method applicable to legends that are deformed such as mirrored or rotated, thus improving the accuracy of legend recognition.
[0035] In conjunction with the fourth embodiment of the first aspect, in the sixth embodiment of the first aspect, the step of matching the target topological relationship with the topological relationship to be identified to determine the legend recognition result further includes:
[0036] Obtain the first bounding rectangle of the first target shape category and the second bounding rectangle of the second target shape category;
[0037] The first bounding rectangle and the second bounding rectangle are scaled respectively to obtain a first target rectangle containing all the elements in the target legend and a second target rectangle containing all the elements in the legend to be identified, and a first scaling ratio, a second scaling ratio, a first length of the preset side length in the first target rectangle and a second length of the preset side length in the second target rectangle are determined.
[0038] The legend recognition result is determined based on the relationship between the first scaling ratio and the second scaling ratio, as well as the size relationship between the first length and the second length.
[0039] The legend recognition method provided in this invention uses scaling ratio and length for matching, which can quickly filter out the topological relationships to be identified that do not match the target topological relationship, thus improving the efficiency of legend recognition.
[0040] According to a second aspect, embodiments of the present invention also provide a legend recognition device, comprising:
[0041] The acquisition module is used to acquire the target topological relationship of the target legend and the legend to be identified. The target topological relationship is the positional relationship between the first target shape category composed of target elements in the target legend and other elements in the target legend.
[0042] A recognition model is used to identify the shape categories composed of each graphic element in the image to be recognized, and to determine all shape categories in the image to be recognized;
[0043] The search module is used to search for a second target shape category that is the same as the first target shape category among all the shape categories;
[0044] The determination module is used to determine the topological relationship to be identified based on the second target shape category and the positional relationship of other elements in the legend to be identified;
[0045] The matching module is used to match the target topological relationship with the topological relationship to be identified to determine the legend recognition result.
[0046] According to a third aspect, embodiments of the present invention provide an electronic device, including: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the legend recognition method described in the first aspect or any embodiment of the first aspect.
[0047] According to a fourth aspect, embodiments of the present invention provide a computer-readable storage medium storing computer instructions for causing the computer to perform the legend recognition method described in the first aspect or any embodiment of the first aspect.
[0048] It should be noted that the corresponding beneficial effects of the legend recognition device, electronic device and computer-readable storage medium provided in the embodiments of the present invention can be found in the description of the corresponding beneficial effects of the legend recognition method above, and will not be repeated here. Attached Figure Description
[0049] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0050] Figures 1a-1b This is a schematic diagram of two legends that have a scaling relationship;
[0051] Figure 2 This is a flowchart of a legend recognition method according to an embodiment of the present invention;
[0052] Figure 3 This is a flowchart of a legend recognition method according to an embodiment of the present invention;
[0053] Figure 4 This is a schematic diagram illustrating the construction of topological relationships according to an embodiment of the present invention;
[0054] Figure 5 This is a flowchart of a legend recognition method according to an embodiment of the present invention;
[0055] Figure 6 This is a structural block diagram of a legend recognition device according to an embodiment of the present invention;
[0056] Figure 7 This is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0057] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0058] The method of treating the entire legend as a block of data for legend recognition involves first analyzing the components within the block, including the geometric feature vectors and text feature vectors of the block data. Then, templates are created based on these templates. Finally, all block data in the entire drawing are traversed to find blocks that match the templated information; these are the legends to be recognized. However, in some scenarios, due to different drawing habits of designers, or because designers forget to perform the necessary operations to combine the legend elements into block data, recognition may fail.
[0059] For legend recognition methods that strictly reference the size information of feature primitives, the first step is to select the primitives to be compared from the legend to be recognized. Then, the geometric relationships of the corresponding primitives are compared under operations such as rotation and mirroring. Geometric relationships include: for straight lines, the length must be the same; for arcs, the radius and angle range must be the same, etc. When the geometric information of all components in the legend can be successfully matched, the combination of these primitives is considered a legend to be recognized. Due to different design habits and styles of designers, the dimensions of the same legend in different drawings, or even different objects of the same legend in the same drawing, may differ, resulting in legend size scaling. For example, Figure 1a Legend 1 and Figure 1bThe two illustrations are identical, but due to the size scaling between them, the illustration recognition method that strictly references the size information of the feature primitives cannot identify that they are the same illustration.
[0060] Based on this, the legend recognition method provided in this embodiment of the invention is based on the shape categories composed of graphic elements. Specifically, after importing the drawing, the electronic device parses the drawing to obtain the categories of each graphic element in the drawing, such as line graphic elements, point graphic elements, text graphic elements, and filled graphic elements, etc. Among them, line graphic elements and point graphic elements can form various shape categories, such as circles, triangles, rectangles, filled graphic elements, and text graphic elements, etc. This method of analyzing the shape categories composed of graphic elements can reduce the amount of data processing; and for the shape categories enclosed by graphic elements, if there are scaling issues, the changes of each shape category in the same legend are consistent, for example, the length has a scaling ratio, the angle has a rotation angle deviation, etc. Therefore, the method of legend recognition based on the shape categories composed of graphic elements can improve the accuracy and efficiency of legend recognition.
[0061] According to an embodiment of the present invention, a legend recognition method embodiment is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0062] This embodiment provides a legend recognition method that can be used in electronic devices such as computers, tablets, and servers. Figure 2 This is a flowchart of a legend recognition method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps:
[0063] S11, obtain the target topological relationship of the target legend and the legend to be identified.
[0064] The target topology relationship refers to the positional relationship between the first target shape category composed of target elements in the target legend and other elements in the target legend.
[0065] Specifically, the first target shape category is used as the basic shape category for establishing the target topology relationship. The target topology relationship is established based on the positional relationships between other elements in the target legend and this first target shape category. The positional relationships with other elements in the target legend include the positional relationships between each other element in the target legend and the first target shape category, or the positional relationships between the elements and the shape categories formed by the other elements in the target legend. The determination of the first target shape category can be achieved by setting priorities for each shape category; after shape category identification of the target legend, the shape category with the highest priority is determined as the first target shape category. Besides using priority to determine the target shape category, other methods can be set, etc., without any restrictions.
[0066] Regarding the positional relationships between other graphic elements in the target legend and the first target shape category, specifically, a topological relationship is established for the positional relationships between the bounding rectangles of each graphic element category and the target shape category:
[0067] (1) Linear primitives: Calculate the length of the linear primitive itself, the distance from the midpoint of the linear primitive to the center point of the bounding rectangle BoundingBox of the target shape category, and the angle between the line connecting the midpoint and the center point of BoundingBox and the horizontal direction.
[0068] (2) Curved line primitives: the length of the line primitive, the distance from the midpoint of the line primitive to the center point of the BoundingBox, the angle between the line connecting the midpoint and the center point of the BoundingBox and the horizontal direction, the range of the arc corresponding to the curve, etc.
[0069] (3) Fill primitives: the area of the fill primitive, the distance between the center point of the fill primitive and the center point of the BoundingBox, the angle between the line connecting the center point of the fill primitive and the center point of the BoundingBox and the horizontal direction, etc.
[0070] (4) Text primitives: the area of the text primitive BoundingBox, the distance between the center point of the text primitive and the center point of the BoundingBox, the angle between the line connecting the center point of the text primitive and the center point of the BoundingBox and the horizontal direction, the content of the text primitive, etc.
[0071] Then, based on these features, the target topological relationships can be established. That is, by utilizing the positional relationships between each primitive and the target shape category, attribute relationships are obtained, thereby establishing the target topological relationships.
[0072] The shape category formed by primitives is determined by judging the geometric relationships between primitives. For example, by traversing the categories of each primitive, the two endpoints of a line primitive are found, and then the categories of the primitives connected to the two endpoints are used to analyze the closed shape, thus obtaining the shape category formed by the primitives. It should be noted that if a shape category belongs to both rectangle and text primitives, then the shape category is rectangle + text primitive; if a shape category belongs to both circle and filled primitives, then the shape category is circle + filled primitive.
[0073] The process of establishing the target topological relationship of the target legend is the same as the process of establishing the topological relationship of the legend to be identified in the following text, as detailed in the following description.
[0074] The target topological relationship of the target legend can be determined by the electronic device after analyzing the target legend, or it can be obtained by the electronic device from other devices; there is no limitation on the acquisition method. The legend to be identified can be pre-stored in the electronic device, imported into the electronic device, etc. The legend recognition method in this embodiment determines whether the legend to be identified matches the target legend.
[0075] S12, identify the shape categories composed of each graphic element in the figure to be identified, and determine all shape categories in the figure to be identified.
[0076] As described above, for shape category recognition, the electronic device identifies the shape categories of all shapes in the drawing by recognizing the closed shape composed of each graphic element and the category of each graphic element. The categories of each graphic element in the drawing are obtained during the drawing parsing process.
[0077] The various shape categories and their corresponding icons include rectangles, triangles, circles, trapezoids, filled shapes, text elements, and so on. Of course, the types of shape categories are not limited to those shown above and may include other shape categories as well.
[0078] S13, search for a second target shape category that is the same as the first target shape category among all shape categories.
[0079] After the analysis in S12, the electronic device obtains the shape categories in the image to be identified. It then searches for second target shape categories that are identical to the first target shape category within each shape category. Since there may be multiple second target shape categories, multiple topological relationships to be identified need to be established using each of these categories. Alternatively, the positions of the first target shape categories in the target image can be combined to filter the multiple second target shape categories, reducing the number of subsequent topological relationships to be identified. For example, if the first target shape is at position A in the target image, a target region can be formed by expanding outwards from position A. Then, corresponding to the image to be identified, the second target shape category is filtered within the corresponding target region. Expanding outwards from position A is to encompass issues such as rotation and mirroring.
[0080] For example, if multiple second target shape categories are identified, these categories are grouped into a set B. Each element b in set B represents a different second target shape category. Corresponding topological relationships are then established for the subsequent distribution of each element b. Finally, these topological relationships are matched with the target topological relationships to determine if the target legend matches the target legend.
[0081] S14. Based on the shape category of the second target and the positional relationships of other elements in the legend to be identified, determine the topological relationship to be identified.
[0082] The determination of the topological relationship to be identified can be established by using the positional relationship between the second target shape category and other graphic elements themselves, or by using the positional relationship between the second target shape category and other shape categories composed of graphic elements. The process of establishing the topological relationship to be identified based on the positional relationship with other graphic elements themselves is similar to the process of establishing the target topological relationship in S11 above; please refer to the above description for details.
[0083] The positional relationships include, but are not limited to, distance, angle, area ratio, text content, etc., which are determined based on the actual shape category.
[0084] The specifics of this step will be described in detail below.
[0085] S15, Match the target topological relationship with the topological relationship to be identified to determine the legend recognition result.
[0086] The electronic device sequentially matches each topological relationship to be identified with the target topological relationship. Specifically, it matches the content corresponding to each shape category in each topological relationship to be identified with the content of the corresponding shape category in the target topological relationship. For example, a coarse match is first performed based on the shape category, and then a fine match is performed on the specific content under each category (such as distance, angle, text content, etc.) to determine the legend recognition result.
[0087] If any of the topological relationships to be identified is consistent with the target topological relationship, then the legend to be identified is consistent with the target legend; if none of the topological relationships to be identified are consistent with the target topological relationship, then the legend to be identified is inconsistent with the target legend.
[0088] The specifics of this step will be described in detail below.
[0089] The legend recognition method provided in this embodiment identifies each graphic element during drawing recognition and then uses the shape category composed of the graphic elements as the basis for legend recognition, which ensures the accuracy of legend recognition. Furthermore, by using shape category to narrow the matching range, the amount of data processing is reduced, and the efficiency of legend recognition is improved.
[0090] This embodiment provides a legend recognition method that can be used in electronic devices such as computers, tablets, and servers. Figure 3 This is a flowchart of a legend recognition method according to an embodiment of the present invention, such as... Figure 3 As shown, the process includes the following steps:
[0091] S21, Obtain the target topological relationship of the target legend and the legend to be identified.
[0092] The target topology relationship refers to the positional relationship between the first target shape category composed of target elements in the target legend and other elements in the target legend.
[0093] Please see details Figure 2 S11 of the illustrated embodiment will not be described again here.
[0094] S22, identify the shape categories composed of each graphic element in the figure to be identified, and determine all shape categories in the figure to be identified.
[0095] Please see details Figure 2 S12 of the illustrated embodiment will not be described again here.
[0096] S23, search for a second target shape category that is the same as the first target shape category among all shape categories.
[0097] In this embodiment, the electronic device searches among all shape categories to obtain at least one second target shape category that is the same as the first target shape category. The at least one second target shape category is formed into a set B, and each second target shape category corresponds to an element b in set B. Subsequently, a topological relationship to be identified is established for each second target shape category.
[0098] For further details, please see Figure 2 S13 of the illustrated embodiment will not be described again here.
[0099] S24. Based on the shape category of the second target and the positional relationships of other elements in the legend to be identified, determine the topological relationship to be identified.
[0100] Specifically, S24 includes:
[0101] S241, obtain the first bounding rectangle of the second target shape category and the second bounding rectangles of other shape categories in the illustration to be identified.
[0102] For the second target shape category, it may be an irregular shape. Irregular shapes are difficult to center, making it difficult to calculate distances, angles, and area ratios. Therefore, this embodiment uses a circumscribed rectangle method to determine positional relationships. Specifically, a first circumscribed rectangle for the second target shape category and second circumscribed rectangles for other shape categories in the illustration to be identified are determined.
[0103] S242, Based on the positional relationship between the first circumscribed rectangle and each of the second circumscribed rectangles, determine the topological relationship to be identified.
[0104] The electronic device calculates the distance between the center points of the first circumscribed rectangle and each of the second circumscribed rectangles, the angle between the line connecting the center points and the horizontal direction, etc., to obtain the relationship between each other shape category in the image to be identified and the second target shape category, thereby determining the topological relationship to be identified.
[0105] In some alternative implementations, S242 includes:
[0106] (1) Based on the positional relationship between the first bounding rectangle and each of the second bounding rectangles, determine the distance and included angle between the first bounding rectangle and each of the second bounding rectangles.
[0107] (2) When there are filled primitives in other shape categories, calculate the area ratio of the corresponding second bounding rectangle to the first bounding rectangle.
[0108] (3) When there are text primitives in other shape categories, get the text content of the text primitive.
[0109] (4) Based on distance, included angle, area ratio and text content, form the topological relationship to be identified.
[0110] The distance and included angle are determined based on the positional relationship between the center points of the first bounding rectangle and each of the second bounding rectangles. If there are filled primitives in other shape categories, it is also necessary to calculate the area ratio of the second bounding rectangle corresponding to the filled primitive to the first bounding rectangle; if there are text primitives in other shape categories, it is also necessary to obtain the text content of the text primitives. The text content is obtained by parsing the image to be recognized.
[0111] To ensure data consistency, the area ratio of non-filled primitives is set to a default value, such as 0; the text content of non-text primitives is set to empty, such as an empty string, and so on. Based on this, the topological content corresponding to each other shape category can be obtained, including but not limited to distance, angle, area ratio, and text content.
[0112] like Figure 4 As shown, the second target shape category is rectangle, and the other shape categories are circle, text primitive, and rhombus + filled primitive. The electronic device determines the second circumscribed rectangle for each of the other shape categories, calculates the distances between the center points of each second circumscribed rectangle and the first circumscribed rectangle, which are d1, d2, and d3 respectively; then calculates the angles between the line connecting the center points of the two circumscribed rectangles and the horizontal line, which are α1, α2, and α3 respectively; then obtains the text content for each of the other shape categories, which are empty, MEP, and empty respectively; and then obtains the area ratios for each of the other shape categories, which are 0, 0, and m respectively.
[0113] Then, for each of the other shape categories, we can obtain the corresponding distance, included angle, text content, and area ratio.
[0114] Including included angles in the topological relationships to be identified enables the identification of deformations such as rotation and mirroring during subsequent topological relationship matching, thus improving the accuracy of legend recognition; and combining text content and fill area ratio further ensures the accuracy of legend recognition.
[0115] In some alternative implementations, step (4) of S242 above includes:
[0116] 4.1) Using distance, included angle, area ratio and text content, form corresponding topological units for other shape categories.
[0117] 4.2) Classify the topological units based on their shape categories to determine the topological relationships to be identified.
[0118] Topological units integrate information belonging to the same shape category, including distance, angle, text content, and area ratio, etc. For example, in electronic devices, various topological units can be represented by the following structure:
[0119]
[0120]
[0121] The specific value of the current shape type (shapeType) is an identifier set according to the corresponding rules. For example, if the current shape type (shapeType) is rectangle, then the value of shapeType is 0.
[0122] When identifying the topological units corresponding to each other shape category, the electronic device classifies the other shape categories corresponding to each topological unit to obtain the topological relationship to be identified. Obtaining the corresponding topological units for each shape category and constructing the topological relationship to be identified as a whole simplifies the process; simultaneously, classifying the topological units reduces the amount of data processing required for subsequent matching, thus improving the efficiency of legend recognition.
[0123] For example, such as Figure 4 As shown, the outermost largest rectangle is ExpandBox. Assuming the selected second target shape category is rectangle, the topological relationship between the second target shape category and the remaining three other shape categories can be represented as follows:
[0124] For circles: ShapeTye is Shape_Circle, distance is d1, strTextInfo is "", dHatchRatio is 0.0, and dAngle is α1;
[0125] For the text "MEP": ShapeTye is Shape_TextEdo, distance is d2, strTextInfo is "MEP", dHatchRatio is 0.0, and dAngle is α2;
[0126] For the rhombus filling: ShapeTye is Shape_HatchEdo, distance is d3, strTextInfo is "", dHatchRatio is dRatio, and dAngle is α3 (assuming the ratio of the area of the BoundingBox to the area of the ExpandBox).
[0127] After constructing the topological units, these units are categorized according to their shape type, and then sorted within each category based on the distance between them to facilitate subsequent topological relationship comparisons. Finally, after organizing all the topological relationships, the topological relationship R to be identified for the given image is obtained.
[0128] S25, Match the target topological relationship with the topological relationship to be identified to determine the legend recognition result.
[0129] Please see details Figure 2 S15 of the illustrated embodiment will not be described again here.
[0130] The legend recognition method provided in this embodiment can accurately determine the position of each shape category by using the bounding rectangle method, since there may be irregular shapes in other shape categories of the legend to be recognized, and their position points are difficult to determine accurately.
[0131] This embodiment provides a legend recognition method that can be used in electronic devices such as computers, tablets, and servers. Figure 5 This is a flowchart of a legend recognition method according to an embodiment of the present invention, such as... Figure 5 As shown, the process includes the following steps:
[0132] S31, Obtain the target topological relationship of the target legend and the legend to be identified.
[0133] The target topology relationship refers to the positional relationship between the first target shape category composed of target elements in the target legend and other elements in the target legend.
[0134] Please see details Figure 2 S11 of the illustrated embodiment will not be described again here.
[0135] S32, identify the shape categories composed of each graphic element in the figure to be identified, and determine all shape categories in the figure to be identified.
[0136] Please see details Figure 3 S22 of the illustrated embodiment will not be described again here.
[0137] S33, search for a second target shape category that is the same as the first target shape category among all shape categories.
[0138] Please see details Figure 2 S13 of the illustrated embodiment will not be described again here.
[0139] S34. Based on the shape category of the second target and the positional relationships of other elements in the legend to be identified, determine the topological relationship to be identified.
[0140] Please see details Figure 3 S24 of the illustrated embodiment will not be described again here.
[0141] S35, Match the target topological relationship with the topological relationship to be identified to determine the legend recognition result.
[0142] Specifically, S35 includes:
[0143] S351, obtain the second category of shape categories and the second quantity under each category in the topological relationship to be identified.
[0144] The second category is the number of shape categories in the topological relation to be identified, and the second quantity is the number of shape categories included under each shape category. Both the second category and the second quantity can be obtained from the topological relation to be identified. As mentioned above, when forming the topological relation to be identified, the topological units have already been classified by the types of shape categories, so the classification result is the second category, and the number of shape categories included under each classification result is the second quantity.
[0145] S352, the second category and the second quantity are matched with the corresponding first category and the first quantity in the target topological relationship to determine the legend recognition result.
[0146] The first category and the first quantity are also obtained from the target topological relationship. The electronic device matches the first category with the second category and the first quantity with the second quantity to obtain the matching result. If there is a mismatched topological relationship to be identified, the topological relationship to be identified is deleted from set B, indicating that it does not match the target legend. When both the category and the quantity match, the remaining topological relationships to be identified in set B are then matched with the distance, angle, area ratio, and text content in S24 above to determine the legend recognition result.
[0147] In some optional implementations, the target topological relationship includes the distance, included angle, area ratio, and text content between the first bounding rectangle of the second target shape category and the second bounding rectangles of the other shape categories. For details on how to obtain the distance, included angle, area ratio, and text content, please refer to the above. Figure 3 The description in the illustrated embodiment will not be repeated here. Based on this, S352 above includes:
[0148] (1) When the first type and the second type and the first quantity and the second quantity are both matched, compare whether the included angle in the topological relationship to be identified is consistent with the included angle in the target topological relationship.
[0149] (2) When there is a discrepancy, calculate the deviation between the included angle in the topology relationship to be determined and the corresponding included angle in the target topology relationship, and determine whether the deviation is within the preset range.
[0150] (3) When the deviation is within the preset range, and the area ratio and text content in the topological relationship to be identified are consistent with the corresponding area ratio and text content in the target topological relationship, it is determined that the legend to be identified matches the target legend.
[0151] If there are no issues with rotation or mirroring, then if two figures are identical, their corresponding included angles will be consistent. In this embodiment, considering rotation and mirroring, when included angles are inconsistent, the included angle deviation is also compared. This is because when rotation or mirroring occurs, if two figures are identical, their included angle deviations will be consistent. Furthermore, considering recognition errors, both the included angle deviation and the comparison of included angles are performed within a certain error range. For example, comparing whether the corresponding included angles dAngle are approximately equal. If they are not approximately equal, the included angle deviation value ΔdAngle for all dAngles is recorded, and finally, it is determined whether all ΔdAngles are approximately equal. If they are all approximately equal, the angle condition can be considered met. Since both mirroring and rotation will ultimately be reflected in the angle dAngle.
[0152] If the primitive is text, compare its corresponding text content (strTextInfo) to see if they are approximately the same; if the primitive is filled, compare its corresponding area ratio (dHatchRatio) to see if they are approximately the same. If all the above comparisons are consistent, then the primitive to be identified is considered to be consistent with the target primitive.
[0153] When performing angle matching, the angle deviation is combined with the matching, which makes the recognition method applicable to legends that are deformed by mirroring and rotation, thus improving the accuracy of legend recognition.
[0154] The legend recognition method provided in this embodiment uses matching based on type and quantity to quickly filter out the topological relationships to be identified that do not match the target topological relationship, thus improving the efficiency of legend recognition.
[0155] In some alternative implementations, S35 further includes:
[0156] (1) Obtain the first bounding rectangle of the first target shape category and the second bounding rectangle of the second target shape category.
[0157] (2) Scale the first bounding rectangle and the second bounding rectangle respectively to obtain the first target rectangle containing all the elements in the target legend and the second target rectangle containing all the elements in the legend to be identified, and determine the first scaling ratio, the second scaling ratio, the first length of the preset side length in the first target rectangle and the second length of the preset side length in the second target rectangle.
[0158] (3) Based on the relationship between the first scaling ratio and the second scaling ratio, and the size relationship between the first length and the second length, the legend recognition result is determined.
[0159] The first and second bounding rectangles are scaled to obtain the corresponding first and second target rectangles. The first target rectangle includes all elements in the target legend, and the second target rectangle includes all elements in the legend to be identified.
[0160] The scaling method for the first and second bounding rectangles is similar; we will describe the scaling of the first bounding rectangle as an example. During scaling, first, we iterate through the constituent elements belonging to this legend. If all these elements are within the first bounding rectangle (BoundingBox), then there is no need to scale the BoundingBox. Otherwise, the scaling ratio is determined according to the following rules:
[0161] Traverse the primitives and find those that cannot be completely contained within the first bounding rectangle (BoundingBox). Calculate the maximum horizontal and vertical offsets of these primitives from the center point of the BoundingBox. Then, take the larger of the horizontal and vertical offsets. If the horizontal offset is large, denoted as 'a', scale it by half the horizontal size of the BoundingBox (denoted as A), with a scaling ratio r = a / A. After obtaining the scaling ratio, scale the first bounding rectangle based on this ratio, and then determine whether it contains all primitives. Repeat this process until all primitives are within the first target rectangle.
[0162] After the scaling process described above, a first target rectangle and a second target rectangle are obtained. The lengths of the longer and shorter sides of both rectangles can be recorded. Taking the longer side as an example, the ratio of the first length to the second length is calculated. Then, two corresponding distances are extracted from the target topological relationship and the topological relationship to be identified, respectively. The ratio of these distances is calculated to see if it is approximately consistent with the ratio of the two lengths. If they are inconsistent, it indicates that the topological relationship to be identified does not match the target topological relationship. If they match, other attributes, such as included angle, area ratio, and text content, are used for matching again. Using scaling ratio and length for matching allows for faster filtering of topological relationships to be identified that do not match the target topological relationship, improving the efficiency of legend recognition.
[0163] As a specific application example of the legend recognition method in this embodiment of the invention, the method includes:
[0164] (1) Recognize the shape categories of all constituent elements in the input target legend. These basic shapes include rectangles, triangles, circles, arrows, star connections '—<', cross connections '—[', etc.
[0165] (2) Determine the first target shape category in the target legend by referring to a certain priority;
[0166] (3) Taking the center point of the first bounding rectangle BoundingBox of the first target shape category as the center, scale its length and width proportionally to ensure that the scaled box can completely contain all the graphic elements that make up the legend. The scaling ratio is dScaleRatio. The scaled BoundingBox is the first target rectangle ExpandBox. At the same time, record the length of the longer side of BoundingBox, maxBorderLength.
[0167] (4) Using the first target shape category as the center, construct the target topology relationship between the first target shape category and other constituent shape categories;
[0168] (5) Identify the shape category of the illustration to be identified and obtain the set A of all shape categories;
[0169] (6) Find the shape set B that matches the first shape category of the target legend;
[0170] (7) Traverse each object b in B, and scale the length and width of the current BoundingBox proportionally according to the scaling ratio dScaleRatio in step (3) at the center point of the second bounding rectangle BoundingBox of b, to obtain the scaled second target rectangle expandedBox, and at the same time record the length of the longer side of the BoundingBox before scaling maxBorderLength2.
[0171] (8) Find all shape categories that are completely contained by expandBox from set A, and construct the topological relationship r to be identified according to the method in step (4);
[0172] (9) Compare R and r in sequence according to the key-value pairs. If they can match completely, the shape combination formed by all the primitives in the current expandBox is a legend to be recognized. Add the relevant recognition results to the results list.
[0173] (10) Is the current traversal over? If not, return to step (7). If the traversal is over, save and output the final recognition result list.
[0174] The comparison logic includes:
[0175] Comparison logic:
[0176] (1) Compare whether the combination of other shape categories and the number of categories contained in the topological relationship are consistent;
[0177] (2) Compare whether the number of graphics in each other shape category is consistent;
[0178] (3) Compare the distance ratio between each shape category under each other shape category and the corresponding object in the target topology R to see if it is consistent with the ratio of maxBorderLength in step (3) and maxBorderLength2 in step (7), that is, determine Figure 4 Does the following relationship hold true:
[0179] (d1 / d2)≈(maxBorderLength / maxBorderLength);
[0180] (4) Compare whether the corresponding dAngle values are approximately equal. If they are not approximately equal, record the deviation value ΔdAngle of all dAngle values. Finally, determine whether all ΔdAngle values are approximately equal. If they are all approximately equal, the angle condition can be considered met.
[0181] (5) If it is a text primitive, compare whether the content of the corresponding strTextInfo is approximately the same;
[0182] (6) If it is a filled primitive, compare whether the corresponding dHatchRatio is approximately consistent.
[0183] If all of the above conditions are met, then the match can be considered successful.
[0184] This embodiment also provides a legend recognition device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0185] This embodiment provides a legend recognition device, such as Figure 6 As shown, it includes:
[0186] The acquisition module 41 is used to acquire the target topology relationship of the target legend and the legend to be identified. The target topology relationship is the positional relationship between the first target shape category composed of target elements in the target legend and other elements in the target legend.
[0187] The identification module 42 is used to identify the shape categories composed of each graphic element in the image to be identified, and to determine all shape categories in the image to be identified;
[0188] Search module 43 is used to search for a second target shape category that is the same as the first target shape category among all shape categories;
[0189] The determining module 44 is used to determine the topological relationship to be identified based on the second target shape category and the positional relationship of other elements in the legend to be identified;
[0190] The matching module 45 is used to match the target topological relationship with the topological relationship to be identified to determine the legend recognition result.
[0191] In this embodiment, the illustration recognition device is presented in the form of a functional unit. Here, a unit refers to an ASIC circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0192] Further functional descriptions of the above modules are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0193] This invention also provides an electronic device having the above-described features. Figure 6 The illustration recognition device shown.
[0194] Please see Figure 7 , Figure 7 This is a schematic diagram of the structure of an electronic device provided in an optional embodiment of the present invention, such as... Figure 7 As shown, the electronic device may include: at least one processor 51, such as a CPU (Central Processing Unit), at least one communication interface 53, memory 54, and at least one communication bus 52. The communication bus 52 is used to enable communication between these components. The communication interface 53 may include a display screen or a keyboard; optionally, the communication interface 53 may also include a standard wired interface or a wireless interface. The memory 54 may be high-speed RAM (Random Access Memory) or non-volatile memory, such as at least one disk storage device. Optionally, the memory 54 may also be at least one storage device located remotely from the aforementioned processor 51. The processor 51 may be combined with... Figure 6 The described apparatus has an application program stored in memory 54, and the processor 51 calls the program code stored in memory 54 to perform any of the above method steps.
[0195] The communication bus 52 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The communication bus 52 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0196] The memory 54 may include volatile memory, such as random-access memory (RAM); the memory may also include non-volatile memory, such as flash memory, hard disk drive (HDD) or solid-state drive (SSD); the memory 54 may also include a combination of the above types of memory.
[0197] The processor 51 can be a central processing unit (CPU), a network processor (NP), or a combination of CPU and NP.
[0198] The processor 51 may further include a hardware chip. This hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0199] Optionally, the memory 54 is also used to store program instructions. The processor 51 can invoke the program instructions to implement the illustration recognition method as shown in any embodiment of this application.
[0200] This invention also provides a non-transitory computer storage medium storing computer-executable instructions that can execute the illustration recognition method in any of the above method embodiments. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk drive (HDD), or solid-state drive (SSD), etc.; the storage medium may also include combinations of the above types of memory.
[0201] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A legend recognition method, characterized in that, include: Obtain the target topological relationship of the target legend and the legend to be identified. The target topological relationship is the positional relationship between the first target shape category composed of target elements in the target legend and other elements in the target legend. The shape categories composed of each graphic element in the image to be identified are identified to determine all shape categories in the image to be identified. Search among all shape categories for a second target shape category that is the same as the first target shape category; Based on the second target shape category and the positional relationships of other elements in the legend to be identified, the topological relationship to be identified is determined; The target topological relationship is matched with the topological relationship to be identified to determine the legend recognition result; The step of determining the topological relationship to be identified based on the shape category of the second target primitive and the positional relationships of other primitives in the legend to be identified includes: Obtain the first bounding rectangle of the second target shape category and the second bounding rectangles of other shape categories in the illustration to be identified; The topological relationship to be identified is determined based on the positional relationship between the first circumscribed rectangle and each of the second circumscribed rectangles.
2. The method according to claim 1, characterized in that, The step of determining the topological relationship to be identified based on the positional relationship between the first circumscribed rectangle and each of the second circumscribed rectangles includes: Based on the positional relationship between the first bounding rectangle and each of the second bounding rectangles, the distance and included angle between the first bounding rectangle and each of the second bounding rectangles are determined; When there are filled primitives in the other shape categories, calculate the area ratio of the corresponding second bounding rectangle to the first bounding rectangle; When a text element exists in one of the other shape categories, the text content of the text element is obtained. The topological relationship to be identified is formed based on the distance, included angle, area ratio, and text content.
3. The method according to claim 2, characterized in that, The process of forming the topological relationship to be identified based on the distance, included angle, area ratio, and text content includes: Using the distance, included angle, area ratio, and text content, topological units of other corresponding shape categories are formed; The topological units are classified based on their corresponding shape categories to determine the topological relationships to be identified.
4. The method according to claim 1, characterized in that, The process of matching the target topological relationship with the topological relationship to be identified to determine the legend recognition result includes: Obtain the second category of shape categories in the topological relationship to be identified, and the second quantity under each category; The second category and the second quantity are matched with the corresponding first category and the first quantity in the target topology relationship to determine the legend recognition result.
5. The method according to claim 4, characterized in that, The target topological relationship includes the angle, area ratio, and text content between the first bounding rectangle of the second target shape category and the second bounding rectangle of the other shape categories. Matching the second type and the second quantity with the corresponding first type and first quantity in the target topological relationship to determine the legend recognition result includes: When the first type matches the second type and the first quantity matches the second quantity, compare whether the included angle in the topological relationship to be identified is consistent with the included angle in the target topological relationship. When there is a discrepancy, calculate the deviation between the included angle in the topological relationship to be determined and the corresponding included angle in the target topological relationship, and determine whether the deviation is within a preset range; When the deviation is within the preset range, and the area ratio and text content in the topological relationship to be identified are consistent with the corresponding area ratio and text content in the target topological relationship, it is determined that the legend to be identified matches the target legend.
6. The method according to claim 4, characterized in that, The process of matching the target topological relationship with the topological relationship to be identified to determine the legend recognition result also includes: Obtain the first bounding rectangle of the first target shape category and the second bounding rectangle of the second target shape category; The first bounding rectangle and the second bounding rectangle are scaled respectively to obtain a first target rectangle containing all the elements in the target legend and a second target rectangle containing all the elements in the legend to be identified, and a first scaling ratio, a second scaling ratio, a first length of the preset side length in the first target rectangle and a second length of the preset side length in the second target rectangle are determined. The legend recognition result is determined based on the relationship between the first scaling ratio and the second scaling ratio, as well as the size relationship between the first length and the second length.
7. A legend recognition device, characterized in that, include: The acquisition module is used to acquire the target topological relationship of the target legend and the legend to be identified. The target topological relationship is the positional relationship between the first target shape category composed of target elements in the target legend and other elements in the target legend. A recognition model is used to identify the shape categories composed of each graphic element in the image to be recognized, and to determine all shape categories in the image to be recognized; The search module is used to search for a second target shape category that is the same as the first target shape category among all the shape categories; The determination module is used to determine the topological relationship to be identified based on the second target shape category and the positional relationship of other elements in the legend to be identified; The matching module is used to match the target topological relationship with the topological relationship to be identified to determine the legend recognition result; Specifically, the determining module is used to: obtain the first bounding rectangle of the second target shape category and the second bounding rectangles of other shape categories in the image to be identified; and determine the topological relationship to be identified based on the positional relationship between the first bounding rectangle and each of the second bounding rectangles.
8. An electronic device, characterized in that, include: A memory and a processor are communicatively connected, the memory stores computer instructions, and the processor executes the illustration recognition method according to any one of claims 1-6 by executing the computer instructions.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to perform the legend recognition method according to any one of claims 1-6.
Citation Information
Patent Citations
Graphic symbol identification method based on indirect distance angle histogram space relation expression model
CN105574535A
Primitive position relationship matching method and device and computer equipment
CN112613395A
Track similarity judgment method and system and computer medium
CN112800351A
Face spatial positioning method, face spatial positioning system, and non-transitory computer-readable recording medium
US20190213392A1