SVG vector diagram-based primitive matching and intelligent identification system and method

By using an SVG vector graphics-based primitive matching and intelligent recognition system, which utilizes hash storage, affine transformation, and multidimensional indexing, the problems of insufficient accuracy and low efficiency in primitive matching are solved, and efficient and accurate recognition and matching of large-scale engineering drawings are achieved.

CN121884384APending Publication Date: 2026-04-17GUANGZHOU ZHIDEI INTELLIGENT TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUANGZHOU ZHIDEI INTELLIGENT TECH CO LTD
Filing Date
2026-01-08
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Existing technologies suffer from insufficient accuracy, low efficiency, and poor robustness to rotation and scaling in primitive matching and recognition. They are particularly difficult to meet the batch processing requirements in large engineering drawings, and the similarity between text annotations and primitive shapes leads to mismatches.

Method used

A graphic element matching and intelligent recognition system based on SVG vector graphics is adopted, including a PDF to SVG and PNG conversion module, a standardization module, an OCR processing module, an index generation module, and a multi-template matching module. Through SHA-256 hash deduplication storage, affine transformation matrix parsing, multi-dimensional indexing, and dynamic tolerance matching algorithms, the system achieves standardization and high-precision matching of graphic elements.

Benefits of technology

It solves the mirror transformation problem caused by different conversion tools, supports fast recognition of graphics with arbitrary orientation, improves the matching success rate and processing efficiency, compresses the time from minutes to seconds, and ensures the accuracy and efficiency of primitive recognition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121884384A_ABST
    Figure CN121884384A_ABST
Patent Text Reader

Abstract

The invention discloses an SVG vector diagram-based primitive matching and intelligent recognition system and method, and relates to the technical field of computer graphic processing and mode recognition. The system stores a PDF file through SHA-256 Hash duplicate removal, format conversion is achieved through a tool, an 800DPI PNG image is generated, and the resolution is verified; the affine transformation matrix is analyzed, coordinate normalization and graphic element classification conversion are executed, and complex paths are split, deduplicated and merged; detecting a character area, and deleting corresponding character elements in the SVG; geometric features are extracted to construct a multi-dimensional index, and a template topological structure is analyzed; and selecting anchor points according to priorities, adapting to multiple rotation directions, matching non-anchor point elements through dynamic tolerance, verifying connection points in combination with adaptive topology tolerance, and finally outputting a matching result containing confidence. The system realizes efficient identification and accurate matching of technical drawings through standardization processing and an intelligent matching algorithm, and is suitable for scenes such as industrial drawing analysis and document digitization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer graphics processing and pattern recognition technology, specifically relating to a primitive matching and intelligent recognition system and method based on SVG vector graphics. Background Technology

[0002] With the digital transformation of industries such as engineering design, manufacturing, and construction, a large number of historical technical drawings need to be converted from non-editable formats such as PDFs and images into parsable vector graphics (such as SVG) for storage, retrieval, and analysis. SVG format can completely preserve the geometric information and topological relationships of graphics, making it an important carrier for the digitization of technical drawings. However, in practical applications, existing technologies have many shortcomings in primitive matching and recognition.

[0003] First, different PDF to SVG conversion tools generate files with differences in coordinate systems, scaling ratios, and rotation directions, resulting in inconsistent geometric parameters for the same graphic element in different files, which affects matching accuracy.

[0004] Secondly, the same template element may appear at different angles and scales in different drawings, and traditional matching methods based on pixels or simple geometric features are not robust to rotation and scaling.

[0005] Furthermore, large-scale engineering drawings contain tens of thousands of graphic elements, and traditional O(n²) matching algorithms are inefficient under large-scale data, making it difficult to meet the needs of batch processing. The drawings also contain a large number of text annotations that may be similar in shape to graphic elements, leading to mismatches; while multi-template matching may produce a large number of overlapping or duplicate matching results, and some results may match in shape but not semantically.

[0006] Existing technologies mostly employ bitmap-based template matching or simple geometric feature matching, which suffer from insufficient accuracy, low efficiency, and poor robustness to rotation and scaling, making it difficult to meet the needs of engineering applications.

[0007] To address the aforementioned problems, this invention proposes a primitive matching and intelligent recognition system and method based on SVG vector graphics. Summary of the Invention

[0008] In order to overcome the shortcomings and deficiencies of the existing technology, the first objective of this invention is to provide a primitive matching and intelligent recognition system based on SVG vector graphics; the second objective of this invention is to provide a primitive matching and intelligent recognition method based on SVG vector graphics.

[0009] The first objective of this invention is achieved through the following technical solution:

[0010] A primitive matching and intelligent recognition system based on SVG vector graphics, including a PDF to SVG and PNG conversion module, a standardization module, an OCR processing module, an index generation module, a multi-template matching module, and a template standardization module;

[0011] The PDF to SVG and PNG conversion module is used to receive PDF format technical drawings, perform deduplication and storage, and then convert the PDF into SVG files and PNG images of a specified resolution.

[0012] The standardization module is used to parse the transformation attributes of graphic elements in SVG files and perform coordinate normalization, classify and identify path elements according to features and convert them into standard graphic elements, split complex paths and perform deduplication and merging to generate standardized SVG files.

[0013] The template standardization module is used to perform the same processing flow as the standardization module on SVG templates in the template library to generate standardized template files.

[0014] The OCR processing module is used to perform text detection on PNG images, delete text regions in SVG files based on the detection results, and generate text-free SVG files.

[0015] The index generation module is used to extract the geometric features of graphic elements in standardized SVG files and build a multidimensional index, and to perform topological analysis on standardized template files to generate a topological model.

[0016] The multi-template matching module is used to dynamically select anchor elements based on multi-dimensional indexes, adapt to multiple rotation directions to perform element matching, and output the matching results after filtering out false matches through topology verification.

[0017] Preferably, the specific processing steps of the PDF to SVG and PNG conversion module include:

[0018] The SHA-256 hash algorithm is used to calculate the hash value of the PDF file, and deduplication is achieved through a database table that maps hash value to file path.

[0019] The pdf2svg tool is used to perform PDF to SVG conversion, converting all pages of the PDF into a single SVG file. Pages are distinguished by group tags. After conversion, graphic element tag validation is performed and the conversion is retried up to 3 times.

[0020] The rsvg-convert tool is used to convert the SVG file into an 800 DPI PNG image, and the resolution is verified using OpenCV before being output.

[0021] Preferably, the process of coordinate normalization performed by the standardization module includes:

[0022] The lxml library is used to parse the transform attribute of the graphic element, extract the affine transformation matrix parameters (a,b,c,d,e,f), and calculate the matrix determinant value det=a×d−b×c;

[0023] If det < 0, it is determined to be a mirror transformation. The sweep-flag value is flipped on the SVG arc element, the endpoint coordinates are transformed according to the transformation formulas x'=a×x+b×y+e and y'=c×x+d×y+f, and the radius is adjusted according to rx'=rx×|a| and ry'=ry×|d|.

[0024] Perform coordinate transformations on all graphic elements: X = a × X + b × Y + e, Y = c × X + d × Y + f, and delete the transform attribute after the transformation.

[0025] Preferably, the process of classifying and recognizing path elements by the standardization module includes:

[0026] Extract filled path elements whose fill attribute is not none; simple closed polygons with 3-4 vertices are identified as triangles and decomposed into line elements; complex filled paths with more than 1 Z command are identified as thick lines and the center line path is extracted.

[0027] Count the number of Bézier curve C commands in non-filled path elements. If there are 4 C commands, it is determined to be a circle based on the bounding box aspect ratio W / H ∈ [0.95, 1.05]; otherwise, it is an ellipse. If there are 1-3 C commands, it is determined to be an arc and marked with the data-type="arc" attribute. If there are no C commands, it is identified as a simple straight line path and converted into a standard line element.

[0028] Mark the path element with fill="black" and fill-rule="nonzero" as a thick line and add the data-thick="true" attribute.

[0029] Preferably, the process of breaking down complex paths into standardized modules includes:

[0030] The data of multiple arc paths are segmented using regular expressions ([MmLlAaZz]), the arc parameters are extracted according to the command sequence, and an independent arc path is constructed with the current point as the starting point and segment number identifiers are added.

[0031] The system splits multiple straight paths into two-point straight line segments, generates direction-independent quadruple unique keys through coordinate sorting to achieve deduplication, and filters out noise line segments with lengths less than a set threshold.

[0032] Preferably, the processing procedure of the index generation module includes:

[0033] Extract the start point, end point, length, and angle normalized to [0°, 180°] of straight line elements; the center and radius of circle elements; the center and axial radius of ellipse elements; and the parameters and center coordinates of arc elements.

[0034] Construct type indexes, precise angle indexes, and statistical indexes;

[0035] The K-nearest neighbor algorithm with K=5 is used to identify the clustered regions of line endpoints with a distance ≤ a set threshold in the standardized template as connection points to construct an undirected graph of element connection relationships.

[0036] Preferably, the matching process of the multi-template matching module includes:

[0037] Anchor points are selected based on priority, including straight lines with special angles, ellipses, arcs, circles, and straight lines with common angles. The expected angles are calculated and candidate anchor points are selected for rotation directions of 0°, 90°, 180°, and 270°.

[0038] Verify the compatibility of candidate anchor point types and angles, calculate the scaling ratio S and filter outliers; calculate the expected position and size of non-anchor point elements according to the relative proportion of anchor points, and search for matching elements through dynamic tolerance.

[0039] Calculate adaptive topology tolerance based on template complexity and scale features, verify endpoint distances after connection point mapping, extract anchor ID, rotation angle, and element mapping relationship to generate a unique signature and remove duplicates, and output matching results with confidence.

[0040] The second objective of this invention is achieved through the following technical solution:

[0041] A method for primitive matching and intelligent recognition based on SVG vector graphics is used to implement a primitive matching and intelligent recognition system based on SVG vector graphics, including the following steps:

[0042] S1. Input preprocessing and format conversion: The PDF file is deduplicated based on the SHA-256 hash algorithm, converted to SVG using the pdf2svg tool, and generated an 800DPI PNG image using rsvg-convert;

[0043] S2. Coordinate system normalization and element standardization: Extract the affine transformation matrix of the transform attribute of SVG elements, calculate the determinant value det=a×d−b×c to determine the chiral change, adjust the arc parameters and perform affine transformation on all coordinate points.

[0044] S3, Intelligent Shape Recognition and Conversion: Classifies path elements according to fill type and Bézier curve command features, and converts them into standardized elements;

[0045] S4. Style Integration and Markup: Integrate SVG element style attributes, adjust line width by stroke-widthnew=stroke-widthold×det, and mark thick line elements;

[0046] S5. Template Standardization: Perform a standardization process on the SVG template library and conduct spot checks to verify the data consistency error between the template and the scene graph.

[0047] S6. Text Processing: Use the OCR sliding window to detect text from the drawing and delete the corresponding text area in the SVG;

[0048] S7. Index Construction: Extract geometric features of SVG elements, construct type index, precise angle index and statistical index, and analyze template topology;

[0049] S8. High-precision matching and topology verification: Select anchor points according to three-level priority, adapt to multiple rotation directions, match non-anchor point elements based on dynamic tolerance, verify connection points through adaptive topology tolerance, and output matching results after deduplication.

[0050] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are:

[0051] 1. The system constructs a complete conversion link from PDF to SVG. It solves the mirror transformation problem caused by different conversion tools by using SHA-256 deduplication storage, 800DPI PNG verification, and affine transformation matrix parsing. It detects chiral changes by using determinant, automatically flips the arc sweep-flag parameter and transforms the coordinates to ensure the geometric consistency of complex paths. At the same time, it achieves global line segment deduplication by using quadruples as unique keys, compressing tens of thousands of original paths to thousands of independent elements, thus reducing the data scale.

[0052] 2. It pioneered the use of rotation-invariant angle representation and a four-level rotation direction matching strategy to support the rapid recognition of graphics with arbitrary orientation; through dynamic tolerance algorithm and adaptive topology tolerance design, it achieves accurate matching within the scale range, and the connection point verification mechanism can filter out topology error matching; it constructs a three-level index structure of type / angle / length to reduce the candidate element search complexity from O(n) to O(1).

[0053] 3. Employing OCR sliding window detection technology based on the drawing, it intelligently removes duplicates from overlapping areas and merges text blocks to accurately locate text regions and delete corresponding SVG elements, avoiding mismatches of text strokes; a three-level priority anchor point selection algorithm dynamically adapts to the optimal anchor point for different rotation directions, improving the matching success rate and reducing processing time from minutes to seconds. Attached Figure Description

[0054] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0055] Figure 1 This invention illustrates a module diagram of the primitive matching and intelligent recognition system based on SVG vector graphics.

[0056] Figure 2 The flowchart of the primitive matching and intelligent recognition method based on SVG vector graphics of the present invention is shown. Detailed Implementation

[0057] 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, and 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] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more exemplary embodiments. Numerous specific details are provided in the following description to give a full understanding of exemplary embodiments of this disclosure. However, those skilled in the art will recognize that the technical solutions of this disclosure can be practiced with one or more of the specific details omitted, or other methods, components, steps, etc., can be employed. In other instances, well-known structures, methods, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of this disclosure.

[0059] Example 1:

[0060] See Figure 1 As shown, the SVG vector graphic primitive matching and intelligent recognition system of this embodiment includes a PDF to SVG and PNG conversion module, a standardization module, a template standardization module, an OCR processing module, an index generation module, and a multi-template matching module.

[0061] PDF to SVG and PNG converter: This module receives PDF technical drawings, performs deduplication, format conversion, and high-resolution image generation. The specific implementation steps are as follows:

[0062] S11. File Reception and Deduplication Storage: A file reception interface is built, supporting local file import and network upload. The SHA-256 hash algorithm is used to calculate the hash value of PDF files, and a database table mapping hash values ​​to file paths is established. Upon receiving a file, its hash value is first calculated and compared with the database table. If a matching hash value exists, the already stored file is directly retrieved; otherwise, the file is stored in the specified directory, and the database record is updated.

[0063] S12. PDF to SVG Conversion: The pdf2svg tool is used to perform the format conversion. The command is executed via Python's subprocess module: pdf2svg [input PDF path] [output SVG path] all. The all parameter specifies that all pages of the PDF be converted into a single SVG file, with pages distinguished by group tags. After conversion, the SVG file undergoes preliminary validation to check for missing graphic element tags. If validation fails, the conversion is retried, up to a maximum of 3 times.

[0064] S13. PNG Image Generation: Use the rsvg-convert tool to convert the SVG file into an 800 DPI PNG image for subsequent OCR processing. Execute the command: rsvg-convert -d800 -p800 -o [output PNG path] [input SVG path], where -d specifies the resolution and -p specifies the pixel density. After generation, use OpenCV to read the PNG image's resolution parameters to verify if it meets the 800 DPI requirement. If not, adjust the parameters and regenerate.

[0065] The standardization module is responsible for coordinate normalization, shape recognition, element transformation, and deduplication and merging of SVG graphic elements. Its implementation consists of the following sub-steps:

[0066] S21, Coordinate system standardization.

[0067] `transform` attribute parsing and chirality determination: The `lxml` library is used to parse the `transform` attribute of each graphic element in the SVG file, extracting the affine transformation matrix parameters (a, b, c, d, e, f), where a and d are scaling factors, b and c are tangent factors, and e and f are translation amounts. The determinant of the transformation matrix is ​​then calculated. : If det < 0, a mirror transformation (chiral change) is determined to have occurred, and the geometric parameters need to be adjusted; if det ≥ 0, the subsequent coordinate transformation is performed directly.

[0068] Adjusting parameters for arc elements: For SVG arc elements ( <path>The tag contains the command A, which extracts its seven parameters, including rx (X-axis radius), ry (Y-axis radius), xrot (rotation angle), large-arc-flag (large arc flag), sweep-flag (clockwise flag), x (endpoint X-coordinate), and y (endpoint Y-coordinate). When a chiral change is detected, the following adjustment is performed: the sweep-flag value is flipped (0→1, 1→0).

[0069] Transform the endpoint coordinates using the transformation matrix formula. : Where a and d are scaling factors, b and c are skew factors; x and y are SVG arc elements ( <path>The original X and Y coordinates of the endpoint (including command A); , These are the X and Y coordinates of the endpoint of the transformed arc.

[0070] Adjust the radius according to the scaling factor: To ensure consistent arc geometry; among which, The original X-axis radius of the arc element; is the original Y-axis radius of the arc element; a and d are the scaling factors of the affine transformation matrix; The adjusted X-axis radius of the arc; This is the adjusted Y-axis radius of the arc.

[0071] Global coordinate transformation: Perform an affine transformation on the coordinates of all graphic elements. The transformation formula is: New X coordinate: New Y-coordinate: ; ;in, , represents the original coordinates of the graphic element; a and d are scaling factors, b and c are skewing factors; e and f are the translation amounts of the affine transformation matrix. , These are the coordinates of the points in the transformed standard coordinate system.

[0072] S22, Intelligent recognition and conversion of path elements.

[0073] To address the large number of path elements in SVG exported from CAD, the processing is categorized by fill type and command characteristics:

[0074] Processing fill-type path elements: Extract path elements with a fill attribute other than none. Classify them by parsing the number of Z-commands (closure commands) and vertices in the path data: Triangle determination: Simple closed polygons with 3-4 vertices are decomposed into three independent line elements. After extracting the coordinates of each vertex, a line generation algorithm is used to create... <line>Label.

[0075] Coarse straight line determination: For complex fill paths with more than 1 Z-commands, a skeleton extraction algorithm (based on distance transformation) is used to extract the centerline path and convert it into a standard line. <line>For labels, the line width is calculated based on the width of the filled area.

[0076] Non-filled path element classification and transformation: Count the number of Bézier curve commands (C commands) in the path data and execute different processing logic:

[0077] Circle / ellipse recognition (4 C commands): Calculate the bounding box of the path coordinates, obtain maxX, minX, maxY, and minY, calculate the width W = maxX - minX, and the height H = maxY - minY. If... It is determined to be a circle, with the center coordinates as follows: , radius is ,generate <circle>Label; otherwise, classify it as an ellipse with an X-axis radius of [missing information]. The radius of the Y-axis is ,generate <ellipse>Label.

[0078] Arc recognition (1-3 C commands): Directly mark it as an arc type, retain the path tag and add the data-type="arc" attribute.

[0079] Line / Polygon Recognition (No C Commands): Identifies simple paths (format: Mx1,y1Lx2,y2) using regular expressions, extracts the start and end coordinates, and converts them to... <line>Tags; complex paths will undergo subsequent splitting processing.

[0080] S23, Style standardization and special marking.

[0081] Style attribute consolidation: Iterate through the `fill`, `stroke`, `stroke-width`, and `style` attributes of the `path` element. Split the key-value pairs in the `style` attribute and merge them with the independent attributes. In case of conflict, the independent attributes take precedence. Adjust the `stroke-width` attribute according to the scaling factor in the transformation matrix. Where stroke-widthold is the original line width of the graphic element; det is the determinant value of the affine transformation matrix; The adjusted line width (to ensure visual consistency).

[0082] Line caps and thick line markers: Set the stroke-linecap of all straight line elements to "butt" to avoid redundancy at joints. For path elements with fill="black" and fill-rule="nonzero", they are judged as thick lines, and the data-thick="true" marker attribute is added for subsequent matching priority settings.

[0083] S24. Complex path splitting and deduplication.

[0084] Multi-segment circular path decomposition: The path data is segmented using a regular expression ([MmLlAaZz]) to obtain command and coordinate sequences. The current point variable is maintained; when an M command is encountered, the current point is updated as the starting point. When an A command is encountered, seven parameters are extracted. An independent circular path is constructed using the current point as the starting point and the endpoint of the parameters as the endpoint, generating a new... <path>The tag is added with the attributes data-arc-segment (segment number) and data-total-segments (total number of segments), and the current point is updated to the endpoint of the arc.

[0085] Multi-segment straight path splitting and deduplication: Parsing the coordinate sequence in the path data, starting from the coordinates in the M command, and grouping every two values ​​as the endpoint, splits the path into multiple two-point straight line segments. A direction-independent segment key generation algorithm is used for deduplication: Coordinate sorting: Compare the X coordinates of the starting and ending points; the one with the larger X coordinate becomes the new endpoint; if the X coordinates are equal, compare the Y coordinates; the one with the larger Y coordinate becomes the new endpoint.

[0086] Key generation: Round the sorted starting point (x1, y1) and ending point (x1, y1) coordinates to 6 decimal places to form a quadruple (x1, y1, x2, y2) as a unique key.

[0087] Filtering: Maintain a hash set to store processed segment keys; skip new segment keys if they already exist; calculate segment length ( If L < 5 units, it is considered noise and will be deleted.

[0088] S25. Merging of standardized documents.

[0089] Collect intermediate files generated from each sub-step (conversion results such as thick lines, triangles, and circles), and use the lxml library to read each file one by one to extract... <svg>Graphical elements within the `<svg>` tag (excluding XML declarations and SVG header tags) are merged into a single SVG file. A secondary coordinate check is performed on the merged file, and elements with residual `transform` attributes are recursively processed. The final result is an SVG file without `transform` attributes and with standardized element types, stored at ` / data / standardized_svg / [hash value].svg`.

[0090] Template standardization module: This module ensures that the coordinate system, element types, and parameter formats of the templates are consistent with those of the scene diagrams. The specific implementation is as follows:

[0091] Template library construction: Create a template library directory / data / template / , and create subdirectories according to industry categories (such as machinery, electronics) to store the original SVG template files;

[0092] Batch standardization processing: Develop a batch processing script that iterates through all files in the template library, calls the core algorithm of the standardization module to perform processing, and generates standardized template files that are stored in / data / standardized_template / .

[0093] Consistency verification: Randomly select 10% of the template files and scene graph files, and compare the element type distribution, coordinate range and style parameters of the two to ensure that the consistency error of the standardized data is ≤0.5%.

[0094] OCR processing module: Responsible for text detection and SVG text region deletion. The specific steps are as follows:

[0095] Sliding window OCR detection: Using the drawing OCR tool, the page segmentation mode was set to PSM3 (fully automatic page segmentation), and the language pack was selected as Chinese-English bilingual (chi_sim+eng). Sliding window detection was performed on an 800DPI PNG image, with the window size set to 256×256 and the step size set to 128, generating a JSON result file containing text content, position coordinates (x1, y1, x2, y2), and confidence scores.

[0096] Results deduplication and integration: For text detection results in overlapping areas (overlap area > 50%), the record with the highest confidence is retained, and adjacent areas with the same content are merged;

[0097] SVG text region deletion: Parse the position coordinates of the OCR result, locate the text element in the SVG through coordinate mapping (PNG to SVG coordinate ratio conversion), and delete the path tag containing the text. <text>The tag generates a text-free SVG file, stored in / data / no_text_svg / [hash value].svg.

[0098] Index generation module: Used to convert standardized SVG into structured index data, improving matching efficiency. Implementation steps:

[0099] Geometric feature extraction: Traverse all elements of the standardized SVG and extract features by type: Line elements: Extract the start point (x1, y1) and end point (x2, y2), and calculate the length. ], the angle θ = arctan2(y2-y1, x2-x1), and θ is standardized to [0°, 180°] (subtract 180° when θ>180°);

[0100] Where (x1, y1) are the coordinates of the starting point of the line segment; (x1, y1) are the coordinates of the ending point of the line segment; L is the length of the line segment; y2−y1 is the difference in Y coordinates between the starting point and the ending point of the line segment; x2−x1 is the difference in X coordinates between the starting point and the ending point of the line segment; and θ is the angle of the line.

[0101] Circular elements: Extract the center (cx, cy) and radius r;

[0102] Ellipse elements: extract center (cx, cy), X-axis radius rx, Y-axis radius ry;

[0103] Arc elements: Extract arc parameters and center coordinates (calculated using an arc fitting algorithm).

[0104] Multidimensional index construction: Three types of indexes are constructed using a dictionary structure: Type index: with the element type (line / circle / ellipse / arc) as the key and the value as a list of features of all elements of that type;

[0105] Precise Angle Index: A list of line elements with the corresponding angle as the key and the normalized angle (retaining one decimal place) as the value;

[0106] Statistical Index: Records the distribution range of the quantity and length / radius of each element type, used for quickly filtering candidate elements.

[0107] Template topology analysis: For the standardized template SVG, traverse all line endpoints and use the K-nearest neighbor algorithm (K=5) to identify connection points (endpoint clusters with a distance ≤ 0.1 units). Construct an undirected graph model, using element IDs as nodes and connection relationships as edges, record the coordinates of the connection endpoints between nodes, and generate a topology JSON file stored at / data / index / template / [template ID]_topology.json.

[0108] Multi-template matching module: Employs a three-level anchor point selection, multi-rotation adaptation, and topology verification strategy to achieve high-precision matching. Specific implementation details:

[0109] 2.6.1 Anchor point dynamic selection and rotation adaptation.

[0110] Three-level anchor point selection: Select anchor point elements from high to low priority: Level 1 anchor point: Special angle lines with an angle distance of more than 5° from 0° or 90°. Count the number of candidate elements for each angle and select the element corresponding to the angle with the fewest elements.

[0111] Secondary anchor points: Shape elements, selected according to the priority of ellipse → arc → circle, with priority given to larger elements;

[0112] Level 3 anchor points: Common angled straight lines (0°, 90°, etc.), select the element with the longest length as the guaranteed anchor point.

[0113] Multi-rotation direction adaptation: Calculates the expected angle of the template anchor point after rotation for four rotation directions: 0°, 90°, 180°, and 270°. (Standardized to [0°, 180°]). Elements within the range of θ_rot ± 0.5° are searched in the precise angle index of the scene graph to form a candidate anchor point list.

[0114] 2.6.2 Candidate anchor point verification and element matching.

[0115] Anchor point compatibility check: For each candidate anchor point, verify its type consistency with the template anchor point; for straight anchor points, calculate the angle difference. If the difference > 90°, take 180° - the difference as the equivalent difference; an equivalent difference ≤ 1° indicates compatibility. Calculate the scaling ratio S: ; Filter outliers with S < 0.05 or S > 20, and tiny elements with S < 0.2 and size < 2 units; where, candidate anchor point feature size: the feature size of candidate anchor points in the scene graph (length for straight lines, radius for circles, axis radius for ellipses, etc.); template anchor point feature size: the feature size of the corresponding anchor point in the template; S: the scaling ratio between the candidate anchor point and the template anchor point.

[0116] Non-anchor point element matching: Using the candidate anchor point as a reference, calculate the size ratio of other elements in the template relative to the anchor point (s_i = element i size / anchor point size), the position ratio vector ((dx_i / anchor point size, dy_i / anchor point size)), and the angle difference Δθ_i. Calculate the expected size (s_i × candidate anchor point size) and expected position (candidate anchor point position + position ratio vector × candidate anchor point size, rotated by the rotation angle) of element i based on the actual size of the candidate anchor point. Construct a search box centered on the expected position with a dynamic position tolerance as the radius.

[0117] Small anchor points (size < 5 units): ;

[0118] Medium anchor points (5 ≤ size ≤ 15 units): ;

[0119] Large anchor points (size > 15 units): Wherein, anchor point size: the feature size of the candidate anchor point; position tolerance: the allowable range of position error when matching non-anchor point elements; size tolerance: the allowable range of size error when matching non-anchor point elements.

[0120] 2.6.3 Topology verification and result deduplication.

[0121] Adaptive topology tolerance calculation: based on template complexity (C=1+0.1×(number of elements-3)) and scale characteristics ( Calculate the basic connection tolerance T0 = C × S; where, C: template complexity coefficient (determined by the total number of template elements); number of elements: the total number of graphic elements contained in the template; S (in the basic tolerance): template scale feature (calculated from the diagonal length of the template bounding box); diagonal length of the template bounding box: the diagonal length of the template SVG element bounding box; T0: basic connection tolerance.

[0122] Adjust according to the scaling ratio: Where, S (scaling adjustment): the scaling ratio of the anchor point size (candidate anchor point feature size / template anchor point feature size); T: the final topology connection tolerance (verifying the positional consistency of the connection points of the elements).

[0123] Connector point verification: Map the coordinates of the template connector points to the scene graph coordinate system through matching transformations (scaling, rotation, translation) to obtain the expected connector point positions. Extract the endpoints of the matching elements of the template connector point associated elements in the scene graph, and verify that the distance from all endpoints to the expected position is ≤T, and the distance between any two endpoints is ≤T. If all connector points pass the verification, the topology is valid.

[0124] Result Deduplication and Output: The anchor point ID, rotation angle, and element mapping relationship of the matching results are extracted to generate a unique signature. These signatures are then sorted in descending order of matching confidence (number of correctly matched elements / total number of elements in the template). For signatures with the same name, the result with the highest confidence is retained. Matching results with different rotation angles are retained independently. The final output is a JSON result file containing anchor point correspondences, transformation parameters, and confidence scores, stored at / data / match_result / [scene graph hash value]_result.json.

[0125] The beneficial effects of this embodiment are as follows: This embodiment achieves efficient and accurate recognition from PDF input to primitive matching through a fully automated processing pipeline. Coordinate system normalization, intelligent shape recognition, and dynamic tolerance matching mechanisms solve format conversion errors, multi-dimensional indexing and topology verification improve matching robustness, and modular design ensures flexible system expansion, thus improving the overall accuracy and efficiency of primitive recognition and matching.

[0126] Example 2:

[0127] See Figure 2 As shown in the figure, the primitive matching and intelligent recognition method based on SVG vector graphics in this embodiment has the following process:

[0128] S1. Input preprocessing and format conversion.

[0129] PDF reception and deduplication: The hash value of the PDF file is calculated using the SHA-256 hash algorithm and compared with the database to achieve deduplication and storage; the pdf2svg tool is called to convert the entire PDF page into SVG, and rsvg-convert is called to generate an 800DPI PNG for OCR.

[0130] S2, Coordinate system normalization and element standardization.

[0131] Transformation matrix analysis: Extract the affine transformation matrix (scaling, skewing, translation parameters) of the transform attribute of the SVG element, calculate the determinant value to determine the chiral change (when the determinant < 0, there is a mirror transformation).

[0132] Arc parameter correction: When a change in chirality is detected, the arc sweep-flag value is flipped (0↔1), the endpoint coordinates are transformed using a transformation matrix, and the ellipse radius is adjusted according to the scaling factor.

[0133] Global coordinate transformation: By unifying all coordinate points to the standard coordinate system through affine transformation formulas, the transform attribute is removed to obtain a geometric representation without coordinate system bias.

[0134] S3, Intelligent Shape Recognition and Transformation.

[0135] Fill path classification: Z command quantity + vertex number determination — 3-4 vertex closed polygons are converted into 3 straight lines; complex fill paths extract the center line and convert it into a thick straight line (stroke).

[0136] Bézier curve processing: Paths with 4 C commands are determined by the aspect ratio of the bounding box (>0.95 is considered a circle, otherwise an ellipse); paths with 1-3 C commands are considered arcs; paths without C commands are converted to lines or polygons.

[0137] Simple path extraction: Regular expressions are used to identify movement and straight line command paths, and the coordinates of the start and end points are extracted to generate standard line elements; complex paths are deduplicated by removing duplicates based on direction without key information, and filtering out noisy short sides with a length of less than 5 units.

[0138] S4. Style integration and tagging.

[0139] Attribute merging: Integrates the independent fill / stroke attributes with the style attribute, prioritizing independent attributes in case of conflict; stroke-width is scaled proportionally to the transformation matrix scaling factor.

[0140] Line caps and markers: Set a button line cap to a straight line; use black fill and a non-zero path marker with data-thick=true for subsequent matching priority determination.

[0141] S5. Template standardization and consistency assurance.

[0142] Template processing: Perform the same standardized process (coordinate transformation, shape recognition, etc.) on the SVG template library to ensure that it is consistent with the coordinate system / parameter format of the scene graph. The consistency error is ≤0.5% in the random sampling verification.

[0143] S6, Text Processing and Textless SVG Generation.

[0144] OCR detection: Tesseract sliding window (256×256 window, step size 128) detects text position, retains high confidence results for overlapping areas, and generates position JSON.

[0145] Text region deletion: Map PNG text coordinates to SVG, delete the corresponding path / tag, and generate a text-free SVG.

[0146] S7, Index Building and Multi-Template Matching.

[0147] Geometric feature extraction: For lines, extract the start / end point / length / angle (normalized from 0° to 180°); for circles / ellipses, extract the center / radius; for text, extract the content / position / font / rotation information.

[0148] Multidimensional index construction: type index (grouped by element type), precise angle index (normalized angle as key), statistical index (length / radius distribution).

[0149] Topology analysis: Template endpoint clustering identifies connection points, and an undirected graph is constructed to record the connection relationships between elements.

[0150] S8, high-precision matching and topology verification.

[0151] Anchor point selection: Three-level priority strategy—Special angle lines (distance from 0° / 90°>5°) → Shape elements (ellipse>arc>circle) → Common angle lines.

[0152] Rotation adaptation: Under rotation directions of 0° / 90° / 180° / 270°, calculate the expected angle of the template anchor point and search for candidate anchor points within the tolerance range in the scene graph angle index.

[0153] Non-anchor point matching: Calculate dynamic tolerance based on anchor point size (small / medium / large anchor point positions / size tolerances are different), and construct a search box to match non-anchor point elements.

[0154] Topology verification: Connecting point coordinate mapping + endpoint distance verification (≤ dynamic connection tolerance) to ensure geometric topology consistency of matching results.

[0155] Deduplication results: Generate a unique signature based on anchor ID + rotation angle + element mapping, and retain the non-repeating result with the highest confidence.

[0156] The beneficial effects of this embodiment are as follows: This embodiment achieves efficient and accurate recognition from PDF input to primitive matching through a fully automated process; coordinate system normalization, intelligent shape recognition and dynamic tolerance matching mechanism solve format conversion errors; multi-dimensional indexing and topology verification improve matching robustness; modular design ensures flexible system expansion; and the overall accuracy and efficiency of primitive recognition and matching are improved.

[0157] All formulas in this invention are dimensionless and calculated numerically. The preset parameters in the formulas can be set by those skilled in the art according to the actual situation.

[0158] The weighting coefficients of this invention are used to measure the degree of influence of different factors or variables on a certain outcome or decision. The weighting coefficient is defined as the numerical value assigned to each factor when comparing and evaluating multiple factors, reflecting their importance or priority. These weighting coefficients can be determined according to specific circumstances and needs, and are usually jointly formulated and confirmed by professionals or relevant stakeholders. By reasonably setting the weighting coefficients, programs or systems can be helped to make decisions or predictions more accurately.

[0159] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

[0160] The preferred embodiments of the present invention disclosed above are merely illustrative of the invention. These preferred embodiments do not exhaustively describe all details, nor do they limit the invention to specific implementations. Clearly, many modifications and variations can be made based on the content of this specification. This specification selects and specifically describes these embodiments to better explain the principles and practical applications of the invention, thereby enabling those skilled in the art to better understand and utilize the invention. The invention is limited only by the claims and their full scope and equivalents.< / text> < / svg> < / path> < / line> < / ellipse> < / circle> < / line> < / line> < / path> < / path>

Claims

1. A primitive matching and intelligent recognition system based on SVG vector graphics, characterized in that, It includes modules for converting PDF to SVG and PNG, standardization, OCR processing, index generation, multi-template matching, and template standardization. The PDF to SVG and PNG conversion module is used to receive PDF technical drawings, perform deduplication and storage, and then convert the PDF into SVG files and PNG images of a specified resolution. The standardization module is used to parse the transformation attributes of graphic elements in SVG files and perform coordinate normalization, classify and identify path elements according to features and convert them into standard graphic elements, split complex paths and perform deduplication and merging to generate standardized SVG files. The template standardization module is used to perform the same processing flow as the standardization module on the SVG templates in the template library to generate standardized template files; The OCR processing module is used to perform text detection on PNG images, delete text regions in SVG files based on the detection results, and generate text-free SVG files. The index generation module is used to extract the geometric features of graphic elements in standardized SVG files and build a multidimensional index, and to perform topological analysis on standardized template files to generate a topological model. The multi-template matching module is used to dynamically select anchor elements based on multi-dimensional indexes, adapt to multiple rotation directions to perform element matching, and output the matching results after filtering out false matches through topology verification.

2. The primitive matching and intelligent recognition system based on SVG vector graphics according to claim 1, characterized in that, The specific processing steps of the PDF to SVG and PNG conversion module include: The SHA-256 hash algorithm is used to calculate the hash value of the PDF file, and deduplication is achieved through a database table that maps hash value to file path. The pdf2svg tool is used to perform PDF to SVG conversion, converting all pages of the PDF into a single SVG file. Pages are distinguished by group tags. After conversion, graphic element tag validation is performed and the conversion is retried up to 3 times. The rsvg-convert tool is used to convert the SVG file into an 800 DPI PNG image, and the resolution is verified using OpenCV before being output.

3. The primitive matching and intelligent recognition system based on SVG vector graphics according to claim 1, characterized in that, The standardization module performs coordinate normalization as follows: The lxml library is used to parse the transform attribute of the graphic element, extract the affine transformation matrix parameters (a,b,c,d,e,f), and calculate the matrix determinant value det=a×d−b×c; If det < 0, it is determined to be a mirror transformation. The sweep-flag value is flipped on the SVG arc element, the endpoint coordinates are transformed according to the transformation formulas x'=a×x+b×y+e and y'=c×x+d×y+f, and the radius is adjusted according to rx'=rx×|a| and ry'=ry×|d|. Perform coordinate transformations on all graphic elements: X = a × X + b × Y + e, Y = c × X + d × Y + f, and delete the transform attribute after the transformation.

4. The primitive matching and intelligent recognition system based on SVG vector graphics according to claim 1, characterized in that, The standardization module's process for classifying and recognizing path elements includes: Extract filled path elements whose fill attribute is not none; simple closed polygons with 3-4 vertices are identified as triangles and decomposed into line elements; complex filled paths with more than 1 Z command are identified as thick lines and the center line path is extracted. Count the number of Bézier curve C commands in non-filled path elements. If there are 4 C commands, it is determined to be a circle based on the bounding box aspect ratio W / H ∈ [0.95, 1.05]; otherwise, it is an ellipse. If there are 1-3 C commands, it is determined to be an arc and marked with the data-type="arc" attribute. If there are no C commands, it is identified as a simple straight line path and converted into a standard line element. Mark the path element with fill="black" and fill-rule="nonzero" as a thick line and add the data-thick="true" attribute.

5. The primitive matching and intelligent recognition system based on SVG vector graphics according to claim 1, characterized in that, The process of breaking down complex paths using standardized modules includes: The data of multiple arc paths are segmented using regular expressions ([MmLlAaZz]), the arc parameters are extracted according to the command sequence, and an independent arc path is constructed with the current point as the starting point and segment number identifiers are added. The system splits multiple straight paths into two-point straight line segments, generates direction-independent quadruple unique keys through coordinate sorting to achieve deduplication, and filters out noise line segments with lengths less than a set threshold.

6. The primitive matching and intelligent recognition system based on SVG vector graphics according to claim 1, characterized in that, The processing steps of the index generation module include: Extract the start point, end point, length, and angle normalized to [0°, 180°] of straight line elements; the center and radius of circle elements; the center and axial radius of ellipse elements; and the parameters and center coordinates of arc elements. Construct type indexes, precise angle indexes, and statistical indexes; The K-nearest neighbor algorithm with K=5 is used to identify the clustered regions of line endpoints with a distance ≤ a set threshold in the standardized template as connection points to construct an undirected graph of element connection relationships.

7. The primitive matching and intelligent recognition system based on SVG vector graphics according to claim 1, characterized in that, The matching process of the multi-template matching module includes: Anchor points are selected based on priority, including straight lines with special angles, ellipses, arcs, circles, and straight lines with common angles. The expected angles are calculated and candidate anchor points are selected for rotation directions of 0°, 90°, 180°, and 270°. Verify the compatibility of candidate anchor point types and angles, calculate the scaling ratio S and filter outliers; calculate the expected position and size of non-anchor point elements according to the relative proportion of anchor points, and search for matching elements through dynamic tolerance. Calculate adaptive topology tolerance based on template complexity and scale features, verify endpoint distances after connection point mapping, extract anchor point IDs, rotation angles, and element mapping relationships to generate unique signatures and remove duplicates, and output matching results with confidence scores. A method for primitive matching and intelligent recognition based on SVG vector graphics, used to implement the primitive matching and intelligent recognition system based on SVG vector graphics as described in claim 1, characterized by comprising the following steps: S1. Input preprocessing and format conversion: The PDF file is deduplicated based on the SHA-256 hash algorithm, converted to SVG using the pdf2svg tool, and generated an 800DPI PNG image using rsvg-convert; S2. Coordinate system normalization and element standardization: Extract the affine transformation matrix of the transform attribute of SVG elements, calculate the determinant value det=a×d−b×c to determine the chiral change, adjust the arc parameters and perform affine transformation on all coordinate points. S3, Intelligent Shape Recognition and Conversion: Classifies path elements according to fill type and Bézier curve command features, and converts them into standardized elements; S4. Style Integration and Markup: Integrate SVG element style attributes, adjust line width by stroke-widthnew=stroke-widthold×det, and mark thick line elements; S5. Template Standardization: Perform a standardization process on the SVG template library and conduct spot checks to verify the data consistency error between the template and the scene graph. S6. Text processing: Use an OCR sliding window to detect text and delete the corresponding text area in the SVG; S7. Index Construction: Extract geometric features of SVG elements, construct type index, precise angle index and statistical index, and analyze template topology; S8. High-precision matching and topology verification: Select anchor points according to three-level priority, adapt to multiple rotation directions, match non-anchor point elements based on dynamic tolerance, verify connection points through adaptive topology tolerance, and output matching results after deduplication.

Citation Information

Cited By

  • A cockpit display and control system graphic tree design check fitting method

    CN122195801A