Methods, apparatus, equipment, and media for CAD vector image recognition based on structured path coding.
By directly structuring SVG path commands and parameters, constructing path-level feature vectors and performing graph-level aggregation, the problems of information loss caused by rasterization and low accuracy of complex primitive recognition in existing technologies are solved, achieving efficient and stable CAD vector image recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGDONG UNIV OF TECH
- Filing Date
- 2026-02-11
- Publication Date
- 2026-05-26
AI Technical Summary
Existing CAD vector image recognition methods are prone to information loss during rasterization, and methods based on point sets and graph neural networks are difficult to accurately recover the continuous contours and topological relationships of complex primitives, resulting in limited recognition accuracy and robustness.
A structured path encoding method is adopted to directly encode SVG path commands and parameters, construct path-level feature vectors and perform graph-level aggregation, avoiding rasterization and point set conversion, and uniformly processing various primitives.
It significantly improves the recognition stability and accuracy of the model at different scaling ratios, simplifies feature engineering, and enhances the recognition accuracy and robustness of complex CAD drawings.
Smart Images

Figure CN122090481A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method, apparatus, device, and medium for recognizing CAD vector graphics based on structured path coding, belonging to the field of computer vector graphics recognition. Background Technology
[0002] Currently, computer-aided design (CAD) drawings have become the core data carrier in the construction industry. CAD drawings are typically stored in vector graphics format. Unlike pixel-based graphics, vector graphics describe shapes using mathematical formulas and have the excellent characteristic of not losing quality when enlarged or reduced.
[0003] In recent years, with the development of deep learning technology, researchers have begun to apply deep learning methods to the task of recognizing CAD drawings. Existing CAD drawing recognition methods can be mainly divided into the following three categories: (1) Rasterization-based method: This method rasterizes CAD vector graphics into traditional pixel images, and then uses deep learning models such as convolutional neural networks (CNN) for recognition. However, the disadvantage of this method is that it ignores the structural information unique to vector graphics, and the rasterization process is usually time-consuming and inefficient.
[0004] (2) Point set-based method: This method treats CAD drawings as point sets, and after sampling, the points are input into mainstream point cloud models (such as Point Transformer) for training to complete the recognition task (related patent: CN202311670533.6, "Vector Recognition Method, Device, Terminal and Storage Medium Based on Point Set Representation").
[0005] (3) Graph Neural Network-based method: This method regards the basic primitives such as endpoints, line segments, and arcs in CAD vector graphics as nodes of the graph, and regards the connections, adjacencies, or topological relationships between primitives as edges. It uses graph neural networks such as graph convolutional networks (GCN) for training, thereby realizing the recognition of CAD vector graphics.
[0006] The main drawbacks of existing technologies are as follows: (1) During the rasterization of vector graphics, the resolution (DPI) must be manually specified. Setting the resolution too low will result in broken lines, obvious jagged edges, and loss of detail; setting it too high will result in huge computational and storage overhead. In addition, to adapt to different needs, the same vector graphic may need to be rasterized multiple times, which makes the processing flow complicated and difficult to deploy in large-scale CAD drawing scenarios.
[0007] (2) CAD architectural drawings are saved in vector format, and their data itself contains rich information such as path geometry, topological relationships, line width, and color. However, existing rasterization schemes, after being converted into pixel images, only retain brightness or color distribution, making it impossible for the model to utilize key structural information such as "which paths constitute a component".
[0008] (3) The point set-based method samples CAD vector graphics into point clouds for recognition, and the path is broken down into discrete coordinate points. For complex primitives composed of multiple superimposed paths or containing closed regions and long curves, this method is difficult to accurately recover their original continuous contours and local geometric features, resulting in recognition results that are too sensitive to sampling density and strategy.
[0009] (4) The graph neural network-based method directly learns the graph structure by constructing basic primitives such as line segments and nodes. However, this approach uses "single primitive" as the modeling unit and lacks a unified description with complete "paths" as intermediate representations. At the same time, when the number of paths in the graph varies greatly, the existing method lacks a stable path-level feature aggregation and whole-graph recognition mechanism, resulting in limited recognition accuracy and robustness for complex CAD drawings. Summary of the Invention
[0010] To address the shortcomings of automatic recognition of CAD architectural drawings, this invention proposes a method, apparatus, device, and medium for CAD vector graphic recognition based on structured path encoding. This method performs structured path encoding on SVG format vector graphics without requiring rasterization or conversion into point sets or graph structures, thus uniformly completing the recognition of symbols in CAD drawings.
[0011] The first objective of this invention is to provide a method for recognizing CAD vector graphics based on structured path encoding.
[0012] The second objective of this invention is to provide a CAD vector image recognition device based on structured path encoding.
[0013] A third objective of this invention is to provide a computer device.
[0014] A fourth objective of this invention is to provide a computer-readable storage medium.
[0015] The first objective of this invention can be achieved by adopting the following technical solution: A method for recognizing CAD vector graphics based on structured path encoding, the method comprising: Obtain the command sequence and parameter sequence corresponding to each SVG path; Based on the command sequence and the parameter sequence, a fixed-length vector representation of the path is obtained through an encoding network; Based on the fixed-length vector representation of the path, the path feature matrix is obtained by arranging the paths sequentially according to their path numbers. Based on the path feature matrix, the graph-level feature vector of the vector map is obtained; Based on the graph-level feature vectors, the recognition result of the vector image is obtained through a neural network.
[0016] Furthermore, before obtaining the command sequence and parameter sequence corresponding to each SVG path, the process also includes: Based on the SVG path syntax, four basic commands related to the contour geometry are selected from all path commands as modeling objects. The four basic commands include move command, line command, elliptical arc command and closed path command. The four basic commands are uniformly encoded into discrete integer IDs and normalized to obtain a set of command types. A mapping relationship between command types and integer IDs is established, wherein the movement command is mapped to 0, the straight line command is mapped to 1, the elliptical arc command is mapped to 2, and the closed path command is mapped to 3. Based on the mapping relationship, the Path, Circle, and Ellipse primitives are uniformly converted into representations consisting of command sequences and parameter sequences.
[0017] Furthermore, based on the mapping relationship, the Path, Circle, and Ellipse primitives are uniformly converted into a representation composed of command sequences and parameter sequences, including: Extracting the command sequence and parameter sequence of a Path element: using regular expressions to extract (cmd) from a string. i (p*) pairs, where the set of command types is cmd i ∈{M,L,A,Z}, cmd i Map to integer command c i = (cmd) i Given numbers ∈ {0, 1, 2, 3}, extract all numbers from the parameter string p* to form a parameter vector. , ; Extract the command sequence and parameter sequence of the circle element: convert the circle element into a combination of a move command, four elliptical arc commands and a closed path command, and construct the first parameter sequence based on the first geometric attribute parameter; Extract the command sequence and parameter sequence of an Ellipse element: Convert the Ellipse element into a combination of a move command, four elliptical arc commands, and a closed path command, and construct the second parameter sequence based on the second geometric attribute parameter; Based on each path sequence, color information and line width information are extracted from SVG attributes and combined into a metadata vector that corresponds one-to-one with the path sequence above.
[0018] Furthermore, the parameter vector The ellipse is standardized to seven dimensions, which represent the x-axis radius, y-axis radius, rotation angle, major arc marker, direction marker, end point x-coordinate, and end point y-coordinate in that order. If there are more than seven parameters, only the first seven parameters will be taken. If the number of parameters is less than seven, then the parameter vector dimension is increased to seven dimensions by padding with zeros.
[0019] Further, the step of obtaining a fixed-length vector representation of the path through an encoding network based on the command sequence and the parameter sequence includes: The command encoding is converted into a command embedding vector by looking up the command embedding matrix; The parameters corresponding to the command are converted into parameter embedding vectors through a multi-layer feedforward neural network; The command embedding vector and the parameter embedding vector are fused together, and positional encoding information is added to form an input sequence; The input sequence is processed using a Transformer structure, which includes several cascaded encoder layers. Each encoder layer includes a multi-head attention layer and a feedforward network layer, and is processed through residual connections and normalization operations. Perform the first aggregation on the output sequence of the Transformer structure to generate a fixed-length vector representation of the path.
[0020] Further, the first aggregation of the output sequence of the Transformer structure to generate a fixed-length vector representation of the path includes: Based on the output sequence, average pooling is used to calculate the mean of the feature vectors at all positions to obtain a fixed-length vector representation of the path. The step of obtaining the graph-level feature vector of the vector map based on the path feature matrix includes: Based on the path feature matrix, a second aggregation is performed to obtain the graph-level feature vector of the vector image.
[0021] Furthermore, the path feature matrix is = ∈ ,in For the first The first vector image The path feature vector of the path, d represents the number of paths in the vector graphic, and d represents the feature dimension.
[0022] The second objective of this invention can be achieved by adopting the following technical solution: A CAD vector graphic recognition device based on structured path encoding, the device comprising: The acquisition module is used to obtain the command sequence and parameter sequence corresponding to each SVG path; The encoding module is used to obtain a fixed-length vector representation of the path through an encoding network based on the command sequence and the parameter sequence. The arrangement module is used to arrange the path feature matrix sequentially according to the path number based on the fixed-length vector representation of the path; The aggregation module is used to obtain the graph-level feature vector of the vector image based on the path feature matrix. The recognition module is used to obtain the recognition result of the vector image based on the graph-level feature vector through a neural network.
[0023] The third objective of this invention can be achieved by adopting the following technical solution: A computer device includes a processor and a memory for storing a processor-executable program, wherein when the processor executes the program stored in the memory, it implements the above-described CAD vector graphic recognition method based on structured path encoding.
[0024] The fourth objective of this invention can be achieved by adopting the following technical solution: A computer-readable storage medium storing a program that, when executed by a processor, implements the above-described CAD vector image recognition method based on structured path encoding.
[0025] The present invention has the following advantages over the prior art: (1) This invention directly performs structured path encoding based on SVG path commands and parameters, without the need to rasterize or convert CAD vector graphics into point sets. This method fully preserves the geometric shape, continuity and hierarchical information of the path, fundamentally avoiding the information loss problem caused by improper rasterization resolution selection or sparse point set sampling, thereby significantly improving the recognition stability and accuracy of the model under different scaling ratios.
[0026] (2) This invention constructs a unified vector graphics representation paradigm by uniformly transcribing various primitives such as path, circle, and ellipse into path sequences based on M / L / A / Z commands. This enables the model to process various primitives within the same encoding space, simplifies feature engineering and network design, and facilitates efficient deployment in large-scale CAD drawing scenarios.
[0027] (3) The present invention uses a sequence encoding module to encode the command sequence and parameter sequence of each path to obtain a path-level feature vector. Then, it performs graph-level aggregation and classification at the path level, so that the recognition process can simultaneously consider the detailed shape inside the path and the combination relationship between multiple paths. It has a better modeling ability for complex symbols or components composed of multiple paths, thus significantly improving the recognition accuracy and robustness on complex CAD vector graphics. Attached Figure Description
[0028] 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 the structures shown in these drawings without creative effort.
[0029] Figure 1 This is a flowchart illustrating a CAD vector graphic recognition method based on structured path encoding, according to an embodiment of the present invention.
[0030] Figure 2 This is a structural diagram of a CAD vector graphic recognition device based on structured path encoding, according to an embodiment of the present invention. Detailed Implementation
[0031] 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. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0032] Example 1: Figure 1 This is a flowchart illustrating a CAD vector graphic recognition method based on structured path encoding, according to an embodiment of the present invention. Figure 1 As shown, the method includes: S101 obtains the command sequence and parameter sequence corresponding to each SVG path.
[0033] In this embodiment, the primitives such as path, circle, and ellipse in the SVG format file (essentially XML text) of CAD architectural drawings are uniformly converted into a representation of discrete command sequence + parameter sequence.
[0034] Furthermore, before obtaining the command sequence and parameter sequence corresponding to each SVG path, the process also includes: S1011 selects four basic commands related to the contour geometry from all path commands as modeling objects according to the SVG path syntax. The four basic commands include the move command, the line command, the elliptical arc command, and the closed path command.
[0035] The four types of commands and their meanings are as follows: (1) M / m: Move the current drawing point (MoveTo), only changing the drawing starting point, without generating an actual line segment; (2) L / l: Draw a line segment (LineTo) from the current point; (3)A / a: Draw an elliptical arc from the current point; (4) Z / z: Close the current path (ClosePath), connecting the current point with the starting point of the path to form a closed contour.
[0036] S1012 encodes the four basic commands into discrete integer IDs and normalizes them to obtain a set of command types. A mapping relationship is established between command types and integer IDs, wherein the movement command is mapped to 0, the straight line command is mapped to 1, the elliptical arc command is mapped to 2, and the closed path command is mapped to 3.
[0037] To facilitate subsequent serialization and model processing, these commands are uniformly encoded as discrete integer IDs, and the original command character set is defined as follows: ={'M','m','L','l','A','a','Z','z'}, First, normalize the case to obtain the set of command types. ={M,L,A,Z}, define the ID set as ID={0,1,2,3}, and based on this, establish a mapping function from command type to integer ID. →ID, the correspondence between commands is as follows: (M) = 0, (L) = 1, (A) = 2, (Z)=3.
[0038] Using this method, both the original path and the arc obtained by converting circle / ellipse will be encoded into the above ID sequence, forming a unified representation of the primitive.
[0039] Based on the mapping relationship, S1013 converts the Path, Circle, and Ellipse primitives into a unified representation composed of command sequences and parameter sequences.
[0040] Furthermore, based on the mapping relationship, the Path, Circle, and Ellipse primitives are uniformly converted into a representation composed of command sequences and parameter sequences, including: S10131 Extracting the command sequence and parameter sequence of Path elements: Using regular expressions, extract (cmd) from the string. i (p*) pairs, where the set of command types is cmd i ∈{M,L,A,Z}, cmd i Map to integer command c i = (cmd) i Given numbers ∈ {0, 1, 2, 3}, extract all numbers from the parameter string p* to form a parameter vector. , .
[0041] Furthermore, the parameter vector The parameters are standardized to seven dimensions, representing the x-axis radius, y-axis radius, rotation angle, large arc marker, direction marker, endpoint x-coordinate, and endpoint y-coordinate in sequence. If there are more than seven parameters, only the first seven parameters are taken. If there are fewer than seven parameters, zero-padding is performed to make the parameter vector seven-dimensional.
[0042] Parsing and serializing Path elements: Using regular expressions, extracting a series of (cmd) elements from the string. i (p*) yes, where cmd i ∈{M,L,A,Z}, cmd i Mapping to integer commands, i.e., c i = (cmd) i Given strings ∈ {0, 1, 2, 3}, extract all numbers from the parameter string p* to obtain the sequence. , When the command is A / a, the parameters satisfy... There are 7 parameters in total. This represents the radius of the ellipse containing the arc along the x-axis. This represents the radius of the ellipse containing the arc along the y-axis, θ represents the rotation angle of the ellipse relative to the x-axis, laf (large-arc-flag) is the large arc flag, which is 0 or 1, used to indicate whether an arc segment less than or equal to 180° or greater than 180° is selected from the start to the end point, sf (sweep-flag) is the direction flag, which is 0 or 1, used to indicate whether the arc is drawn counterclockwise or clockwise from the start to the end point, and x, y represent the coordinates of the arc's end point in the SVG coordinate system. If the obtained parameters... If the value is greater than 7, then only the first 7 are taken; if the value is less than 7, then only the first If the value is less than 7, then zeros are padded to make up to 7 parameters, resulting in the final command sequence for the path. =( , ... ), parameter sequence =( , ... ).
[0043] S10132 Extract the command sequence and parameter sequence of the circle element: Convert the circle element into a combination of a move command, four elliptical arc commands and a closed path command, and construct the first parameter sequence based on the first geometric attribute parameter.
[0044] Converting a circle element into a command sequence: In this method, a circle is converted into a sequence of basic command combinations. Specifically, a circle is converted into a combination of one M command, four A (arc) commands, and one Close Path command. Details are as follows: Reading geometric parameters: First, read the basic information from the attributes: =cx, =cy, =r. ( , This indicates the position of the center of the arc along the x-axis and y-axis. (Indicates the radius).
[0045] Construction command and parameters: command ID =0, parameter =( + , ), which is the right boundary point of the Circle + , (Using this as the starting point.) Command ID= =2, =0,1,2,3, For command A, the angle range of the current arc segment is: = , = The coordinates of the endpoint of the arc segment are: = + cos( ), = + cos( Therefore, its corresponding parameter is =( , ,0,0,1, , ), Closed Path ID =3, the parameter is empty, therefore =(), using this method, the command sequence length corresponding to Circle is 6, and the command sequence C=(0,2,2,2,2,3). The path length of the circle is calculated using the analytic formula. =2 .
[0046] S10133 Extracts the command sequence and parameter sequence of an Ellipse element: Converts the Ellipse element into a combination of a move command, four elliptical arc commands, and a closed path command, and constructs a second parameter sequence based on the second geometric attribute parameter.
[0047] Converting Ellipse elements into command sequences: In this method, the processing of Ellipse is similar to that of circle in version 1.22, converting the Ellipse element into a combination of 1 M command, 4 A commands, and 1 ClosePath command, as follows: Reading geometric parameters: First, read the basic information from the attributes: =cx, =cy, =rx, =ry. ( , Indicates the position of the center of the circle on the x-axis and y-axis. , These represent the radii on the x-axis and y-axis, respectively.
[0048] Construction commands and parameters: 1: Initial MoveTo, command ID: =0, parameter =( + , ). 2: Command ID= =2, =0,1,2,3, For instruction A, the angle range of the current arc segment is: = , = The coordinates of the endpoint of the arc segment are: = + cos( ), = + cos( Therefore, its corresponding parameter is =( , ,0,0,1, , ),3: The command ID corresponding to ClosePath is =3, parameter =(), For calculating the perimeter of an ellipse, in order to quickly obtain the length feature in batch processing, this invention adopts an approximate calculation, assuming... =max( , ), =min( , ), circumference of the ellipse ≈2 b+4 - ).
[0049] S10134 extracts color and line width information from SVG attributes based on each path sequence and combines them into a metadata vector that corresponds one-to-one with the path sequence above.
[0050] This method enables a unified representation of primitives, converting paths, circles, and ellipses into a single set of command IDs and parameter sequences. This allows subsequent networks to learn within a unified input space, eliminating the need to process different SVG element types separately.
[0051] S102 Based on the command sequence and the parameter sequence, a fixed-length vector representation of the path is obtained through an encoding network.
[0052] In this embodiment, the sequence encoding module for feature extraction of SVG path command sequences is implemented using an existing Transformer-structured encoding network. The path sequence encoding module takes the command ID sequence and parameter sequence corresponding to a single SVG path as input and outputs a fixed-length vector representation of the path for subsequent vector image recognition tasks.
[0053] For any SVG path, after data preprocessing and SVG serialization, the command ID sequence and parameter sequence of that path can be obtained, where the command ID sequence is denoted as... =( , ,..... L represents the number of path commands. ∈{0,1,2,3}, where 0~3 represent the aforementioned move command, line command, and arc command, respectively. The parameter vector sequence is denoted as... =( , ,..... ), each of which ∈ These are the seven-dimensional control parameters corresponding to the current command.
[0054] Further, the step of obtaining a fixed-length vector representation of the path through an encoding network based on the command sequence and the parameter sequence includes: S1021 converts the command encoding into a command embedding vector by looking up the command embedding matrix.
[0055] Sequence encoding module setting command embedding matrix ∈ , where d is the hidden dimension. The command ID at position t in the path. The command embedding vector is obtained through table lookup operations: = [ ]∈ .
[0056] S1022 converts the parameters corresponding to the command into parameter embedding vectors through a multi-layer feedforward neural network.
[0057] To represent the continuous parameter information corresponding to each command, in this invention, the sequence encoding module is configured with a two-layer feedforward neural network. The seven-dimensional parameters are nonlinearly mapped to obtain a parameter embedding vector. Specifically, the weights of the first layer are denoted as... ∈ , bias is ∈ The weight of the second layer is ∈ , bias is ∈ Then for the parameter at position t have == ( + ), = + ,in The ReLU activation function is used. It is a parameter embedding vector of dimension d.
[0058] S1023 The command embedding vector and the parameter embedding vector are fused together, and position encoding information is added to form an input sequence.
[0059] Command embeddings and parameter embeddings are fused by vector addition to obtain a joint representation at the token level. = + ∈ To incorporate sequence order information, the sequence encoding module employs a sine-cosine positional encoding method. For the sequence position index t and feature dimension index k, the positional encoding function is defined as: PE(t, 2k) = sin( ), PE(t,2k+1)=cos( The above position codes are used to construct a position vector. ∈ This is then added to the joint embedding vector to obtain the input representation incorporating positional information: = + ∈ Arrange the input sequence of the entire path into matrix form: that is, Z = ∈ .
[0060] S1024 uses a Transformer structure to process the input sequence. The Transformer structure includes several encoder layers connected in series. Each encoder layer includes a multi-head attention layer and a feedforward network layer, and is processed through residual connections and normalization operations.
[0061] In this invention, the sequence coding unit is implemented using an existing transformer coding structure. The coding structure includes several cascaded encoder layers. Each encoder layer includes a multi-head attention layer and a feedforward network layer, and is implemented through residual connections and normalization operations. (Note: The original text contains some formatting errors and inconsistencies. A more accurate translation would require the full context.) The output of the layer encoding is The output is denoted as Then the operation of each layer can be represented as: =MHA( )+ , =FFN( )+ Where MHA represents multi-head attention operation, FFN is a feedforward network, and the first layer input is... = The path sequence obtained after N layers of encoders can be represented as: H= = ∈ .in ∈ The feature vector representing the position of the t-th command.
[0062] S1025 performs the first aggregation on the output sequence of the Transformer structure to generate a fixed-length vector representation of the path.
[0063] Furthermore, the first aggregation of the output sequence of the Transformer structure to generate a fixed-length vector representation of the path includes: based on the output sequence, using average pooling, averaging the feature vectors at all positions to obtain a fixed-length vector representation of the path.
[0064] In this invention, in order to obtain a fixed-length feature representation of a single path, the sequence encoding module processes the output sequence. The first aggregation is performed along the sequence length dimension. In one embodiment, the path-level aggregation unit uses average pooling to average the feature vectors at all positions, resulting in a path-level embedding vector: = ∈ , This encoding of the path can be used by subsequent recognition modules. Path-level aggregation can also employ max pooling or weighted attention pooling, and this invention does not limit the approach.
[0065] S103 Based on the fixed-length vector representation of the path, arrange them sequentially according to the path number to obtain the path feature matrix.
[0066] S104 Obtains the graph-level feature vector of the vector map based on the path feature matrix.
[0067] Further, obtaining the graph-level feature vector of the vector image based on the path feature matrix includes: performing a second aggregation based on the path feature matrix to obtain the graph-level feature vector of the vector image.
[0068] S105 uses a neural network to obtain the recognition result of the vector image based on the graph-level feature vector.
[0069] In this invention, the vector graphic recognition module performs vector graphic recognition using path features as input. Specifically, for the same SVG vector graphic, the path feature vectors output by the path feature encoding module are first arranged sequentially according to their path numbers to obtain a path feature matrix. = ∈ ,in For the first The first vector image The path feature vector of the path, Let d be the number of paths in the vector image and d be the feature dimension. Based on this, the graph-level aggregation unit in the vector image recognition module performs a second aggregation on the path feature matrix to obtain a graph-level feature vector representing the entire vector image. The method of average pooling in the implementation method, namely = Alternatively, aggregation methods such as weighted summation or max pooling can be used, and this invention does not limit the specific aggregation methods used.
[0070] The vector graphics recognition module uses existing fully connected neural networks to analyze the graph-level features. The mapping is performed, and the predicted score for each symbol category is output. Assuming the target task contains C categories, the classification head can contain one or more fully connected layers. Taking a two-layer structure as an example, the hidden layer parameters are first used... , Calculate intermediate features. = ( + ), and then output the number of layers , Obtain the prediction score vectors for each category = + ,in ∈ Each dimension corresponds to a score for a category, and the recognition results of the vector graphics can be obtained through functions such as Softmax.
[0071] Example 2: Figure 2 This is a structural diagram of a CAD vector graphic recognition device based on structured path encoding, according to an embodiment of the present invention. Figure 2 As shown, the device includes: The acquisition module 201 is used to acquire the command sequence and parameter sequence corresponding to each SVG path; The encoding module 202 is used to obtain a fixed-length vector representation of the path through an encoding network based on the command sequence and the parameter sequence. The arrangement module 203 is used to arrange the path features sequentially according to the path number based on the fixed-length vector representation of the path to obtain the path feature matrix; The aggregation module 204 is used to obtain the graph-level feature vector of the vector map based on the path feature matrix; The recognition module 205 is used to obtain the recognition result of the vector image based on the graph-level feature vector through a neural network.
[0072] Example 3: Embodiments of this application also provide a computer device, including: a memory storing an executable program; and a processor for running the program, wherein the program executes the methods in various embodiments of the present invention during runtime.
[0073] The aforementioned memory can refer to devices inside a computer used to store data and programs, including RAM, hard disks, etc. RAM can be used to temporarily store running programs and data, while hard disks can be used to store programs and data long-term. Memory enables the computer to read and write data and execute programs. The aforementioned processor is responsible for executing instructions in computer programs and performing data processing. It can also be responsible for controlling and executing various operations, including arithmetic operations, logical operations, and data transmission.
[0074] Example 4: Embodiments of this application also provide a computer-readable storage medium including a stored executable program, wherein, when the executable program is running, it controls the device where the computer-readable storage medium is located to perform the methods of various embodiments of the present invention.
[0075] The aforementioned computer storage media can refer to the media used in computer memory to store certain discontinuous physical quantities. Computer storage media mainly include semiconductors, magnetic cores, magnetic drums, magnetic tapes, laser discs, etc. Computer-readable storage media include stored programs, which can be a set of instructions that a computer can recognize and execute, running on an electronic computer to meet certain information needs.
[0076] Example 5: Embodiments of this application also provide a computer program product, including a computer program that, when executed by a processor, implements the methods of various embodiments of the present invention.
[0077] The aforementioned computer program products can refer to software programs that have been written, tested, and released, and can run on computers or other devices. Computer program products can include application programs, operating systems, utility software, etc., used to achieve specific functions or solve specific problems.
[0078] Example 6: Embodiments of this application also provide a computer program product, including a non-volatile computer-readable storage medium for storing a computer program that, when executed by a processor, implements the methods in various embodiments of the present invention.
[0079] The aforementioned non-volatile computer-readable storage medium can refer to a medium for storing data. Non-volatile computer-readable storage media can retain data without loss when power is off and can be used to store long-term data, such as operating systems, applications, and user files. Non-volatile storage media can include hard disk drives, solid-state drives, optical disks, and flash memory storage devices, etc.
[0080] Example 7: Embodiments of this application also provide a computer program that, when executed by a processor, implements the methods described in the various embodiments of the present invention.
[0081] The aforementioned computer program can refer to a set of instructions used to tell the computer to perform specific tasks or operations. Computer programs can be written by programmers using specific programming languages and can include algorithms, data structures, logic, and control flow. Computer programs can be used for a variety of purposes, including application software, operating systems, etc.
[0082] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0083] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0084] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0085] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0086] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0087] In summary, this invention effectively avoids the information loss problem in vector graphics during rasterization caused by inappropriate resolution selection. Simultaneously, it overcomes the inherent limitations of point-set sampling methods in accurately representing the overall contour and topological structure of complex primitives. Furthermore, by introducing a unified structured path encoding, this invention enables the same recognition model to be widely applied to various types of CAD vector symbols and primitives.
[0088] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A CAD vector diagram recognition method based on structured path coding, characterized in that, include: Obtain the command sequence and parameter sequence corresponding to each SVG path; Based on the command sequence and the parameter sequence, a fixed-length vector representation of the path is obtained through an encoding network; Based on the fixed-length vector representation of the path, the path feature matrix is obtained by arranging the paths sequentially according to their path numbers. Based on the path feature matrix, the graph-level feature vector of the vector map is obtained; Based on the graph-level feature vectors, the recognition result of the vector image is obtained through a neural network.
2. The CAD vector figure recognition method according to claim 1, characterized in that, Before obtaining the command sequence and parameter sequence corresponding to each SVG path, the process also includes: Based on the SVG path syntax, four basic commands related to the contour geometry are selected from all path commands as modeling objects. The four basic commands include move command, line command, elliptical arc command and closed path command. The four basic commands are uniformly encoded into discrete integer IDs and normalized to obtain a set of command types. A mapping relationship between command types and integer IDs is established, wherein the movement command is mapped to 0, the straight line command is mapped to 1, the elliptical arc command is mapped to 2, and the closed path command is mapped to 3. Based on the mapping relationship, the Path, Circle, and Ellipse primitives are uniformly converted into representations consisting of command sequences and parameter sequences.
3. The CAD vector figure recognition method according to claim 2, characterized in that, Based on the mapping relationship, the Path, Circle, and Ellipse primitives are uniformly converted into a representation consisting of command sequences and parameter sequences, including: Extracting the command sequence and parameter sequence of a Path element: using regular expressions to extract (cmd) from a string. i (p*) pairs, where the set of command types is cmd i ∈{M,L,A,Z}, cmd i Map to integer command c i = (cmd) i Given numbers ∈ {0, 1, 2, 3}, extract all numbers from the parameter string p* to form a parameter vector. , ; Extract the command sequence and parameter sequence of the circle element: convert the circle element into a combination of a move command, four elliptical arc commands and a closed path command, and construct the first parameter sequence based on the first geometric attribute parameter; Extract the command sequence and parameter sequence of an Ellipse element: Convert the Ellipse element into a combination of a move command, four elliptical arc commands, and a closed path command, and construct the second parameter sequence based on the second geometric attribute parameter; Based on each path sequence, color information and line width information are extracted from SVG attributes and combined into a metadata vector that corresponds one-to-one with the path sequence above.
4. The CAD vector graphic recognition method according to claim 3, characterized in that, parameter vector The ellipse is standardized to seven dimensions, which represent the x-axis radius, y-axis radius, rotation angle, major arc marker, direction marker, end point x-coordinate, and end point y-coordinate in that order. If there are more than seven parameters, only the first seven parameters will be taken. If the number of parameters is less than seven, then the parameter vector dimension is increased to seven dimensions by padding with zeros.
5. The CAD vector graphic recognition method according to claim 1, characterized in that, The step of obtaining a fixed-length vector representation of the path through an encoding network based on the command sequence and the parameter sequence includes: The command encoding is converted into a command embedding vector by looking up the command embedding matrix; The parameters corresponding to the command are converted into parameter embedding vectors through a multi-layer feedforward neural network; The command embedding vector and the parameter embedding vector are fused together, and positional encoding information is added to form an input sequence; The input sequence is processed using a Transformer structure, which includes several cascaded encoder layers. Each encoder layer includes a multi-head attention layer and a feedforward network layer, and is processed through residual connections and normalization operations. Perform the first aggregation on the output sequence of the Transformer structure to generate a fixed-length vector representation of the path.
6. The CAD vector graphic recognition method according to claim 5, characterized in that, The first aggregation of the output sequence of the Transformer structure to generate a fixed-length vector representation of the path includes: Based on the output sequence, average pooling is used to calculate the mean of the feature vectors at all positions to obtain a fixed-length vector representation of the path. The step of obtaining the graph-level feature vector of the vector map based on the path feature matrix includes: Based on the path feature matrix, a second aggregation is performed to obtain the graph-level feature vector of the vector image.
7. The CAD vector graphic recognition method according to claim 1, characterized in that, The path feature matrix is: = ∈ ,in For the first The first vector image The path feature vector of the path, d represents the number of paths in the vector graphic, and d represents the feature dimension.
8. A CAD vector graphic recognition device based on structured path coding, characterized in that, include: The acquisition module is used to obtain the command sequence and parameter sequence corresponding to each SVG path; The encoding module is used to obtain a fixed-length vector representation of the path through an encoding network based on the command sequence and the parameter sequence. The arrangement module is used to arrange the path feature matrix sequentially according to the path number based on the fixed-length vector representation of the path; The aggregation module is used to obtain the graph-level feature vector of the vector image based on the path feature matrix. The recognition module is used to obtain the recognition result of the vector image based on the graph-level feature vector through a neural network.
9. A computer device comprising a processor and a memory for storing a processor-executable program, characterized in that, When the processor executes the program stored in the memory, it implements the CAD vector graphic recognition method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a program, characterized in that, When the program is executed by the processor, it implements the CAD vector graphic recognition method according to any one of claims 1 to 7.