A method and device for OCR identification of import goods declaration form
By obtaining the coordinates of the product code header and judging the character attributes in the rows to determine the line spacing, it solves the problem that the product number and name, specification and model column content are closely together after OCR recognition of the imported goods customs declaration form, and achieves accurate branch processing.
Patent Information
- Application Number
- CN202111012168.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-31
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2041-08-31
AI Technical Summary
In the OCR recognition processing of the imported goods customs declaration, the two columns of product number and product name and specification model are closely together, resulting in OCR recognition as one column of content, and the boundaries of each row cannot be accurately distinguished.
By obtaining the header coordinates of the product code, traverse the row starting characters within the preset coordinate range, determine whether the characters in the row are preset attributes, determine whether the row is a new row, and use the vertical space between the starting characters of the two rows. The coordinate difference determines the line spacing, thereby achieving column and row separation.
It effectively solves the boundary problem of being unable to distinguish the product name and the content of each line in the specification and model column after OCR recognition, and achieves accurate branch processing of imported goods customs declaration forms.
Smart Images

Figure CN113723301B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image recognition technology, and in particular to a method and device for OCR recognition and branch processing of import commodity declaration forms. Background Art
[0002] In the field of cross-border e-commerce, customs declaration agents usually obtain customs declaration information provided by customers. The customs declaration information can be in electronic or paper form.
[0003] The import declaration materials provided by the customer must include the import goods declaration form. If the import goods declaration form is in paper form, it will be converted into an electronic form through OCR recognition processing.
[0004] After OCR recognition processing is performed on the import goods declaration form, the commodity number and commodity name and specification model columns in the import goods declaration form are usually closely connected in the table, resulting in OCR recognition as one column of content. In addition, since the commodity number column is not accurately recognized, there is a technical problem that the boundaries of each row of the commodity name and specification model columns cannot be distinguished. Summary of the invention
[0005] The present application provides an OCR recognition and line processing method and device for an import goods declaration form, which solves the technical problem that after the import goods declaration form is subjected to OCR recognition processing, the commodity number and commodity name and specification model columns in the import goods declaration form are usually close to each other in the table, resulting in OCR recognition as one column of content, and since the commodity number column is not accurately recognized, there is a technical problem that the boundaries of each row of content in the commodity name and specification model columns cannot be distinguished.
[0006] In view of this, the first aspect of the present application provides an import goods declaration form OCR identification branch processing method, the method comprising:
[0007] S101, obtaining a first coordinate corresponding to a header of a commodity code, where the first coordinate includes a first horizontal coordinate and a first vertical coordinate;
[0008] S102, based on the first coordinate, determining the starting character of the nth row within a preset coordinate range, where n≥1;
[0009] S103, if a preset number of characters in the nth row are preset attributes, recording a second coordinate of the starting character, the second coordinate comprising a second horizontal coordinate and a second vertical coordinate, the second vertical coordinate being the top vertical coordinate of the starting character;
[0010] S104, subtracting the second ordinate of the nth row from the second ordinate of the n-1th row to determine the ordinate interval of the n-1th row;
[0011] S105, set n=n+1, and return to step S102.
[0012] Optionally, the step S102 specifically includes:
[0013] Within the preset coordinate range of the first horizontal coordinate, traverse downward along the first vertical coordinate to determine the starting character of the nth row traversed, where n≥1.
[0014] Optionally, the step S103 specifically includes:
[0015] Starting from the initial character of the nth row, identifying the preset attributes of a preset number of characters;
[0016] If a preset number of characters in the nth row are preset attributes, the second coordinate of the starting character is recorded, the second coordinate includes a second horizontal coordinate and a second vertical coordinate, and the second vertical coordinate is the top vertical coordinate of the starting character.
[0017] Optionally, the step S103 further includes:
[0018] If any character among the preset number of characters in the nth row does not have the preset attribute, the character is matched with a preset character template. If the match is successful, the character is converted into a corresponding character of the preset attribute. If the match fails, the nth row is ignored.
[0019] Optionally, after step S102 and before step S103, the following steps are further included:
[0020] If the preset keyword is identified in the nth line, the line branching process is stopped, otherwise the process continues.
[0021] A second aspect of the present application provides an OCR identification branch processing device for an import goods declaration form, the device comprising:
[0022] An acquiring unit, used for acquiring a first coordinate corresponding to the header of the commodity code, where the first coordinate includes a first horizontal coordinate and a first vertical coordinate;
[0023] a recognition unit, configured to determine, based on the first coordinate, a starting character of the nth row within a preset coordinate range, where n≥1;
[0024] an attribute judgment unit, configured to record a second coordinate of the starting character if a preset number of characters in the nth row have a preset attribute, the second coordinate comprising a second horizontal coordinate and a second vertical coordinate, the second vertical coordinate being the top vertical coordinate of the starting character;
[0025] A determination unit, configured to subtract the second ordinate of the nth row from the second ordinate of the n-1th row to determine the ordinate interval of the n-1th row;
[0026] The iteration unit is used to set n=n+1 and jump to the recognition unit.
[0027] Optionally, the identification unit is specifically used for:
[0028] Within the preset coordinate range of the first horizontal coordinate, traverse downward along the first vertical coordinate to determine the starting character of the nth row traversed, where n≥1.
[0029] Optionally, the attribute determination unit is specifically used to:
[0030] Starting from the initial character of the nth row, identifying the preset attributes of a preset number of characters;
[0031] If a preset number of characters in the nth row are preset attributes, the second coordinate of the starting character is recorded, the second coordinate includes a second horizontal coordinate and a second vertical coordinate, and the second vertical coordinate is the top vertical coordinate of the starting character.
[0032] Optionally, the attribute determination unit is further used to:
[0033] If any character among the preset number of characters in the nth row does not have the preset attribute, the character is matched with a preset character template. If the match is successful, the character is converted into a corresponding character of the preset attribute. If the match fails, the nth row is ignored.
[0034] Optionally, it also includes:
[0035] The end judgment unit is used to stop the line-by-line processing if a preset keyword is identified in the nth line, and continue the execution otherwise.
[0036] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0037] In the present application, a method and device for OCR recognition and line division processing of an import goods declaration form are provided. By traversing the starting characters of the nth row within a preset coordinate range based on the first coordinate corresponding to the header of the commodity code, it is determined whether the row is a new row by judging whether a preset number of characters in the nth row have preset attributes, such as being uniformly numbers. The line spacing of the row is determined by using the difference in the second vertical coordinate between the starting characters of the two rows, and column and line division are achieved at the same time. This solves the problem that after the import goods declaration form is subjected to OCR recognition processing, the commodity number and commodity name and specification model columns in the import goods declaration form are usually closely connected in the table, resulting in OCR recognition as one column of content, and since the commodity number column is not accurately recognized, there is a technical problem that the boundaries of each row of the commodity name and specification model columns cannot be distinguished. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A method flow chart of an OCR identification branch processing method for an import goods declaration form in this application;
[0039] Figure 2 This is a structural diagram of an OCR recognition branch processing device for import goods declaration forms in this application. DETAILED DESCRIPTION
[0040] 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 are within the scope of protection of this application.
[0041] The present application designs an OCR recognition and line processing method and device for an import goods declaration form, which solves the technical problem that after the import goods declaration form is subjected to OCR recognition processing, the commodity number and commodity name and specification model columns in the import goods declaration form are usually close to each other in the table, resulting in OCR recognition as one column of content, and since the commodity number column is not accurately recognized, there is a technical problem that the boundaries of each row of content in the commodity name and specification model columns cannot be distinguished.
[0042] For easier understanding, see Figure 1 , Figure 1 Flow chart of a method for processing an import goods declaration form OCR identification branch in an embodiment of the present application, as shown in FIG. Figure 1 As shown, specifically:
[0043] S101, obtaining a first coordinate corresponding to a header of a commodity code, where the first coordinate includes a first horizontal coordinate and a first vertical coordinate;
[0044] It should be noted that after the characters of the commodity code are recognized by OCR, the header of the table is the character "商". Obtain the first coordinate corresponding to the character "商". Among them, the first abscissa can be the abscissa of the left boundary of the character "商", or the abscissa of the right boundary of the character "商". The first ordinate can be the ordinate of the top of the character "商", or the ordinate of the bottom of the character "商".
[0045] S102. Based on the first coordinate, determine the starting character of the nth row within the preset coordinate range, where n≥1;
[0046] It should be noted that based on the first abscissa and the first ordinate of the character "商", determine the starting character of the nth row within the preset coordinate range. It can be understood that by traversing downward along the first ordinate, the first starting character found corresponds to the first row, and the second starting character may correspond to the second row. However, the second starting character may also be the second row of the commodity name and specification model. In the actual import cargo declaration form, a complete commodity name and specification model may contain multiple lines of content, and further judgment is required.
[0047] S103. If the preset number of characters in the nth row have the preset attribute, record the second coordinate of the starting character. The second coordinate includes the second abscissa and the second ordinate, and the second ordinate is the ordinate of the top of the starting character;
[0048] It should be noted that if the first preset number of characters in the nth row have the preset attribute, it can be determined that this row corresponds to the first row of the commodity code. For example: the first 10 characters are all numbers, or the first 2 characters are English and the 3rd - 10th characters are numbers. Its specific rule setting is formulated according to the coding rules of the commodity code. After determining the start of the commodity code, it is necessary to record the actual second coordinate of the starting character of the commodity code. Among them, in order to better perform line breaks, it is necessary to record the ordinate of the top of the starting character.
[0049] S104. Subtract the second ordinate of the nth row from the second ordinate of the (n - 1)th row to determine the ordinate interval of the (n - 1)th row;
[0050] It should be noted that after obtaining the second ordinate of the starting character of the nth row, subtract it from the second ordinate of the starting character determined in the previous row, that is, the (n - 1)th row, so as to determine the ordinate interval of the (n - 1)th row. For example: the second ordinate of the starting character of the first row is 10, and the second ordinate of the starting character of the second row is 0, then the line spacing of the first row is 10, and the ordinate interval is from 0 to 10.
[0051] S105. Let n = n + 1, and return to step S102.
[0052] It should be noted that, in an import goods declaration form, there may be 2 or more commodity information, so it is necessary to set n=n+1 and then return to search for the starting character of the nth line again.
[0053] Furthermore, step S102 specifically includes:
[0054] Within the preset coordinate range of the first horizontal coordinate, traverse downward along the first vertical coordinate to determine the starting character of the nth row traversed, where n≥1.
[0055] It should be noted that based on the first horizontal coordinate and the first vertical coordinate of the "Shang" character, the starting character of the nth row is determined within the preset coordinate range. For example, based on the first horizontal coordinate, within the horizontal coordinate range of ±50, the character is searched downward along the first vertical coordinate.
[0056] It can be understood that when traversing downward along the first vertical coordinate, the first starting character found corresponds to the first line, and the second starting character may correspond to the second line, but the second starting character may also be the second line of the product name and specification model. However, in the actual import goods declaration form, a complete product name and specification model may contain multiple lines of content, which requires further judgment.
[0057] Furthermore, step S103 specifically includes:
[0058] Starting with the initial character of the nth row, identifying the preset attributes of a preset number of characters;
[0059] If a preset number of characters in the nth row are preset attributes, the second coordinate of the starting character is recorded, the second coordinate includes a second horizontal coordinate and a second vertical coordinate, and the second vertical coordinate is the top vertical coordinate of the starting character.
[0060] It should be noted that if the starting character is used as the starting point in the nth line, and the first preset number of characters are preset attributes, the first line of the product code corresponding to the line can be determined, for example: the first 10 characters are all numbers, or the first 2 characters are English and the 3rd to 10th characters are numbers. The specific rules are set according to the coding rules of the product code. After determining the start of the product code, it is necessary to record the actual second coordinate of the starting character of the product code, where the top vertical coordinate of the starting character needs to be recorded in order to better perform line separation.
[0061] Furthermore, step S103 further includes:
[0062] If any character among the preset number of characters in the nth line does not have the preset attribute, the character is matched with the preset character template. If the match is successful, the character is converted into the corresponding character of the preset attribute. If the match fails, the nth line is ignored.
[0063] It should be noted that if the nth line takes the starting character as the starting point, and there is any character in the previous preset number of characters that does not have the preset attribute, the character will be matched with the preset character template, for example: English o or O is converted to the number 0, English l is converted to the number 1, English S or s is converted to the number 5, English b is converted to the number 6, English B is converted to the number 8, English q is converted to the number 9, etc., and the number can also be converted to English. The preset character template is matched according to the attribute rules of the characters in the specific position according to the actual product code. If the match is successful, it may be that the OCR recognition accuracy is not enough. After all the conversions, the second coordinate of the starting character is still recorded. If the match is not successful, the content of the line will be ignored. For example, if it is recognized that the preset number of characters in the second line cannot be matched, the second line may be the content of the product name and specification model, and the search for the next line will be ignored.
[0064] Furthermore, after step S102 and before step S103, the following steps are further included:
[0065] If the preset keyword is recognized in the nth line, the line branch processing is stopped, otherwise the execution continues.
[0066] It should be noted that in the import goods declaration form, preset keywords will be configured at the end of the table content. The appearance of preset keywords in the recognition content of the nth line means that the table content recognition has been completed and no branch processing will be performed.
[0067] See also Figure 2 , Figure 2 FIG. 1 is a schematic diagram of a structure of an OCR recognition branch processing device for an import goods declaration form in an embodiment of the present application, such as Figure 2 As shown, specifically:
[0068] An acquisition unit 201 is used to acquire a first coordinate corresponding to the header of the commodity code, where the first coordinate includes a first horizontal coordinate and a first vertical coordinate;
[0069] The recognition unit 202 is used to determine the starting character of the nth line within a preset coordinate range based on the first coordinate, where n≥1;
[0070] The attribute judgment unit 203 is used to record the second coordinate of the starting character if a preset number of characters in the nth row have a preset attribute, the second coordinate including a second horizontal coordinate and a second vertical coordinate, and the second vertical coordinate is the top vertical coordinate of the starting character;
[0071] A determination unit 204, configured to subtract the second ordinate of the nth row from the second ordinate of the n-1th row to determine the ordinate interval of the n-1th row;
[0072] The iteration unit 205 is used to set n=n+1 and jump to the recognition unit.
[0073] Furthermore, the identification unit is specifically used for:
[0074] Within the preset coordinate range of the first horizontal coordinate, traverse downward along the first vertical coordinate to determine the starting character of the nth row traversed, where n≥1.
[0075] Furthermore, the attribute judgment unit is specifically used for:
[0076] Starting with the initial character of the nth row, identifying the preset attributes of a preset number of characters;
[0077] If a preset number of characters in the nth row are preset attributes, the second coordinate of the starting character is recorded, the second coordinate includes a second horizontal coordinate and a second vertical coordinate, and the second vertical coordinate is the top vertical coordinate of the starting character.
[0078] Furthermore, the attribute determination unit is also used for:
[0079] If any character among the preset number of characters in the nth line does not have the preset attribute, the character is matched with the preset character template. If the match is successful, the character is converted into the corresponding character of the preset attribute. If the match fails, the nth line is ignored.
[0080] Furthermore, it also includes:
[0081] The end judgment unit is used to stop the line-by-line processing if a preset keyword is recognized in the nth line, and continue the execution otherwise.
[0082] In an embodiment of the present application, a method and device for OCR recognition and line branching processing of an import goods declaration form are provided. The method traverses the starting characters of the nth row within a preset coordinate range based on the first coordinate corresponding to the header of the commodity code, and determines whether the row is a new row by judging whether a preset number of characters in the nth row have preset attributes, such as being uniformly numbers. The line spacing of the row is determined by using the difference in the second vertical coordinate between the starting characters of the two rows, and column and line branching are achieved at the same time. This solves the problem that after the import goods declaration form is subjected to OCR recognition processing, the commodity number and commodity name and specification model columns in the import goods declaration form are usually identified as one column of content by OCR because the contents of the two columns in the table are close together, and the technical problem of being unable to distinguish the boundaries of each row of the commodity name and specification model columns due to the failure to accurately identify the commodity number column.
[0083] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0084] The terms "first", "second", "third", "fourth", etc. (if any) in the specification 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, for example. 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.
[0085] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0086] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0087] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0088] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0089] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (full name in English: Read-Only Memory, English abbreviation: ROM), random access memory (full name in English: Random Access Memory, English abbreviation: RAM), disk or optical disk and other media that can store program codes.
[0090] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for processing OCR recognition branches of import goods declaration forms, It is characterized in that include: S101, obtaining a first coordinate corresponding to a header of a commodity code, where the first coordinate includes a first horizontal coordinate and a first vertical coordinate; S102, based on the first coordinate, determining the starting character of the nth row within a preset coordinate range, where n≥1; S103, if a preset number of characters in the nth row are preset attributes, recording a second coordinate of the starting character, the second coordinate comprising a second horizontal coordinate and a second vertical coordinate, the second vertical coordinate being the top vertical coordinate of the starting character; S104, subtracting the second ordinate of the nth row from the second ordinate of the n-1th row to determine the ordinate interval of the n-1th row; S105, set n=n+1, and return to step S102; The step S102 specifically includes: Traverse downward along the first ordinate within the preset coordinate range of the first abscissa to determine the starting character of the nth row traversed, where n≥1; The step S103 specifically includes: Starting from the initial character of the nth row, identifying the preset attributes of a preset number of characters; If a preset number of characters in the nth row are preset attributes, then a second coordinate of the starting character is recorded, the second coordinate comprising a second horizontal coordinate and a second vertical coordinate, and the second vertical coordinate is the top vertical coordinate of the starting character; The step S103 further includes: If any character among the preset number of characters in the nth row does not have the preset attribute, the character is matched with a preset character template. If the match is successful, the character is converted into a corresponding character of the preset attribute. If the match fails, the nth row is ignored.
2. The import goods declaration form OCR recognition branch processing method according to claim 1, It is characterized in that After step S102 and before step S103, the following steps are further included: If the preset keyword is identified in the nth line, the line branching process is stopped, otherwise the process continues.
3. An OCR recognition branch processing device for import goods declaration forms, It is characterized in that include: An acquiring unit, used for acquiring a first coordinate corresponding to the header of the commodity code, where the first coordinate includes a first horizontal coordinate and a first vertical coordinate; a recognition unit, configured to determine, based on the first coordinate, a starting character of the nth row within a preset coordinate range, where n≥1; an attribute judgment unit, configured to record a second coordinate of the starting character if a preset number of characters in the nth row have a preset attribute, the second coordinate comprising a second horizontal coordinate and a second vertical coordinate, the second vertical coordinate being the top vertical coordinate of the starting character; A determination unit, configured to subtract the second ordinate of the nth row from the second ordinate of the n-1th row to determine the ordinate interval of the n-1th row; An iteration unit, used for setting n=n+1 and jumping to the recognition unit; Traverse downward along the first ordinate within the preset coordinate range of the first abscissa to determine the starting character of the nth row traversed, where n≥1; The attribute judgment unit is specifically used for: Starting from the initial character of the nth row, identifying the preset attributes of a preset number of characters; If a preset number of characters in the nth row are preset attributes, then a second coordinate of the starting character is recorded, the second coordinate comprising a second horizontal coordinate and a second vertical coordinate, and the second vertical coordinate is the top vertical coordinate of the starting character; The attribute judgment unit is also used for: If any character among the preset number of characters in the nth row does not have the preset attribute, the character is matched with a preset character template. If the match is successful, the character is converted into a corresponding character of the preset attribute. If the match fails, the nth row is ignored.
4. The import goods declaration form OCR recognition branch processing device according to claim 3, It is characterized in that Also includes: The end judgment unit is used to stop the line-by-line processing if a preset keyword is recognized in the nth line, and continue the execution otherwise.
Citation Information
Patent Citations
Method and device for identifying table content in image file and memory medium
CN108734089A
Method for performing high-accuracy line division on OCR result of text picture
CN112396056A
