A method for separating text and graphics of a secondary graph paper of a power system
Patent Information
- Application Number
- CN202411609256.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2044-11-12
AI Technical Summary
然而在实际识图过程中,线条与文字的交织相互干扰,使得图纸信息的识别和提取难度增大
[0010]本发明在工作中,通过pyautocad编写自动化脚本,能够高效地从存量图纸中获取到可供训练的数据集,整个过程无需人工打标签。相较于传统人工耗时且易出错的操作方法,极大地提高了效率和质量。又利用Unet的鲁棒性,通过图到图的学习,根据训练数据集训练出能够自动进行图文分离的模型(即将原图分解成线条子图+文字子图的模型)。在完成图文分离后,对于后续处理如文字检测识别、元器件检测等,带来很大的便捷。不仅优化了整个图纸处理流程,降低对数据集的依赖,提高了图纸处理的准确性和高效性,还为图纸信息的精准提取和有效利用奠定了坚实基础。
Smart Images

Figure CN119479004B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of power system technology, and in particular to a method for separating text and graphics in secondary power system drawings. Background Technology
[0002] With technological advancements and the increasing complexity of power systems, early power secondary drawings stored in bitmap format are no longer suitable for the needs of modern power systems. Against this backdrop, exploring methods for drawing digitization has become a key research area. Compared to traditional manual drawing digitization methods, which suffer from low efficiency, difficulty in ensuring accuracy, poor consistency, challenges in version control, large workload, and high costs, digitization offers a more comprehensive approach.
[0003] Secondary power system drawings contain a large number of conductor relationships, various components, tables, and text annotations. Lines constitute the elements of components, conductor relationships, and tables, while text primarily serves for labeling, naming, and retrieval. These elements are crucial for the operation, maintenance, and upgrading of power systems. However, in actual drawing interpretation, the interweaving of lines and text interferes with each other, increasing the difficulty of identifying and extracting information from the drawings. Text annotations are closely linked to the circuit topology, potentially disrupting the continuity of lines and affecting the correct understanding and extraction of information from line connections. Simultaneously, the interference between lines and text reduces recognition accuracy; intersecting lines may be misinterpreted as part of text, and text annotations may be misjudged as graphic elements. This mutual interference significantly increases the difficulty of the identification process.
[0004] With the development of information technology and intelligentization in power systems, the demand for converting traditional paper drawings into digital drawings is increasing. How to achieve this conversion and improve its reliability are pressing issues that need to be addressed. Summary of the Invention
[0005] To address the above problems, this invention proposes a method for separating text and graphics in secondary power system drawings to improve accuracy and reliability.
[0006] The technical solution of this invention is: a method for separating text and graphics in secondary drawings of a power system, comprising the following steps: 1) Data preparation: Based on CAD drawings of the same style, an automated CAD plugin is developed to export the original drawing, line drawings, and text sub-drawings from the drawings at the same resolution and size. Figure 3 Zhang Tu; 2) Data training: The original image, line sub-image, and text sub-image exported from the data preparation will be used as the training dataset. The original image will be used as the input data for the model, while the line sub-image and text sub-image will be used as the corresponding output data for the model. The model will be trained using the UNet network to obtain a general image-text separation model. 3) Use the image-text separation model to segment the drawing to obtain text sub-images and line sub-images.
[0007] An automated CAD plugin based on the PyAutoCAD library was developed to filter out the text portion of the original drawing, obtaining clean text and line sub-images, which were then exported as bitmaps, resulting in the original drawing, text sub-images, and line sub-images.
[0008] Automated CAD plugins developed based on the PyAutocad library include: 1.1) Environment preparation: Install Python and Pyautocad libraries to ensure that AutoCAD supports ActiveX Automation programs to control AutoCAD; 1.2) Write a plugin: Write a Python script that will run as a plugin and use the API provided by the Pyautocad library to establish a connection with AutoCAD; The plugin's functional logic is as follows: it analyzes objects in the drawing to distinguish between lines and text; 1.3) Plugin Installation and Testing: Install the written plugin into the CAD software and test and debug it; specifically: open the CAD drawing file to be processed through the plugin; loop through all graphic entity objects in the CAD drawing, filter out text and line elements according to the object's attributes, and store them separately; 1.4) Graphic Export: Determine and set the parameters of the image to be exported to ensure that the exported images have the same specifications; use PyAutoCAD's image export function to export the original image, text sub-image, and line sub-image respectively.
[0009] Step 2) includes: 2.1) Data Processing 2.11) Convert the original image to grayscale while preserving brightness information; divide the pixel values in the grayscale image by 255 to normalize the data to between 0 and 1; 2.12) Increase data diversity through rotation, flipping, and scaling methods; 2.2) Constructing the UNet model 2.21) The model architecture includes an encoder and a decoder. It also includes skip connections for fusing feature maps from the encoder with feature maps from the decoder; 2.22) Loss function selection: Cross-entropy loss function; 2.3) Training process 2.31) The processed original image is used as the model input. In the encoder, several intermediate features are obtained by continuous convolutional pooling, with the number of channels doubling each time. 2.32) Then, decoding is performed, and the spatial resolution of the image is restored by a series of transpose convolutions using the resize function, with each channel being halved to obtain intermediate features; 2.33) By using a span connection, the intermediate features at the same position between the encoder and decoder are fused and finally mapped to two-channel output, which respectively represent the predicted line sub-image and text sub-image information; 2.34) Compare the output segmentation map of the model with the corresponding ground truth segmentation map and calculate the loss function; calculate the gradient of the model according to the backpropagation algorithm and update the model parameters according to the gradient information; 2.35) Repeat the above steps to perform iterative training and finally obtain the general graphic-text separation model of the power system secondary drawings.
[0010] In its operation, this invention utilizes pyautocad to write automated scripts, efficiently acquiring training datasets from existing drawings without requiring manual labeling. Compared to traditional, time-consuming, and error-prone manual methods, this significantly improves efficiency and quality. Furthermore, leveraging the robustness of Unet, it trains a model capable of automatically separating text and images (decomposing the original image into line sub-images and text sub-images) based on the training dataset through image-to-image learning. After text and image separation, subsequent processing such as text detection and recognition, and component detection becomes much more convenient. This not only optimizes the entire drawing processing workflow, reduces dependence on datasets, and improves the accuracy and efficiency of drawing processing, but also lays a solid foundation for the accurate extraction and effective utilization of drawing information. Attached Figure Description
[0011] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the accompanying drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. In the drawings, the parts are not necessarily drawn to scale.
[0012] Figure 1 This is a schematic diagram of the UNet image-text separation architecture in this invention; Figure 2 This is a schematic diagram of a sample output from data preparation using an automated CAD plugin, as described in this invention. Figure 3 This is a schematic diagram of the text-image separation result of the trained UNet according to the present invention. Detailed Implementation
[0013] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0014] Secondary drawings for power systems are divided into two types: text and lines. This invention utilizes existing CAD drawings and combines them with an automation plugin to export three sub-images: the original image, text, and lines, thus obtaining a large number of sample drawings. These sample drawings are then used to train a UNet model, resulting in a general-purpose image-text separation model. This model processes a large number of early scanned drawings, separating them into text and line sub-images to avoid mutual interference between text and line recognition. Specifically, text becomes simpler in the text sub-image, eliminating interference from lines. Subsequent tasks such as component detection and connection relationship detection also become clearer in the line sub-image, improving the efficiency and accuracy of subsequent drawing recognition.
[0015] Specifically, refer to Figure 1-3 This invention provides a method for separating text and graphics in secondary drawings of a power system, comprising: 1) Data preparation Based on CAD drawings of the same style—that is, CAD drawings with similar design standards, symbol representations, text styles and sizes, overall layouts, and proportional drawing conventions—an automated CAD plugin is developed to export clean text and line sub-drawings of the same resolution and size, resulting in the original drawing, line sub-drawings, and text sub-drawings. Figure 3 This process involves creating a large number of sample drawings.
[0016] Pyautocad is a library for simplifying the writing of AutoCAD ActiveX Automation scripts in Python. It allows users to interact with AutoCAD through Python code and perform various drawing and editing tasks.
[0017] This invention develops a plugin for CAD drawings of a specific style. It utilizes the functionality of the PyAutocad library to separate text and lines based on the inherent attributes of objects in the CAD drawing (font style, line type, etc.). This plugin is only applicable to CAD drawing formats that can be recognized and processed by PyAutocad.
[0018] This invention uses an automated CAD plugin based on the PyAutocad library to filter out the text portion of the original drawing, obtaining clean text sub-images and line sub-images, which are then exported as bitmaps to obtain the original image, text sub-images, and line sub-images.
[0019] 1.1) Environment preparation: Install Python and Pyautocad libraries, and ensure that AutoCAD supports ActiveX Automation programs to control AutoCAD.
[0020] 1.2) Write a plugin: Write a Python script that will run as a plugin. Use the API interface provided by the Pyautocad library to establish a connection with AutoCAD. The functional logic of the plugin is as follows: by analyzing the objects in the drawing, distinguishing elements such as lines and text, the plugin can export the original drawing, line sub-drawings, and text sub-drawings from the CAD drawing.
[0021] 1.3) Plugin Installation and Testing: Install the developed plugin into the CAD software, conduct thorough testing and debugging to ensure the plugin functions correctly and achieves its intended purpose. Specifically: Open the CAD drawing file to be processed through the plugin; iterate through all graphic entities in the CAD drawing, filter out different elements such as text and lines based on the object's attributes (text attributes, text content, etc.), and store them separately.
[0022] 1.4) Graphic Export: Determine and set the resolution, size and other parameters of the image to be exported to ensure that the exported images have the same specifications; use PyAutocad's image export function to export the original image, text sub-image and line sub-image respectively.
[0023] After testing, the plugin successfully separated lines, text, and other elements in drawings, functioning correctly and meeting requirements. Based on this automated plugin, a large number of samples—the original image, line sub-images, and text sub-images—can be quickly generated from existing data for training the UNet model, serving as crucial data for training the image-text separation algorithm. Furthermore, no manual annotation is required, significantly improving work efficiency.
[0024] 2) Data training: The original image, line sub-image, and text sub-image exported from the data preparation process are used as the training dataset for data training. The original image serves as the input data for the model, while the line and text sub-images serve as the corresponding model output data, trained using the UNet network. By constructing a UNet model with a single-channel input and two-channel output, a general-purpose image-text separation model is obtained. The specific training process is as follows: 2.1) Data Processing 2.11) Convert the original image to grayscale, retaining only the brightness information to simplify the data complexity; divide the pixel values in the grayscale image by 255 to normalize the data to between 0 and 1, thereby accelerating the training process. 2.12) Increase data diversity and improve model generalization ability by rotating, flipping, scaling and other methods.
[0025] 2.2) Constructing the UNet model 2.21) Model Architecture The encoder consists of multiple convolutional and pooling layers, which gradually reduce the spatial dimension of the image while increasing the depth of the feature map, enabling the model to capture higher-level image features. Decoder: Composed of multiple convolutional layers and upsampling layers, it gradually restores the spatial dimensions of the image while reducing the depth of the feature map, which helps to more accurately construct image details; Skip connections: fuse feature maps from the encoder with feature maps from the decoder to retain more spatial information.
[0026] 2.22) Loss function calculation: Select an appropriate loss function (cross-entropy loss) and calculate the difference between the predicted segmentation map and the actual segmentation map.
[0027] 2.3) Training process 2.31) The processed original image is used as the model input. In the encoder, several intermediate features are obtained by continuous convolutional pooling, with the number of channels doubling each time. 2.32) Then, decoding is performed, and the image spatial resolution is restored by a series of transpose convolutions using the resize (image resizing) function, with each channel being halved to obtain intermediate features; 2.33) By using a span connection, the intermediate features at the same position between the encoder and decoder are fused and finally mapped to two-channel output, which respectively represent the predicted line sub-image and text sub-image information; 2.34) Compare the model's output segmentation map with the corresponding ground truth segmentation map and calculate the loss function. Calculate the model's gradient using the backpropagation algorithm and update the model parameters based on the gradient information to reduce the loss value.
[0028] 2.35) Repeat the above steps to perform iterative training and finally obtain the general graphic-text separation model of the power system secondary drawings.
[0029] 3) The general text-image separation model for secondary drawings of power systems is used to segment the drawings to obtain text sub-images and line sub-images, which provides a foundation for subsequent digital conversion of drawings.
[0030] This invention proposes a method for separating text and images in secondary power system drawings. The aim is to obtain a large number of sample drawings by developing a CAD plugin, train the UNet network, and obtain a general text and image separation model. This improves the accuracy and efficiency of drawing information processing and provides basic support for the digital and intelligent development of power systems.
[0031] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for separating text and graphics in secondary drawings of a power system, characterized in that, Includes the following steps: 1) Data preparation: Based on CAD drawings of the same style, an automated CAD plugin is developed to export three images—the original drawing, the line drawing, and the text drawing—at the same resolution and size. 2) Data training: The original image, line sub-image, and text sub-image exported from the data preparation will be used as the training dataset. The original image will be used as the input data for the model, while the line sub-image and text sub-image will be used as the corresponding output data for the model. The model will be trained using the UNet network to obtain a general image-text separation model. 3) Use the image-text separation model to segment the drawing, resulting in text sub-images and line sub-images; Step 2) includes: 2.1) Data Processing 2.11) Convert the original image to grayscale while preserving brightness information; divide the pixel values in the grayscale image by 255 to normalize the data to between 0 and 1; 2.12) Increase data diversity through rotation, flipping, and scaling methods; 2.2) Constructing the UNet model 2.21) The model architecture includes an encoder and a decoder. It also includes skip connections for fusing feature maps from the encoder with feature maps from the decoder; 2.22) Loss function selection: Cross-entropy loss function; 2.3) Training process 2.31) The processed original image is used as the model input. In the encoder, several intermediate features are obtained by continuous convolutional pooling, with the number of channels doubling each time. 2.32) Then, decoding is performed, and the spatial resolution of the image is restored by a series of transpose convolutions using the resize function, with each channel being halved to obtain intermediate features; 2.33) By using a span connection, the intermediate features at the same position between the encoder and decoder are fused and finally mapped to two-channel output, which respectively represent the predicted line sub-image and text sub-image information; 2.34) Compare the output segmentation map of the model with the corresponding ground truth segmentation map and calculate the loss function; calculate the gradient of the model according to the backpropagation algorithm and update the model parameters according to the gradient information; 2.35) Repeat the above steps to perform iterative training and finally obtain the general graphic-text separation model of the power system secondary drawings.
2. The method for separating text and graphics in secondary power system drawings according to claim 1, characterized in that, An automated CAD plugin based on the PyAutoCAD library was developed to filter out the text portion of the original drawing, obtaining clean text and line sub-images, which were then exported as bitmaps, resulting in the original drawing, text sub-images, and line sub-images.
3. The method for separating text and graphics in secondary drawings of a power system according to claim 2, characterized in that, Automated CAD plugins developed based on the PyAutocad library include: 1.1) Environment preparation: Install Python and Pyautocad libraries to ensure that AutoCAD supports ActiveX Automation programs to control AutoCAD; 1.2) Write a plugin: Write a Python script that will run as a plugin and use the API provided by the Pyautocad library to establish a connection with AutoCAD; The plugin's functional logic is as follows: it analyzes objects in the drawing to distinguish between lines and text; 1.3) Plugin Installation and Testing: Install the written plugin into the CAD software and test and debug it; specifically: open the CAD drawing file to be processed through the plugin; loop through all graphic entity objects in the CAD drawing, filter out text and line elements according to the object's attributes, and store them separately; 1.4) Graphic Export: Determine and set the parameters of the image to be exported to ensure that the exported images have the same specifications; use PyAutoCAD's image export function to export the original image, text sub-image, and line sub-image respectively.
Citation Information
Patent Citations
Automatic drawing method and device for secondary circuit of power system and electronic equipment
CN116776404A
Automatic identification method and terminal for electric drawing of hydraulic power plant
CN117912023A