A method for converting non-vector PDF drawings to CAD vector drawings

Non-vector PDF drawings are converted into CAD vector drawings through pixel thinning and eight-direction search methods, which solves the problem of difficult conversion of non-vector drawings, achieves high automation and wide applicability, and optimizes the conversion effect.

CN118429480BActive Publication Date: 2024-10-01SOUTHEAST UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410489169.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-23
Publication Date
2024-10-01
Estimated Expiration
2044-04-23

AI Technical Summary

Technical Problem

The existing technology is difficult to convert non-vector PDF drawings into CAD vector drawings, resulting in limited information mobility and drawing transmission, high dependence on manual drawing methods, and low automation level.

Method used

The pixel thinning and eight-direction search methods are used to convert non-vector PDF drawings into binary images, and then the point coordinates are mapped through the

Benefits of technology

It realizes the widely applicable conversion of non-vector PDF drawings into CAD vector drawings, improves the degree of automation, can adapt to different graphics types, removes noise, and optimizes the conversion effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118429480B_ABST
    Figure CN118429480B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for converting non-vector PDF drawings to CAD vector graphics, including: performing morphological processing on the image of non-vector drawings that cannot be parsed and read in PDF format to form a binary image with only black and white; performing pixel refinement on the binary image, and using the refined single-pixel point image as the center line in the PDF drawing; establishing an adjacent point search algorithm under multiple cycles through eight-direction division based on pixel points, finding the closed connection sequence of each pixel point, that is, the connection sequence between line segments under the vector graphics; mapping the center of the pixel image to vectorized CAD point coordinates; replicating the pixel connection sequence to the coordinate connection, and using the third-party open source library ezdxf to write the CAD image with coordinate points and polyline connections into the dxf file format to form a vector drawing that replicates PDF in equal proportion. The method solves the problem of difficulty in reading and converting traditional non-vector PDF drawings to CAD.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method for converting a non-vector PDF drawing to a CAD vector drawing, and belongs to the technical field of intelligent conversion of vectorized and non-vectorized drawing formats. Background Art

[0002] In the current field of drawing applications, vector graphics have the advantages of small storage files, editable and modifiable, and easy printing compared to traditional non-vector bitmaps. The conversion process from vector graphics to ordinary bitmaps is very simple, but the reverse process from non-vector graphics to vector graphics is very difficult, because vector graphics are not as good as traditional bitmaps. Figure 1 Once it is downgraded to a non-vector image, its mathematical logic relationship is lost, that is, only a one-way conversion relationship from vector to non-vector can be established, which causes serious troubles to the overall information flow and drawing transmission. Therefore, it is an urgent need to establish a conversion method based on non-vector PDF drawings to CAD vector drawings in the current field of drawing intelligence.

[0003] There is a conversion method under vector graphics PDF in the prior art. The key point is that the PDF format at this time is a parsable vector graphics, and the corresponding CAD line drawing can be generated by format parsing and reading. However, when facing a non-vector PDF, only garbled characters can be read, and the corresponding line CAD drawing cannot be generated. This method is only effective for special types of situations and cannot be widely applied to PDF conversion.

[0004] In addition, the following scheme emphasizes the use of manual tracing methods to reproduce the outlines of non-vectorized drawings. Although this method is applicable to all types of PDF drawings, it is heavily dependent on manual operations and lacks adaptive adjustments for different graphics. It has a low level of automation and a narrow application scenario. Summary of the invention

[0005] The technical problem to be solved by the present invention is: to provide a conversion method based on non-vector PDF drawings to CAD vector drawings, using pixel refinement as the first-stage algorithm and an eight-direction search method as the second-stage algorithm, converting the file conversion problem into a problem of image simulation change, and solving the problem of difficulty in reading and converting traditional non-vector PDF drawings to CAD.

[0006] The present invention adopts the following technical solutions to solve the above technical problems:

[0007] A method for converting non-vector PDF drawings to CAD vector drawings comprises the following steps:

[0008] Step 1, perform morphological processing on the non-vector drawing in PDF format to obtain a binary image with only black and white colors;

[0009] Step 2, performing pixel thinning on the binary image obtained in step 1 to obtain a single pixel thickness image;

[0010] Step 3, searching the black pixels in the single-pixel thickness image in eight directions, and saving the searched pixels in a list in order;

[0011] Step 4, mapping each pixel point in the single-pixel thickness image to a point coordinate in an XY coordinate system, sequentially replicating the pixel points in the list obtained by searching in step 3 to the point coordinates corresponding to the XY coordinate system, and connecting the point coordinates to obtain a multi-segment connection;

[0012] Step 5, use the exdxf third-party open source parsing library in Python language to write the point coordinates and polyline connections obtained in step 4 into the dxf format, save it, and get the CAD vector image.

[0013] As a preferred embodiment of the present invention, the specific process of step 1 is as follows:

[0014] The non-vector drawings in PDF format are binarized using the global threshold method, that is, pixels greater than 0 are filled with black pixels, and pixels less than or equal to 0 are filled with white pixels, to obtain a binary image with only black and white colors.

[0015] As a preferred solution of the present invention, the specific process of step 2 is as follows:

[0016] Step 2.1, traverse any pixel in the binary image obtained in step 1, if the current pixel is black, determine whether there are 2 to 6 black pixels in the eight neighboring pixels of the current pixel, if so, proceed to step 2.2, otherwise proceed to step 2.4;

[0017] Step 2.2, starting from any neighboring pixel point of the eight neighboring pixel points of the current pixel point, determine whether the pixel values ​​of two adjacent neighboring pixel points have changed in a clockwise or counterclockwise direction, and count the number of changes. If the pixel values ​​of any two adjacent neighboring pixel points of the eight neighboring pixel points have changed only once, proceed to step 2.3, otherwise proceed to step 2.4;

[0018] Step 2.3, determine whether the black pixels in the eight neighboring pixels of the current pixel are connected. If so, fill the current pixel with white pixels, otherwise proceed to step 2.4;

[0019] Step 2.4, traverse the next pixel point in the binary image obtained in step 1 according to steps 2.1-2.3 until no pixel point turns white.

[0020] As a preferred solution of the present invention, the specific process of step 3 is as follows:

[0021] Step 3.1, for any black pixel point P0 in the single-pixel thickness image, set the corresponding list line, and store P0 as the first point in the list line;

[0022] Step 3.2, obtain the pixel values ​​of the neighboring pixels of P0 in eight directions, and start from the upper left neighboring pixel of P0. If the first black pixel P1 is found in the clockwise direction, save the first black pixel P1 found in the clockwise direction into the list line and go to step 3.3; if no black pixel is found in the clockwise direction, go to step 3.5;

[0023] Step 3.3, obtain the pixel values ​​of the neighboring pixels in eight directions of Pi, and start from the upper left neighboring pixel of Pi to find the first black pixel, i≥1;

[0024] Step 3.4, if the first black pixel P(i+1) is found in the clockwise direction, save the first black pixel P(i+1) found in the clockwise direction to the list line, and set i=i+1, and return to step 3.3; if no black pixel is found in the clockwise direction, go to step 3.5;

[0025] Step 3.5, save P0 and all the first black pixels found into line in order;

[0026] Step 3.6, delete all pixels in line from all black pixels in the single-pixel thickness image. For the remaining black pixels in the single-pixel thickness image, return to step 3.1 and perform a new cycle to find a new list until no new list is generated;

[0027] Step 3.7, for all the lists found, delete the lists with only 1 pixel and only 2 pixels, and save the remaining lists.

[0028] As a preferred solution of the present invention, in step 4, if the pixel size of the single-pixel thickness image is N*M, a corresponding XY coordinate system is established, and the x-th horizontal and y-th vertical pixel point in the single-pixel thickness image, that is, the point coordinates (x, y) on the XY coordinate system, realizes a 1:1 replication of the single-pixel thickness image to the XY coordinate system.

[0029] A computer device comprises a memory, a processor, and a computer program stored in the memory and capable of running on the processor. When the processor executes the computer program, the steps of the method for converting non-vector PDF drawings to CAD vector drawings are implemented.

[0030] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for converting a non-vector PDF drawing to a CAD vector drawing are implemented.

[0031] Compared with the prior art, the present invention adopts the above technical solution and has the following technical effects:

[0032] 1. The conversion method of the present invention is processed from the graphic pixel layer and has wide applicability for the reverse conversion of all non-vector graphics.

[0033] 2. The conversion method of the present invention uses binarization and pixel method as the pre-processing basis, pixel refinement as the first-stage algorithm, and eight-direction search method as the second-stage algorithm, creatively transforming the file conversion problem into the problem of image simulation change. The overall method can output points and lines in a vector state, has adaptive computing capabilities, and can be applied to multiple types of automation scenarios. Its built-in algorithms all have adaptive properties, do not require human intervention, and have a high degree of automation.

[0034] 3. The conversion method of the present invention equivalently reproduces the drawing composition in the non-vector image from the pixel layer, and includes a line segment optimization scheme that can remove short lines formed by some noise points, thereby visually optimizing the overall conversion effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 It is a flow chart of the method for converting non-vector PDF drawings to CAD vector drawings based on the present invention;

[0036] Figure 2 is the PDF image after the original binarization in the embodiment of the present invention;

[0037] Figure 3 It is a schematic process from a multi-pixel thickness map to a single-pixel thickness map;

[0038] Figure 4 is a pixel-thinned PDF image according to an embodiment of the present invention;

[0039] Figure 5 It is a CAD image after vector conversion according to an embodiment of the present invention (its vectorization feature is demonstrated by local point selection). DETAILED DESCRIPTION

[0040] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be interpreted as limiting the present invention.

[0041] like Figure 1As shown, the present invention aims to provide a new method for converting CAD vector images that can be applied to non-vector PDF drawings. The idea is to use binarization and pixel method as the pre-processing basis, pixel refinement as the first-stage algorithm, and eight-direction search method as the second-stage algorithm. It creatively transforms the file conversion problem into the problem of image simulation change. The overall method can output points and lines in a vector state, has adaptive computing capabilities, and can be applied to multiple types of automation scenarios. The specific steps are as follows:

[0042] Step 1: Perform morphological processing on the non-vector drawings that cannot be parsed and read in PDF format to form a binary image with only black and white. Since the main body of the PDF drawing is composed of blank and line areas, the binarization operation of the global threshold method is used, that is, the points with pixels greater than 0 can be judged as line areas and filled with black pixels, and the rest of the areas are filled with white. The case effect is as follows Figure 2 shown.

[0043] Step 2: Pixel thinning is performed on the processed binary image to obtain an image with a single pixel thickness, which is used to replace the center line point of the image with multi-pixel thickness.

[0044] The pixel thinning method is a method of establishing a cyclic mechanism to continuously erode the stripe boundaries in the image (specifically erode the drawing line segments in the present invention) to finally obtain the drawing skeleton. The specific steps are as follows:

[0045] 1) Input a binary image;

[0046] 2) Traverse each pixel in the image. If the current line segment pixel is black, determine whether there are 2-6 black points in the eight-directional neighborhood of the current pixel (i.e., up, down, left, right, up-left, up-right, down-left, down-right) (if not, proceed to the next point);

[0047] 3) Whether the number of times the pixel value of the neighboring pixel point in the eight directions in the clockwise direction changes has only changed once (if not satisfied, proceed to the next point);

[0048] 4) Check whether the 2-6 points in the eight-direction area are connected and consistent (if not, proceed to the next point);

[0049] 5) If all of the above conditions are met, turn the point white and proceed to the next point;

[0050] 6) When no more elements satisfy the condition and turn white, exit the loop and output the result.

[0051] At the same time, the mathematical judgment of the pixel refinement method can be specifically expressed as follows:

[0052] 2≤N(p0)≤6

[0053] S(p0)=1

[0054] p1*p3*p5=0

[0055] P3*p5*p7=0

[0056] p1*p3*p7=0

[0057] p1*p5*p7=0

[0058] Among them, N(p0) represents the number of black pixel markers in the eight-directional neighborhood, S(p0) represents the number of times the pixel values ​​in the eight-directional neighborhood change from black to white and from white to black in a clockwise direction; the last four formulas represent that among the 2-6 black pixels in the eight-directional neighborhood, there must be one white pixel, resulting in the overall disconnection. Figure 3 The detailed schematic diagram shows the case effect. Figure 4 shown.

[0059] Step 3: Search the adjacent points in eight directions for the binary image of the single pixel, and a large number of independent line segments are searched, which save the connection order of the pixel points in the form of a series. Specifically:

[0060] 1) For the refined binary pixel map, there are a total of black points Pn, starting from any point P0 (it is recommended to take the top and bottom points);

[0061] 2) Calculate the pixel values ​​of its eight-directional neighborhood, generally in a clockwise direction. When the first black area point P1 is found in the clockwise direction, record it after P0 and save it in the list line1;

[0062] 3) Loop and search to add to the list until the next point cannot be found, then exit the loop, at which point list line1 = [P0, P1, .... Pm];

[0063] 4) Delete the m+1 points from the above population, and search again in the Pn-m-1 points for a new cycle. Finally, we get x lists [line1, line2...linex];

[0064] 5) Taking local noise into consideration, delete the lines with only 1-2 points, and the remaining combinations can form a polyline, that is, the order in which the pixels are arranged.

[0065] Step 4: Map the center of the pixel image to x and y point coordinates, and replicate the pixel connection sequence in step 3 to the corresponding x and y coordinate connections to form a polyline connection in the drawing.

[0066] Based on the image pixel size N*M, a corresponding coordinate system is established. The x-th pixel point in the horizontal direction and the y-th pixel point in the vertical direction are the corresponding coordinate points (x, y). This method can achieve a 1:1 replication of the morphology.

[0067] Step 5: Use the exdxf third-party open source parsing library in Python language to write the above points and polylines into dxf format.

[0068] Using the third-party open source library ezdxf, write the coordinate point Pn and the polyline connection linex into the dxf file format and save it in dxf format. At this time, the drawing has points connected by lines and clickable polylines, which can be easily re-edited and combined to meet the definition of vector graphics. The case effect is as follows Figure 5 shown.

[0069] Based on the same inventive concept, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the aforementioned method for converting non-vector PDF drawings to CAD vector drawings are implemented.

[0070] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the aforementioned method for converting non-vector PDF drawings to CAD vector drawings are implemented.

[0071] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0072] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.

[0073] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0074] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0075] The above embodiments are only for illustrating the technical idea of ​​the present invention, and cannot be used to limit the protection scope of the present invention. Any changes made on the basis of the technical solution in accordance with the technical idea proposed by the present invention shall fall within the protection scope of the present invention.

Claims

1. A method for converting non-vector PDF drawings to CAD vector drawings, characterized in that: The steps include: Step 1, perform morphological processing on the non-vector drawing in PDF format to obtain a binary image with only black and white colors; Step 2, performing pixel thinning on the binary image obtained in step 1 to obtain a single pixel thickness image; Step 3, searching the black pixels in the single-pixel thickness image in eight directions, and saving the searched pixels in a list in order; Step 4, mapping each pixel point in the single-pixel thickness image to a point coordinate in an XY coordinate system, sequentially replicating the pixel points in the list obtained by searching in step 3 to the point coordinates corresponding to the XY coordinate system, and connecting the point coordinates to obtain a multi-segment connection; Step 5, use the exdxf third-party open source parsing library in Python language to write the point coordinates and polyline connections obtained in step 4 into the dxf format, save it, and get the CAD vector diagram.

2. The method for converting non-vector PDF drawings to CAD vector drawings according to claim 1, characterized in that: The specific process of step 1 is as follows: The non-vector drawings in PDF format are binarized using the global threshold method, that is, pixels greater than 0 are filled with black pixels, and pixels less than or equal to 0 are filled with white pixels, to obtain a binary image with only black and white colors.

3. The method for converting non-vector PDF drawings to CAD vector drawings according to claim 1, characterized in that: The specific process of step 2 is as follows: Step 2.1, traverse any pixel in the binary image obtained in step 1, if the current pixel is black, determine whether there are 2 to 6 black pixels in the eight neighboring pixels of the current pixel, if so, proceed to step 2.2, otherwise proceed to step 2.4; Step 2.2, starting from any neighboring pixel point of the eight neighboring pixel points of the current pixel point, determine whether the pixel values ​​of two adjacent neighboring pixel points have changed in a clockwise or counterclockwise direction, and count the number of changes. If the pixel values ​​of any two adjacent neighboring pixel points of the eight neighboring pixel points have changed only once, proceed to step 2.3, otherwise proceed to step 2.4; Step 2.3, determine whether the black pixels in the eight neighboring pixels of the current pixel are connected. If so, fill the current pixel with white pixels, otherwise proceed to step 2.4; Step 2.4, traverse the next pixel point in the binary image obtained in step 1 according to steps 2.1-2.3 until no pixel point turns white.

4. The method for converting non-vector PDF drawings to CAD vector drawings according to claim 1, characterized in that: The specific process of step 3 is as follows: Step 3.1, for any black pixel point P0 in the single-pixel thickness image, set the corresponding list line, and store P0 as the first point in the list line; Step 3.2, obtain the pixel values ​​of the neighboring pixels of P0 in eight directions, and start from the upper left neighboring pixel of P0. If the first black pixel P1 is found in the clockwise direction, save the first black pixel P1 found in the clockwise direction into the list line and go to step 3.3; if no black pixel is found in the clockwise direction, go to step 3.5; Step 3.3, obtain the pixel values ​​of the neighboring pixels in eight directions of Pi, and start from the upper left neighboring pixel of Pi to find the first black pixel, i≥1; Step 3.4, if the first black pixel P(i+1) is found in the clockwise direction, save the first black pixel P(i+1) found in the clockwise direction into the list line, set i=i+1, and return to step 3.3; If no black pixel is found in the clockwise direction, go to step 3.5; Step 3.5, save P0 and all the first black pixels found into line in order; Step 3.6, delete all pixels in line from all black pixels in the single-pixel thickness image. For the remaining black pixels in the single-pixel thickness image, return to step 3.1 and perform a new cycle to find a new list until no new list is generated; Step 3.7, for all the lists found, delete the lists with only 1 pixel and only 2 pixels, and save the remaining lists.

5. The method for converting non-vector PDF drawings to CAD vector drawings according to claim 1, characterized in that: In step 4, if the pixel size of the single-pixel thickness image is N*M, a corresponding XY coordinate system is established, and the x-th horizontal and y-th vertical pixel point in the single-pixel thickness image, that is, the point coordinates (x, y) on the XY coordinate system, realizes a 1:1 replication of the single-pixel thickness image to the XY coordinate system.

6. A computer device comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, characterized in that: When the processor executes the computer program, the steps of the method for converting non-vector PDF drawings to CAD vector drawings as described in any one of claims 1 to 5 are implemented.

7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for converting a non-vector PDF drawing to a CAD vector drawing as described in any one of claims 1 to 5 are implemented.