Method and device for identifying object in PDF (Portable Document Format) document based on drawing
By reading the drawing information of PDF documents, analyzing brush data and combining line segments, and combining cached data to generate regional objects, the problems of PDF document recognition error and large calculation amount in the prior art are solved, and efficient and accurate document processing and the ability to quickly process massive documents is achieved.
Patent Information
- Application Number
- CN202311218406.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-20
- Publication Date
- 2025-03-21
AI Technical Summary
The existing PDF document recognition methods mainly rely on OCR, which have problems such as large identification errors and high computational volume and high configuration of graphics cards, making it difficult to efficiently process massive documents.
By reading the drawing information of each page in the PDF document, the page stream is obtained, and the brush data is parsed into multiple line segments, the line segments are combined to obtain the area data, and after filtering, the cache data is combined to obtain the area object.
It realizes more efficient and accurate PDF document processing, avoids misreading caused by color size problems, can quickly read transparent tables, is fast and has low cost, is suitable for implementation on the CPU, and is easy to process massive documents in parallel.
Smart Images

Figure CN119672746A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a method and device for identifying objects in a PDF document based on drawing. Background Art
[0002] There is a large amount of unstructured (document) data in the system, with many formats, including common Microsoft Word (.doc, .docx), Microsoft Excel (.xls, xlsx), Microsoft PowerPoint (.ppt, pptx), portable files (.pdf), various professional statistics, reports, etc. A single file contains different types of information, such as text, pictures, tables, etc.
[0003] PDF is a popular and portable document format. Users can use the PDF printer provided by Adobe to output all printable content into PDF internal objects. Therefore, it is very popular and has a dominant position in the market. Since PDF itself is mainly aimed at drawing and typesetting, its internal object organization is similar to the painting process, where one stroke, one line, one word, and one picture gradually cover and overlap, and finally form a visible area (page). The content in PDF documents is fragmented and isolated, and it is difficult to extract. This is mainly manifested in the following aspects: the text in PDF exists independently, without paragraphs or format organization, so what you get will be one word at a time. It may be that a sentence is saved from the last word, or it may be the first sentence in a paragraph, followed by a header, and then the second sentence; there is no table object in PDF. All the tables you see are intertwined horizontal and vertical line segments or very small rectangles. The text, pictures and other information in the table are also unrelated to the table segments. It is only the spatial position that makes it appear in the corresponding position. There is no organizational relationship between the two, and it is impossible to directly search and extract them at one time. Related content: There are two types of images in PDF, external embedded images, like ordinary JPG, PNG, this type of image is distorted when scaled to a very high multiple, and the other type is "vector images" composed of line segments, paths, color blocks, etc. drawn step by step by drawing lines, coloring, etc. This type of image can be enlarged many times without distortion because it retains the drawing process, but "vector images" do not exist in PDF. What is retained in PDF is the lines, color blocks and other information of the "vector image" drawing process, which constitutes a visual image. It is not a complete object in itself. These lines are no different from all lines such as tables and dividing lines.
[0004] The existing PDF document recognition method mainly uses OCR (Optical Character Recognition), and the process is to screenshot the pages in the PDF document to form an image, and then use OCR to perform text recognition on the image. Summary of the invention
[0005] In order to achieve more efficient and accurate processing of PDF documents, an embodiment of the present invention provides a method and device for object recognition in a PDF document based on drawing.
[0006] In a first aspect, an embodiment of the present invention provides a method for object recognition in a PDF document based on drawing, the method comprising:
[0007] Read the drawing information of each page in the PDF document respectively to obtain the page stream corresponding to each page;
[0008] Classifying each of the page flows to obtain corresponding brush data and cache data; the cache data at least includes text, pictures, coloring methods and filling methods;
[0009] Parsing the brush data into multiple line segments, and combining the line segments to obtain region data;
[0010] Filtering the area data to obtain an identified area;
[0011] A region object is obtained according to the identified region and the cached data.
[0012] In one or some optional implementations of the embodiment of the present application, parsing the brush data into multiple line segments and combining the line segments to obtain region data includes:
[0013] Parsing the brush data into a plurality of line segments;
[0014] removing non-horizontal or non-vertical line segments from the plurality of line segments;
[0015] Select two line segments from the plurality of line segments at a time, and determine whether the two line segments intersect;
[0016] If so, the two line segments are combined to generate a graphic region;
[0017] The above steps are repeatedly performed until all intersecting line segments among the plurality of line segments are combined to generate a graphic region, thereby obtaining the region data.
[0018] In one or some optional implementations of the embodiment of the present application, combining the two line segments to generate a graphic area includes:
[0019] Obtaining the positions and endpoint coordinates of the two line segments, and determining the coordinates of four vertices of the graphic area;
[0020] Connect the four vertex coordinates to obtain a graphic area.
[0021] In one or some optional implementations of the embodiment of the present application, filtering the area data to obtain the identified area includes:
[0022] Removing graphic regions whose sizes are smaller than a first preset threshold in the region data;
[0023] Removing graphic regions whose sizes exceed a second preset threshold in the region data;
[0024] Removing the inner graphic area from the graphic areas nested in the regional data;
[0025] The graphic area in the regional data that is beyond the header or footer is removed.
[0026] In one or some optional implementations of the embodiment of the present application, the removing of the inner graphic area among the nested graphic areas in the regional data includes:
[0027] Determine whether there is a nested structure consisting of multiple graphic areas in the area data;
[0028] If so, for each graphic region, determine whether it is contained in other graphic regions;
[0029] If so, the graphic area is deleted from the area data.
[0030] In one or some optional implementations of the embodiment of the present application, obtaining the region object according to the identified region and the cached data includes:
[0031] The cache data covered by the identified area and the identified area are used as area objects.
[0032] In a second aspect, an embodiment of the present invention provides a device for identifying objects in a PDF document based on drawing, the device comprising:
[0033] The first acquisition module is used to read the drawing information of each page in the PDF document respectively to obtain the page stream corresponding to each page;
[0034] A second acquisition module is used to classify each of the page flows to obtain corresponding brush data and cache data; the cache data at least includes text, pictures, coloring methods and filling methods;
[0035] A first combining module, used for parsing the brush data into a plurality of line segments, and combining the line segments to obtain region data;
[0036] A first filtering module, used for filtering the area data to obtain an identification area;
[0037] The third acquisition module is used to obtain the area object according to the identified area and the cache data.
[0038] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-mentioned method for object recognition in a PDF document based on drawing.
[0039] In a fourth aspect, an embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for object recognition in a PDF document based on drawing as described above is implemented.
[0040] In a fifth aspect, an embodiment of the present invention provides a computer program product comprising instructions, which, when executed on a computer device, enables the computer device to execute the above-mentioned method for identifying objects in a PDF document based on drawing.
[0041] In a sixth aspect, an embodiment of the present invention provides a chip, the chip including a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a computer program or instruction to implement the object recognition method in a drawing-based PDF document as described above.
[0042] The beneficial effects of the above technical solution provided by the embodiment of the present invention include at least:
[0043] The drawing-based object recognition method in a PDF document provided by an embodiment of the present invention obtains a page stream by reading the drawing information of each page in the PDF document, and obtains brush data, text data, image data and other data therein. Since the objects stored in the PDF itself are directly read, misreading of text and line segments due to color, size and other issues is avoided. The transparent border table can be read, the brush data is parsed to obtain multiple line segments, the line segments are combined to obtain regional data, and the regional objects are obtained after filtering and combined with cached text, image and other data. There is no need to perform complex image processing and analysis, the speed is fast and the cost is low, and the document processing can be completed efficiently in a short time. Good results can be achieved on the CPU, and there is no high demand for the GPU. It is easy to use multiple computers to form a cluster to process massive documents in parallel.
[0044] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.
[0045] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0047] Figure 1 It is a flowchart of a method for object recognition in a PDF document based on drawing provided in an embodiment of the present application;
[0048] Figure 2 is a schematic diagram of a generated graphic area provided in an embodiment of the present application;
[0049] Figure 3 is a schematic diagram of an object recognition region process provided by an embodiment of the present application;
[0050] Figure 4 is a schematic diagram of an object recognition result provided by an embodiment of the present application;
[0051] Figure 5 This is a schematic diagram of a processing log provided in an embodiment of the present application;
[0052] Figure 6 It is a schematic diagram of extracting a table area object to Excel provided in an embodiment of the present application;
[0053] Figure 7 It is a framework flow chart of a method for object recognition in a PDF document based on drawing provided in an embodiment of the present application;
[0054] Figure 8 is a flowchart of object recognition provided by an embodiment of the present application;
[0055] Fig. 9 A schematic diagram of the structure of a device for identifying objects in a PDF document based on drawing provided in an embodiment of the present application. DETAILED DESCRIPTION
[0056] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0057] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0058] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0059] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0060] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0061] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0062] It should be understood that the size of the serial numbers of the steps in the following embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0063] In order to illustrate the technical solution of the present application, a specific embodiment is provided below for illustration.
[0064] The inventors have found that the existing PDF document recognition methods are mainly based on OCR, and the process is to screenshot the entire page in the PDF to form a picture, and then perform text recognition and line segment recognition by OCR. There are errors in the use of OCR for recognition, and it may cause misreading when the text is small or the font and typeface are very different. OCR cannot recognize transparent (usually used for placeholders) or areas composed of line segments with very small color difference between the front and back. OCR has a large amount of calculation and requires a high-configuration graphics card. To process massive documents, a large number of GPU clusters are required, which is costly. Based on this, the inventors have made the present invention after further research and development, providing a method, device, equipment and medium for object recognition in PDF documents based on drawing.
[0065] Embodiment 1
[0066] The embodiment of the present invention provides a method for object recognition in a PDF document based on drawing, referring to Figure 1 As shown, the method includes:
[0067] S101: Reading drawing information of each page in the PDF document respectively to obtain a page stream corresponding to each page.
[0068] In the embodiment of the present application, in the above step S101, the drawing information of each page in the PDF document is read respectively. The first step is to read the page tree of the PDF document. The page tree (Page Tree) is the organizational structure of the PDF document. It organizes the pages in the document in a tree-like hierarchical structure to facilitate subsequent processing; the second step is to draw the content of each page in the page tree respectively to obtain the drawing information, thereby obtaining the page stream (ContentStream) of the current page. The page stream list of all page streams in the PDF document can be obtained by looping. Among them, the content contained in the page stream depends on the elements on the page, including text (font, size, position and content of the text), pictures (position, size and attributes of the image), coloring method, filling method, brush data, color and graphic attributes, layers and masks, annotations and interactive elements, etc. In a specific embodiment, the above specific operations are based on the open source software PdfBox, which provides the ability to extract PDF basic objects. Import the PDF document into PdfBox, use the 'document.getPages()' function to get the PDF page tree, which is a collection of all pages, and use the 'page.getContents()' function to get the page stream.
[0069] S102: Classify each of the page flows to obtain corresponding brush data and cache data;
[0070] In the embodiment of the present application, the above step S102 parses and classifies the page flow obtained in step S101, and reads each drawing instruction in the page flow by analyzing the page flow. The drawing instructions in the page flow usually appear in the form of operators and parameters. According to the read drawing instructions, the drawing type can be identified. After the type of the drawn shape is determined, attribute information such as coordinates, color, line width, etc. can be extracted from the drawing instructions. After reading the drawing instructions, the drawing types are divided into brushes, text, pictures and other types, and object recognition is performed on the brush data. The text, pictures and other data are cached. After the identification area in the brush data is obtained, the area object is generated. Among them, other data includes coloring method, filling method, color and graphic attributes, layers and masks, annotations and interactive elements, etc.
[0071] In a specific embodiment, the 'PDPageContentStream' class in PdfBox can be used to traverse the page stream list, analyze the drawing instructions therein, and extract various graphic drawing instructions and attribute information.
[0072] S103: Parse the brush data into multiple line segments, and combine the line segments to obtain region data.
[0073] In the embodiment of the present application, the step S103 of parsing the brush data into multiple line segments and combining the line segments to obtain the region data includes:
[0074] Parsing the brush data into a plurality of line segments;
[0075] Remove non-horizontal or non-vertical line segments from multiple line segments;
[0076] Select two line segments from multiple line segments at a time and determine whether the two line segments intersect;
[0077] If so, combine the two line segments to generate a graphic region;
[0078] Repeat the above steps until all intersecting line segments are combined to generate a graphic region, thereby obtaining region data.
[0079] Among them, two line segments are combined to generate a graphic area, including:
[0080] Get the positions and endpoint coordinates of the two line segments, and determine the coordinates of the four vertices of the graphics area;
[0081] Connect the four vertex coordinates to obtain the graphic area.
[0082] Read the brush data, parse the brush data, and identify the various painting methods therein. The brush data includes multiple painting methods such as paths, rectangles, line segments, and Bezier curves. Regardless of which painting method it belongs to, the brush data can be disassembled into one or more small line segments. For example, for paths, it will involve analyzing the straight lines and curve segments in its path. For rectangles, it can be decomposed into four sides, and Bezier curves need to be further decomposed to obtain smaller line segments. This process converts the brush data into a simpler line segment representation. After the line segments are parsed, the line segments are combined to form a region. The specific steps include: the first step is to remove non-horizontal and non-vertical line segments, which can quickly find the border line segments composed of only horizontal or vertical line segments, remove a large number of interfering oblique lines in the vector map, and reduce the amount of calculation; the second step is to select two line segments each time to determine whether the two line segments intersect: if the two line segments intersect, a graphic region is generated. Knowing the positions of the two line segments and the coordinates of the endpoints, the four vertex coordinates of the graphic region can be calculated, and the four vertex coordinates are connected in sequence to obtain the graphic region. After the generation of the graphic area is completed, two new line segment combinations are reselected for judgment; if the two line segments do not intersect, and the intersecting line segments among all the line segments have been combined to generate the graphic area, the loop is terminated to obtain the regional data composed of all the graphic areas.
[0083] For example, see Figure 2 The figure shows the graphic area generated by executing the above step S103, wherein the shape of the graphic area is a rectangle, the outer frame is the generated graphic area, and the interior is line segments, wherein the first and second figures are independent line segments; the third and fifth figures are oblique lines and multiple intersecting oblique lines, and in the step of removing non-horizontal or non-vertical line segments, the line segments in these two cases will be removed; the fourth figure is an example of the target graphic area, where a horizontal line segment intersects with a vertical line segment to generate a corresponding graphic area.
[0084] S104: Filter the region data to obtain a recognition region.
[0085] In the embodiment of the present application, the process of filtering the regional data in the above step S104 includes:
[0086] Removing graphic regions whose sizes are smaller than a first preset threshold in the region data;
[0087] Removing graphic regions whose sizes exceed a second preset threshold value in the region data;
[0088] Remove the inner graphic area from the graphic area nested in the regional data;
[0089] Remove the graphic area in the area data that is beyond the header or footer.
[0090] Among them, the inner graphic area in the graphic area nested in the regional data is removed, including:
[0091] Determine whether there is a nested structure consisting of multiple graphic areas in the area data;
[0092] If so, for each graphic region, determine whether it is contained in other graphic regions;
[0093] If so, delete the graphic area from the area data.
[0094] In an embodiment of the present application, first, each graphic area in the regional data is checked, and the graphic areas with a size smaller than a first preset threshold are removed, and only relatively larger graphic areas are retained, wherein the first preset threshold is set in advance. In a specific implementation case, the first preset threshold can be set to 5 PDF size units; next, similarly, the graphic areas in the graphic area whose size exceeds the second preset threshold are removed, and the second preset threshold here represents the page range, that is, those graphic areas that exceed the page range are removed; if there is a header or footer in the page, those graphic areas that are located beyond the header or footer range are removed; in the regional data, there may be nested graphics, that is, one graphic area is completely contained in another graphic area, and there is no intersection between the two graphic areas. If this happens, the inner graphic area is removed to prevent repeated reading of cached data in the overlapping area.
[0095] In the present application, refer to Figure 3 As shown, after obtaining the brush data, the specific process of executing the above steps S103 and S104 to realize generating the recognition area may include: first, executing reading of the brush data. Then, executing line segment parsing, parsing the read brush data into multiple line segments. Then, executing filtering of horizontal and vertical line segments, removing non-horizontal or non-vertical line segments, and retaining horizontal line segments and vertical line segments. Then, executing intersection merging, selecting two line segments from the retained horizontal line segments and vertical line segments each time, and judging whether the two line segments intersect; if so, combining the two line segments to generate a graphic area; repeating the process of selecting line segments, until the intersecting line segments in the retained horizontal line segments and vertical line segments are combined to generate a graphic area, and obtaining the regional data. Then, executing filtering and de-overlapping, removing the graphic area whose size is less than the first preset threshold, the graphic area whose size exceeds the second preset threshold, the inner graphic area in the nested graphic area, and the graphic area whose position exceeds the header or footer in the regional data, and finally obtaining the recognition area.
[0096] S105: Obtaining a region object according to the identified region and the cached data.
[0097] In an embodiment of the present application, in the above step S105, an area object is obtained based on the recognition area and the cached data. Specifically, the obtained recognition area is combined with the content covered by the recognition area to obtain an area object, that is, all data with position attributes in the cached data within the recognition area, such as text content, line segments, colors, etc., are merged with the recognition area to obtain the area object.
[0098] For example, see Figure 4 As shown, the table in the first column, the table in the second column, the two charts in the third column, the two charts above the fourth column, and the table below are all recognized area objects, and the covered contents in the area objects are all combinations of line segments, text, and coloring.
[0099] In a specific embodiment, this solution uses PdfBox to implement a processing log diagram of a certain page of a PDF document as shown in the following figure: Figure 5 As shown in the figure, the processing log of page 26 in the PDF document is shown. Using this solution to process PDF documents to obtain region objects is a preliminary processing step in the cluster processing of massive documents. The subsequent processing methods will have various additional processing according to different requirements. For example, the region object corresponding to the table in the PDF page can be extracted as Excel, such as Figure 6 As shown, the left side is a PDF page with a table area object, and the right side is the result page after extracting the contents of the table area object to Excel.
[0100] In order to facilitate those skilled in the art to understand the present solution, the specific implementation process of the object recognition method in a PDF document based on drawing provided by an embodiment of the present invention is described more clearly and completely below:
[0101] Reference Figure 7 As shown, in the process of using PdfBox object recognition, the PDF document is imported into PdfBox, the page tree is read, and the steps of object recognition are performed starting from the first page of the PDF document. During the object recognition execution process of the current page, it is determined whether there is a next page in the page tree. If so, the page is entered and the steps of object recognition are continued. If not, the processing of the PDF document is terminated. The page stream list of all page streams of the PDF document can be obtained through looping.
[0102] When performing the steps to identify objects for each page, refer to Figure 8As shown, first, execute the above step S101, the content of the page can be drawn separately to obtain drawing information, that is, read the drawing content, so as to obtain the page flow of the current page. Then, execute the above step S102, classify the painting according to the obtained page flow, that is, read the drawing instructions, and distinguish between brushes, text, pictures and other types of data. Then, execute the above steps S103 and S104, obtain the regional data based on the brush data and then obtain the recognition area, and cache the text, pictures and other types of data to obtain the cache content, that is, cache data. Finally, execute the above step S105, generate an object according to the recognition area and the cache content, that is, obtain the regional object.
[0103] The object recognition method in the PDF document based on drawing provided by the embodiment of the present scheme obtains the page flow by reading the drawing information of each page in the PDF document, and obtains the brush data, text data, picture data and other data therein, parses the brush data, obtains multiple line segments, combines the line segments to obtain the area data, and obtains the area object by combining the cached text, picture and other data after filtering. The objects stored in the PDF itself can be read without misreading text and line segments due to color and size issues; transparent tables can be read; the speed is fast, which is basically equivalent to the speed of opening a document; the cost is low, and good results can be achieved on the CPU, and the GPU is not very demanding, and it is easy to use multiple computers to form a cluster to process massive documents in parallel.
[0104] Embodiment 2
[0105] Based on the same inventive concept, the embodiment of the present invention also provides a device for identifying objects in a PDF document based on drawing, referring to Fig. 9 As shown, the device comprises:
[0106] The first acquisition module is used to read the drawing information of each page in the PDF document respectively to obtain the page stream corresponding to each page;
[0107] A second acquisition module is used to classify each of the page flows to obtain corresponding brush data and cache data; the cache data at least includes text, pictures, coloring methods and filling methods;
[0108] A first combining module, used for parsing the brush data into a plurality of line segments, and combining the line segments to obtain region data;
[0109] A first filtering module, used for filtering the area data to obtain an identification area;
[0110] The third acquisition module is used to obtain the area object according to the identified area and the cache data.
[0111] Embodiment 3
[0112] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, a drawing-based object recognition method in a PDF document as described in the first embodiment above is implemented.
[0113] Embodiment 4
[0114] Based on the same inventive concept, an embodiment of the present invention further provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, a drawing-based object recognition method in a PDF document as described in the first embodiment is implemented.
[0115] Embodiment 5
[0116] Based on the same inventive concept, an embodiment of the present invention further provides a computer program product comprising instructions. When the computer program product is executed on a computer device, the computer device executes a drawing-based object recognition method in a PDF document as described in the first embodiment above.
[0117] Embodiment 6
[0118] Based on the same inventive concept, an embodiment of the present invention further provides a chip, the chip including a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run a computer program or instruction to implement a drawing-based object recognition method in a PDF document as described in the above embodiment 1.
[0119] 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 and optical storage, etc.) containing computer-usable program code.
[0120] 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.
[0121] 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.
[0122] 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 A step that specifies a function in one or more boxes.
[0123] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A method for object recognition in a PDF document based on drawing, characterized in that: include: Read the drawing information of each page in the PDF document respectively to obtain the page stream corresponding to each page; Classifying each of the page flows to obtain corresponding brush data and cache data; the cache data at least includes text, pictures, coloring methods and filling methods; Parsing the brush data into multiple line segments, and combining the line segments to obtain region data; Filtering the area data to obtain an identified area; A region object is obtained according to the identified region and the cached data.
2. The method according to claim 1, characterized in that The step of parsing the brush data into a plurality of line segments and combining the line segments to obtain region data includes: Parsing the brush data into a plurality of line segments; removing non-horizontal or non-vertical line segments from the plurality of line segments; Select two line segments from the plurality of line segments at a time, and determine whether the two line segments intersect; If so, the two line segments are combined to generate a graphic region; The above steps are repeatedly performed until all intersecting line segments among the plurality of line segments are combined to generate a graphic region, thereby obtaining the region data.
3. The method according to claim 2, characterized in that The step of combining the two line segments to generate a graphic area includes: Obtaining the positions and endpoint coordinates of the two line segments, and determining the coordinates of four vertices of the graphic area; Connect the four vertex coordinates to obtain a graphic area.
4. The method according to claim 1, characterized in that The filtering of the area data to obtain the identified area includes: Removing graphic regions whose sizes are smaller than a first preset threshold in the region data; Removing graphic regions whose sizes exceed a second preset threshold in the region data; Removing the inner graphic area from the graphic areas nested in the regional data; The graphic area in the regional data that is beyond the header or footer is removed.
5. The method according to claim 4, characterized in that The removing of the inner graphic area in the graphic area nested in the regional data comprises: Determine whether there is a nested structure consisting of multiple graphic areas in the area data; If so, for each graphic region, determine whether it is contained in other graphic regions; If so, the graphic area is deleted from the area data.
6. The method according to claim 1, characterized in that The obtaining of a region object according to the identified region and the cached data includes: The cache data covered by the identified area and the identified area are used as area objects.
7. A device for object recognition in a PDF document based on drawing, characterized in that: include: The first acquisition module is used to read the drawing information of each page in the PDF document respectively to obtain the page stream corresponding to each page; A second acquisition module is used to classify each of the page flows to obtain corresponding brush data and cache data; the cache data at least includes text, pictures, coloring methods and filling methods; A first combining module, used for parsing the brush data into a plurality of line segments, and combining the line segments to obtain region data; A first filtering module, used for filtering the area data to obtain an identification area; The third acquisition module is used to obtain the area object according to the identified area and the cache data.
8. A computer-readable storage medium storing instructions, which, when executed on a terminal, enables the terminal to execute the method for object recognition in a PDF document based on drawing according to any one of claims 1 to 6.
9. A computer device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the object recognition method in a PDF document based on drawing as claimed in any one of claims 1 to 6 when executing the computer program.
10. A computer program product comprising instructions, which, when executed on a computer device, enables the computer device to execute the method for object recognition in a PDF document based on drawing according to any one of claims 1 to 6.
11. A chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a computer program or instruction to implement the object recognition method in a PDF document based on drawing according to any one of claims 1 to 6.