An OCR-based work ticket recognition method, an electronic device, and a storage medium
By combining OCR technology with two-dimensional coordinate algorithms and regular expression matching, the content of work orders can be automatically identified and filled in, solving the problem of low efficiency in manually filtering text content in existing technologies, and achieving efficient text content extraction and filling.
Patent Information
- Application Number
- CN202310801234.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-30
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2043-06-30
AI Technical Summary
Existing OCR technology requires manual text filtering when recognizing work tickets, which is inefficient, labor-intensive, and difficult to be compatible with various work tickets with similar layouts.
After using OCR to recognize work tickets, the recognized data is divided into page, row, and block objects using a two-dimensional coordinate algorithm. Regular expression matching and JSON configuration files are used to automatically fill the data to the target location, supporting the recognition of single-line, multi-line, and table-type data.
It achieves automated recognition and text filling, improving recognition efficiency, reducing manual operation, and adapting to the differences in various work order templates.
Smart Images

Figure CN117409429B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a work ticket recognition method based on OCR, an electronic device and a storage medium. BACKGROUND
[0002] Optical Character Recognition (OCR) is an important research direction in the field of pattern recognition. With the continuous development and innovation of Internet technology, OCR image recognition technology is widely used in many fields because of its convenience and speed. From the past character recognition of scanned files to the current recognition of picture text in natural scenes, such as recognizing the text in identity cards, bank cards, door plates, bills and various network pictures.
[0003] In practical applications, the most commonly used method is to manually filter and copy the required text content through OCR image recognition. However, this usage method is often limited and requires manual selection of the desired data from the recognized text content. SUMMARY
[0004] In view of the technical defects mentioned in the background art, the purpose of the embodiments of the present application is to provide a work ticket recognition method based on OCR, an electronic device and a storage medium.
[0005] To achieve the above-mentioned purpose, in a first aspect, the embodiments of the present application provide a work ticket recognition method based on OCR, comprising:
[0006] adopting OCR to recognize the work ticket to obtain recognition data;
[0007] adopting a two-dimensional coordinate algorithm to process the recognition data twice to obtain filling data;
[0008] recognizing a work ticket template to obtain a target position;
[0009] adopting a regular matching method to fill the filling data into the target position.
[0010] As a specific implementation of the present application, the filling data is obtained, specifically:
[0011] obtaining the X-axis coordinate and Y-axis coordinate of the recognition data;
[0012] re-layouting and merging the recognition data according to the X-axis coordinate and Y-axis coordinate, and dividing the recognition data into page objects, line objects and block objects according to a division rule.
[0013] As a specific implementation of the present application, the work ticket template is recognized to obtain the target position, specifically:
[0014] According to the work ticket format, and according to the division rule, it is divided into multiple page objects, line objects and block objects.
[0015] The division rule is:
[0016] The two-dimensional coordinate algorithm calculates the text reliability according to the longitudinal Y-axis value, and identifies the block objects within the error allowable range as a line object;
[0017] The two-dimensional coordinate algorithm calculates the text center point according to the horizontal X-axis value, and arranges the block objects in the line object from left to right according to the center point X-axis value.
[0018] In a second aspect, the embodiment of the present application provides a work ticket recognition method based on OCR, comprising:
[0019] The work ticket is recognized and processed by using OCR, and different formats of filling data are obtained;
[0020] For multiple different work ticket templates, multiple program codes with different logics and a same configuration file are set;
[0021] The current work ticket is recognized, and a target program code is determined from the multiple program codes with different logics according to the recognition result;
[0022] Based on the same configuration file, the target program code is used to read and fill the filling data to the corresponding position of the current work ticket, and display is performed.
[0023] The configuration file is a JSON configuration file, which is used for unified management of configuration information of multiple work ticket templates, and the configuration information includes start conditions, end conditions, content positions and custom filtering information of required data information.
[0024] In a third aspect, the embodiment of the present application provides an electronic device, which recognizes a work ticket based on an OCR technology, comprising:
[0025] A first processing unit is configured to recognize and process the work ticket by using OCR, and obtain filling data in different formats;
[0026] A setting unit is configured to set multiple program codes with different logics and a same configuration file for multiple different work ticket templates;
[0027] A second processing unit is configured to recognize the current work ticket, and determine a target program code from the multiple program codes with different logics according to the recognition result;
[0028] The third processing unit is configured to read and fill the padding data into the corresponding position of the current work ticket based on the same configuration file and the target program code, and display the padding data.
[0029] In a fourth aspect, an embodiment of the present application further provides another electronic device, comprising a processor, an input device, an output device and a memory, which are connected with each other, wherein the memory is configured to store a computer program, the computer program comprises program instructions, and the processor is configured to invoke the program instructions to execute the method steps of the first aspect.
[0030] In a fifth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, the computer program comprises program instructions, and the program instructions are executed by a processor to implement the method steps of the first or second aspect.
[0031] The work ticket recognition scheme based on OCR provided by the embodiment of the present application can automatically fill the content recognized by OCR into the corresponding position, without manually selecting and screening the data that the user wants, thereby improving the recognition efficiency and reducing the workload. BRIEF DESCRIPTION OF DRAWINGS
[0032] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the drawings needed in the specific embodiments or prior art description will be briefly introduced as follows.
[0033] Figure 1 is a work ticket splitting schematic diagram;
[0034] Figure 2 is a single-row data layout format diagram;
[0035] Figure 3 is a multi-row data layout format diagram;
[0036] Figure 4 is a table data layout format diagram;
[0037] Figure 5 is a flowchart of the work ticket recognition method based on OCR provided by the first embodiment of the present application;
[0038] Figure 6 is a flowchart of the work ticket recognition method based on OCR provided by the sixth embodiment of the present application;
[0039] Figure 7 is a comparison schematic diagram before and after work ticket recognition;
[0040] Figure 8 is a structural diagram of an electronic device;
[0041] Figure 9 is another structural diagram of an electronic device. DETAILED DESCRIPTION
[0042] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative effort belong to the scope of protection of the present application.
[0043] It should be understood that, when used in the specification and the appended claims, the terms "comprise" and "include" indicate the presence of described features, integers, steps, operations, elements, and / or components, but do not exclude one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0044] The inventive concept of the present application is that, in view of the need for manual screening of self-required text content in the prior art, if only a single work ticket needs to be identified and automatically filled, the text title can be accurately matched, and the desired text content can be obtained according to the requirement. When multiple work tickets with little difference in layout need to be identified and adapted at the same time, considering the difference in text title and content layout, a flexible regular expression is used to configure the screening and matching of the text title. That is, no matter whether the text title is different in multiple cases or the content layout is single-line, multi-line, or table, a regular expression can be configured to automatically extract and fill the text content we need by means of program writing.
[0045] In a specific implementation, the embodiment of the present application designs a work ticket identification program. The program uses a JSON file to configure configuration information required to obtain data by analyzing the content and layout of multiple different work ticket document samples, uses program codes with different logics to identify multiple different work ticket templates according to different identification conditions, and achieves the effect of automatically identifying and obtaining effective content and filling it into the corresponding position.
[0046] The main features are as follows:
[0047] (1) According to the format of the work ticket, it can be divided into multiple pages, lines, and block objects for program use. Each page object is composed of multiple line objects, and each line object is composed of multiple block objects. The hierarchical ordering structure is recorded.
[0048] (2) The two-dimensional coordinate algorithm calculates the text reliability according to the longitudinal Y-axis value, and identifies the block objects within the error allowable range as a line object.
[0049] (3) Two-dimensional coordinate algorithm calculates the text center point according to the horizontal X-axis value, and arranges the block objects in the line object from left to right according to the center point X-axis value.
[0050] (4) The JSON configuration file is used to uniformly manage the work ticket template configuration information, and mainly includes the start condition, end condition, content position and other custom filtering information of the required data information.
[0051] (5) Multiple work ticket templates use the same configuration file, and different logical program codes are used to read different formats of text content.
[0052] (6) Support the recognition and reading of the same text title under single-line, multi-line and table type data.
[0053] (7) Use queue processing data, which can take multiple photos and sequentially execute the identification task, and the tasks do not conflict with each other. Multiple photos are executed to identify the task, and the subsequent task will not cover the same title data, and only the data that is not successfully identified in the previous task will be supplemented.
[0054] That is, the embodiment of the application provides a work ticket (referring to a document used in a specific function) self-defined content extraction technical solution. The technical solution can reformat and merge the disordered content data after OCR recognition according to the coordinate algorithm, decompose the disordered content data into page objects, line objects and block objects, match the required text title according to the regular idea, and finally obtain the required text content according to the requirement.
[0055] In order to better understand the embodiment of the application, the related content involved will be described as follows:
[0056] 1. Program description
[0057] Through the coordinate algorithm, the work ticket can be decomposed into page objects as shown in Figure 1 , and the logic of the page object is processed by the program logic to obtain the data required to be filled.
[0058] 2. Flow description
[0059] (1) Single-line data
[0060] The single-line data layout format may exist in two cases as shown in Figure 2 . As can be seen from the figure, if the subscript at the end of the regular matching content is equal to the length of the current block object data, the next block object data of the line object is taken; otherwise, the block object data excluding the regular matching result is taken.
[0061] (2) Multi-line data
[0062] The multi-line data layout format may exist in two cases as shown in Figure 3The two cases are shown. As can be seen from the figure, by comparing the two cases, the difference lies in whether the text title and the starting position of the text content are in the same line, and the processing method is to splice all the contents from the starting line (the line where the text title is located) to the ending line, and then remove the text title part to obtain the complete text content, and finally according to the needs, the data is logically processed.
[0063] (3) Table data
[0064] The table data layout format is as shown in the figure. The table data is mainly composed of three parts of title, table header and content, and the required data is only the content, and the processing method is to process from the next line of the starting line to the line of the ending line, if the regular matching is the table header, then skip, otherwise, according to the needs, the content 1 and the content 2 in the figure are logically processed. Figure 4
[0065] Please refer to Figure 5 , the first embodiment of the present application provides an OCR-based work ticket recognition method, comprising:
[0066] S101, using OCR to recognize the work ticket to obtain recognition data.
[0067] In this embodiment, the work ticket is recognized by using the OCR technology, and the messy content data can be obtained.
[0068] S102, using a two-dimensional coordinate algorithm to process the recognition data twice to obtain filled data.
[0069] The foregoing recognized, messy content data, how to complete the automatic selection and filling thereof, in this embodiment, a two-dimensional coordinate algorithm is used to realize, specifically:
[0070] Obtain the X-axis coordinate and Y-axis coordinate of the recognition data;
[0071] According to the X-axis coordinate and Y-axis coordinate, the recognition data is re-laid out and merged, and the recognition data is divided into page objects, line objects and block objects according to the division rule.
[0072] Among them, each page object is composed of a plurality of line objects, and each line object is composed of a plurality of block objects, and the division rule is as follows:
[0073] The two-dimensional coordinate algorithm calculates the text reliability according to the longitudinal Y-axis value, and identifies the block objects within the error allowable range as a line object;
[0074] The two-dimensional coordinate algorithm calculates the text center point according to the horizontal X-axis value, and arranges the block objects in the line object from left to right according to the center point X-axis value.
[0075] S103, recognizing the work ticket template to obtain the target position.
[0076] In the embodiment, the work order is divided into a plurality of page objects, line objects and block objects according to the work order format and the aforementioned division rule, and a hierarchical order structure of the objects, i.e. target positions to be filled, is recorded.
[0077] S104, the filling data is filled into the target positions by using a regular matching mode.
[0078] The specific regular matching mode can refer to the description in the foregoing flow description part.
[0079] Please refer to Figure 6 and Figure 7 The second embodiment of the present application provides an OCR-based work order recognition method, which comprises the following steps:
[0080] S201, using OCR to recognize and process a work order, to obtain filling data in different formats.
[0081] It should be noted that the specific process of step S201 can refer to steps S101 and S102 in the foregoing method embodiment.
[0082] S202, setting a plurality of program codes with different logics and a same configuration file for a plurality of different work order templates.
[0083] The configuration file is a JSON configuration file, which is used to uniformly manage configuration information of the plurality of work order templates, and the configuration information comprises start conditions, end conditions, content positions and other custom filtering information of required data information.
[0084] Please refer to Figure 7 For example, template 1 and template 2 need to take the content of the title "number", and the data formats of both are multi-line content formats, so the program logic used by template 1 and template 2 is the same. However, if one is a multi-line content format and the other is a table content format, the program logic used by them is different. That is, the same content layout format can use program code logic, and even if the titles are different, it is also OK, and the regular expression can be configured to take "number" or "work order number" as the title.
[0085] S203, recognizing a current work order, and determining a target program code from a plurality of program codes with different logics according to a recognition result.
[0086] For example, if it is recognized that the current work order is template 1, it can be determined that the target program code required in the current recognition process is 1.
[0087] S204, based on the same configuration file, the target program code is used to read and fill the padding data to the corresponding position of the current work ticket, and display.
[0088] From the above description, it can be seen that the work ticket recognition scheme based on OCR provided by the embodiment of the application can automatically fill the content recognized by OCR to the corresponding position, without manually selecting and screening the data that the user wants, thereby improving the recognition efficiency and reducing the workload.
[0089] Based on the same inventive concept, the embodiment of the application provides an electronic device for recognizing a work ticket based on an OCR technology. As shown in Figure 8 The electronic device comprises:
[0090] A first processing unit is configured to recognize and secondarily process the work ticket by using the OCR to obtain padding data in different formats;
[0091] A setting unit is configured to set a plurality of program codes with different logics and a same configuration file for a plurality of different work ticket templates;
[0092] A second processing unit is configured to recognize the current work ticket, and determine the target program code from the plurality of program codes with different logics according to the recognition result;
[0093] A third processing unit is configured to read and fill the padding data to the corresponding position of the current work ticket by using the target program code based on the same configuration file, and display.
[0094] The first processing unit is specifically configured to:
[0095] recognize the work ticket by using the OCR to obtain recognition data;
[0096] obtain the X-axis coordinate and the Y-axis coordinate of the recognition data;
[0097] re-layout and merge the recognition data according to the X-axis coordinate and the Y-axis coordinate, and divide the recognition data into page objects, line objects and block objects according to a division rule;
[0098] The division rule is that:
[0099] a two-dimensional coordinate algorithm calculates the text reliability according to the longitudinal Y-axis value, and identifies that the block objects within the error allowable range form a line object;
[0100] the two-dimensional coordinate algorithm calculates the text center point according to the horizontal X-axis value, and arranges the block objects in the line object from left to right according to the center point X-axis value.
[0101] As another preferred embodiment of the application, as shown in Figure 9As shown, the electronic device can include one or more processors 101, one or more input devices 102, one or more output devices 103, and a memory 104, which are connected to each other through a bus 105. The memory 104 is configured to store a computer program, the computer program including program instructions, and the processor 101 is configured to invoke the program instructions to perform the method steps described in the method embodiment shown in FIG. 6. Figure 5 or the method steps described in the method embodiment shown in FIG. 6.
[0102] It should be understood that, in the embodiments of the present application, the processor 101 can be a central processing unit (CPU), and the processor can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.
[0103] The input device 102 can include a keyboard, etc., and the output device 103 can include a display (LCD, etc.), a speaker, etc.
[0104] The memory 104 can include read-only memory and random access memory, and provide instructions and data for the processor 101. A portion of the memory 104 can also include non-volatile random access memory. For example, the memory 104 can also store device type information.
[0105] In a specific implementation, the processor 101, the input device 102, and the output device 103 described in the embodiments of the present application can perform the implementation described in the embodiment of the OCR-based work ticket recognition method provided by the embodiments of the present application, and will not be described here.
[0106] It should be noted that more specific workflow of the electronic device is described in the foregoing method embodiment part, and will not be described here.
[0107] In addition, corresponding to the foregoing method embodiment and electronic device, the embodiments of the present application provide a computer readable storage medium, the computer readable storage medium stores a computer program, the computer program includes program instructions, and the program instructions are executed by the processor to realize the OCR-based work ticket recognition method.
[0108] The computer readable storage medium can be an internal storage unit of the electronic device, such as a hard disk or a memory of the system. The computer readable storage medium can also be an external storage device of the system, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. Further, the computer readable storage medium can include both the internal storage unit and the external storage device of the system. The computer readable storage medium is used to store the computer program and other programs and data required by the system. The computer readable storage medium can also be used to temporarily store data that has been output or will be output.
[0109] The aforementioned storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0110] The above description is merely a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present application, and these modifications or replacements shall be encompassed within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims
1. An OCR-based work ticket recognition method, characterized by, The method comprises the following steps: The work ticket is recognized by using OCR to obtain recognition data; The recognition data is disordered content data; The recognition data is processed again by using a two-dimensional coordinate algorithm to obtain filling data; The work ticket template is recognized to obtain a target position; The filling data is filled into the target position by using a regular matching method; The regular matching method is as follows: For single-line data, if the end subscript of the regular matching content is equal to the length of the current block object data, the next block object data of the line object is taken, otherwise, the block object data excluding the regular matching result is taken; For multi-line data, all contents from the line where the text title is located to the end line are spliced, and the text title part is removed to obtain complete text content; For table data, from the start line to the end line, if the table header is matched, it is skipped, otherwise, the content is processed according to the required logic; the table data comprises a title, a table header and content; The filling data is obtained by: Obtaining the X-axis coordinate and Y-axis coordinate of the recognition data; The recognition data is re-laid out and merged according to the X-axis coordinate and Y-axis coordinate, and the recognition data is divided into page objects, line objects and block objects according to a division rule; The work ticket template is recognized to obtain a target position, and the method comprises the following steps: According to the work ticket format, the work ticket is divided into multiple page objects, line objects and block objects according to a division rule; the division rule is as follows: The two-dimensional coordinate algorithm calculates the text reliability according to the vertical Y-axis value, and the block objects within the error allowable range are identified as a line object; The two-dimensional coordinate algorithm calculates the text center point according to the horizontal X-axis value, and the block objects in the line object are arranged from left to right according to the center point X-axis value.
2. An OCR-based work ticket recognition method, characterized by, The method comprises the following steps: The work ticket is recognized and processed again by using OCR to obtain filling data in different formats; For multiple different work ticket templates, multiple program codes with different logics and a same configuration file are set; The current work ticket is recognized, and the target program code is determined from the multiple program codes with different logics according to the recognition result; Based on the same configuration file, the filling data is read and filled into the corresponding position of the current work ticket by using the target program code and a regular matching method, and is displayed; The regular matching method is as follows: For single-line data, if the end subscript of the regular matching content is equal to the length of the current block object data, the next block object data of the line object is taken, otherwise, the block object data excluding the regular matching result is taken; For multi-line data, all contents from the line where the text title is located to the end line are spliced, and the text title part is removed to obtain complete text content; For table data, from the start line to the end line, if the table header is matched, it is skipped, otherwise, the content is processed according to the required logic; the table data comprises a title, a table header and content; The filling data is obtained by: Obtaining the X-axis coordinate and Y-axis coordinate of the recognition data; The recognition data is re-laid out and merged according to the X-axis coordinate and Y-axis coordinate, and the recognition data is divided into page objects, line objects and block objects according to a division rule; The division rule is as follows: The two-dimensional coordinate algorithm calculates the text reliability according to the longitudinal Y-axis value, and identifies the block objects within the error allowable range as a row object; The two-dimensional coordinate algorithm calculates the text center point according to the transverse X-axis value, and arranges the block objects in the row object from left to right according to the center point X-axis value.
3. The work ticket identification method of claim 2, wherein The configuration file is a JSON configuration file, and is used for uniformly managing configuration information of a plurality of work ticket templates.
4. An electronic device, comprising: The electronic device identifies the work ticket based on an OCR technology, and includes a processor, an input device, an output device and a memory. The first processing unit is configured to identify and secondarily process the work ticket by using the OCR to obtain filling data in different formats. The setting unit is configured to set a plurality of program codes with different logics and the same configuration file for a plurality of different work ticket templates. The second processing unit is configured to identify the current work ticket, and determine a target program code from the plurality of program codes with different logics according to an identification result. The third processing unit is configured to read and fill the filling data into a corresponding position of the current work ticket by using the target program code and a regular matching method based on the same configuration file, and display the filling data. The regular matching method is specifically as follows: For single-row data, if an end subscript of the regular matching content is equal to a length of current block object data, a next block object data of the row object is taken, otherwise, the block object data from which the regular matching result is removed is taken. For multi-row data, all contents from a line where a text title is located to an ending line are spliced, and the text title part is removed to obtain complete text content. For table data, from a starting line to an ending line, if a table header is matched, the table header is skipped, otherwise, the content is processed according to a required logic; the table data includes a title, a table header and content. The filling data is obtained by specifically: obtaining X-axis coordinates and Y-axis coordinates of the identification data; re-layouting and merging the identification data according to the X-axis coordinates and the Y-axis coordinates, and dividing the identification data into page objects, row objects and block objects according to a division rule; identifying the work ticket template to obtain a target position, which is specifically as follows: dividing the work ticket template into a plurality of page objects, row objects and block objects according to a division rule; the division rule is as follows: the two-dimensional coordinate algorithm calculates the text reliability according to the longitudinal Y-axis value, and identifies the block objects within the error allowable range as a row object; the two-dimensional coordinate algorithm calculates the text center point according to the transverse X-axis value, and arranges the block objects in the row object from left to right according to the center point X-axis value.
5. An electronic device, comprising: The electronic device identifies the work ticket based on an OCR technology, and includes a processor, an input device, an output device and a memory, which are connected to each other. The memory is configured to store a computer program, the computer program includes program instructions, and the processor is configured to invoke the program instructions to execute the method in claim 2.
6. A computer-readable storage medium storing a computer program, the computer program comprising program instructions, characterized in that, The program instructions are executed by the processor to implement the method in claim 2.
Citation Information
Patent Citations
Method for extracting and organizing unstructured sheet document data under big data environment
CN105630916A
Bill information collection method and device, computer equipment and storage medium
CN111858977A
Character recognition method, device and system for shopping receipt and computer readable medium
CN113903040A
Office receipt application form processing method and device, equipment and medium
CN116151201A