Secondary drawing vectorization method of power system
Through the combination method of UNet graphic separation model, OCR technology, skeleton topology traceability and YOLO detection components, the secondary drawings of the power system are automatically processed, solving the problem of inefficient conversion of early stock drawings to vector drawings, and achieving an efficient and accurate drawing vectorization process.
Patent Information
- Application Number
- CN202411609258.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-12
- Publication Date
- 2025-02-28
AI Technical Summary
In the prior art, most of the early stock drawings were in bitmap formats, which were easily distorted after being enlarged and not easy to edit. Converting bitmap drawings into vector drawings requires a lot of manual operations, which is inefficient.
The UNet graphic separation model is adopted to identify text through OCR, vectorized repair is performed based on skeleton topology traceability and polygon approximation methods, combined with YOLO detection components and replaced with standard graphic elements, to realize the automated drawing vectorization process.
It improves the efficiency and accuracy of drawing vectorization, reduces manual operations, and the generated CAD documents are of high quality, supports Chinese recognition, reduces dependence on training data sets, and improves recognition accuracy and stability.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of power systems, and in particular to a secondary drawing vectorization method for power systems. Background Art
[0002] In the power industry, drawings are an important basis for design and construction. Many early stock drawings are in bitmap format, which has the disadvantages of being distorted after enlarging and not easy to edit. With the development of technology, vector drawings are favored because of their infinite magnification without distortion and easy editing. However, converting bitmap drawings to vector drawings usually requires a lot of manual operations and is inefficient. Summary of the invention
[0003] In view of the above problems, the present invention provides a method for vectorizing secondary drawings of an electric power system to solve the problem of low efficiency of traditional manual drawing.
[0004] The technical solution of the present invention is: a method for vectorizing a secondary drawing of an electric power system, comprising the following steps:
[0005] S1, UNet image and text separation, obtain text sub-image and line sub-image;
[0006] S2, performing OCR (optical character recognition) on the text sub-image;
[0007] S3, perform vectorization on line sub-images and repair and beautify vector images;
[0008] S4 and Yolo v5 (a classic monitoring network) detect components and replace them with standard primitives;
[0009] S5. Results generation.
[0010] In the present invention, S1, using the Unet network, inputting the original image, outputting the line sub-image + text sub-image, and using UNet for training to obtain a universal image-text separation model, including:
[0011] S1.1: Data preparation, using existing CAD drawings, through automated scripts, exporting them into three sub-images: original image, text, and line;
[0012] S1.2: Take the original image obtained in S1.1 as input, and the text sub-image and line sub-image as output, and build a UNet model with single-channel input and two-channel output. Through training, a universal image-text separation model is obtained, which specifically includes:
[0013] 1) Convert the original image to grayscale, divide it by 255, and normalize it to between 0 and 1;
[0014] 2) Take the original image as input, and in the encoder, through continuous convolution pooling, each time the channel is doubled to obtain several intermediate features;
[0015] 3) Decode again, and through the continuous resize function, halve the channel each time to obtain the intermediate features;
[0016] 4) The intermediate features at the same position between the encoder and decoder are fused through a span connection and finally mapped to two channels (the two channels correspond to the line sub-image and the text sub-image respectively);
[0017] 5) Use text sub-images and line sub-images as standard output.
[0018] S2. Perform OCR recognition on the text sub-image:
[0019] Use the text detection model to detect on the text sub-image, and then use the text recognition model on each detected rectangular area to obtain the position and content of the text;
[0020] Among them, the text detection model uses the detection model of PaddleOCR, inputs the text sub-image, and outputs the circumscribed rectangular hot zone of the text area;
[0021] The text recognition model, since recognition is mainly aimed at printed fonts, uses text generation and enhancement technology to generate a large number of various font samples and conduct training.
[0022] In the application, the detection model inputs a text sub-image and outputs a rectangular area of text, and the recognition model inputs a text image of a rectangular area and outputs the text content, thereby obtaining the position and content of the text.
[0023] S3. Vectorization on line sub-images and repair and beautification of vector images:
[0024] Based on the skeleton, the topology is traced and the graph is generated. The line segment vector map is obtained by using the polygon approximation method, and the edges are classified by GCN (graph neural network), and the coordinates of the horizontal and vertical connected areas are averaged, and the bound is calculated to obtain the complete line segment. In this way, vector connectivity and orthogonality repair can be stably achieved. The specific steps are:
[0025] S3.1 image to graph
[0026] S3.11, binarize the line sub-image (convert the original image into a black and white binary image);
[0027] S3.12, image thinning, obtaining a skeleton image with only a single line (image skeleton algorithm, making the image content become a single line);
[0028] S3.13, perform 3x3 convolution on the foreground points on the skeleton image, with the convolution kernel at 0 in the middle and 1 around it;
[0029] S3.14. Find all endpoints and nodes and perform floodfill (irrigation filling algorithm, filling a connected area by stacking) tracing;
[0030] S3.15. Create a graph. Due to pixel tracing, the path is pixel-dense. It is necessary to use a polygon simplification algorithm to simplify the traced dense points to obtain the graph form of the skeleton image.
[0031] S3.2 Vector Graphics Beautification
[0032] Since the graph in the above method is obtained from an image and has been subjected to a polygon simplification algorithm, the orthogonality of the lines cannot be guaranteed, and defects are unavoidable at the corners of the broken lines. Therefore, the graph needs to be beautified, specifically:
[0033] S3.21. Graph edge classification. In a quadratic graph, most elements are horizontal and vertical, and a small number of components or connections are diagonal. Therefore, all paths in the graph can be divided into four categories: horizontal lines, vertical lines, diagonal lines, and noise:
[0034] Horizontal line: horizontal line;
[0035] Vertical line: vertical line;
[0036] Slash: slash;
[0037] Noise: Error segments introduced by the polygon simplification algorithm.
[0038] S3.22, Unicom regional subgraph division, according to S3.21, the graph is divided into several subgraphs, the principles are as follows:
[0039] Those that are interconnected and in the same horizontal direction are a subgraph;
[0040] They are connected to each other and are vertical, forming a word picture;
[0041] When extracting the horizontal direction, the noise is regarded as the horizontal direction, and when extracting the vertical direction, it is regarded as the vertical direction;
[0042] S3.23, orthogonal repair, for the division results of S3.22, for the node sets connected horizontally, the y values of the vertical coordinates of the nodes are adjusted to be consistent so that they are on the same horizontal line; for the node sets connected vertically, the x values of the vertical coordinates of the nodes are adjusted to be consistent so that they are on the same vertical line;
[0043] a. When calculating coordinates, the path should be used instead of the node, which means that when calculating coordinates, the path information between nodes is considered instead of the coordinates of a single node;
[0044] b. The coordinates of the path are represented by the average of the vectors of the two endpoints. That is, the coordinates of each path are represented by the average of the coordinates of the two endpoints (x1, y1) and (x2, y2). The average coordinates are
[0045] c. The weight of the path is defined as the modulus of the difference between the two endpoint vectors, that is, the length of the line segment, which can be expressed as The longer the path, the greater the weight;
[0046] d. Calculate the unified coordinate X or Y set of a set of horizontal or vertical connected paths through the weighted average method, that is, multiply the average coordinate of each path by its weight (path length), then add them up, and finally divide by the total weight.
[0047] e. Verify whether the coordinates of the horizontal and vertical connecting nodes meet the orthogonality requirements, and output the path node coordinates after orthogonal repair.
[0048] S4. YOLO detects components and replaces them with standard primitives:
[0049] S4.1. Use the Yolo network to detect the components in the original image. Draw a rectangular box for each detected component to mark the position of the component in the image. Use pre-made standard graphics to replace the component rectangular box to standardize it. This detection work is performed on the line sub-image.
[0050] Drawing pre-processing and post-processing optimization during component inspection:
[0051] Since components are all line elements and have strict drawing ratios, traditional image preprocessing and direct scaling are not suitable. For texture information and large blocks of color information, such as pedestrian detection and vehicle detection, the image is directly scaled to the input size of the YOLO model, such as 480x480, 720x720, etc. However, for drawings, the size of a single image is usually above 3000, or even up to 8000. Direct scaling will result in: line distortion, even disappearance, and component deformation.
[0052] Therefore, the tiled sub-image detection method is used here to process large images. The process of this method is as follows:
[0053] a. Divide the original image into tiles of a specific size, such as 720*720, and ensure that there is at least 50 pixels of overlap between tiles to avoid the detection target being cut at the tile boundary.
[0054] b. Use the Yolo network to detect the target of each tile and merge the original output detection results of Yolo; the detection output result of Yolo for the tile is a series of rectangles, as well as category coding, confidence and other information;
[0055] c. Merge all tiles and restore the detected rectangle coordinates from the tile coordinate system to the original large image coordinate system; then find the bestbox (the best rectangle in the detected target) and other adjacent bestboxes based on the confidence level; calculate the intersection-over-union ratio of all rectangles, use the non-maximum suppression (NMS) algorithm to merge overlapping rectangles, and also use the confidence level to find the best rectangle for detecting the target in the overlapping area.
[0056] S4.2. Use graphic primitives to restore components. Since the line relationship of components is more complex and more difficult to repair than ordinary connections, pre-made vector graphics primitives are used to replace the detected components. Specifically, it includes:
[0057] S4.21. Use CAD design tools to store various components into independent dxf unit files;
[0058] S4.22. According to the YOLO detection result, fill the corresponding primitives in the dxf primitive file independently stored in S4.21 into the rectangular box of the YOLO detection result.
[0059] The graphic element designed in the present invention is a fixed graphic, but how to place it in the corresponding position requires adapting the position, size, direction, and fine-tuning of the connection points. For the above problems, the following methods are adopted:
[0060] S4.221. When making graphics primitives, operate within the unit range, that is, vector graphics are limited to the unit square of 0-1, so as to calculate the scaling ratio later and ensure the scalability and versatility of graphics primitives;
[0061] S4.222. The graphics element is divided into three layers: point, line and surface. The point layer marks the connection points to ensure accurate docking during placement. The line layer draws the component lines to ensure the basic shape and structure of the graphics element. The surface layer marks the fill surface and draws an erase area (the background lines in the original image will be erased if they fall into the erase area, which can effectively prevent line contamination).
[0062] S4.223. Calculate the scaling and translation factors based on the position and size of the rectangle:
[0063] In the horizontal direction, when the size of the primitive in the unit square is W unit ×H unit , the size of the detected rectangular box is W rect ×H rect , then its scaling factor is
[0064]
[0065] Among them, S x S is the horizontal scaling ratio of the element. y The scaling ratio of the primitive in the vertical direction;
[0066] The translation factor is the distance the primitive needs to be moved in order to place it in the correct position of the detected rectangle. Assume that the coordinates of the upper left corner of the detected rectangle are (X rect ,Y rect ), the translation factor is calculated as follows:
[0067] T x =X rect
[0068] T y =Y rect
[0069] Among them, T x is the distance that the element needs to move horizontally, that is, the horizontal coordinate of the upper left corner of the rectangular box; T y The distance that the element needs to move in the vertical direction, that is, the vertical coordinate of the upper left corner of the rectangular box;
[0070] S4.224, calculate the number and position of the intersections of the rectangle and the background lines on the four sides of top, bottom, left and right;
[0071] S4.225, according to the location of the wiring point of the graphic element, the location of the intersection of the rectangle and the background line, make accurate direction and position matching;
[0072] S4.226. Insert the graphic element as a block element of CAD into the corresponding position of the drawing.
[0073] S5. Results Generation:
[0074] Combine the above OCR results, vector graphics results and component detection results, and write them into dxf to form the final CAD document;
[0075] The generated results are saved in the form of DXF files, divided into three layers: text, vector, and component graphics, and can be viewed using CAD software.
[0076] The beneficial effects of the present invention are as follows: a text-image separation model is trained based on the Unet network, which avoids the cumbersome and error-prone process of manually exporting images and cutting out images, and improves efficiency and accuracy. OCR recognition is performed on the text sub-image, and the text position and content can be quickly and fully automatically obtained with the help of PaddleOCR, which supports Chinese well, efficiently and stably. In terms of line sub-image processing, the line connection relationship information acquisition and vector image repair and beautification are realized based on multiple technologies such as skeleton topology tracing, polygon approximation, GCN, etc., which ensures the connectivity and orthogonality of vectors, and combines multiple algorithms to give full play to their respective advantages to make data processing more accurate and efficient. YOLO is used to detect components and replace them with standard primitives. The tiled sub-image detection method solves the problems of line distortion and component deformation in large image processing, reduces the dependence on training data sets, and improves recognition accuracy and stability. The primitive design achieves precise placement through methods such as layering and calculating scaling and translation factors. The final generated CAD document is saved in layers as a DXF file, which can be conveniently viewed with CAD software, providing an efficient, accurate and intelligent solution for the secondary drawing processing of the power system, which helps to improve the quality and efficiency of drawing vectorization work and promote the development of drawing processing technology in the power field. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] In order to more clearly illustrate the specific implementation of the present invention or the technical solution in the prior art, the following briefly introduces the drawings required for the specific implementation or the prior art description. In the drawings, each part is not necessarily drawn according to the actual scale.
[0078] Figure 1 It is a schematic diagram of separating the original image, line sub-image, and text sub-image of the present invention;
[0079] Figure 2 It is a schematic diagram of the UNet image-text separation structure of the present invention;
[0080] Figure 3 It is a schematic diagram of OCR text detection and recognition of the present invention;
[0081] Figure 4 It is the detection result of isolated points, loops and breakpoints realized by using the Unicom domain of the present invention;
[0082] Figure 5 It is a schematic diagram of the drawing line vectorization and vector map beautification of the present invention;
[0083] Figure 6 It is a schematic diagram of the YOLO detection components of the present invention;
[0084] Figure 7 is a schematic diagram of a prefabricated vector primitive of the present invention;
[0085] Figure 8It is the overall block diagram of generating vectorized CAD files from secondary drawings of the present invention. DETAILED DESCRIPTION
[0086] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0087] In the description of the present invention, it should be understood that the terms "upper", "lower", "left", "right", "vertical", "horizontal", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In the description of the present invention, unless otherwise specified, "plurality" means two or more.
[0088] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0089] refer to Figure 1-Figure 8 The present invention provides a method for vectorizing a secondary drawing of an electric power system, comprising the following steps:
[0090] S1, UNet image and text separation, obtain text sub-image and line sub-image;
[0091] S2, performing OCR (optical character recognition) on the text sub-image;
[0092] S3, perform vectorization on line sub-images and repair and beautify vector images;
[0093] S4 and Yolo v5 (a classic monitoring network) detect components and replace them with standard primitives;
[0094] S5. Results generation.
[0095] Step S1: Use the UNet network to separate text and images to obtain a text sub-graph + a line segment sub-graph. Separating text and lines in the drawing will help with subsequent processing. The text becomes simpler on the text sub-graph, eliminating the interference of lines. Component detection and connection relationship detection also become clear on the line sub-graph.
[0096] By using existing CAD drawings and automated scripts, we can export them into three sub-images: original image, text, and lines. Then we use UNet to train them and obtain a universal image-text separation model.
[0097] (1) Data preparation: using existing CAD drawings, through automated scripts, exporting them into three sub-images: original image, text, and line. The present invention uses pyautocad to filter out the text part in the original document, obtain pure text sub-images and line sub-images, and then export them into bitmaps to obtain three images: original image, text sub-image, and line sub-image. Using the original image as input, output two images: text sub-image and line sub-image. Using this method, a large number of samples can be quickly obtained from the stock data without manual labeling.
[0098] Pyautocad (a Python extension package for AutoCAD that can be used to automate operations) is a Python library for interacting with AutoCAD. It allows developers to control AutoCAD through Python scripts and perform various operations such as creating, modifying, and exporting drawings. Pyautocad communicates with AutoCAD through the COM (Windows extension component) interface, so it is mainly suitable for AutoCAD on the Windows platform.
[0099] (2) The original image obtained in (1) is used as input, and the text sub-image and line sub-image are used as output. A UNet model with single-channel input and two-channel output is constructed. Through training, a universal image-text separation model is obtained. Specifically, it includes:
[0100] 1) Convert the original image to grayscale, divide it by 255, and normalize it to between 0 and 1;
[0101] 2) Take the original image as input, and in the encoder, through continuous convolution pooling, each time the channel is doubled to obtain several intermediate features;
[0102] 3) Decode again, and through the continuous resize function, halve the channel each time to obtain the intermediate features;
[0103] 4) The intermediate features at the same position between the encoder and decoder are fused through a span connection and finally mapped to two channels (the two channels correspond to the line sub-image and the text sub-image respectively);
[0104] 5) Use text sub-images and line sub-images as standard output.
[0105] The present invention uses pyautocad to write an automated script, which can quickly obtain a training data set from the stock drawings without manual labeling. The robustness of Unet is also used to train a model that can automatically separate images and texts (i.e., a model that decomposes the original image into line sub-images + text sub-images).
[0106] If pyautocad is not used, it is necessary to manually export the cad drawings into images, and then use drawing tools to cut out the line parts and text parts, which is time-consuming, labor-intensive, and prone to errors. UNet is suitable for image-to-image learning, and can train a universal model based on the data set.
[0107] After the image and text are separated in the present invention (after the original image is decomposed into line sub-images and text sub-images), subsequent processing such as text detection and recognition, component detection, and schematic diagram link relationship is greatly facilitated. Text detection and recognition are clear on the text sub-image; and the connection relationship between components and schematic diagrams is clear on the line sub-image. For subsequent text and component detection, etc., the dependence on data sets can be reduced.
[0108] Step S2: Perform OCR recognition on the text sub-image: Input the drawing into the image-text separation model to obtain the text sub-image, and use the OCR technology on the text sub-image to detect and recognize the text.
[0109] The text detection model is used to detect the text sub-image, and then the text recognition model is used for each detected rectangular area to obtain the position and content of the text.
[0110] Among them, the text detection model uses the detection model of PaddleOCR (PaddleOCR is Baidu's open source OCR framework, which is a conventional model, mature and can be used directly), inputs a text sub-image, and outputs the circumscribed rectangular hot zone of the text area; the text recognition model, because the recognition is mainly aimed at printed fonts, uses text generation and enhancement technology to generate a large number of various font samples and train them (the built-in model of PaddleOCR is very mature and can basically be used directly).
[0111] In the application, the detection model inputs a text sub-image and outputs a rectangular area of text, and the recognition model inputs a text image of a rectangular area and outputs the text content, thereby obtaining the position and content of the text.
[0112] Using OCR technology, you can quickly and automatically obtain the location and content of text in an image. PaddleOCR, as Baidu's open source OCR framework, has good support for Chinese and is efficient and stable.
[0113] Step S3: Perform vectorization on the line sub-graph and repair and beautify the vector graph: In the power drawings, especially the terminal block diagram, schematic diagram, etc., the line connection relationship is very important information. Next, the line connection relationship information is obtained on the line sub-graph output by the image-text separation model.
[0114] Based on the skeleton, the topology is traced and the graph is generated. The line segment vector map is obtained by using the polygon approximation method, and the edges are classified by GCN (graph neural network), and the coordinates of the horizontal and vertical connected areas are averaged, and the bound is calculated to obtain the complete line segment. In this way, vector connectivity and orthogonality repair can be stably achieved.
[0115] S3.1 image to graph
[0116] S3.11, binarize the line sub-image (convert the original image into a black and white binary image);
[0117] S3.12, image thinning, obtaining a skeleton image with only a single line (image skeleton algorithm, making the image content become a single line);
[0118] S3.13, perform 3x3 convolution on the foreground points on the skeleton image, with the convolution kernel at 0 in the middle and 1 around it;
[0119] Among them, those with no neighbors are isolated points, those with one neighbor are endpoints, those with two neighbors are paths, and those with three or more neighbors are nodes;
[0120] S3.14. Find all endpoints and nodes and perform floodfill (irrigation filling algorithm, filling a connected area by stacking) tracing;
[0121] Among them, isolated points are ignored, all nodes and endpoints are regarded as nodes (node elements in the graph), and paths are regarded as edges (edge elements in the graph);
[0122] S3.15. Create a graph
[0123] Due to pixel tracing, the path is pixel-dense, and a polygon simplification algorithm is needed to simplify the dense points of tracing. For example, the original horizontal broken line is composed of many points. After simplification, ideally only endpoints and corners are left. This expression is simpler. The final skeleton image is in graph form.
[0124] S3.2 Vector Graphics Beautification
[0125] Since the graph in the above method is obtained from an image and has been subjected to a polygon simplification algorithm, the orthogonality of the lines cannot be guaranteed and defects are unavoidable at the corners of the broken lines. Therefore, the graph needs to be beautified.
[0126] S3.21. Graph edge classification. Since most of the elements in a quadratic graph are horizontal and vertical, a small number of components or connections are diagonal. Therefore, all the paths in the graph can be divided into four categories: horizontal lines, vertical lines, diagonal lines, and noise.
[0127] Horizontal line: horizontal line;
[0128] Vertical line: vertical line;
[0129] Slash: slash;
[0130] Noise: Error segments introduced by the polygon simplification algorithm.
[0131] S3.22, Unicom regional subgraph division, according to S3.21, the graph is divided into several subgraphs, the principles are as follows:
[0132] a. They are interconnected and horizontal, forming a subgraph;
[0133] b. They are connected to each other and are in the same vertical direction, forming a character diagram;
[0134] c. When extracting the horizontal direction, the noise is regarded as the horizontal direction, and when extracting the vertical direction, it is regarded as the vertical direction;
[0135] S3.23, orthogonal repair, for the division results of S3.22, for the node sets connected horizontally, the y values of the vertical coordinates of the nodes are adjusted to be consistent so that they are on the same horizontal line; for the node sets connected vertically, the x values of the vertical coordinates of the nodes are adjusted to be consistent so that they are on the same vertical line;
[0136] a. When calculating coordinates, the path should be used instead of the node, which means that when calculating coordinates, the path information between nodes is considered instead of the coordinates of a single node;
[0137] b. The coordinates of the path are represented by the average of the vectors of the two endpoints. That is, the coordinates of each path are represented by the average of the coordinates of the two endpoints (x1, y1) and (x2, y2). The average coordinates are
[0138] c. The weight of the path is defined as the modulus of the difference between the two endpoint vectors, that is, the length of the line segment, which can be expressed as The longer the path, the greater the weight;
[0139] d. Calculate the unified coordinate X or Y set of a set of horizontal or vertical connected paths through the weighted average method, that is, multiply the average coordinate of each path by its weight (path length), then add them up, and finally divide by the total weight.
[0140] e. Verify whether the coordinates of the horizontal and vertical connecting nodes meet the orthogonality requirements, and output the path node coordinates after orthogonal repair.
[0141] The above method combines traditional image processing methods, computational geometry methods, graph theory methods and graph convolution methods, giving full play to the advantages of various methods. The image processing algorithm converts the image into a graph, and uses the computational geometry algorithm to simplify the edges to make the data concise and clear. The robustness of GCN is used to classify the edges. Then, the graph theory algorithm is used to repair the vector data by region.
[0142] Step S4: YOLO detects components and replaces them with standard primitives
[0143] S41. Use the YOLO network to detect the components in the original image. Draw a rectangular box for each detected component to indicate the position of the component in the image. Use pre-made standard graphics to replace the component rectangular box to standardize it. This detection work is performed on the line sub-image.
[0144] Drawing pre-processing and post-processing optimization in the component detection process, because components are all line elements and have strict drawing ratios. Therefore, traditional image pre-processing and direct scaling are not suitable. For texture information and large blocks of color information, such as pedestrian detection and vehicle detection, the image is directly scaled to the input size of the YOLO model, such as 480x480, 720x720, etc., but for drawings, the size of a single image is usually more than 3000, or even up to 8000. Direct scaling will result in: line distortion, or even disappearance, and component deformation.
[0145] Therefore, the tiled sub-image detection method is used to process large images. The process of this method is as follows:
[0146] a. Divide the original image into tiles of a specific size, such as 720*720, and ensure that there is at least 50 pixels of overlap between tiles to avoid the detection target being cut at the tile boundary.
[0147] b. Use the Yolo network to detect the target of each tile and merge the original output detection results of Yolo; the detection output result of Yolo for the tile is a series of rectangles, as well as category coding, confidence and other information;
[0148] c. Merge all tiles and restore the detected rectangle coordinates from the tile coordinate system to the original large image coordinate system; then find the bestbox (the best rectangle in the detected target) and other adjacent bestboxes based on the confidence level; calculate the intersection-over-union ratio of all rectangles, use the non-maximum suppression (NMS) algorithm to merge overlapping rectangles, and also use the confidence level to find the best rectangle for detecting targets in the overlapping area. This process ensures that even at the tile boundary, it can be accurately detected and marked, effectively processing large images.
[0149] The present invention performs YOLO detection on line sub-graphs, so that the pictures are purer without text interference, the dependence on training data sets is greatly reduced, and the recognition accuracy and stability are greatly improved.
[0150] Use slicing instead of image scaling, fuse the slice information into the original coordinate system, and then perform bestbox filtering to avoid the loss and proportional distortion of line images caused by image scaling.
[0151] S42. Use graphic primitives to restore components. Since the line relationship of components is more complicated than that of ordinary connections and more difficult to repair, prefabricated vector primitives are used to replace the detected components.
[0152] S4.21. Use CAD design tools to store various components into independent dxf unit files;
[0153] S4.22. According to the YOLO detection result, fill the corresponding primitives in the dxf primitive file stored independently in 1) into the rectangular box of the YOLO detection result.
[0154] The graphic element designed by the present invention is a fixed graphic, but how to place it in the corresponding position requires adapting the position, size, direction, and wiring point fine-tuning. The position and size can be calculated based on the rectangular frame of the component detection. However, for a component, such as a resistor, it is necessary to ensure that after replacing the graphic element, the graphic element is placed horizontally or vertically according to the original image, and after placement, the wiring points on both sides of the resistor must be aligned with the background wires.
[0155] For the above problems, take the following approach:
[0156] S4.221. When making graphics primitives, operate within the unit range, that is, vector graphics are limited to the unit square of 0-1, so as to calculate the scaling ratio later and ensure the scalability and versatility of graphics primitives;
[0157] S4.222. The graphics element is divided into three layers: point, line and surface. The point layer marks the connection points to ensure accurate docking during placement. The line layer draws the component lines to ensure the basic shape and structure of the graphics element. The surface layer marks the fill surface and draws an erase area (the background lines in the original image will be erased if they fall into the erase area, which can effectively prevent line contamination).
[0158] S4.223, calculate the scaling and translation factors based on the position and size of the rectangle,
[0159] In the horizontal direction, when the size of the primitive in the unit square is W unit ×H unit , the size of the detected rectangular box is W rect ×H rect , then its scaling factor is:
[0160]
[0161] Among them, S x S is the horizontal scaling ratio of the element. y The scaling ratio of the primitive in the vertical direction;
[0162] The translation factor is the distance the primitive needs to be moved in order to place it in the correct position of the detected rectangle. Assume that the coordinates of the upper left corner of the detected rectangle are (X rect ,Y rect ), the translation factor is calculated as follows:
[0163] T x =X rect
[0164] T y =Y rect
[0165] Among them, T x is the distance that the element needs to move horizontally, that is, the horizontal coordinate of the upper left corner of the rectangular box; T y The distance that the element needs to move in the vertical direction, that is, the vertical coordinate of the upper left corner of the rectangular box;
[0166] S4.224, calculate the number and position of the intersections of the rectangle and the background lines on the four sides of top, bottom, left and right;
[0167] S4.225, according to the location of the wiring point of the graphic element, the location of the intersection of the rectangle and the background line, make accurate direction and position matching;
[0168] S4.226. Insert the graphic element as a block element of CAD into the corresponding position of the drawing.
[0169] At this point, you will get the complete converted CAD drawing.
[0170] Step 5: Results Generation
[0171] The above OCR results, vector graphics results and component detection results are combined and written into dxf to form the final CAD document.
[0172] The generated results are saved in the form of DXF files, divided into three layers: text, vector, and component graphics, and can be viewed using CAD software.
[0173] Regarding the contents disclosed in this case, there are a few points that need to be explained:
[0174] (1) The drawings of the embodiments disclosed in this case only involve the structures involved in the embodiments disclosed in this case, and other structures can refer to the general design;
[0175] (2) In the absence of conflict, the embodiments and features of the embodiments disclosed in this case can be combined with each other to obtain new embodiments;
[0176] The above are only specific implementation methods disclosed in this case, but the protection scope of the present disclosure is not limited thereto. The protection scope disclosed in this case should be based on the protection scope of the claims.
Claims
1. A method for vectorizing secondary drawings of a power system, characterized in that: The following steps are involved: S1, UNet image and text separation, obtain text sub-image and line sub-image; S2, perform OCR on the text sub-image; S3, perform vectorization on line sub-images and repair and beautify vector images; S4 and Yolo v5 detect components and replace them with standard primitives; S5. Results generation.
2. The method for vectorizing secondary drawings of a power system according to claim 1, characterized in that: Step S1 includes: S1.1: Data preparation, using existing CAD drawings, through automated scripts, exporting them into three sub-images: original image, text, and line; S1.2: Take the original image obtained in S1.1 as input, and the text sub-image and line sub-image as output, and build a UNet model with single-channel input and two-channel output. Through training, a universal image-text separation model is obtained, which specifically includes: 1) Convert the original image to grayscale, divide it by 255, and normalize it to between 0 and 1; 2) Take the original image as input, and in the encoder, through continuous convolution pooling, each time the channel is doubled to obtain several intermediate features; 3) Decode again, and use continuous resize functions to halve the channels each time to obtain intermediate features; 4) The intermediate features at the same position between the encoder and decoder are fused through a span connection and finally mapped to two channels, which correspond to the line sub-image and the text sub-image respectively; 5) Use text sub-images and line sub-images as standard output.
3. The method for vectorizing secondary drawings of a power system according to claim 1, characterized in that: In step S2, The text detection model is used to detect the text sub-image, and then the text recognition model is used for each detected rectangular area to obtain the position and content of the text.
4. The method for vectorizing secondary drawings of a power system according to claim 1, characterized in that: Step S3 includes: S3.1 image to graph S3.11, binarizing the line sub-image; S3.12, image thinning, obtaining a skeleton image with only a single line; S3.
13. Perform 3x3 convolution on the foreground points on the skeleton image, with the convolution kernel at 0 in the middle and 1 around it. S3.
14. Find all endpoints and nodes and perform floodfill tracing; S3.15, create a graph, use the polygon simplification algorithm to simplify the traced dense points, and obtain the graph form of the skeleton image; S3.2 Vector Graphics Beautification S3.21, Graph edge classification, divide all the paths of the graph into four categories: horizontal lines, vertical lines, diagonal lines and noise; S3.22, Unicom regional subgraph division, according to S3.21, the graph is divided into several subgraphs, the principles are as follows: Those that are interconnected and in the same horizontal direction are a subgraph; They are connected to each other and are vertical, forming a word picture; When extracting the horizontal direction, the noise is regarded as the horizontal direction, and when extracting the vertical direction, it is regarded as the vertical direction; S3.23, orthogonal repair, for the division results of S3.22, for the set of horizontally connected nodes, adjust the y values of the vertical coordinates of the nodes to be consistent so that they are on the same horizontal line; for the set of vertically connected nodes, adjust the x values of the vertical coordinates of the nodes to be consistent so that they are on the same vertical line.
5. The method for vectorizing secondary drawings of a power system according to claim 1, characterized in that: Step S4 includes: S4.
1. Use the Yolo network to detect the components in the original image. Draw a rectangular box for each detected component to mark the position of the component in the image. Use pre-made standard graphics elements to replace the component rectangular box to standardize it. The image is processed using the tiled sub-image detection method. The process of this method is as follows: a. Divide the original image into tiles of a specific size; b. Use the Yolo network to detect the target of each tile and merge the original output detection results of Yolo; c. Merge all tiles and restore the detected rectangle coordinates from the tile coordinate system to the original large image coordinate system; Then find the bestbox and other adjacent bestboxes according to the confidence level; calculate the intersection and union ratio of all rectangular boxes, Use the non-maximum suppression algorithm to merge overlapping rectangles, and also use the confidence to find the best rectangle to detect the target in the overlapping area; S4.
2. Use graphic primitives to restore components and replace detected components using prefabricated vector graphics primitives; specifically including: S4.
21. Use CAD design tools to store various components into independent dxf unit files; S4.
22. According to the YOLO detection result, fill the corresponding primitives in the dxf primitive file independently stored in S4.21 into the rectangular box of the YOLO detection result.
6. The method for vectorizing secondary drawings of a power system according to claim 5, characterized in that: When placing graphics, take the following approach: S4.
221. When making graphics primitives, operate within the unit range, and limit all vector graphics to the unit square of 0-1; S4.222, the graphics elements are divided into three layers: point, line and surface. The point layer marks the wiring points; the line layer draws the component lines; the surface layer marks the fill surface and draws an erase area; S4.
223. Calculate the scaling and translation factors based on the position and size of the rectangle: In the horizontal direction, when the size of the primitive in the unit square is W unit ×H unit , the size of the detected rectangular box is W rect ×H rect , then its scaling factor is: Among them, S x S is the horizontal scaling ratio of the element. y The scaling ratio of the primitive in the vertical direction; The translation factor is the distance that the primitive needs to move. Assume that the coordinates of the upper left corner of the detected rectangle are (X rect ,Y rect ), the translation factor is calculated as follows: T x =X rect T y =Y rect Among them, T x T is the distance that the element needs to move in the horizontal direction; y The distance that the element needs to move in the vertical direction; S4.224, calculate the number and position of the intersections of the rectangle and the background lines on the four sides of top, bottom, left and right; S4.225, according to the location of the wiring point of the graphic element, the location of the intersection of the rectangle and the background line, make accurate direction and position matching; S4.
226. Insert the graphic element as a block element of CAD into the corresponding position of the drawing.
7. The method for vectorizing secondary drawings of a power system according to claim 1, characterized in that: Step S5 includes: Combine the above OCR results, vector graphics results and component detection results, and write them into dxf to form the final CAD document; The generated results are saved in the form of DXF files, divided into three layers: text, vector, and component graphics, and can be viewed using CAD software.
Citation Information
Patent Citations
Engineering drawing vector conversion and primitive semantic extraction method
CN102880868A
CAD primitive automatic identification and replacement method
CN112256896A
Method for scanning and converting paper electric power engineering drawing into electronic edition CAD drawing
CN114529936A
Electric power drawing composition analysis method and system
CN114627486A
Character and band width line identification method of electrical CAD (Computer Aided Design) drawing scanning graph
CN115100657A