A method and device for generating a DXF file, an electronic device, and a storage medium
By using multimodal large models and diffusion models to optimize Bézier curve paths, the problems of low automation and incomplete information transmission in the automated generation of traffic accident scene drawings were solved, achieving efficient and accurate DXF file generation and improving drawing quality and analysis efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 国家市场监督管理总局缺陷产品召回技术中心
- Filing Date
- 2025-11-11
- Publication Date
- 2026-06-26
Smart Images

Figure CN121458820B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of engineering drawing technology, and more specifically, to a method, apparatus, electronic device, and storage medium for generating DXF files. Background Technology
[0002] Currently, the generation of traffic accident scene drawings mainly relies on a combination of manual investigation and post-production mapping. On-site investigators collect image data through photography, and then professional cartographers use general image processing software (such as Adobe Illustrator) to manually trace and vectorize the photos, or use segmentation tools based on traditional computer vision algorithms for preliminary processing. Finally, the scene map in standard DXF format is manually drawn in CAD software.
[0003] The above methods have significant drawbacks: First, they have a low degree of automation, heavily relying on the experience of professionals and manual operation, and taking a long time to transform images into finished drawings; second, general vectorization tools are poorly adapted to complex accident scenarios, making it difficult to accurately identify specific targets such as vehicles, road markings, and debris, and the generated outlines are rough and require extensive retouching; third, the information conversion from image semantics to engineering drawings relies entirely on manual labor, resulting in the inability to automatically generate and transmit key information such as layer structure and dimension annotations, causing a "semantic gap" in the data processing flow and hindering the efficiency and accuracy of accident analysis. Summary of the Invention
[0004] In view of this, the purpose of this application is to provide a method, apparatus, electronic device and storage medium for generating DXF files to overcome the problems in the prior art.
[0005] In a first aspect, embodiments of this application provide a method for generating a DXF file, the method comprising:
[0006] Input the accident scene images and corresponding text prompts into the preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels;
[0007] Based on the target contour coordinates and the semantic tags, the target vector mask is converted into SVG code containing graphic elements and physical attributes with semantic tags;
[0008] The semantic tags are used to create corresponding DXF layers, the graphic elements are converted into corresponding DXF primitives, and the physical attributes are inherited as metadata into the DXF file to convert the SVG code into a DXF file.
[0009] In some technical solutions of this application, the aforementioned multimodal large model includes a natural language model and an image segmentation model; the step of inputting the accident scene image and corresponding text prompts into the preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels includes:
[0010] The text prompt is encoded using a natural language processing model to generate a text feature vector;
[0011] The accident scene image is segmented using an image segmentation model, and combined with the text feature vector to generate an initial segmentation mask with semantic labels.
[0012] The target vector mask is generated based on the initial segmentation mask with semantic labels.
[0013] In some technical solutions of this application, generating the target vector mask based on the initial segmentation mask with semantic tags includes:
[0014] Contour extraction is performed on the initial segmentation mask to obtain the target contour composed of discrete pixels;
[0015] The path optimization method based on the diffusion model vectorizes the target contour to generate a Bézier curve path.
[0016] The semantic tags are associated with the optimized Bézier curve path to form the target vector mask.
[0017] In some technical solutions of this application, the above method optimizes the Bézier curve path in the following ways:
[0018] The diffusion model is used to perform multiple rounds of iterative optimization on the discrete pixels of the target contour. In each round of iteration, based on the control point coordinates output in the previous round and the geometric features of the target contour, the loss function is calculated and backpropagated to update the control point position.
[0019] When the loss function value is less than a preset threshold, the iteration is terminated and the final Bézier curve control point parameters are output to generate an optimized Bézier curve path.
[0020] In some technical solutions of this application, the above-mentioned conversion of the target vector mask into SVG code with semantic tags and graphic elements and physical attributes based on the target contour coordinates and the semantic tags includes:
[0021] Based on the semantic tags, create corresponding grouping elements for each target, and assign semantic category attributes and unique identifier attributes to the grouping elements;
[0022] The optimized Bézier curve path is converted into the corresponding vector path element, and the physical properties of the target are calculated based on the target contour coordinates.
[0023] The grouping elements, the vector path elements, and the physical attributes are assembled according to the SVG specification to generate the SVG code.
[0024] In some technical solutions of this application, the above method also includes:
[0025] The DXF file is verified to obtain the verification result, and a rectification instruction is generated based on the verification result.
[0026] In some technical solutions of this application, the above method verifies the DXF file in the following ways:
[0027] Verify whether the layer structure of the DXF file is complete and whether it contains all the corresponding layers generated based on semantic tags;
[0028] Verify the geometric consistency between DXF primitives and original graphic elements;
[0029] Verify that physical attributes, as metadata, have been correctly inherited into the DXF file, and verify the integrity and accuracy of its data format.
[0030] Secondly, embodiments of this application provide an apparatus for generating DXF files, the apparatus comprising:
[0031] The generation module is used to input accident scene images and corresponding text prompts into a preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels;
[0032] The conversion module is used to convert the target vector mask into SVG code with semantic tags and graphic elements and physical attributes based on the target contour coordinates and the semantic tags.
[0033] The conversion module is used to create a corresponding DXF layer through the semantic tags, convert the graphic elements into corresponding DXF primitives, and inherit the physical attributes as metadata into the DXF file, so as to convert the SVG code into a DXF file.
[0034] Thirdly, embodiments of this application provide an electronic device, a processor, a memory, and a bus. The memory stores machine instructions executed by the processor. When the electronic device is running, the processor communicates with the memory via the bus. When the machine instructions are executed by the processor, the steps of the above-described method for generating DXF files are performed.
[0035] Fourthly, embodiments of this application provide a computer storage medium storing a computer program, which, when run by a processor, executes the steps of the above-described method for generating DXF files.
[0036] The technical solutions provided by the embodiments of this application may include the following beneficial effects:
[0037] The method of this application includes inputting accident scene images and corresponding text prompts into a preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic tags; converting the target vector mask into SVG code with semantic tags and physical attributes based on the target contour coordinates and the semantic tags; creating a corresponding DXF layer through the semantic tags, converting the graphic elements into corresponding DXF primitives, and inheriting the physical attributes as metadata into the DXF file, so as to convert the SVG code into a DXF file.
[0038] This application realizes end-to-end automated generation from accident scene images to standard DXF engineering drawings. Through intelligent parsing of multimodal large models and path optimization based on advanced generative models, it not only significantly improves data processing efficiency but also significantly improves vectorization quality in complex scenarios. At the same time, it constructs a complete semantic information transmission chain, enabling the output engineering drawings to automatically possess standardized layer structures and physical attribute metadata, effectively solving the shortcomings of traditional methods in terms of efficiency, accuracy, and information integrity.
[0039] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0040] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 A flowchart illustrating a method for generating a DXF file according to an embodiment of this application is shown;
[0042] Figure 2 This illustration shows a schematic diagram of an apparatus for generating DXF files according to an embodiment of this application;
[0043] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0044] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the accompanying drawings in this application are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this application. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate operations implemented according to some embodiments of this application. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this application, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.
[0045] Furthermore, the described embodiments are merely some, not all, of the embodiments of this application. The components of the embodiments of this application described and illustrated herein can typically be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0046] It should be noted that the term "comprising" will be used in the embodiments of this application to indicate the presence of the features declared thereafter, but does not exclude the addition of other features.
[0047] Currently, the generation of traffic accident scene drawings mainly relies on a combination of manual investigation and post-production mapping. On-site investigators collect image data through photography, and then professional cartographers use general image processing software (such as Adobe Illustrator) to manually trace and vectorize the photos, or use segmentation tools based on traditional computer vision algorithms for preliminary processing. Finally, the scene map in standard DXF format is manually drawn in CAD software.
[0048] The above methods have significant drawbacks: First, they have a low degree of automation, heavily relying on the experience of professionals and manual operation, and taking a long time to transform images into finished drawings; second, general vectorization tools are poorly adapted to complex accident scenarios, making it difficult to accurately identify specific targets such as vehicles, road markings, and debris, and the generated outlines are rough and require extensive retouching; third, the information conversion from image semantics to engineering drawings relies entirely on manual labor, resulting in the inability to automatically generate and transmit key information such as layer structure and dimension annotations, causing a "semantic gap" in the data processing flow and hindering the efficiency and accuracy of accident analysis.
[0049] Based on this, embodiments of this application provide a method, apparatus, electronic device, and storage medium for generating DXF files, which are described below through embodiments.
[0050] Figure 1 The diagram illustrates a flowchart of a method for generating a DXF file according to an embodiment of this application, wherein the method includes steps S101-S104; specifically:
[0051] S101. Input the accident scene photos and corresponding text prompts into the preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels;
[0052] S102. Based on the target contour coordinates and the semantic tags, convert the target vector mask into SVG code with semantic tags for graphic elements and physical attributes;
[0053] S103. Create a corresponding DXF layer using the semantic tags, convert the graphic elements into corresponding DXF primitives, and inherit the physical attributes as metadata into the DXF file to convert the SVG code into a DXF file.
[0054] This application realizes end-to-end automated generation from accident scene images to standard DXF engineering drawings. Through intelligent parsing of multimodal large models and path optimization based on advanced generative models, it not only significantly improves data processing efficiency but also significantly improves vectorization quality in complex scenarios. At the same time, it constructs a complete semantic information transmission chain, enabling the output engineering drawings to automatically possess standardized layer structures and physical attribute metadata, effectively solving the shortcomings of traditional methods in terms of efficiency, accuracy, and information integrity.
[0055] The following describes some embodiments of this application in detail. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0056] This application provides a method for generating DXF files, specifically for accident scenes. An accident scene refers to a traffic accident scenario recorded by an image acquisition device, containing various visual elements with clear engineering significance. This scene mainly includes the following three key elements: road infrastructure elements: including road boundaries, lane lines, curbs, and other road components with standard geometric features; these elements provide spatial reference for accident reconstruction; accident-related elements: including the complete outline of the vehicles involved, the distribution area of debris, tire brake marks, and other dynamically formed on-site traces; these elements directly record the dynamic process of the accident; and scale reference elements: including objects of known standard dimensions (such as standard lane width, vehicle length, etc.); these elements provide a measurement benchmark for the conversion from pixel coordinates to real-world scale.
[0057] High-resolution accident scene images are acquired using reconnaissance cameras or aerial photography equipment, along with corresponding text prompts. These text prompts are structured semantic instructions designed to guide the multimodal large-scale model in targeted image analysis, such as semantic guidance for extracting vehicle contours and recognizing road markings. After obtaining the accident scene images and text prompts, an input data buffer is established for the accident scene images (JPG / PNG format, resolution ≥ 1920×1080) and the text prompts (e.g., "road width," "road markings," "roadside"). The images and text are initially stored and labeled. The images are normalized: each pixel value is divided by 255 to scale them to the [0,1] range while preserving the original size and channel information. Then, both are input into the preset multimodal large-scale model, which outputs a target vector mask containing target contour coordinates and semantic labels. This vector mask not only accurately describes the geometry and positional relationships of each target, but also clarifies the category attributes of each target through semantic tags, providing a structured data foundation for subsequent SVG code generation and DXF file conversion.
[0058] In an optional implementation, the multimodal large model is composed of a natural language processing model and an image segmentation model working together. Specifically, the image segmentation model employs a fine-tuned version of the Segment Anything Model (SAM). The training data for this model includes 100,000 labeled accident scene images, covering targets such as vehicles, roads, and road markings, and has been specifically optimized for accident scene features. These two models achieve cross-modal understanding through feature-level fusion, jointly completing the conversion process from multimodal input to target vector mask.
[0059] The specific implementation steps are as follows: First, the input text prompts are subjected to deep semantic parsing and encoding processing using a natural language processing model. This model is based on a Transformer architecture (such as BERT) and uses pre-trained language understanding capabilities to process text prompts such as extracting vehicle outlines and recognizing road markings. After splitting the text into word vectors, these vectors are converted into 768-dimensional text feature vectors through the model's encoding layer. This process captures the semantic information and engineering intent in the text, providing clear guidance for subsequent image segmentation.
[0060] Next, the image segmentation model receives input from two sources: visual features extracted from the accident scene image via a convolutional neural network, and text feature vectors output by the aforementioned natural language processing model. In the feature fusion module, a cross-modal attention mechanism is employed to achieve deep fusion of visual and text features, fusing image features and text prompt vectors element-wise. Specifically, the text features serve as the query vector, used to retrieve the most relevant region in the visual feature space, enabling the model to focus more on key information in the text prompts, thereby establishing a correspondence between semantic concepts and visual content.
[0061] Based on the fused features, the image segmentation model generates an initial segmentation mask with semantic labels through its decoder. The fused features are input into the mask decoder of the SAM, which processes them through multiple convolutional layers and activation functions to generate the initial segmentation mask with semantic labels. In this process, each segmented region carries a corresponding semantic label, such as vehicle, road_mark, etc., achieving simultaneous pixel-level classification and semantic annotation, with each target corresponding to a unique label.
[0062] Furthermore, after obtaining the initial segmentation mask, due to the complexity of the accident scene environment and the inherent technical limitations in the image segmentation process, the initial segmentation mask needs to be optimized. These limitations are specifically manifested in the following ways: the segmentation model is prone to generating overlapping or broken masks when processing targets with severe occlusion or blurred boundaries; the model has low confidence in recognizing low-contrast areas (such as debris similar in color to the road surface); and the directly generated mask boundaries have pixel-level jagged edges, which do not meet the smoothness requirements of engineering drawings. The optimization process includes optimizing the overlapping regions of the initial segmentation mask by using a non-maximum suppression algorithm to process overlapping segmentation regions; performing confidence filtering on the processed segmentation mask to remove regions with confidence levels below a preset threshold, obtaining the target region; and performing edge smoothing processing on the retained target region to eliminate boundary jagged edges and fill internal holes, resulting in the optimized initial segmentation mask.
[0063] The specific optimization process includes: performing overlap mask optimization and processing the initial segmentation results using a non-maximum suppression algorithm. An overlap rate threshold of 30% is set. When the overlap area ratio between multiple masks exceeds this threshold, the prediction confidence of these masks is automatically compared, retaining only the mask with the highest confidence while removing other overlapping masks. This operation effectively solves the mask overlap problem between vehicles and debris, and between different vehicle parts. Next, confidence filtering and mask repair are performed. A confidence threshold of 0.85 is set to automatically filter out segmentation results with confidence levels below this value. For the filtered low-confidence regions, the system records their location information and, based on the spatial distribution characteristics of adjacent high-confidence masks, uses a mask completion algorithm for reasonable shape inference and repair. Simultaneously, edge smoothing is performed on the retained masks, filling small holes in the masks through morphological closing operations and using Gaussian filtering to eliminate edge jaggedness.
[0064] After the above optimization process, not only was the accuracy of the segmentation results significantly improved and obvious erroneous segmentation regions eliminated, but high-quality input data was also provided for subsequent vectorization conversion, ensuring that the final generated target vector mask has a complete geometric structure and accurate semantic annotation. This optimization step plays a crucial role in obtaining reliable technical results in complex accident scene environments.
[0065] After obtaining the optimized initial segmentation mask, it needs to be converted into a target vector mask containing accurate geometric and semantic information. This conversion process is achieved through the following technical steps:
[0066] Contour extraction is performed on the optimized initial segmentation mask to obtain the target contour composed of discrete pixels. Specifically, a sliding window method is used to sample key nodes of the contour points, retaining one key node for every 10 consecutive pixels. The position of the key node is determined by calculating the gradient change of the pixels. This process effectively reduces redundant nodes while preserving the key geometric features of the contour. For example, in a specific implementation, the original pixel sequence of the vehicle contour is: [(x1,y1), (x2,y2), ..., (x100,y100)]. After key node sampling, 12 key nodes are retained, with the coordinates of each key node accurate to one decimal place, and the connection relationships between the nodes are stored.
[0067] A path generator based on a diffusion model is used to vectorize the sampled key nodes. The training data for this path generator consists of 10,000 sets of contour point-Bezier curve pairings, covering target contours of different types and complexities. Bezier curve paths are generated using the diffusion model-based path generator.
[0068] When generating the Bézier curve path, the initial path obtained directly from the contour extraction has problems such as jagged edges, too many redundant nodes, and noise interference, so it needs to be optimized. The optimization process includes performing multiple rounds of iterative optimization on the discrete pixels of the target contour using the diffusion model. In each iteration, based on the control point coordinates output in the previous round and the geometric features of the target contour, the loss function is calculated and backpropagated to update the control point positions.
[0069] When the loss function value is less than a preset threshold, the iteration is terminated and the final Bézier curve control point parameters are output to generate an optimized Bézier curve path.
[0070] Specifically, a pre-trained diffusion model is used to iteratively optimize the discrete pixels of the target contour through multiple rounds. This diffusion model is based on a denoising diffusion probability model architecture and uses a large amount of contour point-Bezier curve pairing data for training. In each iteration, the model calculates the degree of matching between the current Bezier curve and the target contour based on the control point coordinates output from the previous round and the geometric features of the target contour.
[0071] Specifically, the following operations are performed in each iteration: generate a Bézier curve path based on the current control point coordinates; calculate the mean Euclidean distance between the generated curve and the discrete pixels of the original target contour as the loss function; calculate the gradient of the loss function with respect to the control point coordinates through the backpropagation algorithm; update the control point position based on the gradient value, so that the Bézier curve gradually approaches the target contour.
[0072] During the optimization process, a dedicated convergence judgment mechanism is set up. When the loss function value is less than a preset threshold (e.g., 0.5%), the iteration process is automatically terminated, and the final Bézier curve control point parameters are output. These parameters include the precise coordinate values of the start point, control points, and end point, with precision retained to three decimal places.
[0073] This optimization process fully considers the characteristics of various complex contours in accident scene images, can adapt to target contours of different shapes and complexities, and ensures that the generated Bézier curve path maintains both geometric accuracy and high data compression rate, providing high-quality input data for subsequent SVG code generation.
[0074] In practice, after inputting key nodes, an optimized Bézier curve path is generated through 20-step diffusion iterations. In the initial iteration phase, curve control points are randomly generated based on the distribution range of the key nodes; the number of control points is determined by the contour complexity, ranging from 3 to 5. During intermediate iterations, the mean Euclidean distance between the curve and the contour points is calculated as the loss function. The control point positions are adjusted using a backpropagation algorithm to gradually reduce the loss function value. The control point positions and loss function values are recorded every 5 iterations. When the loss function value stabilizes below a preset threshold, Bézier curve parameters that satisfy a path node compression rate ≥ 70% and a curvature error < 0.5% are output, with the parameters accurate to three decimal places.
[0075] After obtaining the optimized Bézier curve path, semantic labels are associated with the optimized Bézier curve path to form a target vector mask. The specific implementation is as follows: A mapping relationship is established between semantic labels and the optimized Bézier curve path. A corresponding data structure is created for each optimized Bézier curve path, containing the following core fields: Geometric data: storing the coordinate sequence of control points of the Bézier curve; Semantic labels: recording the corresponding target category identifier, such as vehicle, road_marking, etc.; Unique identifier: generated using the rule of target type + sequence number, such as car_001. In practice, the semantic label information in the initial segmentation mask is queried, and each label is bound to the corresponding Bézier curve path. This association process is based on the spatial position relationship of the target in the image, ensuring that the contours extracted from the same region inherit their original semantic information.
[0076] After obtaining the target vector mask, SVG code needs to be generated. This includes: creating corresponding grouping elements for each target based on the semantic tags, and assigning semantic category attributes and unique identifier attributes to the grouping elements; converting the optimized Bézier curve path into corresponding vector path elements, and calculating the target's physical properties based on the target contour coordinates; assembling the grouping elements, the vector path elements, and the physical properties according to the SVG specification to generate the SVG code.
[0077] The implementation process is as follows: Based on the semantic tags in the target vector mask, create corresponding SVG grouping elements for each independent target. Specifically, in implementation: use... <g>The tag creates a grouping container, sets a class attribute for each group, and sets the attribute value to the corresponding semantic tag (e.g., class="vehicle"); generates a unique identifier for each group element and sets an id attribute (e.g., id="car_1"); calculates physical properties based on the target contour coordinates: extracts the boundary coordinates of the target contour and calculates the size of the circumscribed rectangle; calculates the diagonal length of the contour using the formula length = √[(x_max - x_min)² + (y_max - y_min)²]; converts the pixel length to the actual physical length by combining a preset image scale (e.g., the conversion relationship between pixels and actual size); the calculation result is in meters, accurate to one decimal place; and adds the calculated physical properties to the grouping element in the form of data-* custom attributes (e.g., data-length=4.8m).
[0078] Convert the optimized Bézier curve path into SVG path elements: Convert Bézier curve parameters into SVG. <path>The d attribute of the tag: According to the SVG path syntax rules, the coordinates of the start point, control point, and end point are written into the d attribute in sequence; the path description includes movement instructions (M), linear instructions (L), and curve instructions (Q / C); specific example: d="M100 200 L150 250Q180 300, 200 280".
[0079] Configure the visual style properties of the path: set the stroke property to define the outline color (e.g., stroke="#FF0000"); set the stroke-width property to define the line width; set the fill property to define the fill color (e.g., fill="none").
[0080] Text annotation generation and code assembly: Generate visual annotations for physical attributes and complete SVG code assembly: Generate annotations for attributes such as data-length. <text>Tags: Position coordinates are set to the offset of the top left corner of the outer rectangle of the target contour; Calculation formula: x = x_min + 10, y = y_min + 10; where x_min and y_min are the coordinates of the top left corner of the outer rectangle of the contour.
[0081] Set text style properties: font size to 12px (font-size="12"); text content includes property name and value (e.g., "length: 4.8m").
[0082] Code assembly according to SVG specifications, complete example:
[0083] <g class="vehicle" id="car1" data-length="4.8m">
[0084] <path d="M100 200 L150 250 Q180 300, 200 280" fill="none" stroke="#FF0000" / >
[0085] <text x="120" y="210" font-size="12"> Length: 4.8m< / text> < / g>
[0086] Through the above steps, the system successfully converts the target vector mask into structured SVG code. This code retains accurate geometric features and contains complete semantic information, physical attributes, and visual annotations, providing standardized input data for subsequent DXF format conversion.
[0087] After obtaining the structured SVG code, it needs to be converted into a DXF file that conforms to the AutoCAD standard. The specific implementation process is as follows:
[0088] Create the corresponding DXF layer structure based on the semantic information in the SVG code:
[0089] Parse the class attribute of the SVG grouping elements and create corresponding DXF layers according to the naming rules of uppercase + _Layer suffix; for example: class="vehicle" → create VEHICLE_Layer layer; the layer name is stored in the layer table of the DXF file to ensure the integrity of the layer structure.
[0090] Set layer display properties:
[0091] Colors are inherited from the stroke value of the SVG element, such as #FF0000 which is converted to DXF color code 1; the layer line width is set to 0.25mm; the layer line style is set to continuous line.
[0092] Convert SVG graphic elements into corresponding DXF primitive entities:
[0093] Convert SVG paths to DXF polylines and parse SVG. <path>The `d` attribute of the element extracts the coordinates of the control points of the Bézier curve, with the coordinate values retained to three decimal places.
[0094] The de Castelli algorithm is used to convert Bézier curves into polylines:
[0095] The number of line segments is determined based on the curve order, using the formula: Number of line segments = Curve order × 5; iterative calculations ensure that the fitting error between each line segment and the original curve is ≤ 0.01 mm.
[0096] Create a POLYLINE entity in DXF:
[0097] Write the polyline vertex coordinate sequence with the same precision as the control point coordinates; set the layer information to which the entity belongs; and preserve the original geometric precision and topological relationships.
[0098] Convert SVG text to DXF multiline text:
[0099] Extract SVG <text>Get the element's attributes, obtain the x / y coordinate values, convert them to DXF coordinate system, extract the font-size property, and convert it to millimeters at a ratio of 1px = 0.264583mm.
[0100] Create a DXF MTEXT entity: retain the complete text content (e.g., "Length: 4.8m"), set accurate position coordinates, configure font parameters, and use Arial font by default.
[0101] Achieve lossless transfer of SVG custom attributes to DXF extended data:
[0102] Parse the custom attributes of the SVG (such as data-length="4.8m").
[0103] Semantic information is stored through DXF's Extended Data (XDATA) mechanism:
[0104] Set group code 100 (application identifier) to "ACAD" and set group code 106 (string data) to "data-length=4.8m".
[0105] Establish the association between metadata and graphic elements:
[0106] The XDATA is bound to the corresponding POLYLINE entity by the entity's unique handle. The entity handle is generated using a unique identifier algorithm to ensure a one-to-one correspondence between metadata and graphic elements.
[0107] Through the above implementation methods, SVG code is converted into DXF files with complete layer structure, accurate geometric data, and rich semantic information, realizing the standard format conversion from web vector graphics to engineering drawings, and providing reliable technical support for the engineering application of accident scene data.
[0108] In an optional implementation, after generating the DXF file, a rigorous verification process is performed to ensure the quality and compliance of the output file, as detailed below:
[0109] Structural integrity verification: Examine the layer table structure of the DXF file to verify that it contains all necessary layers generated based on semantic tags (such as VEHICLE_Layer, ROAD_Layer). For any missing layers detected, automatically record the layer name and the reason for the absence, and generate a detailed error report.
[0110] Calculate the correspondence between the number of targets in the SVG source file and the number of primitives in the DXF file: Set a fault tolerance mechanism: allow a difference of ≤1 (considering automatic target repair due to occlusion); when the difference exceeds the fault tolerance range, the system marks it as an anomaly and records detailed information.
[0111] Standardized output processing: Verified DXF files are converted to an AutoCAD 2018 compatible format, ensuring the file structure and data format fully comply with the target version's specifications. The output file contains complete graphic entities (POLYLINE, MTEXT), layer information, and extended data (XDATA). The output file size is within a reasonable range, ensuring direct import into mainstream engineering analysis software (such as PC-Crash) without data loss or formatting errors during the import process.
[0112] The compliance verification system establishes an automated compliance verification mechanism based on industry standards, which is implemented through a four-step process: "standard mapping - feature extraction - multi-dimensional comparison - anomaly correction".
[0113] Standard database construction: Structured industry standard data is pre-stored, establishing a three-level indexing system: standard number + target type + verification dimension. Typical standards include: GA / T 1179 "Graphic Symbols for Road Traffic Accident Scenes" and GB 5768 "Road Traffic Signs and Markings," etc. The database supports dynamic updates, accessing the latest industry standard revisions via API interfaces; historical version data is retained, supporting the tracing and comparison of standard changes.
[0114] Standard representation example:
[0115]
[0116] The multi-dimensional verification logic, taking "truck icon compliance verification" as an example, performs the following verification steps:
[0117] Step 1: Layer and semantic tag validation
[0118] Layer attribution verification: Extract the layer name of the truck icon in the DXF file and compare it with the layer requirements corresponding to "Vehicle-Truck" in the standard database (must belong to VEHICLE_Layer). If the layer name is ROAD_Layer, determine "Layer error", record "Truck icon needs to be moved to VEHICLE_Layer", and mark the location of the error and the current layer name.
[0119] Semantic tag validation: Check whether the SVG's class attribute or the DXF's XDATA extension data contains the "truck" tag by string matching. If missing, it is determined as "semantic missing", and "class='truck' needs to be added to identify the truck type" is recorded, along with the correct tag format and position.
[0120] Step 2: Verify graphic dimensions and scale
[0121] Size Conversion: Based on the scale indicated in the document (e.g., 1:50), convert the pixel dimensions of the truck icon to its physical dimensions (unit: cm). The conversion formula is: Physical Size = Pixel Dimension × Scale Factor, where the scale factor = 1 / scale. Example: If the primitive pixel length = 200px, resolution = 100px / cm, and the scale is 1:50, then the scale factor = 50, and the actual icon length = 200 / 100 × 50 = 100cm = 1m.
[0122] Standard comparison: The rule "minimum length of truck icon ≥ 3cm (at 1:50 scale)" in the standard database is called to compare the converted size. If the actual length = 2cm < 3cm, it is determined that "size is insufficient", and "the icon length needs to be extended to more than 3cm (corresponding pixel length ≥ 300px)" is recorded, and the specific pixel value that needs to be extended is calculated.
[0123] Step 3: Metadata integrity and accuracy verification
[0124] Required field validation: Check whether it contains predefined metadata such as data-length (actual length) and data-width (actual width), and perform the validation by traversing the list of metadata.
[0125] If data-length is missing, determine "data missing", record "the actual length of the truck needs to be added (e.g., data-length='9.5m')", and explain the importance of this metadata and the filling specifications.
[0126] Accuracy Verification: Verify the consistency between metadata values and graphic dimensions (based on proportional conversion), and calculate the difference and deviation rate between the two. Example: Icon length 3cm (1:50 ratio) → Corresponding actual length = 3 × 50 = 150cm = 1.5m, but data-length is labeled "9.2m" (a reasonable truck length). Determine "database and graphic ratio contradict each other", record "icon length needs to be adjusted to 9.2m / 50 = 18.4cm (pixel length ≥ 1840px)", and explain the basis and method of adjustment.
[0127] Step 4: Verify symbol codes against industry standards
[0128] Symbol code matching: Extract the "graphic code" of the truck element in the DXF file (e.g., the truck code is "T" in the standard), compare it with the database mapping table, and verify it through exact code value matching. If the code is "C" (car code), it is determined that "code is incorrect", and it is recorded that "the graphic code needs to be corrected from 'C' to 'T'", and the correct code comparison table is provided.
[0129] Drawing Standard Verification: Check whether the truck icon contains features required by industry standards (such as a cab-to-cargo ratio ≥ 1:3), and verify this by calculating the size ratio of the two. If the cab occupies 1 / 5, it is judged as "drawing non-standard", and it is recorded that "the cab-to-cargo ratio needs to be adjusted to 1:3 or higher", and specific adjustment suggestions are given.
[0130] Anomaly Handling and Rectification Report Generation:
[0131] Validation result classification:
[0132] Critical errors: Key items that affect the determination of liability for an accident (such as dimensional deviation > 10%, semantic labeling errors) are marked in red and require priority rectification.
[0133] General errors: Minor items that do not affect the core analysis (such as non-standard metadata format) are marked in yellow and can be rectified in subsequent steps.
[0134] Rectification instruction generation: Generates "location + correction suggestions" for each anomaly. Example report snippet:
[0135] [Truck Icon Verification Report]
[0136] 1. Critical errors (2 items):
[0137] Layer error: The current layer is ROAD_Layer, and needs to be moved to VEHICLE_Layer;
[0138] Insufficient size: The actual icon length is 2cm < the standard 3cm. It is recommended to extend it to 3.2cm (pixel length ≥ 320px).
[0139] 2. General Errors (1 item):
[0140] Metadata format: data-length="9.2" is missing the unit "m", it is recommended to add it to data-length="9.2m".
[0141] [Verification Conclusion] Failed. Please correct the above suggestions and re-verify.
[0142] Automatic correction support: For items that can be corrected programmatically (such as layer migration and code replacement), a "one-click correction" function is provided, which automatically corrects the error by calling the DXF file editing interface. Example: Automatically move the truck element from ROAD_Layer to VEHICLE_Layer and update the code to "T". Record the attribute changes before and after the correction.
[0143] Through the above comprehensive verification system, the system can ensure that the output DXF files meet professional standards in terms of technical specifications and industry compliance, providing a reliable guarantee for the engineering application of accident scene data.
[0144] In an optional implementation, the vehicle collision scene DXF is generated as follows:
[0145] I. Input Data
[0146] Data source: High-resolution aerial photographs of the accident scene or images taken by investigation cameras, with a resolution of no less than 4000×3000 pixels, ensuring that details such as road markings, vehicle positions, and debris distribution are clearly visible. Data format: JPEG / PNG format, stored in a specified folder on the local disk.
[0147] II. Processing Flow
[0148] S1. Large model vectorization
[0149] Text prompt construction: Based on core information from the accident scene, structured prompt words are designed: Road traffic accident scene images are analyzed to extract information such as road width, road markings, vehicle outlines, debris distribution, and tire tracks, which are then output as high-precision vector masks. Additional instructions: Road marking details are prioritized for preservation, redundant nodes are merged, and lightweight vector data is output.
[0150] Model Execution: Image segmentation is performed using SAM (Segment Anything Model), generating an initial vector mask containing elements such as roads, vehicles, and debris. The original mask has approximately 1200 nodes. Path optimization is performed using the Path Generator algorithm: the Douglas-Peucker algorithm is used to simplify curves, compressing the number of nodes to 350, reducing the amount of data while maintaining graphic accuracy. Intersecting paths are automatically pruned to eliminate overlapping areas and improve the quality of the vector graphics.
[0151] S2. SVG code generation
[0152] Element Classification and Encoding: Road Element: Extract road width and marking information, assign the `class="road"` attribute when generating SVG code, and set the line style to solid line, line width 2px, and color #000000.
[0153] ```xml
[0154] <path class="road" d="M100,200 L300,200" stroke="#000000" stroke-width="2" fill="none" / >
[0155] ```
[0156] Fragmented Area: The identified fragmented area is filled with blue (#0000FF), given the `class="debris"` attribute, and has an opacity of 0.5 added to enhance the visualization.
[0157] ```xml
[0158] <path class="debris" d="M400,150 A50,50 0 1 0 450,200 Z" fill="#0000FF" fill-opacity="0.5" / >
[0159] ```
[0160] Vehicle outline: Mark the outer outline of the vehicle, generate a closed path, set `class="vehicle"`, and set the line style to dashed (stroke-dasharray="5,5").
[0161] S3. DXF Conversion
[0162] Layer creation: Automatically create three layers: VEHICLE, DEBRIS, and ROAD using Python's `ezdxf` library.
[0163] Python
[0164] import ezdxf
[0165] doc = ezdxf.new('R2010')
[0166] doc.layers.new(name='VEHICLE', color=7)
[0167] doc.layers.new(name='DEBRIS', color=1)
[0168] doc.layers.new(name='ROAD', color=2)
[0169] ```
[0170] S4, Primitive Transformation
[0171] Fragmentation Area: Convert the fragmentation path in the SVG to a HATCH primitive in DXF, select `ANSI31` for the fill pattern, and set the scale to 0.5.
[0172] Tire Tracks: Converts curved tire tracks into SPLINE curves while preserving the curvature characteristics of the original path.
[0173] Road markings: Converted to LINE line primitives, precisely matching coordinates and styles in SVG.
[0174] S5. Drawing Output:
[0175] After completing the conversion of all elements, set the drawing unit to millimeters (m), add a drawing frame and scale bar annotation, and finally generate a DXF file that conforms to the AutoCAD standard and save it to the specified directory.
[0176] III. Result Verification
[0177] Accuracy verification: Comparing the original site photos with the generated DXF drawings, the error of key elements (such as road width and vehicle position) is controlled within ±2cm.
[0178] Compatibility verification: It can be fully opened and edited in mainstream AutoCAD software, and layers and elements are displayed normally.
[0179] Figure 2 This invention provides a schematic diagram of a DXF file generation apparatus according to an embodiment of the present application. The apparatus includes:
[0180] The generation module is used to input accident scene images and corresponding text prompts into a preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels;
[0181] The conversion module is used to convert the target vector mask into SVG code with semantic tags and graphic elements and physical attributes based on the target contour coordinates and the semantic tags.
[0182] The conversion module is used to create a corresponding DXF layer through the semantic tags, convert the graphic elements into corresponding DXF primitives, and inherit the physical attributes as metadata into the DXF file, so as to convert the SVG code into a DXF file.
[0183] The multimodal large model includes a natural language model and an image segmentation model; the step of inputting accident scene images and corresponding text prompts into the preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels includes:
[0184] The text prompt is encoded using a natural language processing model to generate a text feature vector;
[0185] The accident scene image is segmented using an image segmentation model, and combined with the text feature vector to generate an initial segmentation mask with semantic labels.
[0186] The target vector mask is generated based on the initial segmentation mask with semantic labels.
[0187] The step of generating the target vector mask based on the initial segmentation mask with semantic labels includes:
[0188] Contour extraction is performed on the initial segmentation mask to obtain the target contour composed of discrete pixels;
[0189] The path optimization method based on the diffusion model vectorizes the target contour to generate a Bézier curve path.
[0190] The semantic tags are associated with the optimized Bézier curve path to form the target vector mask.
[0191] The Bézier curve path is optimized in the following way:
[0192] The diffusion model is used to perform multiple rounds of iterative optimization on the discrete pixels of the target contour. In each round of iteration, based on the control point coordinates output in the previous round and the geometric features of the target contour, the loss function is calculated and backpropagated to update the control point position.
[0193] When the loss function value is less than a preset threshold, the iteration is terminated and the final Bézier curve control point parameters are output to generate an optimized Bézier curve path.
[0194] The step of converting the target vector mask into SVG code containing semantically tagged graphic elements and physical attributes based on the target contour coordinates and the semantic tags includes:
[0195] Based on the semantic tags, create corresponding grouping elements for each target, and assign semantic category attributes and unique identifier attributes to the grouping elements;
[0196] The optimized Bézier curve path is converted into the corresponding vector path element, and the physical properties of the target are calculated based on the target contour coordinates.
[0197] The grouping elements, the vector path elements, and the physical attributes are assembled according to the SVG specification to generate the SVG code.
[0198] The verification module is used to verify the DXF file, obtain the verification result, and generate rectification instructions based on the verification result.
[0199] The DXF file is verified using the following method:
[0200] Verify whether the layer structure of the DXF file is complete and whether it contains all the corresponding layers generated based on semantic tags;
[0201] Verify the geometric consistency between DXF primitives and original graphic elements;
[0202] Verify that physical attributes, as metadata, have been correctly inherited into the DXF file, and verify the integrity and accuracy of its data format.
[0203] like Figure 3 As shown, this application provides an electronic device for executing the DXF file generation method described in this application. The device includes a memory, a processor, a bus, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the DXF file generation method described above.
[0204] Specifically, the aforementioned memory and processor can be general-purpose memory and processor, without any specific limitations. When the processor runs the computer program stored in the memory, it can execute the aforementioned method for generating DXF files.
[0205] Corresponding to the DXF file generation method in this application, this application embodiment also provides a computer storage medium storing a computer program, which is executed by a processor to perform the steps of the above-described DXF file generation method.
[0206] Specifically, the storage medium can be a general-purpose storage medium, such as a removable disk or hard disk, and when the computer program on the storage medium is run, it can execute the above-mentioned method for generating DXF files.
[0207] In the embodiments provided in this application, it should be understood that the disclosed systems and methods can be implemented in other ways. The system embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and there may be other division methods in actual implementation. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the coupling or direct coupling or communication connection shown or discussed may be through some communication interface; the indirect coupling or communication connection between systems or units may be electrical, mechanical, or other forms.
[0208] 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; they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0209] In addition, the functional units in the embodiments provided in this application 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.
[0210] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion 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 this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0211] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0212] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The protection scope of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this application; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application. All should be covered within the protection scope of this application. Therefore, the protection scope of this application should be determined by the protection scope of the claims.< / text> < / path> < / text> < / path> < / g>
Claims
1. A method for generating DXF files, characterized in that, The method includes: Input the accident scene images and corresponding text prompts into the preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels; Based on the target contour coordinates and the semantic tags, the target vector mask is converted into SVG code containing graphic elements and physical attributes with semantic tags; The semantic tags are used to create corresponding DXF layers, the graphic elements are converted into corresponding DXF primitives, and the physical attributes are inherited as metadata into the DXF file to convert the SVG code into a DXF file. The step of inputting accident scene images and corresponding text prompts into a preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels includes: The accident scene image and corresponding text prompts are input into a pre-defined multimodal large model. First, the input text prompts are subjected to deep semantic parsing and encoding by a natural language processing model to generate text feature vectors. Next, the image segmentation model receives the visual features extracted from the accident scene image through a convolutional neural network and the text feature vector. In the feature fusion module, a cross-modal attention mechanism is used to achieve deep fusion of visual and text features. Based on the fused features, the image segmentation model generates an initial segmentation mask with semantic labels through its decoder. Contour extraction is performed on the optimized initial segmentation mask to obtain the target contour composed of discrete pixels. A path generator based on a diffusion model is used to vectorize the sampled key nodes to generate a Bézier curve path. The semantic labels are associated with the optimized Bézier curve path to form a target vector mask.
2. The method according to claim 1, characterized in that, The method optimizes the Bézier curve path in the following way: The diffusion model is used to perform multiple rounds of iterative optimization on the discrete pixels of the target contour. In each round of iteration, based on the control point coordinates output in the previous round and the geometric features of the target contour, the loss function is calculated and backpropagated to update the control point position. When the loss function value is less than a preset threshold, the iteration is terminated and the final Bézier curve control point parameters are output to generate an optimized Bézier curve path.
3. The method according to claim 1, characterized in that, The step of converting the target vector mask into SVG code containing semantically tagged graphic elements and physical attributes based on the target contour coordinates and the semantic tags includes: Based on the semantic tags, create corresponding grouping elements for each target, and assign semantic category attributes and unique identifier attributes to the grouping elements; The optimized Bézier curve path is converted into the corresponding vector path element, and the physical properties of the target are calculated based on the target contour coordinates. The grouping elements, the vector path elements, and the physical attributes are assembled according to the SVG specification to generate the SVG code.
4. The method according to claim 1, characterized in that, The method further includes: The DXF file is verified to obtain the verification result, and a rectification instruction is generated based on the verification result.
5. The method according to claim 4, characterized in that, The method verifies the DXF file in the following ways: Verify whether the layer structure of the DXF file is complete and whether it contains all the corresponding layers generated based on semantic tags; Verify the geometric consistency between DXF primitives and original graphic elements; Verify that physical attributes, as metadata, have been correctly inherited into the DXF file, and verify the integrity and accuracy of its data format.
6. An apparatus for generating DXF files, characterized in that, The device includes: The generation module is used to input accident scene images and corresponding text prompts into a preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels; The conversion module is used to convert the target vector mask into SVG code with semantic tags and graphic elements and physical attributes based on the target contour coordinates and the semantic tags. The conversion module is used to create a corresponding DXF layer through the semantic tags, convert the graphic elements into corresponding DXF primitives, and inherit the physical attributes as metadata into the DXF file, so as to convert the SVG code into a DXF file; The step of inputting accident scene images and corresponding text prompts into a preset multimodal large model to generate a target vector mask containing target contour coordinates and semantic labels includes: The accident scene image and corresponding text prompts are input into a pre-defined multimodal large model. First, the input text prompts are subjected to deep semantic parsing and encoding by a natural language processing model to generate text feature vectors. Next, the image segmentation model receives the visual features extracted from the accident scene image through a convolutional neural network and the text feature vector. In the feature fusion module, a cross-modal attention mechanism is used to achieve deep fusion of visual and text features. Based on the fused features, the image segmentation model generates an initial segmentation mask with semantic labels through its decoder. Contour extraction is performed on the optimized initial segmentation mask to obtain the target contour composed of discrete pixels. A path generator based on a diffusion model is used to vectorize the sampled key nodes to generate a Bézier curve path. The semantic labels are associated with the optimized Bézier curve path to form a target vector mask.
7. An electronic device, characterized in that, include: The device includes a processor, a memory, and a bus. The memory stores machine instructions that the processor executes. When the electronic device is running, the processor communicates with the memory via the bus. When the machine instructions are executed by the processor, they perform the steps of the method for generating a DXF file as described in any one of claims 1 to 5.
8. A computer storage medium, characterized in that, The computer storage medium stores a computer program that, when executed by a processor, performs the steps of the method for generating a DXF file as described in any one of claims 1 to 5.