Method, device and electronic equipment for extracting a text field
By combining image preprocessing and target detection models with the text recognition technology of the CTC model, the problem of the existing technology being unable to extract target text fields that meet business needs from tax payment certificate images is solved, and high-accuracy text field extraction is achieved.
Patent Information
- Application Number
- CN202111428606.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2041-11-29
AI Technical Summary
Existing technologies cannot effectively extract target text fields that meet business needs from tax payment certificate images, resulting in low extraction accuracy.
Through image preprocessing, object detection, and text recognition technologies, including angle correction, noise filtering, object detection models (such as the YOLO model) and text recognition using the CTC model, combined with preset extraction rules, target text fields that meet business needs are extracted.
The extraction accuracy of the target text field is improved, ensuring the restoration of image information and the accuracy of text recognition, and meeting the precise extraction needs of business needs.
Smart Images

Figure CN114202766B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing, and in particular to a method, device and electronic device for extracting text fields. Background Art
[0002] With the advancement of image processing technology, text fields in images such as tax payment certificates can be identified using techniques such as HOG (Histogram of Oriented Gradient) and LBP (Local Binary Patterns). However, this approach specifically extracts all text fields in the tax payment certificate image and cannot specifically extract the target text fields that meet business requirements. Summary of the Invention
[0003] The present application provides a method, device and electronic device for extracting text fields, which are used to extract target text fields in tax payment certificate images, solve the problem in the existing technology that it is impossible to extract target text fields that meet business needs in tax payment certificate images, and effectively improve the accuracy of extracting target text fields in tax payment certificate images.
[0004] In a first aspect, the present application provides a method for extracting a text field, the method comprising:
[0005] Acquire an original image containing a text field, and determine each target image region in the original image, wherein the target image region is a region in the image to be processed containing the text field;
[0006] Performing text recognition on the text fields in the respective target image regions to obtain text fields corresponding to the respective target image regions;
[0007] According to preset extraction rules, target text fields that meet business requirements are extracted from the text fields.
[0008] In one possible design, obtaining an original image containing a text field includes: obtaining an image to be processed containing a text field, rotating the image to be processed according to a preset angle to obtain N rotated images corresponding to the image to be processed at different rotation angles, then projecting the text field in the rotated image in a given direction, and superimposing the projections of the rotated images in the given direction to obtain projection values of the rotated images, thereby determining N projection values corresponding to the N rotated images, and selecting, among the N projection values, a rotated image corresponding to a minimum projection value, and using the rotated image as the original image.
[0009] In one possible design, after obtaining the original image containing the text field, the method further includes: dividing the original image into multiple image blocks, calculating the Euclidean distance between two image blocks, and determining image blocks whose Euclidean distance is less than a preset threshold as similar image blocks, then identifying the similar image blocks as similar areas, obtaining one or more similar areas in the original image, and then performing denoising processing on each similar area in the original image to obtain the original image after the denoising processing.
[0010] In a possible design, each target image region is determined in the original image, including: extracting image features in the original image based on a target detection model, and then determining each target image region in the original image according to the image features.
[0011] In one possible design, a target text field that meets business needs is extracted from a text field according to preset extraction rules, including: obtaining an association relationship between the target text field and the text field based on a preset database, and then extracting the target text field that meets business needs from the text field in the original image according to the association relationship.
[0012] In a possible design, after extracting the target text field that meets the business requirements from the text field, the method further includes: sending the target text field to a front-end display interface for display.
[0013] The above method can extract the target text field, solving the problem in the prior art of being unable to extract the target text field that meets business requirements from the tax payment certificate image, and can achieve the following technical effects:
[0014] 1. By performing image preprocessing on the original image, the original image is corrected to a set state based on angle correction and noise filtering, and the noise pixels in the original image are filtered out to restore the image information of the original image to the greatest extent, which is conducive to improving the accuracy of determining each target image area in the original image;
[0015] 2. By performing image detection on the original image, based on the target detection model, we achieve end-to-end fast text field detection through modeling regression tasks. We use small convolution kernels to achieve lightweight feature calculations and fully connected layers to achieve text box prediction, which can quickly detect the target image area in the image.
[0016] 3. Through text recognition, the CTC model is introduced to merge pixel information with a temporal relationship to align the text content in the image. By performing a one-to-one conversion from "image to text", the text field corresponding to the target image area is recognized, improving recognition accuracy.
[0017] 4. Through preset extraction rules, based on target field retrieval, line text alignment, and multi-line text merging processing, the coordinate analysis method is specifically introduced to ensure the accuracy of the output target text field.
[0018] In a second aspect, the present application provides a device for extracting a text field, the device comprising:
[0019] a target image region determination module, which obtains an original image containing a text field and determines various target image regions in the original image, wherein the target image region is a region in the image to be processed containing the text field;
[0020] a text field recognition module, performing text recognition on the text fields in the respective target image regions to obtain the text fields corresponding to the respective target image regions;
[0021] The target text field extraction module extracts the target text field that meets the business requirements from the text field according to preset extraction rules.
[0022] In one possible design, the module for determining the target image area is specifically used to obtain an image to be processed containing a text field; rotate the image to be processed according to a preset angle to obtain N rotated images with different rotation angles corresponding to the image to be processed, where N is a positive integer greater than or equal to 1; project the text field in the rotated image in a given direction, superimpose the projections of the rotated images in the given direction to obtain the projection values of the rotated images, and determine N projection values corresponding to the N rotated images; among the N projection values, select the rotated image corresponding to the smallest projection value, and use the rotated image as the original image.
[0023] In one possible design, the module for determining the target image area is specifically used to divide the original image into multiple image blocks, wherein the image blocks represent partial images in the original image; calculate the Euclidean distance between two image blocks, and determine two image blocks whose Euclidean distance is less than a preset threshold as similar image blocks; identify the similar image blocks as similar areas to obtain one or more similar areas in the original image; and perform denoising on each similar area in the original image to obtain the original image after the denoising.
[0024] In a possible design, the target image area determination module is specifically used to extract image features in the original image based on a target detection model; and determine each target image area in the original image according to the image features.
[0025] In one possible design, the target text field extraction module is specifically used to obtain the association relationship between the target text field and the text field based on a preset database; according to the association relationship, the target text field that meets business needs is extracted from the text field in the original image.
[0026] In a possible design, after the target text field extraction module is executed, it is further configured to send the target text field to a front-end display interface for display.
[0027] In a third aspect, the present application provides an electronic device, comprising:
[0028] Memory for storing computer programs;
[0029] The processor is configured to implement the above-mentioned method steps for extracting a text field when executing the computer program stored in the memory.
[0030] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the computer program implements the above-mentioned method steps for extracting a text field.
[0031] For each of the above-mentioned aspects from the second to the fourth aspects and the technical effects that may be achieved by each of the aspects, please refer to the above-mentioned description of the technical effects that can be achieved by the first aspect or various possible solutions in the first aspect, and no further details will be given here. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A flowchart of a method for extracting text fields provided in this application;
[0033] Figure 2 A schematic diagram of a projection-based angle correction algorithm provided in this application;
[0034] Figure 3 A schematic diagram of angle correction provided by this application;
[0035] Figure 4 A schematic diagram of the network architecture of a YOLO model provided in this application;
[0036] Figure 5 A schematic diagram of target detection provided in this application;
[0037] Figure 6 A schematic diagram of extracting a target text field provided by this application;
[0038] Figure 7 A schematic diagram of an output target text field provided by this application;
[0039] Figure 8 A schematic diagram of a device for extracting text fields provided by this application;
[0040] Figure 9 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail with reference to the accompanying drawings. The specific operating methods in the method embodiments can also be applied to device embodiments or system embodiments. It should be noted that in the description of the present application, "multiple" is understood as "at least two". "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. A is connected to B, which can represent the following two situations: A is directly connected to B and A is connected to B through C. In addition, in the description of the present application, words such as "first" and "second" are only used to distinguish the purpose of description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying order.
[0042] The embodiments of the present application provide a method, device, and electronic device for extracting text fields, which solve the problem that the existing technology cannot extract target text fields that meet business needs from tax payment certificate images.
[0043] It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention and are not used to limit the present invention. In addition, the embodiments and features in the embodiments of this application may be combined with each other if there is no conflict.
[0044] See Figure 1 As shown, the embodiment of the present application provides a method for extracting text fields, and the specific process is as follows:
[0045] Step 101: obtaining an original image containing a text field, and determining each target image area in the original image;
[0046] After acquiring the original image, the target image areas in the original image can be determined by performing image preprocessing and image detection operations on the original image. Here, the image preprocessing may include performing angle correction on the original image and / or performing noise filtering on the original image. The target image area is the area in the original image that contains the text field.
[0047] It is worth noting that the original image is not limited to the tax payment certificate image, but can also be other certificate images, or any image containing text fields. The tax payment certificate image is taken as an example for the following detailed explanation.
[0048] The specific processes of S1 angle correction, S2 noise filtering, and S3 image detection are explained below.
[0049] S1 angle correction:
[0050] The angle correction of the original image can be achieved by using a projection-based angle correction algorithm, such as the Radon transform algorithm, which finds the angle of maximum projection value by projecting in a given direction, thereby determining the tilt angle of the original image.
[0051] Specifically, the projection-based angle correction algorithm mainly uses the characteristics that the image projection is longest along the normal direction and shortest along the horizontal direction. If the original image is represented as a binary function f(x,y), then the projection of the original image in a given direction can be expressed as the line integral of f(x,y) in that direction. Figure 2 As shown, the projection of f(x,y) in the x direction can be expressed as the line integral of f(x,y) in the vertical direction; the projection of f(x,y) in the y direction can be expressed as the line integral of f(x,y) in the horizontal direction; the projection of f(x,y) along the x' direction can be expressed as the line integral of f(x,y) along the y' direction.
[0052] It's worth noting that f(x,y) can be projected along any given direction to obtain a line integral along that direction. Taking the projection of f(x,y) along the x' direction as an example, the specific formula for calculating the line integral of f(x,y) along the y' direction can be found in Formula 1 below.
[0053]
[0054] Among them, (x, y) is the original coordinate of the original image, (x', y') is the new coordinate of the original coordinate (x, y) rotated by angle θ, R θ (x') is the line integral of the original image along the y' direction.
[0055] In addition, the above-mentioned projection-based angle correction algorithm is only one possible angle correction algorithm, and is also applicable to other correction algorithms, which will not be elaborated in detail here.
[0056] For example, it is determined whether the original image is in a set state. If so, no angle correction is performed on the original image. If not, an angle correction algorithm is used to adjust the original image to the set state. For example, the horizontal direction is used as the given direction, and the set state is a state in which the text field in the original image is parallel to the horizontal direction. Figure 3 As shown, when the original image is not in the set state, the angle of the original image is adjusted so that the adjusted image is in the set state, and the adjusted image at this time is used as the original image.
[0057] The above-mentioned angle correction method helps to improve the accuracy of determining the target image area.
[0058] S2 Noise Filtering:
[0059] The noise filtering of the original image can be achieved by using the Non-Local Means (NLM) algorithm. Of course, other filtering algorithms can also be used to achieve noise filtering. Here, the noise filtering process is specifically described below using the Non-Local Means (NLM) algorithm as an example.
[0060] Specifically, the non-local mean filtering algorithm primarily exploits the non-local self-similarity of images. This property, characterized by the recurring texture or structure of non-local regions in an image, effectively preserves image edges and details. For example, in an image, there are many blocks with identical pixels, and the noise within them is uncorrelated. Processing these blocks can effectively remove noise from the image.
[0061] For example, the original image is first divided into several image blocks, and then the Euclidean distance between the image blocks is calculated to determine the similar image blocks among the several image blocks, and the similar image blocks are identified as a similar area, and then one or more similar areas in the original image are determined, and then each similar area is averaged to achieve the purpose of removing noise in the original image.
[0062] See the following formula 2, which is a specific calculation formula for using the non-local mean filtering algorithm to filter noise from the original image.
[0063]
[0064]
[0065] Where w(i, j) represents the weighted average similarity of image blocks, determined by the Euclidean distance between the two image blocks. Since the similarity between pixels in an image is significantly affected by physical distance, alignment and normalization are required. Z(i) is the distance between the processed image blocks.
[0066] It is worth noting that the above-mentioned Euclidean distance is only one possible way to determine similar image blocks and does not constitute a limitation to the embodiments of the present application.
[0067] The above noise filtering method helps to improve the accuracy of subsequent text field extraction.
[0068] S3 Image Detection:
[0069] Image detection on the original image can be implemented based on an object detection model algorithm, such as the YOLO (You Only Look Once) model algorithm, which can identify text fields in the original image to determine the target image area in the original image.
[0070] Specifically, the network architecture of the YOLO model can be found in Figure 4 As shown in the figure, the YOLO model is a one-step object detection model that can model the text field detection task as a regression problem. In practical applications, the YOLO model uses an end-to-end network to complete the process from inputting the original image to outputting the location and category of the target image region. In the YOLO model, the image features in the original image are first extracted using a convolutional neural network (CNN). Then, a fully connected layer (FC) is used to obtain the predicted probability values of the location and category of the target image region in the original image.
[0071] For example, see Figure 5 As shown in the figure, after the image detection processing of the YOLO model, each target image area in the original image can be determined.
[0072] It is worth noting that the above YOLO model is only one possible model for target detection, and other applicable target detection models are not elaborated in detail here.
[0073] By using the above-mentioned image detection method, each target image area in the original image is determined, which effectively improves the accuracy of determining the target image area and helps to improve the accuracy of subsequent text field extraction.
[0074] Step 302: performing text recognition on the text fields in the respective target image regions to obtain the text fields corresponding to the respective target image regions;
[0075] In the application embodiment, "feature extraction" and "text prediction" can be used to achieve text recognition for text fields in each target image area. Text recognition can perform corresponding processing on different text fields, that is, converting image information of various written forms into text information with a unified representation.
[0076] Specifically, during the feature processing phase, a convolutional neural network (CNN) is used to extract image features from the original image. Then, a recurrent neural network (RNN) is used to extract text sequence features. Because the extracted image features are affected by factors such as writing style, character size, and font, the predicted text fields may contain multiple predictions for the same letters, such as "Hello" being predicted as "Heellloooo."
[0077] Furthermore, in the "text prediction" stage, the embodiment of the present application introduces the CTC (Connectionist Temporal Classification) model to perform text prediction, and aligns and compresses redundant features, such as adjusting the incorrectly predicted "Heellloooo" to "Hello", thereby ensuring that the predicted text field corresponds one-to-one to the detected target image area.
[0078] The above-mentioned text recognition method can effectively improve the accuracy of identifying text fields in each target image area.
[0079] Step 303: extracting target text fields that meet business requirements from the text fields according to preset extraction rules.
[0080] In the embodiment of the present application, the preset extraction rule is to extract the target text field from the text fields corresponding to each target image area. The target text field can be found in Figure 6 As shown, the target text field is output according to the specified format. The output target text field can be found in Figure 7 Here, the extraction process may include target field retrieval, line text alignment, and multi-line text merging. The following will provide a detailed description of the three parts with reference to the accompanying drawings.
[0081] The first part is target field search: first, set the search rules of the target field according to the characteristics of the target field, and then search and match the text field based on the search rules.
[0082] Here, the association relationship between the target text field and the text field can be obtained based on the preset database, and then the target text field that meets the business requirements can be extracted from the text fields corresponding to each target image area according to the association relationship.
[0083] It should be noted that for the convenience of presenting the technical solution provided by the embodiments of the present application more completely in combination with the second part and the third part, the extracted target text fields will be expressed as target fields below. Those skilled in the art should understand that the target text fields can be extracted through the processing operations of the first part. In addition, the first part can be combined with the second part or / and the third part to implement the optimized technical solution provided by the embodiments of the present application.
[0084] Specifically, for the original image of the tax payment certificate, text fields such as "China", "Tax", "Verification Code", "Taxpayer Identification Number", "20************", "******************M", etc. can be extracted. Set the retrieval rules for the target fields according to the actual business needs, that is, preset a database. If fields such as "China" and "Tax" are not set as target fields in the retrieval rules, then these text fields will not be retrieved; only target fields such as "Verification Code", "Taxpayer Identification Number", "20************", "******************M", etc. will be retrieved. After retrieving the target fields, match the target fields according to the preset matching rules, such as the method of regular matching.
[0085] For example, preset the matching rules according to the actual business needs. For example, the specific content corresponding to the "Taxpayer Identification Number" is "numbers + capital letters"; the specific content corresponding to the "Verification Code" is "numbers starting with 20", etc. Through this method, the matching of the target fields can be achieved.
[0086] As Figure 6 shown, according to the preset matching rules, match the text field "Verification Code" with the text field "20************" to obtain the matching result "Verification Code: 20************", and match the text field "Taxpayer Identification Number" with the text field "******************M" to obtain the matching result "Taxpayer Identification Number: ******************M", etc.
[0087] Second part: Line text alignment. In the first part, there are cases of multiple-line target field matching. Here, by introducing the method of coordinate analysis, analyze the multiple-line target fields to improve the matching accuracy in the scenario of multiple-line target fields.
[0088] Specifically, for the original image of the tax payment certificate, there are cases of multiple-line matching for target fields such as "Original Document Number", "Tax Type", "Item Name", "Tax Period", "Date of Tax Payment (Refund)", "Actual Tax Payment (Refund) Amount", etc. According to the method of rule matching, there may be problems of multiple-line interleaved matching.
[0089] like Figure 6 As shown, "Original voucher number", "tax type", "item name", "tax period", "entry (refund) date", and "actual paid (refund) amount" each match three "target fields". Assume that the first row "31****************" matched under the "Original Voucher Number" corresponds to "Tax Type" as "Local Education Surcharge", the corresponding "Item Name" as "Value Added Tax Local Education Surcharge", the corresponding "Tax Time" as "2021-06-01 to 2021-06-30", the corresponding "Entry (Refund) Date" as "2021-07-08", and the corresponding "Actual Paid (Refund) Amount" as "1339.00"; the second row "31****************" matched under the "Original Voucher Number" corresponds to "Tax Type" as "Education Surcharge", the corresponding "Item Name" as "Value Added Tax Education Surcharge", the corresponding "Tax Time" as "2021-0601 to 2021-06-30", the corresponding "Entry (Refund) Date" as "2021-07-08", and the corresponding "Actual Paid (Refund) Amount" as "2008.50". The problem of staggered matching of multiple rows is that the "education surcharge" in the second row is matched to the "1339.00" in the first row.
[0090] To address this issue, in the row text alignment process, we first determine the target fields corresponding to multiple rows. Next, we determine the reference text and its vertical coordinate, and then determine the average height of the target fields in the same row as the reference text. See Formula 3 for the specific calculation formula for row text alignment.
[0091]
[0092] Among them, y R is the ordinate of the reference text, y' is the ordinate of the target field in the same row as the reference text, and h avg is the average height of the reference text.
[0093] It should be noted that "0.5" in Formula 3 is a possible preset threshold value, which can be set according to actual application requirements. Formula 3 is explained below with reference to the accompanying drawings.
[0094] See also Figure 6 As shown, first take the first line "31****************" under the "Voucher Number" on the left as the reference text, and the vertical coordinate of the reference text is y RThen, based on the actual application, set the vertical axis floating height range. Based on this height range, determine the other target fields on the same row as the reference text. After determining the relationship for the first row, use "31****************" in the second row under "Voucher Number" as the reference text. Repeat the above process until the target fields are aligned.
[0095] Part 3: Merging multiple lines of text, mainly for the case of multiple lines of text, such as Figure 6 As shown, it is assumed that the target text segment "Tax Authority" corresponds to two target text segments "State Administration of Taxation ** Economic Development Zone" and "Tax Bureau First Tax Office", but in the actual application scenario, the corresponding two target fields should be one target field, that is, "State Administration of Taxation ** Economic Development Zone Tax Bureau First Tax Office". In this case, a multi-text merge operation is required.
[0096] Specifically, we first identify "Tax Authority" as the reference text. Then, by comparing the vertical and horizontal coordinates of the reference text, we determine the target fields to be merged: "State Administration of Taxation ** Economic Development Zone" and "Tax Bureau First Tax Office." See Formula 4 for the specific calculation formula for merging multiple documents.
[0097]
[0098] Among them, y R is the vertical coordinate of the reference text, x R is the horizontal coordinate of the reference text, w R is the width of the reference text, y' is the vertical coordinate of the target field to be merged, x' is the horizontal coordinate of the target field to be merged, h avg is the average height of the reference text.
[0099] It should be noted that “0.5” and “1.5” in Formula 4 are both possible preset thresholds, which can be set according to actual application requirements.
[0100] In addition, the drawings and example description terms provided in the embodiments of this application are only used as examples to facilitate understanding by those skilled in the art and are not for other purposes. Their usage specifications comply with relevant national regulations.
[0101] At this point, through the processing of the above three parts, the target text field can be extracted, and through the processing of target field retrieval, line text alignment, and multi-line text merging, the accuracy of target text field extraction can be effectively improved.
[0102] The method of the embodiment of the present application realizes the extraction of the target text field, solves the problem in the prior art that it is impossible to extract the target text field that meets business requirements from the tax payment certificate image, and can achieve the following technical effects:
[0103] 1. By performing image preprocessing on the original image, the original image is corrected to a set state based on angle correction and noise filtering, and the noise pixels in the original image are filtered out to restore the image information of the original image to the greatest extent, which is conducive to improving the accuracy of determining each target image area in the original image;
[0104] 2. By performing image detection on the original image, based on the target detection model, we achieve end-to-end fast text field detection through modeling regression tasks. We use small convolution kernels to achieve lightweight feature calculations and fully connected layers to achieve text box prediction, which can quickly detect the target image area in the image.
[0105] 3. Through text recognition, the CTC model is introduced to merge pixel information with a temporal relationship to align the text content in the image. By performing a one-to-one conversion from "image to text", the text field corresponding to the target image area is recognized, improving recognition accuracy.
[0106] 4. Through preset extraction rules, based on target field retrieval, line text alignment, and multi-line text merging processing, the coordinate analysis method is specifically introduced to ensure the accuracy of the output target text field.
[0107] Based on the method provided in the above-mentioned embodiment of the present application, the target text field can also be sent to the front-end display interface, and personalized display services can be provided to users according to actual application requirements.
[0108] Based on the same inventive concept, the present application also provides a device for extracting text fields, which is used to extract target text fields from tax payment certificate images, thereby solving the problem in the prior art that target text fields that meet business needs cannot be extracted from tax payment certificate images, and effectively improving the accuracy of extracting target text fields. Figure 8 , the device comprises:
[0109] The target image region determination module 801 acquires an original image containing a text field, and determines various target image regions in the original image, wherein the target image region is a region containing the text field in the image to be processed;
[0110] A text field recognition module 802 performs text recognition on the text fields in the target image regions to obtain text fields corresponding to the target image regions;
[0111] The target text field extraction module 803 extracts the target text field that meets the business requirements from the text fields according to preset extraction rules.
[0112] In one possible design, the target image area determination module 801 is specifically used to obtain an image to be processed containing a text field; rotate the image to be processed according to a preset angle to obtain N rotated images with different rotation angles corresponding to the image to be processed, where N is a positive integer greater than or equal to 1; project the text field in the rotated image in a given direction, superimpose the projections of the rotated images in the given direction to obtain the projection values of the rotated images, and determine N projection values corresponding to the N rotated images; among the N projection values, select the rotated image corresponding to the smallest projection value, and use the rotated image as the original image.
[0113] In one possible design, the target image area determination module 801 is specifically used to divide the original image into multiple image blocks, wherein the image blocks represent partial images in the original image; calculate the Euclidean distance between two image blocks, and determine two image blocks whose Euclidean distance is less than a preset threshold as similar image blocks; identify the similar image blocks as similar areas to obtain one or more similar areas in the original image; and perform denoising on each similar area in the original image to obtain the original image after the denoising.
[0114] In a possible design, the target image area determination module 801 is specifically configured to extract image features in the original image based on a target detection model; and determine each target image area in the original image according to the image features.
[0115] In one possible design, the target text field extraction module 803 is specifically used to obtain the association relationship between the target text field and the text field based on a preset database; according to the association relationship, the target text field that meets business needs is extracted from the text field in the original image.
[0116] In a possible design, after the target text field extraction module 803, it is also used to send the target text field to the front-end display interface for display.
[0117] Based on the above device, the target text field in the tax payment certificate image is extracted, which solves the problem in the existing technology that the target text field that meets business needs cannot be extracted in the tax payment certificate image, and effectively improves the accuracy of extracting the target text field.
[0118] Based on the same inventive concept, an electronic device is also provided in an embodiment of the present application. The electronic device can realize the functions of the aforementioned device for extracting text fields. Figure 9 , the electronic device includes:
[0119] At least one processor 901, and a memory 902 connected to the at least one processor 901. The specific connection medium between the processor 901 and the memory 902 is not limited in the embodiment of the present application. Figure 9 In the example, the processor 901 and the memory 902 are connected via a bus 900. Figure 9 The bus 900 can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, Figure 9 The diagram is represented by only one thick line, but this does not mean that there is only one bus or one type of bus. Alternatively, the processor 901 may also be referred to as a controller, without limitation to the name.
[0120] In the embodiment of the present application, the memory 902 stores instructions that can be executed by at least one processor 901. The at least one processor 901 can execute the method for extracting text fields discussed above by executing the instructions stored in the memory 902. The processor 901 can implement Figure 8 The functions of each module in the device shown.
[0121] Among them, the processor 901 is the control center of the device, which can use various interfaces and lines to connect the various parts of the entire control device, and monitor the device as a whole by running or executing instructions stored in the memory 902 and calling data stored in the memory 902, the various functions of the device and processing data.
[0122] In one possible design, processor 901 may include one or more processing units. Processor 901 may integrate an application processor and a modem processor. The application processor primarily processes the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 901. In some embodiments, processor 901 and memory 902 may be implemented on the same chip. In some embodiments, they may also be implemented on separate chips.
[0123] The processor 901 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method for extracting text fields disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.
[0124] The memory 902 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 902 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 902 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 902 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0125] By designing and programming the processor 901, the code corresponding to the method for extracting text fields described in the above embodiment can be fixed into the chip, so that the chip can execute the code when running. Figure 1 The steps of the method for extracting text fields in the embodiment shown are as follows: How to design and program the processor 901 is a technique well known to those skilled in the art and will not be described in detail here.
[0126] Based on the same inventive concept, an embodiment of the present application further provides a storage medium storing computer instructions. When the computer instructions are executed on a computer, the computer executes the method for extracting text fields discussed above.
[0127] In some possible implementations, various aspects of the method for extracting text fields provided in the present application may also be implemented in the form of a program product, which includes program code. When the program product is run on a device, the program code is used to enable the control device to execute the steps of the method for extracting text fields according to various exemplary implementations of the present application described above in this specification.
[0128] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0129] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0130] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0131] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps for the function specified in one or more boxes.
[0132] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.
Claims
1. A method for extracting a text field, characterized in that: The method comprises: Acquire an original image containing a text field, and determine target image regions in the original image, wherein the target image regions are regions of the image to be processed containing the text field; the original image is an image obtained after processing the image to be processed; Performing text recognition on the text fields in the respective target image regions to obtain text fields corresponding to the respective target image regions; Based on a preset database, obtain the association relationship between the target text field and the text field; extracting target text fields that meet business requirements from the text fields in the original image according to the association relationship; Determining the target text fields corresponding to a plurality of lines, determining the reference text and the vertical coordinate of each line of the reference text, and determining the average height of the target text fields in the same line as the reference text; determining the target text field in the same line as the reference text based on the vertical coordinate and the average height; Determine the horizontal coordinate and the width of the reference text, determine the target text field to be merged based on the horizontal coordinate and the width, and determine the target text field to be merged based on the vertical coordinate and the average height; merge the target text field to be merged.
2. The method according to claim 1, wherein The obtaining of the original image containing the text field includes: Get the image to be processed that contains the text field; Rotating the image to be processed according to a preset angle to obtain N rotated images corresponding to the image to be processed at different rotation angles, where N is a positive integer greater than or equal to 1; Projecting the text field in the rotated image in a given direction, superimposing the projections of the rotated image in the given direction to obtain a projection value of the rotated image, and determining N projection values corresponding to the N rotated images; Among the N projection values, a rotated image corresponding to a minimum projection value is selected, and the rotated image is used as the original image.
3. The method according to any one of claims 1 to 2, characterized in that After obtaining the original image containing the text field, the method further includes: Dividing the original image into a plurality of image blocks, wherein the image blocks represent partial images in the original image; Calculating the Euclidean distance between two image blocks, and determining an image block whose Euclidean distance is less than a preset threshold as a similar image block; Identifying the similar image blocks as similar regions, and obtaining one or more similar regions in the original image; De-noising is performed on each similar region in the original image to obtain the original image after the de-noising.
4. The method according to claim 1, wherein Determining each target image area in the original image includes: Extracting image features from the original image based on a target detection model; And according to the image features, each target image area in the original image is determined.
5. The method according to claim 1, wherein After extracting the target text field that meets the business requirements from the text field, the method further includes: The target text field is sent to the front-end display interface for display.
6. A device for extracting a text field, characterized in that: The device comprises: a target image region determination module, which obtains an original image containing a text field and determines various target image regions in the original image, wherein the target image region is a region of the image to be processed containing the text field; the original image is an image obtained after processing the image to be processed; a text field recognition module, performing text recognition on the text fields in the respective target image regions to obtain the text fields corresponding to the respective target image regions; A target text field extraction module obtains the association relationship between the target text field and the text field based on a preset database; according to the association relationship, extracts the target text field that meets the business needs from the text field in the original image; determines the target text fields corresponding to multiple lines, determines the reference text of each line and the vertical coordinate of the reference text, and determines the average height of the target text fields in the same line as the reference text; determines the target text fields in the same line as the reference text based on the vertical coordinate and the average height; determines the horizontal coordinate of the reference text and the width of the reference text, determines the target text field to be merged through the horizontal coordinate and the width, and determines the target text field to be merged through the vertical coordinate and the average height; merges the target text fields to be merged.
7. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the method according to any one of claims 1 to 5 when executing the computer program stored in the memory.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Method and device for identifying reading sequence of layout
CN102479173A
A method for detect and correcting bill direction and an automatic ticket checking system
CN109447067A
Method for extracting target field in bill image and related device
CN112052858A
Certificate identification method and device
CN113011426A