Table information determination method and device, storage medium and electronic device
By preprocessing the engineering drawing images and determining the coordinates of rectangular frames, the problem of low table information recognition efficiency is solved, and the effect of efficient identification and reducing manual intervention is achieved.
Patent Information
- Application Number
- CN202411447548.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2024-12-27
AI Technical Summary
In the prior art, identifying table information in engineering drawings is inefficient, requiring a lot of manual intervention and high computing resource occupancy, especially because the existence of interference items seriously affects the identification efficiency.
By preprocessing the engineering drawing images, a binarized image is generated and a contour image is generated using horizontal line masks and vertical line masks, the coordinate set of rectangular boxes is determined, and the table range is determined, and text recognition is performed to extract table information.
It improves the efficiency of identification of table information, reduces manual intervention, optimizes the use of computing resources, and enhances the recognition speed and accuracy.
Smart Images

Figure CN119206753A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of image data processing, and in particular to a method, device, storage medium and electronic device for determining table information. Background Art
[0002] At present, when extracting tables from engineering drawing images, it is usually necessary to recognize the text content of the image, and then manually exclude the recognition content of the non-table part before comparing and entering the information of the table part. This process requires a lot of manpower, and because the image recognition process also needs to recognize interference items outside the table, it takes up additional computing resources and slows down the recognition speed. For example, too many interference items will seriously affect the efficiency of recognizing table information.
[0003] Therefore, in the related art, when recognizing a table in an image, there is a technical problem of how to improve the recognition efficiency of table information.
[0004] Regarding the problem of how to improve the recognition efficiency of table information in related technologies, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present application provide a method, device, storage medium and electronic device for determining table information, so as to at least solve the problem of how to improve the recognition efficiency of table information in the related art.
[0006] According to an embodiment of the embodiments of the present application, a method for determining table information is provided, including: preprocessing an acquired engineering drawing image to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing; generating a contour image based on the first horizontal line mask and the first vertical line mask, and obtaining a first coordinate set corresponding to all first rectangular boxes in the contour image, wherein the first coordinate set includes at least the vertex coordinates of all the first rectangular boxes; determining a first table range in the binary image based on the first coordinate set, wherein a target table is included in the first table range; performing text recognition on the target table to obtain table information in the target table.
[0007] In an exemplary embodiment, a first coordinate set corresponding to all first rectangular frames in the engineering image is obtained based on a contour image generated by the first horizontal line mask and the first vertical line mask, including: obtaining a first pixel position of a pixel point corresponding to the first horizontal line mask and a second pixel position of a pixel point corresponding to the first vertical line mask; taking an OR value for each first pixel position and each second pixel position to obtain the contour image; obtaining a first rectangular frame by performing rectangular fitting on the contour image, wherein the vertex coordinates of the first rectangular frame are located on the coordinate axis where the default origin of the binary image is located; and generating the first coordinate set according to the vertex coordinates corresponding to all the first rectangular frames.
[0008] In an exemplary embodiment, determining a first table range in the binary image based on the first coordinate set includes: determining a first coordinate point having a maximum horizontal coordinate value and a maximum vertical coordinate value from the first coordinate set; determining a first horizontal coordinate set and a first vertical coordinate set based on the first coordinate set; determining a second coordinate point based on the first horizontal coordinate set and the first vertical coordinate set when it is determined that the first horizontal coordinate set and the first vertical coordinate set meet a first preset condition; and determining the first table range based on the second coordinate point and the first coordinate point.
[0009] In an exemplary embodiment, determining a first horizontal coordinate set and a first vertical coordinate set based on the first coordinate set includes: taking the first coordinate point as the starting point, sorting all horizontal coordinates in the first coordinate set in descending order to obtain a first horizontal coordinate set, wherein the first horizontal coordinate set includes at least a second coordinate set, and the difference between the vertical coordinate value of the coordinate point in the second coordinate set and the maximum value of the vertical coordinate is less than a first preset threshold; and taking the first coordinate point as the starting point, sorting all vertical coordinates in the first coordinate set in descending order to obtain a first vertical coordinate set, wherein the first vertical coordinate set includes at least a third coordinate set, and the difference between the horizontal coordinate value of the coordinate point in the third coordinate set and the maximum value of the horizontal coordinate is less than a second preset threshold.
[0010] In an exemplary embodiment, when it is determined that the first horizontal coordinate set and the first vertical coordinate set meet a first preset condition, the second coordinate point is determined based on the first horizontal coordinate set and the first vertical coordinate set, including: the first preset condition is that the number of coordinate points in the second coordinate set and the number of coordinate points in the third coordinate set are both greater than a first preset value; when it is determined that the first preset condition is met, all horizontal coordinates in the second coordinate set are sorted in descending order with the first coordinate point as the starting point to obtain a second horizontal coordinate set, wherein the second horizontal coordinate set includes at least a fourth coordinate set, and the corresponding coordinates in the fourth coordinate set are The difference between the ordinate values of adjacent coordinate points is less than a first preset threshold value; and, taking the first coordinate point as the starting point, all the ordinates in the third coordinate set are sorted in descending order to obtain a second ordinate set, wherein the second ordinate set includes at least a fifth coordinate set, and the difference between the ordinate values of adjacent coordinate points in the fifth coordinate set is less than a second preset threshold value; when it is determined that the number of coordinate points in the fourth coordinate set and the number of coordinate points in the fifth coordinate set are both greater than the second preset value, determine a second coordinate point with the first minimum ordinate value of the fourth coordinate set as the ordinate and the first minimum ordinate value of the fifth coordinate set as the ordinate.
[0011] In an exemplary embodiment, the method also includes: the first preset condition is that the number of coordinate points in the second coordinate set and the number of coordinate points in the third coordinate set are both greater than a first preset value; when it is determined that the first horizontal coordinate set and the first vertical coordinate set do not meet the first preset condition, the first coordinate point is deleted from the first coordinate set to obtain a sixth coordinate set; based on the sixth coordinate set, a third horizontal coordinate set and a third vertical coordinate set are determined; when it is determined that the third horizontal coordinate set and the third vertical coordinate set meet the second preset condition, the second coordinate point is determined based on the third horizontal coordinate set and the third vertical coordinate set.
[0012] In an exemplary embodiment, determining the first table range based on the second coordinate point and the first coordinate point includes: determining a second horizontal line mask corresponding to the horizontal coordinate of the first coordinate point and a second vertical line mask corresponding to the vertical coordinate of the first coordinate point, and determining a third horizontal line mask corresponding to the horizontal coordinate of the second coordinate point and a third vertical line mask corresponding to the vertical coordinate of the second coordinate point; determining a target contour image consistent with the mask range from the contour image, wherein the mask range represents a range formed by the second horizontal line mask, the second vertical line mask, the third horizontal line mask and the third vertical line mask; performing image fitting on the contour object corresponding to the target contour image to obtain a fitted second rectangular frame; determining the image range corresponding to all the second rectangular frames in the binary image as the first table range, wherein a seventh coordinate set is generated corresponding to the vertex coordinates of all the second rectangular frames.
[0013] In an exemplary embodiment, the target table included in the first table range is determined in the following manner: text recognition is performed on any second rectangular box to obtain the first text information; when it is determined that the similarity between the first text information and the main table information is greater than a third preset threshold, a target table is generated according to the vertex coordinates in the seventh coordinate set and the first text information; when it is determined that the similarity between the first text information and the main table information is less than or equal to the third preset threshold, if it is determined that the similarity between the first text information and the appendix information is greater than a fourth preset threshold, a plurality of third rectangular boxes whose similarity between the first text information and the appendix information is greater than the fourth preset threshold are determined; a third coordinate point having a minimum second horizontal coordinate value and a fourth coordinate point having a maximum third horizontal coordinate value are determined from the vertex coordinates of the plurality of third rectangular boxes; a second table range is determined within the first table range according to the third coordinate point and the fourth coordinate point, and the target table included in the second table range is determined.
[0014] In an exemplary embodiment, a target table is generated according to the vertex coordinates in the seventh coordinate set and the first text information, including: traversing the horizontally connected area within the range of the first table to obtain horizontal line segments, and generating a first line segment set based on all horizontal line segments, wherein the horizontally connected area is determined based on the second horizontal line mask and the third horizontal line mask; for each vertex coordinate included in the seventh coordinate set, obtaining the vertical distance between each vertex coordinate and the horizontal line segments in the first line segment set; determining a first serial number corresponding to any second rectangular frame in the vertical direction according to the size of the vertical distance, wherein the smaller the vertical distance, the smaller the first serial number; for multiple cells included in any second rectangular frame, determining a second serial number corresponding to each cell in the horizontal direction, wherein the second serial number is calculated according to the vertex coordinate of each cell. The plurality of cells are sorted according to the size of the horizontal coordinate of the target, and the second serial number of each cell corresponds to the first serial number; a first cell set corresponding to any second rectangular box is generated based on the correspondence between the first serial number and the second serial number, and the first cell set at least includes the first serial number of any second rectangular box and the second serial number of each cell; the plurality of first cell sets are sorted according to the size of the first serial number, and the sorted plurality of first cell sets are merged to obtain a second cell set; text recognition is performed on all cells corresponding to the second cell set to obtain the second text information of each cell; when it is determined that the similarity between the second text information and the main table information is greater than a third preset threshold, a target table is generated according to the vertex coordinates corresponding to each cell and the second text information of each cell.
[0015] In an exemplary embodiment, determining the target table included in the second table range includes: obtaining a first cell whose horizontal coordinate value is greater than the second horizontal coordinate minimum value and whose horizontal coordinate value is less than the third horizontal coordinate maximum value from the second cell set, and generating a third cell set based on multiple first cells; traversing the horizontally connected area within the second table range to obtain horizontal line segments, and generating a second line segment set based on all horizontal line segments, wherein the horizontally connected area is determined based on the second horizontal line mask and the third horizontal line mask; for the first vertex coordinate of the second cell included in the third cell set, obtaining the vertical distance between the first vertex coordinate and the horizontal line segment in the second line segment set; determining a third serial number corresponding to the second cell in the vertical direction according to the size of the vertical distance, wherein the smaller the vertical distance, the smaller the third serial number; for multiple second cells The method comprises the steps of: selecting a plurality of sub-cells contained in a grid, determining a fourth serial number corresponding to each sub-cell in the horizontal direction, wherein the fourth serial number is obtained by sorting the plurality of sub-cells according to the size of the horizontal coordinates of the vertex coordinates of the second cell, and the fourth serial number of each sub-cell corresponds to the third serial number; generating a fourth cell set corresponding to the second cell based on the correspondence between the third serial number and the fourth serial number, wherein the fourth cell set at least includes the third serial number of the second cell and the fourth serial number of each sub-cell; sorting the plurality of fourth cell sets according to the size of the third serial number, and merging the sorted plurality of fourth cell sets to obtain a fifth cell set; performing text recognition on all sub-cells corresponding to the fifth cell set to obtain third text information of each sub-cell, and generating a target table according to the vertex coordinates corresponding to each sub-cell and the third text information of each sub-cell.
[0016] According to another aspect of an embodiment of the present application, a device for determining table information is also provided, including: a processing module, used to preprocess the acquired engineering drawing image to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing; an acquisition module, used to generate a contour image based on the first horizontal line mask and the first vertical line mask, and obtain a first coordinate set corresponding to all first rectangular boxes in the contour image, wherein the first coordinate set includes at least the vertex coordinates of all the first rectangular boxes; a determination module, used to determine a first table range in the binary image based on the first coordinate set, wherein the first table range contains a target table; and a recognition module, used to perform text recognition on the target table to obtain table information in the target table.
[0017] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned method for determining the table information when running.
[0018] According to another aspect of an embodiment of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the method for determining the table information through the computer program.
[0019] In the embodiment of the present application, after the engineering drawing image is processed into a binary image, a contour image is generated based on the first horizontal line mask and the first vertical line mask of the binary image, and then the first coordinate set corresponding to all rectangular frames in the contour image is obtained, and the first table range containing the target table is determined according to the first coordinate set, and the text recognition of the target table is performed to obtain the table information in the target table. The above technical solution solves the problem of how to improve the recognition efficiency of table information, thereby achieving the effect of improving the recognition efficiency of table information. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0021] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0022] Figure 1 It is a hardware environment diagram of a method for determining table information in an embodiment of the present application;
[0023] Figure 2 is a flowchart of a method for determining table information according to an embodiment of the present application;
[0024] Figure 3 is a schematic diagram of an engineering drawing according to an embodiment of the present application;
[0025] Figure 4 is a schematic diagram of a table in an engineering drawing according to an embodiment of the present application;
[0026] Figure 5 is a schematic flow chart of a method for determining table information according to an embodiment of the present application;
[0027] Figure 6It is a structural block diagram of a device for determining table information according to an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] According to one aspect of an embodiment of the present application, a method for determining table information is provided. Optionally, in this embodiment, the above method for determining table information can be applied to Figure 1 In the hardware environment composed of the terminal device 102 and the server 104 shown in FIG. Figure 1 As shown, the server 104 is connected to the terminal device 102 via a network, and can be used to provide services (such as application services, etc.) for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 104. Cloud computing and / or edge computing services can be configured on the server or independently of the server to provide data computing services for the server 104.
[0031] The network may include but is not limited to at least one of the following: a wired network, a wireless network. The wired network may include but is not limited to at least one of the following: a wide area network, a metropolitan area network, a local area network, and the wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal device 102 may not be limited to a PC, a mobile phone, a tablet computer, etc.
[0032] In this embodiment, a method for determining table information is provided, which is applied to the above terminal device. Figure 2 : is a flowchart of a method for determining table information according to an embodiment of the present application, the process includes the following steps:
[0033] Step S202, preprocessing the acquired engineering drawing image to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing;
[0034] Optionally, in the above step S202, the engineering image drawing is a drawing used to plan and design engineering projects, an important tool for guiding construction and manufacturing, including structural drawings or design drawings, parameter tables of materials and parts, etc. The preprocessing of the engineering drawing image includes, for each pixel point, extracting the values of the red channel, green channel and blue channel respectively according to the color information of the original image, recombining the above values to convert them into an RGB image, adjusting the image size of the engineering drawing image, and performing Gaussian blur and other processing on the engineering drawing image.
[0035] Optionally, the morphological processing in the above step S202 includes performing kernel size formatting on the image. The kernel size formatting can adapt the size of each image to obtain the best display effect. Assuming that there is an image set, the image formats in the image set are not uniform, some images are larger in size, and some are smaller in size, then it is necessary to define a standard image processing format to facilitate unified processing of images, thereby improving the accuracy of image recognition.
[0036] It can be understood that the vertical line mask and the horizontal line mask of the image are filters used in image processing and computer vision to detect vertical lines and horizontal lines in the image. The above-mentioned first horizontal line mask and the first vertical line mask are generated based on the recognition results of the edge frame lines in the engineering drawing image. For example, a horizontal line mask is generated for the recognized horizontal frame lines of the engineering drawing image.
[0037] Step S204, generating a contour image based on the first horizontal line mask and the first vertical line mask, and acquiring a first coordinate set corresponding to all first rectangular boxes in the contour image, wherein the first coordinate set at least includes vertex coordinates of all first rectangular boxes;
[0038] Step S206, determining a first table range in the binary image based on the first coordinate set, wherein the first table range includes a target table;
[0039] Step S208: performing text recognition on the target table to obtain table information in the target table.
[0040] Through the above steps, the acquired engineering drawing image is preprocessed to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing; a contour image is generated based on the first horizontal line mask and the first vertical line mask, and a first coordinate set corresponding to all first rectangular boxes in the contour image is obtained, wherein the first coordinate set at least includes the vertex coordinates of all the first rectangular boxes; a first table range in the binary image is determined based on the first coordinate set, wherein the first table range contains a target table; text recognition is performed on the target table to obtain table information in the target table, which solves the problem of how to improve the recognition efficiency of table information in the related art, thereby achieving the effect of improving the recognition efficiency of table information.
[0041] In an exemplary embodiment, the implementation process of obtaining the first coordinate set corresponding to all first rectangular boxes in the engineering image based on the contour image generated based on the first horizontal line mask and the first vertical line mask in the above-mentioned step S204 specifically includes: obtaining the first pixel position of the pixel point corresponding to the first horizontal line mask and the second pixel position of the pixel point corresponding to the first vertical line mask; taking the OR value of each first pixel position and each second pixel position to obtain the contour image; obtaining a first rectangular box by performing rectangular fitting on the contour image, wherein the vertex coordinates of the first rectangular box are located on the coordinate axis where the default origin of the binary image is located; and generating the first coordinate set according to the vertex coordinates corresponding to all the first rectangular boxes.
[0042] Optionally, in the above embodiment, for example, for the first coordinate set set rect One of the rectangular boxes included in , the coordinates are expressed as (x1, y1, x2, y2), where (x1, y1) is the vertex coordinate of the upper left corner of the rectangular box, and (x2, y2) is the vertex coordinate of the lower right corner of the rectangular box.
[0043] In an exemplary embodiment, the implementation process of determining the first table range in the binary image based on the first coordinate set in the above-mentioned step S206 includes the following steps: step S11, determining a first coordinate point with a maximum horizontal coordinate value and a maximum vertical coordinate value from the first coordinate set; step S12, determining a first horizontal coordinate set and a first vertical coordinate set based on the first coordinate set; step S13, when it is determined that the first horizontal coordinate set and the first vertical coordinate set meet a first preset condition, determining a second coordinate point based on the first horizontal coordinate set and the first vertical coordinate set; step S14, determining the first table range based on the second coordinate point and the first coordinate point.
[0044] Through the above embodiments, the range where the table exists can be located from the engineering drawing image, so that interference from other information can be eliminated when identifying the table information, thereby improving the recognition efficiency of the table information.
[0045] In an exemplary embodiment, the implementation process of determining the first horizontal coordinate set and the first vertical coordinate set according to the first coordinate set in the above step S12 specifically includes: taking the first coordinate point as the starting point, sorting all the horizontal coordinates in the first coordinate set in descending order to obtain a first horizontal coordinate set, wherein the first horizontal coordinate set includes at least a second coordinate set, and the difference between the vertical coordinate value of the coordinate point in the second coordinate set and the maximum value of the vertical coordinate is less than a first preset threshold; and taking the first coordinate point as the starting point, sorting all the vertical coordinates in the first coordinate set in descending order to obtain a first vertical coordinate set, wherein the first vertical coordinate set includes at least a third coordinate set, and the difference between the horizontal coordinate value of the coordinate point in the third coordinate set and the maximum value of the horizontal coordinate is less than a second preset threshold.
[0046] Optionally, in the above embodiment, by setting the first preset threshold, the second preset threshold can filter out the horizontal coordinate set (second coordinate set) within the table range from all the horizontal coordinates (first horizontal coordinate set), and filter out the vertical coordinate set (third coordinate set) within the table range from all the vertical coordinates (first vertical coordinate set).
[0047] In an exemplary embodiment, in the above step S13, when it is determined that the first horizontal coordinate set and the first vertical coordinate set satisfy the first preset condition, the implementation process of determining the second coordinate point based on the first horizontal coordinate set and the first vertical coordinate set specifically includes: the first preset condition is that the number of coordinate points in the second coordinate set and the number of coordinate points in the third coordinate set are both greater than a first preset value; when it is determined that the first preset condition is satisfied, sorting all horizontal coordinates in the second coordinate set in descending order with the first coordinate point as the starting point to obtain a second horizontal coordinate set, wherein the second horizontal coordinate set includes at least a fourth coordinate set, the The difference between the vertical coordinate values of adjacent coordinate points in the fourth coordinate set is less than a first preset threshold value; and, taking the first coordinate point as the starting point, all the vertical coordinates in the third coordinate set are sorted in descending order to obtain a second vertical coordinate set, wherein the second vertical coordinate set includes at least a fifth coordinate set, and the difference between the horizontal coordinate values of adjacent coordinate points in the fifth coordinate set is less than a second preset threshold value; when it is determined that the number of coordinate points in the fourth coordinate set and the number of coordinate points in the fifth coordinate set are both greater than the second preset value, determine a second coordinate point with the first minimum horizontal coordinate value of the fourth coordinate set as the horizontal coordinate and the first minimum vertical coordinate value of the fifth coordinate set as the vertical coordinate.
[0048] It should be noted that the above-mentioned first preset value is a positive integer, which is used to represent the size of the coordinate set, that is, the number of coordinate points. The length and width of the table can be determined by the above-mentioned first minimum horizontal coordinate value, the first minimum vertical coordinate value and the first coordinate point, and then the table range can be determined.
[0049] Optionally, when it is determined that the number of coordinate points in the fourth coordinate set and the number of coordinate points in the fifth coordinate set are both less than a second preset value, the coordinates of the central pixel point of the binary image are determined as the second coordinate point.
[0050] In an exemplary embodiment, the implementation process of determining the first horizontal coordinate set and the first vertical coordinate set according to the first coordinate set in the above step S12 also includes: the first preset condition is that the number of coordinate points in the second coordinate set and the number of coordinate points in the third coordinate set are both greater than a first preset value; when it is determined that the first horizontal coordinate set and the first vertical coordinate set do not meet the first preset condition, the first coordinate point is deleted from the first coordinate set to obtain a sixth coordinate set; based on the sixth coordinate set, a third horizontal coordinate set and a third vertical coordinate set are determined; when it is determined that the third horizontal coordinate set and the third vertical coordinate set meet the second preset condition, the second coordinate point is determined based on the third horizontal coordinate set and the third vertical coordinate set.
[0051] In an exemplary embodiment, the implementation process of determining the first table range according to the second coordinate point and the first coordinate point in the above-mentioned step S14 specifically includes: step S21, determining the second horizontal line mask corresponding to the horizontal coordinate of the first coordinate point and the second vertical line mask corresponding to the vertical coordinate of the first coordinate point, and determining the third horizontal line mask corresponding to the horizontal coordinate of the second coordinate point and the third vertical line mask corresponding to the vertical coordinate of the second coordinate point; step S22, determining a target contour image consistent with the mask range from the contour image, wherein the mask range represents the range formed by the second horizontal line mask, the second vertical line mask, the third horizontal line mask and the third vertical line mask; step S23, performing image fitting on the contour object corresponding to the target contour image to obtain a fitted second rectangular frame; step S24, determining the image range corresponding to all the second rectangular frames in the binary image as the first table range, wherein the vertex coordinates of all the second rectangular frames generate a seventh coordinate set corresponding to them.
[0052] In an exemplary embodiment, the target table included in the first table range in step S14 can be determined in the following manner: step S31, performing text recognition on any second rectangular box to obtain first text information; step S32, generating a target table according to the vertex coordinates in the seventh coordinate set and the first text information when it is determined that the similarity between the first text information and the main table information is greater than the third preset threshold; step S33, when it is determined that the similarity between the first text information and the main table information is less than or equal to the third preset threshold, if it is determined that the similarity between the first text information and the appendix information is greater than the fourth preset threshold, then determining a plurality of third rectangular boxes whose similarity between the first text information and the appendix information is greater than the fourth preset threshold; step S34, determining a third coordinate point having a minimum second horizontal coordinate value and a fourth coordinate point having a maximum third horizontal coordinate value from the vertex coordinates of the plurality of third rectangular boxes; step S35, determining a second table range within the first table range according to the third coordinate point and the fourth coordinate point, and determining the target table included in the second table range.
[0053] It can be understood that, among them, the above-mentioned main table information may include, for example, the input main table name or main table header, and the first text information and the main table information are matched. If the match is successful, it means that the rectangular box corresponds to the main table, and the extracted information is summarized and the main table information is generated. The appendix represents a supplementary table of the main table. Similarly, the appendix information has the same meaning as the main table information, which will not be repeated here.
[0054] In an exemplary embodiment, the implementation process of generating a target table according to the vertex coordinates in the seventh coordinate set and the first text information in the above-mentioned step S32 specifically includes: traversing the horizontally connected area within the range of the first table to obtain horizontal line segments, and generating a first line segment set based on all horizontal line segments, wherein the horizontally connected area is determined based on the second horizontal line mask and the third horizontal line mask; for each vertex coordinate included in the seventh coordinate set, obtaining the vertical distance between each vertex coordinate and the horizontal line segment in the first line segment set; determining the first serial number corresponding to any second rectangular frame in the vertical direction according to the size of the vertical distance, wherein the smaller the vertical distance, the smaller the first serial number; for multiple cells included in any second rectangular frame, determining the second serial number corresponding to each cell in the horizontal direction, wherein the second serial number is calculated according to each The plurality of cells are sorted according to the size of the horizontal coordinate of the vertex coordinate of a cell, and the second serial number of each cell corresponds to the first serial number; a first cell set corresponding to any second rectangular box is generated based on the correspondence between the first serial number and the second serial number, and the first cell set at least includes the first serial number of any second rectangular box and the second serial number of each cell; the plurality of first cell sets are sorted according to the size of the first serial number, and the sorted plurality of first cell sets are merged to obtain a second cell set; text recognition is performed on all cells corresponding to the second cell set to obtain the second text information of each cell; when it is determined that the similarity between the second text information and the main table information is greater than a third preset threshold, a target table is generated according to the vertex coordinates corresponding to each cell and the second text information of each cell.
[0055] In an exemplary embodiment, the implementation process of determining the target table included in the second table range in the above step S35 includes: obtaining a first cell whose horizontal coordinate value is greater than the minimum value of the second horizontal coordinate and whose horizontal coordinate value is less than the maximum value of the third horizontal coordinate from the second cell set, and generating a third cell set based on multiple first cells; traversing the horizontally connected area within the second table range to obtain horizontal line segments, and generating a second line segment set based on all horizontal line segments, wherein the horizontally connected area is determined based on the second horizontal line mask and the third horizontal line mask; for the first vertex coordinate of the second cell included in the third cell set, obtaining the vertical distance between the first vertex coordinate and the horizontal line segment in the second line segment set; determining the third serial number corresponding to the second cell in the vertical direction according to the size of the vertical distance, wherein the smaller the vertical distance, the smaller the third serial number; For multiple sub-grids included in multiple second cells, determine the fourth serial number corresponding to each sub-grid in the horizontal direction, wherein the fourth serial number is obtained by sorting the multiple sub-grids according to the size of the horizontal coordinates of the vertex coordinates of the second cell, and the fourth serial number of each sub-grid corresponds to the third serial number; based on the correspondence between the third serial number and the fourth serial number, generate a fourth cell set corresponding to the second cell, the fourth cell set at least includes the third serial number of the second cell and the fourth serial number of each sub-grid; sort the multiple fourth cell sets according to the size of the third serial number, and merge the sorted multiple fourth cell sets to obtain a fifth cell set; perform text recognition on all sub-grids corresponding to the fifth cell set to obtain the third text information of each sub-grid, and generate a target table according to the vertex coordinates corresponding to each sub-grid and the third text information of each sub-grid.
[0056] In order to better understand the process of the method for determining the above-mentioned table information, the implementation method flow of determining the above-mentioned table information is described below in combination with an optional embodiment, but it is not used to limit the technical solution of the embodiment of the present application.
[0057] In an alternative embodiment, Figure 3 is a schematic diagram of an engineering drawing according to an embodiment of the present application, such as Figure 3 As shown, the engineering drawing of this embodiment includes a structural diagram range and a table range in the lower right corner. Figure 4 This is a schematic diagram of the table range in the above engineering drawing, such as Figure 4 As shown, the table area includes a main table and two subsidiary tables, and the edges of the subsidiary tables are aligned with the main table.
[0058] Compared with the traditional identification method of manually filtering out the target table information from the entire content of the identified engineering drawing, the method for determining the table information provided in this embodiment can locate the table area in the image for identification, eliminating the need for manual further screening of the table information. The specific process is as follows Figure 5 As shown, the following steps are included:
[0059] Step S501: start;
[0060] Step S502: acquiring an engineering drawing image, such as a drawing file in PDF format, according to an input drawing number (which may also be a material-specific number of an engineering material or a number in other forms);
[0061] Optionally, the method of acquiring the engineering drawing image in the above step S502 may be to first acquire the drawing link and then further acquire the drawing image through the link.
[0062] Step S503: pre-processing the acquired engineering drawing image, for example, converting the engineering drawing image into an RGB image, adjusting the image resolution, and separating the foreground and the background by Gaussian blur and adaptive threshold segmentation to obtain a binary image;
[0063] Step S504: performing morphological processing on the image, for example, generating a horizontal line mask and a horizontal contour of the image through an opening operation, a dilation operation, etc.;
[0064] Step S505: performing morphological processing on the image, for example, generating a vertical line mask and a vertical contour of the image (equivalent to the above-mentioned contour image) through an opening operation, a dilation operation, etc.;
[0065] It should be noted that, in the above steps S504 and S505, the kernel size of the image in the horizontal direction and the vertical direction can be defined according to the height and width of the image when performing the opening operation. The specific formula is as follows:
[0066] kernel h =(max(1,int(h / scale)),1),kernel v =(1,max(1,int(w / scale)));
[0067] Among them, kernel h is the horizontal kernel size, kernel vis the vertical kernel size, h is the image height, w is the image width, scale is a preset hyperparameter, and scale can be adjusted according to the effect of image opening operation, int is the rounding function, and max is the maximum value function. By formatting the kernel size of each image, the size of each image can be adjusted to obtain the best image display effect, thereby improving the recognition accuracy.
[0068] Step S506: Take the OR value of the pixel position of the horizontal line mask (i.e., the first pixel position) and the pixel position of the vertical line mask (i.e., the second pixel position) to generate a contour image, the above-mentioned contour image includes the contour of each cell of the table in the image, perform edge detection on the contour image and perform rectangular approximation fitting (i.e., matrix fitting) to obtain multiple rectangular frames (i.e., the first rectangular frames). Figure 3 As shown in the figure, the upper left corner of the engineering drawing image can be used as the default origin, and the corresponding coordinate axis ( Figure 3 (not shown), then obtain the vertex coordinates of each rectangular box based on the coordinate axis to obtain the coordinate set set rect (first coordinate set), such as Figure 4 As shown, for example, the coordinate set set rect It can include the coordinates of a rectangular box (x1, y1, x2, y2), (x1, y1) are the vertex coordinates of the upper left corner of the rectangular box, (x2, y2) are the vertex coordinates of the lower right corner of the rectangular box, wherein (x1, y1) are the vertex coordinates closest to the origin among all the vertex coordinates of the rectangular box, and (x2, y2) are the vertex coordinates farthest from the origin among all the vertex coordinates of the rectangular box.
[0069] Optionally, pass a coordinate set rect You can also determine the circumscribed rectangle of the rectangle with the largest coordinate value, and then determine the edge of the drawing by the circumscribed rectangle, such as Figure 4 As shown, for example, the upper left corner of the engineering drawing image is used as the default origin, then the coordinate with the largest coordinate value (x2, y2) can be used to determine the circumscribed rectangle and thus the edge of the drawing according to the origin and (x2, y2);
[0070] Step S507: Starting from the lower right corner of the engineering drawing image, according to the lower right vertex of the rectangular box, search for adjacent cells in the vertical direction in turn to determine the vertical coordinate range of the table in the engineering drawing image, for example, from Figure 4 The lower right corner coordinate (x2, y2) in the cell is searched upwards in adjacent cells in turn until the lower right corner coordinate of the topmost cell is determined;
[0071] Step S508: starting from the lower right corner of the engineering drawing image, according to the lower right corner vertex of the rectangular box, search for adjacent cells in the horizontal direction in sequence to determine the horizontal coordinate range of the table in the engineering drawing image;
[0072] In the above steps S508 and S509, a coordinate set set may be selected. rect The largest coordinate point C1(x2, y2) (i.e. the first coordinate point) in the coordinate set set, and then start from the largest coordinate point rect Each horizontal axis in is sorted in descending order to obtain the set set rect_x1 (i.e. the first horizontal coordinate set), starting from the maximum coordinate point, the coordinate set set rect Each vertical coordinate in is sorted in descending order to obtain the set set rect_y1 (i.e. the first vertical coordinate set). rect_x1 Select the coordinate set R1 (i.e., the second coordinate set) within the vertical coordinate difference m1 (i.e., the first preset threshold) of C1, and in the set set rect_y1 A coordinate set R2 (i.e., the third coordinate set) is selected from the set R1 (i.e., the third coordinate set) within the horizontal coordinate difference m2 (i.e., the second preset value) of C1. If the lengths of the sets R1 and R2 are both greater than n (i.e., the first preset value), that is, the number of rectangular frames is greater than n, the edge of the table can be determined based on R1 and R2, and then the vertical coordinate range and horizontal coordinate range of the table in the engineering drawing image can be determined. The set length represents the number of coordinate points in the set. Set R1 corresponds to the above-mentioned second coordinate set, and the length of set R1 represents the number of coordinate points in the second coordinate set.
[0073] Step S509: intercepting the table area according to the horizontal coordinate range and the vertical coordinate range, performing rectangular approximation fitting on the closed contour, and obtaining the cell coordinates;
[0074] In the above steps, starting from the coordinate point C1, R1 and R2 are sorted from large to small according to the ordinate and abscissa to generate the set set. rect_x2 (i.e. the second horizontal coordinate set) and set rect_y2 (i.e. the second vertical coordinate set), starting from C1, in the set rect_x2 In the set, traverse along the ordinate in turn, select the coordinate points whose difference between the horizontal coordinate values of adjacent coordinate points is within m1 to generate set R3 (i.e., the fourth coordinate set), and in the set set rect_y2 In the example, the horizontal coordinates are traversed in sequence, and the coordinate points whose differences between the vertical coordinate values of adjacent coordinate points are within m2 are selected to generate a set R4 (i.e., the fifth coordinate set). If the lengths of sets R3 and R4 are both greater than n, the minimum values x1 and y1 of sets R3 and R4 are set as the second coordinate point C2 (x1, y1). The table range (i.e., the first table range) can be determined based on the coordinates C1 and C2, and then a rectangular fit is performed on the closed contour within the table range to obtain a vertex coordinate set (i.e., the seventh coordinate set) containing all table cells (i.e., the second rectangular frame).
[0075] Step S510: determining the transverse line segments of the transverse connected area within the table range, and traversing the transverse connected area according to the transverse line segments to generate a transverse line segment set (ie, a first line segment set).
[0076] Step S511: Calculate the Euclidean distance (vertical distance) between the upper left vertex coordinates of all table cells and the horizontal line segment, group the cells according to the shortest distance, and sort the cell vertex coordinates according to the distance. The smaller the distance, the smaller the first serial number. Then, sort the coordinates from large to small according to the size of the horizontal coordinate to obtain the second serial number of the cell vertex coordinates. The first serial number is used for grouping, and the second serial number is used for sorting within the group.
[0077] Step S512: traverse each cell in sequence according to the first sequence number and the second sequence number, start traversing from the group with the smallest first sequence number, start traversing from the coordinate with the smallest second sequence number in each group of coordinates, and use a deep learning algorithm to identify the cell content to obtain text information of each cell (equivalent to the second text information);
[0078] Step S513: using text similarity matching, such as setting a similarity threshold, regular matching, etc., to filter out table information that matches the input material specific number or name information from the recognized cell text. For example, if the similarity is greater than a threshold t (i.e., a third preset threshold), the match is successful, a key-value pair is generated according to the table information and the input information, and then the information of the cell is extracted, and the extracted information is summarized to generate the main table information;
[0079] Step S514: traverse the grouped cells grouped according to the first sequence number in turn, and if the input name information is matched in the identification information of one group of cells, use this group information as the header of the appendix.
[0080] Step S515: According to the horizontal coordinate range of the table header, intercept the attached table area, for example, record the cells of the group where the table header is located as the set name loc , the collection length is L, extract name loc Minimum value of the horizontal coordinate x left and the maximum value x right , extract the cell vertex coordinate set (i.e., the seventh coordinate set) with the horizontal coordinate in x left and x right The cells between generate the cell set R res_sch , R res_sch The cell identification information in is summarized to obtain the appendix information.
[0081] Optionally, the appendix determination process in step S515 is implemented in the same steps as the overall table range determination process in step S509, and the set R is traversed in sequence.res Extract the minimum value x of the horizontal coordinate from each group of information left and the maximum value x right , extract the horizontal coordinate at x left and x right Through the above process, the second table range (schedule) can be further determined from the first table range in the same way as the first table range. Although the same method is used, the two determination processes have different effects. Step S509 is used to determine the total table range in the binary image, and step S515 is used to determine the appendix range in the total table range. The appendix can also be determined directly by manual box selection, and the present application is not limited to this.
[0082] Step S516: determining the horizontal line segments of the horizontally connected area in the appendix area, and traversing the horizontally connected area according to the horizontal line segments to generate a set of horizontal line segments;
[0083] Step S517: Calculate the Euclidean distance (i.e., vertical distance) between the upper left vertex of the table cell and the fitting line segment, generate horizontal groups for the table cells according to the shortest distance, and sort them within the group according to the horizontal axis. The specific process can refer to the above step S511 and will not be repeated here;
[0084] Step S518: record the length of the cell occupied by the schedule header as L2, and traverse the cells of each horizontal group in step S517 according to the length of the schedule header to determine whether the schedule content is aligned with the header column name;
[0085] Step S519: using text similarity matching, such as setting a similarity threshold, regular matching, etc., to filter out table information that matches the input material specific number or name information from the recognized cell text, and then generate key-value pairs according to the cell content and cell coordinate table of the above table;
[0086] Step S520: writing the key-value pair information generated by the cell content of the above table and the cell coordinate table into a database;
[0087] Step S521: End.
[0088] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0089] Figure 6 is a structural block diagram of a device for determining table information according to an embodiment of the present application, such as Figure 6 As shown, including:
[0090] A processing module 62 is used to pre-process the acquired engineering drawing image to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing;
[0091] An acquisition module 64 is configured to generate a contour image based on the first horizontal line mask and the first vertical line mask, and acquire a first coordinate set corresponding to all first rectangular frames in the contour image, wherein the first coordinate set at least includes vertex coordinates of all first rectangular frames;
[0092] A determination module 66, configured to determine a first table range in the binary image based on the first coordinate set, wherein the first table range includes a target table;
[0093] The recognition module 68 is used to perform text recognition on the target table to obtain table information in the target table.
[0094] Through the above-mentioned device, the acquired engineering drawing image is preprocessed to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing; a contour image is generated based on the first horizontal line mask and the first vertical line mask, and a first coordinate set corresponding to all first rectangular boxes in the contour image is obtained, wherein the first coordinate set at least includes the vertex coordinates of all the first rectangular boxes; a first table range in the binary image is determined based on the first coordinate set, wherein the first table range contains a target table; text recognition is performed on the target table to obtain table information in the target table, which solves the problem of how to improve the recognition efficiency of table information in the related art, thereby achieving the effect of improving the recognition efficiency of table information.
[0095] In an exemplary embodiment, the acquisition module 64 is also used to: acquire the first pixel position of the pixel point corresponding to the first horizontal line mask and the second pixel position of the pixel point corresponding to the first vertical line mask; take the OR value of each first pixel position and each second pixel position to obtain the contour image; obtain a first rectangular frame by performing rectangular fitting on the contour image, wherein the vertex coordinates of the first rectangular frame are located on the coordinate axis where the default origin of the binary image is located; and generate the first coordinate set based on the vertex coordinates corresponding to all the first rectangular frames.
[0096] In an exemplary embodiment, the above-mentioned determination module 66 also includes: a first determination unit, used to determine a first coordinate point with a maximum horizontal coordinate value and a maximum vertical coordinate value from the first coordinate set; a second determination unit, used to determine a first horizontal coordinate set and a first vertical coordinate set based on the first coordinate set; a third determination unit, used to determine a second coordinate point based on the first horizontal coordinate set and the first vertical coordinate set when it is determined that the first horizontal coordinate set and the first vertical coordinate set meet a first preset condition; and a fourth determination unit, used to determine the first table range based on the second coordinate point and the first coordinate point.
[0097] In an exemplary embodiment, the second determination unit is further used to: sort all horizontal coordinates in the first coordinate set in descending order with the first coordinate point as the starting point to obtain a first horizontal coordinate set, wherein the first horizontal coordinate set includes at least a second coordinate set, and the difference between the vertical coordinate value of the coordinate point in the second coordinate set and the maximum value of the vertical coordinate is less than a first preset threshold; and sort all vertical coordinates in the first coordinate set in descending order with the first coordinate point as the starting point to obtain a first vertical coordinate set, wherein the first vertical coordinate set includes at least a third coordinate set, and the difference between the horizontal coordinate value of the coordinate point in the third coordinate set and the maximum value of the horizontal coordinate is less than a second preset threshold.
[0098] In an exemplary embodiment, the third determination unit is further used for: the first preset condition is that the number of coordinate points in the second coordinate set and the number of coordinate points in the third coordinate set are both greater than a first preset value; when it is determined that the first preset condition is met, all horizontal coordinates in the second coordinate set are sorted in descending order with the first coordinate point as the starting point to obtain a second horizontal coordinate set, wherein the second horizontal coordinate set includes at least a fourth coordinate set, and the difference between the vertical coordinate values of adjacent coordinate points in the fourth coordinate set is less than a first preset threshold; and all vertical coordinates in the third coordinate set are sorted in descending order with the first coordinate point as the starting point to obtain a second vertical coordinate set, wherein the second vertical coordinate set includes at least a fifth coordinate set, and the difference between the horizontal coordinate values of adjacent coordinate points in the fifth coordinate set is less than a second preset threshold; when it is determined that the number of coordinate points in the fourth coordinate set and the number of coordinate points in the fifth coordinate set are both greater than the second preset value, a second coordinate point is determined with the first minimum horizontal coordinate value of the fourth coordinate set as the horizontal coordinate and the first minimum vertical coordinate value of the fifth coordinate set as the vertical coordinate.
[0099] In an exemplary embodiment, the second determination unit is also used for: the first preset condition is that the number of coordinate points in the second coordinate set and the number of coordinate points in the third coordinate set are both greater than a first preset value; when it is determined that the first horizontal coordinate set and the first vertical coordinate set do not meet the first preset condition, deleting the first coordinate point from the first coordinate set to obtain a sixth coordinate set; determining a third horizontal coordinate set and a third vertical coordinate set based on the sixth coordinate set; when it is determined that the third horizontal coordinate set and the third vertical coordinate set meet the second preset condition, determining the second coordinate point based on the third horizontal coordinate set and the third vertical coordinate set.
[0100] In an exemplary embodiment, the fourth determination unit is further used to: determine the second horizontal line mask corresponding to the horizontal coordinate of the first coordinate point and the second vertical line mask corresponding to the vertical coordinate of the first coordinate point, and determine the third horizontal line mask corresponding to the horizontal coordinate of the second coordinate point and the third vertical line mask corresponding to the vertical coordinate of the second coordinate point; determine a target contour image consistent with the mask range from the contour image, wherein the mask range represents the range formed by the second horizontal line mask, the second vertical line mask, the third horizontal line mask and the third vertical line mask; perform image fitting on the contour object corresponding to the target contour image to obtain a fitted second rectangular frame; determine the image range corresponding to all second rectangular frames in the binary image as the first table range, wherein a seventh coordinate set is generated corresponding to the vertex coordinates of all second rectangular frames.
[0101] In an exemplary embodiment, the fourth determination unit is further used to: perform text recognition on any second rectangular box to obtain first text information; when it is determined that the similarity between the first text information and the main table information is greater than a third preset threshold, generate a target table based on the vertex coordinates in the seventh coordinate set and the first text information; when it is determined that the similarity between the first text information and the main table information is less than or equal to the third preset threshold, if it is determined that the similarity between the first text information and the appendix information is greater than a fourth preset threshold, determine multiple third rectangular boxes whose similarity between the first text information and the appendix information is greater than the fourth preset threshold; determine a third coordinate point with a minimum second horizontal coordinate value and a fourth coordinate point with a maximum third horizontal coordinate value from the vertex coordinates of the multiple third rectangular boxes; determine a second table range within the first table range based on the third coordinate point and the fourth coordinate point, and determine the target table contained in the second table range.
[0102] In an exemplary embodiment, the fourth determination unit is further used to: traverse the horizontally connected area within the range of the first table to obtain horizontal line segments, and generate a first line segment set based on all horizontal line segments, wherein the horizontally connected area is determined based on the second horizontal line mask and the third horizontal line mask; for each vertex coordinate included in the seventh coordinate set, obtain the vertical distance between each vertex coordinate and the horizontal line segments in the first line segment set; determine the first serial number corresponding to any second rectangular frame in the vertical direction according to the size of the vertical distance, wherein the smaller the vertical distance, the smaller the first serial number; for multiple cells included in any second rectangular frame, determine the second serial number corresponding to each cell in the horizontal direction, wherein the second serial number is the size of the horizontal coordinate of the vertex coordinate of each cell. A plurality of cells are sorted, and the second serial number of each cell corresponds to the first serial number; a first cell set corresponding to any second rectangular box is generated based on the correspondence between the first serial number and the second serial number, and the first cell set at least includes the first serial number of any second rectangular box and the second serial number of each cell; the plurality of first cell sets are sorted according to the size of the first serial number, and the sorted plurality of first cell sets are merged to obtain a second cell set; text recognition is performed on all cells corresponding to the second cell set to obtain the second text information of each cell; when it is determined that the similarity between the second text information and the main table information is greater than a third preset threshold, a target table is generated according to the vertex coordinates corresponding to each cell and the second text information of each cell.
[0103] In an exemplary embodiment, the fourth determination unit is further used to: obtain from the second cell set a first cell whose horizontal coordinate value is greater than the second horizontal coordinate minimum value and whose horizontal coordinate value is less than the third horizontal coordinate maximum value, and generate a third cell set based on multiple first cells; traverse the horizontally connected area within the second table range to obtain horizontal line segments, and generate a second line segment set based on all horizontal line segments, wherein the horizontally connected area is determined based on the second horizontal line mask and the third horizontal line mask; for the first vertex coordinate of the second cell included in the third cell set, obtain the vertical distance between the first vertex coordinate and the horizontal line segment in the second line segment set; determine the third serial number corresponding to the second cell in the vertical direction based on the size of the vertical distance, wherein the smaller the vertical distance, the smaller the third serial number; for multiple second cells included in sub-grids, determining a fourth serial number corresponding to each sub-grid in the horizontal direction, wherein the fourth serial number is obtained by sorting the multiple sub-grids according to the size of the horizontal coordinates of the vertex coordinates of the second cell, and the fourth serial number of each sub-grid corresponds to the third serial number; generating a fourth cell set corresponding to the second cell based on the correspondence between the third serial number and the fourth serial number, wherein the fourth cell set at least includes the third serial number of the second cell and the fourth serial number of each sub-grid; sorting the multiple fourth cell sets according to the size of the third serial number, and merging the sorted multiple fourth cell sets to obtain a fifth cell set; performing text recognition on all sub-grids corresponding to the fifth cell set to obtain the third text information of each sub-grid, and generating a target table according to the vertex coordinates corresponding to each sub-grid and the third text information of each sub-grid.
[0104] An embodiment of the present application further provides a storage medium, which includes a stored program, wherein the program executes any of the above methods when it is run.
[0105] Optionally, in this embodiment, the storage medium may be configured to store program codes for executing the following steps:
[0106] S1, preprocessing the acquired engineering drawing image to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing;
[0107] S2, generating a contour image based on the first horizontal line mask and the first vertical line mask, and acquiring a first coordinate set corresponding to all first rectangular boxes in the contour image, wherein the first coordinate set at least includes vertex coordinates of all first rectangular boxes;
[0108] S3, determining a first table range in the binary image based on the first coordinate set, wherein the first table range includes a target table;
[0109] S4, performing text recognition on the target table to obtain table information in the target table.
[0110] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0111] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0112] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0113] S1, preprocessing the acquired engineering drawing image to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing;
[0114] S2, generating a contour image based on the first horizontal line mask and the first vertical line mask, and acquiring a first coordinate set corresponding to all first rectangular boxes in the contour image, wherein the first coordinate set at least includes vertex coordinates of all first rectangular boxes;
[0115] S3, determining a first table range in the binary image based on the first coordinate set, wherein the first table range includes a target table;
[0116] S4, performing text recognition on the target table to obtain table information in the target table.
[0117] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0118] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0119] Obviously, those skilled in the art should understand that the above modules or steps of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0120] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for determining table information, characterized in that: include: Preprocessing the acquired engineering drawing image to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing; Generate a contour image based on the first horizontal line mask and the first vertical line mask, and obtain a first coordinate set corresponding to all first rectangular boxes in the contour image, wherein the first coordinate set at least includes vertex coordinates of all first rectangular boxes; Determine a first table range in the binary image based on the first coordinate set, wherein the first table range includes a target table; Perform text recognition on the target table to obtain table information in the target table.
2. The method for determining table information according to claim 1, characterized in that: Acquiring a first coordinate set corresponding to all first rectangular frames in the engineering image based on the contour image generated by the first horizontal line mask and the first vertical line mask includes: Acquire a first pixel position of a pixel point corresponding to the first horizontal line mask and a second pixel position of a pixel point corresponding to the first vertical line mask; Taking the OR value of each first pixel position and each second pixel position to obtain the contour image; Obtaining a first rectangular frame by performing rectangular fitting on the contour image, wherein the vertex coordinates of the first rectangular frame are located on the coordinate axis where the default origin of the binary image is located; The first coordinate set is generated according to the vertex coordinates corresponding to all the first rectangular frames.
3. The method for determining table information according to claim 1, characterized in that: Determining a first table range in the binary image based on the first coordinate set includes: Determine a first coordinate point having a maximum abscissa and a maximum ordinate from the first coordinate set; Determine a first horizontal coordinate set and a first vertical coordinate set according to the first coordinate set; When it is determined that the first horizontal coordinate set and the first vertical coordinate set meet a first preset condition, a second coordinate point is determined based on the first horizontal coordinate set and the first vertical coordinate set; and the first table range is determined based on the second coordinate point and the first coordinate point.
4. The method for determining table information according to claim 3, characterized in that: Determining a first horizontal coordinate set and a first vertical coordinate set according to the first coordinate set includes: Sorting all horizontal coordinates in the first coordinate set in descending order with the first coordinate point as a starting point to obtain a first horizontal coordinate set, wherein the first horizontal coordinate set includes at least a second coordinate set, and a difference between a vertical coordinate value of a coordinate point in the second coordinate set and the maximum vertical coordinate value is less than a first preset threshold; And taking the first coordinate point as the starting point, all the vertical coordinates in the first coordinate set are sorted in descending order to obtain a first vertical coordinate set, wherein the first vertical coordinate set includes at least a third coordinate set, and the difference between the horizontal coordinate value of the coordinate point in the third coordinate set and the maximum horizontal coordinate value is less than a second preset threshold.
5. The method for determining table information according to claim 4, characterized in that: In the case where it is determined that the first set of horizontal coordinates and the first set of vertical coordinates meet a first preset condition, determining the second coordinate point based on the first set of horizontal coordinates and the first set of vertical coordinates includes: The first preset condition is that the number of coordinate points in the second coordinate set and the number of coordinate points in the third coordinate set are both greater than a first preset value; In the case where it is determined that the first preset condition is met, all the horizontal coordinates in the second coordinate set are sorted in descending order with the first coordinate point as the starting point to obtain a second horizontal coordinate set, wherein the second horizontal coordinate set includes at least a fourth coordinate set, and the difference between the vertical coordinate values of adjacent coordinate points in the fourth coordinate set is less than a first preset threshold; and all the vertical coordinates in the third coordinate set are sorted in descending order with the first coordinate point as the starting point to obtain a second vertical coordinate set, wherein the second vertical coordinate set includes at least a fifth coordinate set, and the difference between the horizontal coordinate values of adjacent coordinate points in the fifth coordinate set is less than a second preset threshold; When it is determined that the number of coordinate points in the fourth coordinate set and the number of coordinate points in the fifth coordinate set are both greater than the second preset value, a second coordinate point is determined with the first minimum horizontal coordinate value of the fourth coordinate set as the horizontal coordinate and the first minimum vertical coordinate value of the fifth coordinate set as the vertical coordinate.
6. The method for determining table information according to claim 4, characterized in that: The method further includes: the first preset condition is that the number of coordinate points in the second coordinate set and the number of coordinate points in the third coordinate set are both greater than a first preset value; When it is determined that the first horizontal coordinate set and the first vertical coordinate set do not satisfy a first preset condition, the first coordinate point is deleted from the first coordinate set to obtain a sixth coordinate set; and a third horizontal coordinate set and a third vertical coordinate set are determined based on the sixth coordinate set; When it is determined that the third set of horizontal coordinates and the third set of vertical coordinates meet a second preset condition, the second coordinate point is determined based on the third set of horizontal coordinates and the third set of vertical coordinates.
7. The method for determining table information according to any one of claims 3 to 6, characterized in that: Determining the first table range according to the second coordinate point and the first coordinate point includes: Determine a second horizontal line mask corresponding to the abscissa of the first coordinate point and a second vertical line mask corresponding to the ordinate of the first coordinate point, and determine a third horizontal line mask corresponding to the abscissa of the second coordinate point and a third vertical line mask corresponding to the ordinate of the second coordinate point; Determine a target contour image consistent with a mask range from the contour image, wherein the mask range represents a range formed by the second horizontal line mask, the second vertical line mask, the third horizontal line mask and the third vertical line mask; Performing image fitting on the contour object corresponding to the target contour image to obtain a fitted second rectangular frame; An image range corresponding to all the second rectangular frames in the binary image is determined as the first table range, wherein a seventh coordinate set is generated corresponding to the vertex coordinates of all the second rectangular frames.
8. The method for determining table information according to claim 7, characterized in that: The target table included in the first table range is determined in the following manner: Perform text recognition on any second rectangular frame to obtain first text information; In the case where it is determined that the similarity between the first text information and the main table information is greater than a third preset threshold, generating a target table according to the vertex coordinates in the seventh coordinate set and the first text information; In the case where it is determined that the similarity between the first text information and the main table information is less than or equal to the third preset threshold, if it is determined that the similarity between the first text information and the appendix information is greater than a fourth preset threshold, a plurality of third rectangular boxes are determined in which the similarity between the first text information and the appendix information is greater than the fourth preset threshold; Determine a third coordinate point having a minimum second horizontal coordinate value and a fourth coordinate point having a maximum third horizontal coordinate value from the vertex coordinates of the plurality of third rectangular frames; A second table range is determined within the first table range according to the third coordinate point and the fourth coordinate point, and a target table included in the second table range is determined.
9. The method for determining table information according to claim 8, characterized in that: Generating a target table according to the vertex coordinates in the seventh coordinate set and the first text information includes: Traversing the horizontally connected areas within the range of the first table to obtain horizontal line segments, and generating a first line segment set based on all the horizontal line segments, wherein the horizontally connected areas are determined based on the second horizontal line mask and the third horizontal line mask; For each vertex coordinate included in the seventh coordinate set, obtaining a vertical distance between each vertex coordinate and a horizontal line segment in the first line segment set; Determine a first serial number corresponding to any second rectangular frame in the vertical direction according to the size of the vertical distance, wherein the smaller the vertical distance is, the smaller the first serial number is; For a plurality of cells included in any one of the second rectangular frames, determine a second serial number corresponding to each cell in the horizontal direction, wherein the second serial number is obtained by sorting the plurality of cells according to the size of the horizontal coordinate of the vertex coordinate of each cell, and the second serial number of each cell corresponds to the first serial number; Generate a first cell set corresponding to any one of the second rectangular boxes based on the correspondence between the first serial number and the second serial number, wherein the first cell set at least includes the first serial number of any one of the second rectangular boxes and the second serial number of each of the cells; sorting the plurality of first cell sets according to the size of the first sequence number, and merging the sorted plurality of first cell sets to obtain a second cell set; Performing text recognition on all cells corresponding to the second cell set to obtain second text information of each cell; When it is determined that the similarity between the second text information and the main table information is greater than a third preset threshold, a target table is generated according to the vertex coordinates corresponding to each cell and the second text information of each cell.
10. The method for determining table information according to claim 9, characterized in that: Determining the target table included in the second table range includes: Acquire, from the second cell set, a first cell whose abscissa value is greater than the second minimum abscissa value and whose abscissa value is less than the third maximum abscissa value, and generate a third cell set based on the plurality of first cells; Traversing the horizontally connected areas within the range of the second table to obtain horizontal line segments, and generating a second line segment set based on all the horizontal line segments, wherein the horizontally connected areas are determined based on the second horizontal line mask and the third horizontal line mask; For a first vertex coordinate of a second cell included in the third cell set, obtaining a vertical distance between the first vertex coordinate and a horizontal line segment in the second line segment set; Determine a third serial number corresponding to the second cell in the vertical direction according to the size of the vertical distance, wherein the smaller the vertical distance is, the smaller the third serial number is; For a plurality of sub-grids included in the plurality of second cells, determining a fourth serial number corresponding to each sub-grid in the horizontal direction, wherein the fourth serial number is obtained by sorting the plurality of sub-grids according to the size of the horizontal coordinates of the vertex coordinates of the second cells, and the fourth serial number of each sub-grid corresponds to the third serial number; Generate a fourth cell set corresponding to the second cell based on the correspondence between the third serial number and the fourth serial number, wherein the fourth cell set at least includes the third serial number of the second cell and the fourth serial number of each sub-cell; sorting the plurality of fourth cell sets according to the size of the third sequence number, and merging the sorted plurality of fourth cell sets to obtain a fifth cell set; Text recognition is performed on all sub-cells corresponding to the fifth cell set to obtain third text information of each sub-cell, and a target table is generated according to the vertex coordinates corresponding to each sub-cell and the third text information of each sub-cell.
11. A device for determining table information, characterized in that: include: A processing module, used for preprocessing the acquired engineering drawing image to obtain a binary image corresponding to the engineering drawing image, wherein the binary image has a first horizontal line mask and a first vertical line mask after morphological processing; an acquisition module, configured to generate a contour image based on the first horizontal line mask and the first vertical line mask, and acquire a first coordinate set corresponding to all first rectangular frames in the contour image, wherein the first coordinate set at least includes vertex coordinates of all first rectangular frames; a determination module, configured to determine a first table range in the binary image based on the first coordinate set, wherein the first table range includes a target table; The recognition module is used to perform text recognition on the target table to obtain table information in the target table.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 10 when executed.
13. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 10 through the computer program.
Citation Information
Patent Citations
Table identification method
CN110647795A
Form recognition method and device in image, electronic equipment and storage medium
CN111814722A
Table extraction method and table extraction system
CN114663897A
Method and system for identifying table structure in table picture and storage medium
CN114926851A
Cited By
Image processing method and device
CN121415429A
Drawing table identification method
CN121789245A