Ticket identification method and device, terminal equipment and storage medium
By acquiring user ticket images and calling templates from the template interface library, and based on the configuration of the reference area and recognition area, the problems of displacement, missed detection, and format errors in ticket recognition by traditional optical character recognition technology are solved, achieving efficient recognition of different types of tickets and reducing processing difficulty and template development costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA MERCHANTS BANK
- Filing Date
- 2023-01-28
- Publication Date
- 2026-04-17
AI Technical Summary
Traditional optical character recognition technology is prone to displacement, missed detection, and format errors when recognizing tickets. Furthermore, fixed-format recognition tools can only handle a certain type of ticket, resulting in low recognition efficiency and high template development costs.
By acquiring user ticket images, identifying user elements, and calling the corresponding templates from the preset template interface library, the recognition of different types of tickets can be achieved based on the template reference area and recognition area configuration.
It effectively identifies different types of tickets, reduces the difficulty of ticket information processing and template development costs, and improves ticket recognition efficiency.
Smart Images

Figure CN116092231B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information recognition technology, and in particular to a ticket recognition method, device, terminal equipment, and storage medium. Background Technology
[0002] In enterprises and organizations, there is a lot of work involved in the statistical management of information in invoices, certificates, proofs, documents, and other forms. For example, for employees' daily expense reimbursements, finance personnel must first enter the amounts from various invoices into the computer in order to facilitate subsequent expense reimbursement statistics.
[0003] To facilitate the entry of ticket information, some software now uses optical character recognition (OCR) technology, which can recognize all the text in an image as text format, allowing users to easily edit the text and organize ticket information on their computers.
[0004] However, traditional optical character recognition technology returns the results line by line. For tickets, since they do not have the neat format of ordinary documents and different types of tickets have different layouts, the returned results are prone to displacement, missed detection, and format errors, which increases the difficulty for business personnel to process ticket information after recognition. Furthermore, fixed-format recognition tools can only handle the recognition of a certain type, which leads to technicians repeatedly developing ticket templates, resulting in low ticket recognition efficiency. Summary of the Invention
[0005] The main purpose of this application is to provide a ticket recognition method, device, terminal equipment, and storage medium, which aims to effectively recognize different types of tickets, reduce the difficulty of ticket information processing and the cost of ticket template development, and improve the efficiency of ticket recognition.
[0006] To achieve the above objectives, this application provides a ticket recognition method, the ticket recognition method comprising:
[0007] Obtain user ticket image;
[0008] Identify the user ticket image to obtain the corresponding user elements;
[0009] Based on the user elements, the corresponding template is called from the preset template interface library. The template is configured based on the preset template reference area and template recognition area.
[0010] Based on the template, the user elements are identified to obtain the recognition result of the user ticket image.
[0011] Optionally, before the step of calling the corresponding template from the preset template interface library based on the user elements, the method further includes:
[0012] Obtain template ticket images;
[0013] Based on the template ticket image, the template reference area and the template recognition area are obtained, and the template reference area and the template recognition area each include at least one;
[0014] Based on the template reference area and the template recognition area, the key fields and template content of the template ticket image are obtained respectively, and used as template elements;
[0015] Based on the template elements, the template is determined and stored in the template interface library.
[0016] Optionally, the step of identifying the user elements based on the template and obtaining the recognition result of the user ticket image includes:
[0017] Based on the user elements and the template elements, the text block scaling ratio of the user ticket image is obtained;
[0018] Based on the scaling ratio of the text block and the user elements, locate the recognition area of the user ticket image;
[0019] Filter the key fields to obtain the content in the user ticket image.
[0020] Optionally, after the step of filtering the key fields to obtain the content in the user ticket image, the method further includes:
[0021] When any of the text blocks is detected to include a preset line of text, the image origin of the user ticket image is obtained;
[0022] Based on the image origin, the distance between each line of text in the text block and other lines of text is detected sequentially to obtain the corresponding distance relationship;
[0023] Based on the distance relationship, sort each line of text to obtain the sorted content.
[0024] Optionally, after the step of obtaining the template reference area and the template recognition area based on the template ticket image, the method further includes:
[0025] Based on the template reference area and the template recognition area, generate and encapsulate the corresponding post-processing rules;
[0026] The step of identifying the user elements based on the template and obtaining the recognition result of the user ticket image includes:
[0027] Based on the template, the user elements of the text block are extracted in a structured manner using the post-processing rules to obtain the recognition result of the user ticket image.
[0028] Optionally, the step of obtaining the user ticket image includes:
[0029] The user ticket image is converted to grayscale and edges are detected to obtain an edge image;
[0030] Detect several straight lines in the edge image and obtain the mode of the straight lines;
[0031] Based on the mode, the user ticket image is rotated and corrected to generate a corresponding black border;
[0032] Fill in the black borders to obtain the tilt-corrected image of the user ticket.
[0033] Optionally, after the step of recognizing the user ticket image and obtaining the corresponding user elements, the method further includes:
[0034] The key fields are sequentially checked to see if they match the user elements. The key fields correspond to a preset image type and include at least one key field.
[0035] If the key field matches the user element, then the key field is marked;
[0036] After traversing the key fields, the number of times the key fields are marked is counted to obtain the matching degree between the user ticket image and the key fields;
[0037] Based on the matching degree, the image type of the user ticket image is obtained.
[0038] This application also proposes a ticket recognition device, which includes:
[0039] The image acquisition module is used to acquire images of user tickets;
[0040] The image recognition module is used to recognize the user ticket image and obtain the corresponding user elements;
[0041] The template invocation module is used to invoke the corresponding template from the preset template interface library according to the user elements. The template is configured based on the preset template reference area and template recognition area.
[0042] The element recognition module is used to recognize the user elements based on the template and obtain the recognition result of the user ticket image.
[0043] This application also proposes a terminal device, which includes a memory, a processor, and a ticket recognition program stored in the memory and executable on the processor. When the ticket recognition program is executed by the processor, it implements the steps of the ticket recognition method described above.
[0044] This application also proposes a computer-readable storage medium storing a ticket recognition program, which, when executed by a processor, implements the steps of the ticket recognition method described above.
[0045] The ticket recognition method, apparatus, terminal device, and storage medium proposed in this application acquire user ticket images; recognize the user ticket images to obtain corresponding user elements; call corresponding templates from a preset template interface library based on the user elements, the templates being configured based on a preset template reference area and a template recognition area; and recognize the user elements based on the templates to obtain the recognition result of the user ticket images. This allows for the rapid recognition of different types of user ticket images to obtain corresponding ticket information. In other words, by configuring corresponding templates based on the reference area and recognition area, calling corresponding templates based on user ticket images, and recognizing elements, the recognized ticket information can be obtained. This effectively recognizes different types of tickets, reduces the difficulty of ticket information processing and the cost of ticket template development, and improves the efficiency of ticket recognition. Attached Figure Description
[0046] Figure 1 This is a schematic diagram of the functional modules of the terminal equipment to which the ticket recognition device belongs in this application belongs;
[0047] Figure 2 This is a flowchart illustrating a first exemplary embodiment of the ticket recognition method of this application;
[0048] Figure 3 This is a flowchart illustrating a second exemplary embodiment of the ticket recognition method of this application;
[0049] Figure 4 This is a flowchart illustrating the ticket recognition method of this application;
[0050] Figure 5 This is a flowchart illustrating a third exemplary embodiment of the ticket recognition method of this application;
[0051] Figure 6 This is a flowchart illustrating a fourth exemplary embodiment of the ticket recognition method of this application;
[0052] Figure 7 The flowchart shows the sorting algorithm involved in the ticket recognition method of this application.
[0053] Figure 8 This is a flowchart illustrating a fifth exemplary embodiment of the ticket recognition method of this application;
[0054] Figure 9 This is a swimlane diagram of the ticket recognition method in this application;
[0055] Figure 10This is a flowchart illustrating the sixth exemplary embodiment of the ticket recognition method of this application;
[0056] Figure 11 This is a flowchart illustrating the seventh exemplary embodiment of the ticket recognition method of this application;
[0057] Figure 12 This is a flowchart illustrating the ticket type identification method of this application.
[0058] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0059] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.
[0060] The main solution of this application embodiment is as follows: acquiring user ticket images; recognizing the user ticket images to obtain corresponding user elements; calling the corresponding template in the preset template interface library according to the user elements, the template being configured based on the preset template reference area and template recognition area; recognizing the user elements based on the template to obtain the recognition result of the user ticket image, quickly recognizing different types of user ticket images to obtain corresponding ticket information, that is, configuring the corresponding template based on the reference area and recognition area, calling the corresponding template and recognizing the elements according to the user ticket image, and then obtaining the recognized ticket information, which can effectively recognize different types of tickets, reduce the difficulty of ticket information processing and the cost of ticket template development, and improve the efficiency of ticket recognition.
[0061] This application embodiment takes into account that Baidu launched a custom template text recognition tool (iOCR) in 2018, enabling users to customize recognition templates for specific styles of invoices and cards through graphical operations, thereby achieving automated data entry. Its application scope is quite wide, such as medical document recognition, financial document recognition, and certificate recognition. Overall, it can perform structured recognition of invoices and documents with relatively uniform formats, realizing the digitization of various cards, certificates, and documents.
[0062] Currently, Megvii's Face++ AI Open Platform has launched a custom template text recognition function. Through self-service template creation, recognition rules are generated, and combined with automatic classification, automated and convenient data acquisition and input are achieved, supporting the recognition of various invoices, documents, cards, and certificates. After creating templates with simple annotations, users can call its API interface to batch recognize similar image content information and obtain predefined output results. Huawei has developed a custom template OCR (Custom OCR) function, which allows users to customize recognition templates, specify key fields to be recognized, and achieve automatic recognition and structured extraction of user-specific image formats. It supports a wide range of formats and allows for the customization of independent templates for each type of document, specifying the key areas to be recognized, thus supporting automatic recognition and structured extraction of different format document and invoice images. Similarly, users can operate through a visual interface, specify the recognition area, complete the template design, and call the service interface.
[0063] However, due to the diverse business types involved in the banking system, the formats of various certificates, bills, and documents differ, and there are no fixed characteristics between different data. Furthermore, various bank documents contain sensitive data involving user privacy, and external non-bank companies require extensive training before providing models. If the training data does not meet real-world usage scenarios, the accuracy will be significantly reduced in actual use. Moreover, these companies only provide API interfaces to users; during communication, images need to be uploaded to the servers deployed on their interfaces. Therefore, for the banking industry, using external API interface recognition services carries the risk of data leakage.
[0064] Therefore, the solution proposed in this application addresses the practical problem of effectively identifying different types of tickets and combines the text detection and recognition capabilities of Optical Character Recognition (OCR) technology to design a custom ticket recognition method based on OCR. This method enables universal ticket recognition functionality and allows for full-scenario adaptation. It supports the creation of templates for any fixed-format cards, receipts, and other tickets involved in business scenarios. This method can be widely used in traditional card and document review, information entry, and other business operations, significantly reducing manpower and time costs and bringing more efficient and high-quality services.
[0065] Specifically, refer to Figure 1 , Figure 1 This is a functional module diagram of the terminal device to which the ticket recognition device of this application belongs. The ticket recognition device can be an independent device capable of ticket recognition and template configuration, and can be implemented on the terminal device in hardware or software form. The terminal device can be a smart mobile terminal with data processing capabilities, such as a mobile phone or tablet computer, or a fixed terminal device or server with data processing capabilities.
[0066] In this embodiment, the terminal device to which the ticket recognition device belongs includes at least an output module 110, a processor 120, a memory 130, and a communication module 140.
[0067] The memory 130 stores the operating system and ticket recognition program. The ticket recognition device can acquire user ticket images; recognize user ticket images to obtain corresponding user elements; call corresponding templates from a preset template interface library based on user elements (the templates are configured based on a preset template reference area and template recognition area); and based on the templates, recognize user elements to obtain the recognition results of the user ticket image, etc., all of which are stored in the memory 130. The output module 110 can be a display screen, etc. The communication module 140 can include a WIFI module, a mobile communication module, and a Bluetooth module, etc., and communicates with external devices or servers through the communication module 140.
[0068] When the ticket recognition program in memory 130 is executed by the processor, it performs the following steps:
[0069] Obtain user ticket image;
[0070] Identify the user ticket image to obtain the corresponding user elements;
[0071] Based on the user elements, the corresponding template is called from the preset template interface library. The template is configured based on the preset template reference area and template recognition area.
[0072] Based on the template, the user elements are identified to obtain the recognition result of the user ticket image.
[0073] Furthermore, when the ticket recognition program in memory 130 is executed by the processor, it also performs the following steps:
[0074] Obtain template ticket images;
[0075] Based on the template ticket image, the template reference area and the template recognition area are obtained, and the template reference area and the template recognition area each include at least one;
[0076] Based on the template reference area and the template recognition area, the key fields and template content of the template ticket image are obtained respectively, and used as template elements;
[0077] Based on the template elements, the template is determined and stored in the template interface library.
[0078] Furthermore, when the ticket recognition program in memory 130 is executed by the processor, it also performs the following steps:
[0079] Based on the user elements and the template elements, the text block scaling ratio of the user ticket image is obtained;
[0080] Based on the scaling ratio of the text block and the user elements, locate the recognition area of the user ticket image;
[0081] Filter the key fields to obtain the content in the user ticket image.
[0082] Furthermore, when the ticket recognition program in memory 130 is executed by the processor, it also performs the following steps:
[0083] When any of the text blocks is detected to include a preset line of text, the image origin of the user ticket image is obtained;
[0084] Based on the image origin, the distance between each line of text in the text block and other lines of text is detected sequentially to obtain the corresponding distance relationship;
[0085] Based on the distance relationship, sort each line of text to obtain the sorted content.
[0086] Furthermore, when the ticket recognition program in memory 130 is executed by the processor, it also performs the following steps:
[0087] Based on the template reference area and the template recognition area, generate and encapsulate the corresponding post-processing rules;
[0088] Furthermore, when the ticket recognition program in memory 130 is executed by the processor, it also performs the following steps:
[0089] Based on the template, the user elements of the text block are extracted in a structured manner using the post-processing rules to obtain the recognition result of the user ticket image.
[0090] Furthermore, when the ticket recognition program in memory 130 is executed by the processor, it also performs the following steps:
[0091] The user ticket image is converted to grayscale and edges are detected to obtain an edge image;
[0092] Detect several straight lines in the edge image and obtain the mode of the straight lines;
[0093] Based on the mode, the user ticket image is rotated and corrected to generate a corresponding black border;
[0094] Fill in the black borders to obtain the tilt-corrected image of the user ticket.
[0095] Furthermore, when the ticket recognition program in memory 130 is executed by the processor, it also performs the following steps:
[0096] The key fields are sequentially checked to see if they match the user elements. The key fields correspond to a preset image type and include at least one key field.
[0097] If the key field matches the user element, then the key field is marked;
[0098] After traversing the key fields, the number of times the key fields are marked is counted to obtain the matching degree between the user ticket image and the key fields;
[0099] Based on the matching degree, the image type of the user ticket image is obtained.
[0100] This embodiment, through the above-described scheme, specifically acquires user ticket images; identifies the user ticket images to obtain corresponding user elements; calls corresponding templates from a preset template interface library based on the user elements, the templates being configured based on a preset template reference area and a template recognition area; and identifies the user elements based on the templates to obtain the recognition results of the user ticket images. This allows for the rapid identification of different types of user ticket images to obtain corresponding ticket information. In other words, by configuring corresponding templates based on the reference area and recognition area, calling the corresponding templates based on the user ticket images, and identifying the elements, the identified ticket information can be obtained. This effectively identifies different types of tickets, reduces the difficulty of ticket information processing and the cost of ticket template development, and improves the efficiency of ticket recognition.
[0101] Based on, but not limited to, the terminal device architecture described above, this application proposes method embodiments.
[0102] Reference Figure 2 , Figure 2 This is a flowchart illustrating a first exemplary embodiment of the ticket recognition method of this application. The ticket recognition method includes:
[0103] Step S210: Obtain the user's ticket image;
[0104] The subject executing the method in this embodiment can be a ticket recognition device, a ticket recognition terminal device, or a server. This embodiment takes a ticket recognition device as an example. The ticket recognition device can be integrated into terminal devices such as smartphones and tablets with data processing functions.
[0105] This embodiment mainly enables the recognition of tickets, especially different types of tickets, reducing the manpower and time costs of ticket recognition, thereby improving the efficiency of ticket recognition.
[0106] Because the banking system involves a wide variety of business operations, and various certificates, bills, and documents have different formats and no fixed characteristics between different data, this application addresses the practical problem of effectively identifying different types of documents. It combines the text detection and recognition capabilities of Optical Character Recognition (OCR) technology to design a custom document recognition method based on OCR. This method achieves universal document recognition functionality and can be adapted to all scenarios. Specifically, it supports the creation of templates for any fixed-format cards, bills, and other documents involved in various business scenarios. It can be widely applied in traditional card verification, information entry, and other business operations, significantly reducing manpower and time costs and providing more efficient and high-quality services. Custom document recognition refers to users defining their desired document templates on the platform, configuring template reference areas and marking the required recognition areas, and using the platform's OCR model detection and recognition capabilities to obtain the recognition results of the custom documents.
[0107] Step S220: Identify the user ticket image and obtain the corresponding user elements;
[0108] Specifically, user elements include variable and fixed elements in the user ticket image, such as ticket keywords and specific ticket information. To quickly recognize tickets, an OCR model can be configured to recognize the user ticket image. That is, the platform provides underlying image preprocessing, detection models, and underlying recognition models, allowing users to choose the appropriate detection and recognition models. Multiple combinations of detection and recognition models are supported, such as digit detection and recognition, English detection and recognition, and Chinese-English-numerical detection and recognition. Image preprocessing corrects the user-uploaded image; the detection model performs full-text detection, returning text blocks to the backend for processing; and the recognition model recognizes the text blocks detected by the detection model and returns them to the backend for further processing.
[0109] Step S230: Based on the user elements, call the corresponding template from the preset template interface library. The template is configured based on the preset template reference area and template recognition area.
[0110] Specifically, the template reference area corresponds to the key fields in the template image and is a fixed element; the template recognition area corresponds to the content in the template image, i.e., the specific information of the ticket, and is a variable element. The configured OCR model can achieve two functions: Function 1: Automatically calls the detection and recognition models to return text areas and text content, which is used to automatically display the text area and return the selected text when the user selects in the configured reference area and recognition area, eliminating the need for manual selection and input, thus speeding up the configuration process; Function 2: After the model is configured, it can automatically associate with the detection and recognition models needed for image recognition after publication. If it is clear that the images to be recognized are all standardized images, horizontally untilted, image preprocessing can be omitted, speeding up the processing flow. The template interface library stores interfaces for different types of ticket templates. By calling the corresponding template interface, templates are obtained, enabling the recognition of various types of tickets, cards, and documents related to checks, freezes, and deductions, with particularly outstanding recognition results for checks, signature cards, and authorization letters, which are frequently used internally by banks. Meeting users' personalized OCR needs and achieving structured recognition and automation of business scenarios can effectively reduce enterprise labor costs and control business risks.
[0111] Step S240: Based on the template, identify the user elements and obtain the recognition result of the user ticket image.
[0112] Specifically, the recognition results include the content and / or key fields of the ticket. Custom ticket technology provides users with the ability to create customized templates for recognition, enabling them to easily and quickly identify image materials with similar elements, extract the text information contained in the images, and then complete subsequent business tasks. It effectively replaces a large amount of simple, mechanical work faced by business personnel, achieving automated processing through OCR recognition and personalized template configuration, thereby reducing operational costs; at the same time, it effectively improves code reuse, allowing technical personnel to focus more on the development and application of new technologies.
[0113] This embodiment, through the above-described scheme, specifically acquires user ticket images; identifies the user ticket images to obtain corresponding user elements; calls corresponding templates from a preset template interface library based on the user elements, the templates being configured based on a preset template reference area and a template recognition area; and identifies the user elements based on the templates to obtain the recognition results of the user ticket images. This allows for the rapid identification of different types of user ticket images to obtain corresponding ticket information. In other words, by configuring corresponding templates based on the reference area and recognition area, calling the corresponding templates based on the user ticket images, and identifying the elements, the identified ticket information can be obtained. This effectively identifies different types of tickets, reduces the difficulty of ticket information processing and the cost of ticket template development, and improves the efficiency of ticket recognition.
[0114] Reference Figure 3, Figure 3 This is a flowchart illustrating a second exemplary embodiment of the ticket recognition method of this application. Based on the above... Figure 2 In the embodiment shown, step S230, before calling the corresponding template from the preset template interface library according to the user elements, and before the template is configured based on the preset template reference area and template recognition area, further includes:
[0115] Step S310: Obtain the template ticket image;
[0116] Because various bank documents involve sensitive data related to user privacy, and external non-bank companies need to conduct extensive training before providing models, the accuracy will be greatly reduced in actual use if the training data cannot meet the real-world usage scenarios. Furthermore, external companies provide API interfaces to users, and during communication, images need to be uploaded to the server where the interface is deployed. Therefore, for banks, using external API interface recognition services carries the risk of data leakage.
[0117] Therefore, in this embodiment, the user selects to create a new custom ticket recognition template. The template configuration requires the user to upload a selected ticket image as the template ticket image. The OCR model reads a template ticket image, and the user completes the template customization by setting the template reference area and template recognition area within the template ticket image.
[0118] It should be noted that template customization can involve several different types of template customization. There can be one or more template images of the same type, and the template ticket image and the user ticket image in subsequent operations must maintain the same format and have elements that remain unchanged in the data of subsequent operations, namely key fields.
[0119] In addition, before configuring the template reference area and template recognition area, OCR model configuration can be performed, including image preprocessing, detection model, and underlying recognition model. The principle and implementation process of OCR model configuration in this embodiment are described in the first embodiment above, and will not be repeated here.
[0120] Step S320: Based on the template ticket image, obtain the template reference area and the template recognition area, wherein the template reference area and the template recognition area each include at least one;
[0121] Specifically, during the template configuration phase, multiple configuration reference areas and configuration recognition areas can be set, and their relative distance ratios can be saved. When a user configures a reference area, a general OCR interface is automatically invoked to return the full text content and text coordinates in advance. The user can then directly and intelligently select text areas, quickly highlighting and selecting continuous text blocks, and automatically filling the recognized content into the field names. This eliminates the need for users to manually select text blocks and enter the selected text content during configuration. Users can revert to the previous step at any time during template creation, and the template supports gradual modifications and adjustments after completion, eliminating the need for a complete redesign and accelerating template development.
[0122] When configuring the reference area, the system generates default text boxes and full-text information. Users can select the text boxes and text content returned by the system, or perform intelligent selection (the system automatically returns the text block clicked by the user). This step can speed up the configuration of the reference area. Alternatively, users can manually select the reference area with the mouse or manually enter the content of the reference area; the reference area is used to locate the elements to be identified in the template ticket image.
[0123] When configuring the recognition area, users can customize the region of elements to be recognized. Users can also perform the aforementioned intelligent selection operation to speed up manual selection and data entry, thereby determining the field content returned by the publishing interface. This improves the configuration experience and allows users to manually select the recognition area to complete personalized recognition area configuration.
[0124] It should be noted that, in this embodiment, selecting four or more template reference areas is preferred; in other embodiments, four or fewer may also be used.
[0125] Step S330: Based on the template reference area and the template recognition area, obtain the key fields and template content of the template ticket image, and use them as template elements;
[0126] Specifically, after configuring the template reference area and template recognition area, the process proceeds to post-processing rule encapsulation. Post-processing rule code is automatically generated based on the full-text recognition results and the user-configured reference and recognition areas. This design incorporates template configuration algorithms, element recognition algorithms, and sorting algorithms. By encapsulating these algorithms into post-processing rules, the entire process of custom ticket recognition can be automated.
[0127] Step S340: Determine the template based on the template elements and store it in the template interface library.
[0128] Specifically, the system displays the recognition results. The system calls post-processing rules and returns the recognition results of the configured elements in key-value pair format. One implementation involves the system checking whether the recognition results match the template elements in the template image; if both match successfully, the template is deemed usable. Another implementation allows users to determine the usability of the template based on the recognition results. If usable, the template is saved and published; if modifications are needed, reconfiguration is required. Alternatively, users can choose to save the template without publishing it, revising it later for maintenance.
[0129] refer to Figure 4 , Figure 4 This is a flowchart illustrating the ticket recognition method described in this application. The system publishes a custom ticket recognition interface. After a user completes the creation of a new custom ticket recognition template, they can directly use this interface. By uploading a ticket image with the same elements (content) as the template ticket image, the system automatically calls the post-processing rules to recognize the elements (key fields) and returns the results to the user.
[0130] This embodiment, through the above-described scheme, specifically involves acquiring a template ticket image; based on the template ticket image, obtaining a template reference area and a template recognition area, each including at least one; obtaining key fields and template content of the template ticket image according to the template reference area and template recognition area, and using them as template elements; and determining the template based on the template elements and storing it in the template interface library. By reading the template ticket image, obtaining the template reference area and template recognition area, and configuring the corresponding template, the potential ticket data leakage problem in commercial OCR applications can be avoided, improving the security of ticket information.
[0131] Reference Figure 5 , Figure 5 This is a flowchart illustrating a third exemplary embodiment of the ticket recognition method of this application. Based on the above... Figure 3 In the illustrated embodiment, step S240, based on the template, identifies the user elements to obtain the recognition result of the user ticket image, including:
[0132] Step S510: Based on the user elements and the template elements, obtain the text block scaling ratio of the user ticket image;
[0133] Specifically, in the image to be recognized stage, the relative positions of multiple reference areas are obtained by using OCR text detection and text recognition technology, and the distance ratio of the relative positions of multiple reference areas in the current image to be recognized is calculated. The ratio is then mapped to the distance ratio between the template reference area and the template recognition area obtained during template configuration, so as to achieve accurate positioning of the recognition area of the image to be recognized and quickly obtain the content field of the recognition area.
[0134] The template elements include: first, listing the elements of the reference area (denoted as ref) and the recognition area (denoted as rec) text blocks, and then calculating them using the coordinate values of the text blocks (the horizontal and vertical coordinates are denoted as X and Y respectively; the coordinate value of the lower left corner is denoted as LD; the coordinate value of the upper left corner is denoted as LU; the coordinate value of the lower right corner is denoted as RD; and the coordinate value of the upper right corner is denoted as RU).
[0135] Single character height (denoted as H) ref ):
[0136] Text box width (denoted as W) rec ):
[0137] Minimum distance between the reference region and the recognition region (denoted as DIST) min ):
[0138] The height difference between each text block (denoted as δ) h );
[0139] The width difference between each text block (denoted as δ) w );
[0140] Step S520: Locate the recognition area of the user ticket image based on the scaling ratio of the text block and the user elements;
[0141] Specifically, the calculation of elements for selecting the recognition area when a user uses a template for recognition is described in detail. First, the scaling ratio of the user's ticket image is calculated. The user elements in the user's ticket image include:
[0142] Single word height (denoted as USER) h );
[0143] Text box width (denoted as USER) w );
[0144] Calculate the scaling ratio of text blocks in the user ticket image:
[0145] Height scaling (denoted as RATIO) H RATIO H =USER h ÷H ref ;
[0146] Width scaling (denoted as RAATIO) W RATIO W =USER w ÷W rec ;
[0147] Locate the text within the recognition area of the user's ticket image:
[0148] Height positioning (denoted as H) rec )H rec =USER h +δ h ×RATIO H ;
[0149] Width positioning (denoted as W) rec W rec =USER w +δ w ×RATIO W ;
[0150] Step S530: Filter the key fields to obtain the content in the user ticket image.
[0151] Specifically, the recognition region is then selected based on the overlap (Intersection over Union (IoU) or Non-maximum Suppression (NMS)), key fields are filtered using regular expressions, and the recognition results are output.
[0152] This embodiment, through the above-described scheme, specifically obtains the text block scaling ratio of the user ticket image based on the user elements and the template elements; locates the recognition area of the user ticket image based on the text block scaling ratio and the user elements; and filters the key fields to obtain the content in the user ticket image. By recognizing user elements and template elements to obtain the text block scaling ratio, and locating the recognition area of the user ticket image based on the text block ratio, the accuracy of ticket recognition can be improved.
[0153] Reference Figure 6 , Figure 6 This is a flowchart illustrating a fourth exemplary embodiment of the ticket recognition method of this application. Based on the above... Figure 5 In the illustrated embodiment, step S530, filtering the key fields to obtain the content in the user ticket image, includes:
[0154] Step S610: When any of the text blocks is detected to include a preset line of text, the image origin of the user ticket image is obtained.
[0155] Step S620: Based on the image origin, the distance between each line of text in the text block and other lines of text is detected sequentially to obtain the corresponding distance relationship;
[0156] Step S630: Sort each line of text according to the distance relationship to obtain the sorted content.
[0157] Specifically, when multi-line recognition is involved, the text blocks need to be sorted. The algorithm designed in this scheme is shown in the figure below.
[0158] refer to Figure 7, Figure 7 This is a flowchart of the sorting algorithm involved in the ticket recognition method of this application. The sorting algorithm is used to correctly match the recognized multi-line text blocks. The detailed algorithm for this step is as follows:
[0159] Step 1: Locate the origin of the user ticket image, find the starting text block of the multi-line text block, and define the text block as the first text block in the first line; for example, select the coordinate value of the upper left corner of the user ticket image as the origin.
[0160] Step 2: Create three new list lists. One list, List1, is used as a global variable storage list. The other two lists, List2 and List3, are used as temporary variable storage lists to store the text blocks of the current line and other lines, respectively.
[0161] Step 3: Calculate the maximum vertical distance from the bottom of the first text block to the origin (this distance is calculated using the ordinate), denoted as Y1; compare the ordinate of the top-left corner of each of the other text blocks with Y1 to obtain the distance relationship, denoted as Y2; if Y2 is less than Y1, it is determined that the text block is in the same row as the first text block and stored in the current row list. If Y2 is greater than Y1, it is determined that the text block is not in the same row, and the text block is stored in another row list, and the next text block is processed.
[0162] Step 4: Loop through the text blocks in the same line until there are no text blocks whose top-left corner y-coordinate is less than Y1. Store the contents of the current line list in the global variable list and clear the contents of the current line list and other line lists.
[0163] Step 5: Recursively run Steps 3 and 4 above to sort the last N lines of text blocks until every multi-line text block has been traversed, and then end the recursive run.
[0164] Step six: After the recursive operation is completed, the text block is split into lines. At this point, the horizontal coordinate values of each line of text block in the global variable list are sorted left and right to complete the final multi-line text matching.
[0165] This embodiment, through the above-described scheme, specifically obtains the image origin of the user ticket image when any of the text blocks is detected to include a preset line of text; based on the image origin, the distance between each line of text in the text block and other lines of text is sequentially detected to obtain the corresponding distance relationship; according to the distance relationship, each line of text is sorted to obtain the sorted content. By sorting multiple lines of text blocks, technical problems such as displacement, missed detection, and formatting errors in the recognition results can be solved, improving the accuracy of ticket recognition and thus improving the efficiency of ticket recognition.
[0166] Reference Figure 8 , Figure 8This is a flowchart illustrating a fifth exemplary embodiment of the ticket recognition method of this application. Based on the above... Figure 3 In the embodiment shown, after obtaining the template reference area and the template recognition area based on the template ticket image in step S320, the method further includes:
[0167] Step S810: Generate and encapsulate corresponding post-processing rules based on the template reference area and the template recognition area;
[0168] Specifically, to reduce the need for technicians to develop different types of ticket templates, this application provides an OCR interface to business users, allowing them to define OCR post-processing rules, which are then automatically encapsulated into post-processing rules. These post-processing rules are used to automatically call the corresponding template to identify elements in the user's ticket image, thereby obtaining the recognition result.
[0169] Step S240, which involves identifying the user elements based on the template to obtain the recognition result of the user ticket image, includes:
[0170] Step S820: Based on the template, the user elements of the text block are extracted in a structured manner using the post-processing rules to obtain the recognition result of the user ticket image.
[0171] Specifically, refer to Figure 9 , Figure 9 This is a swimlane diagram illustrating the ticket recognition method of this application. After a user completes the creation of a custom ticket recognition template, this interface can be used directly when recognizing tickets. The system automatically calls post-processing rules to recognize the elements (key fields) by having the user upload a ticket image with the same elements (content) as the template image, and returns the results to the user. This reduces workload and unnecessary communication time for both parties, improving work efficiency.
[0172] This embodiment, through the above-described scheme, specifically generates and encapsulates corresponding post-processing rules based on the template reference area and the template recognition area; based on the template, the user elements of the text block are structurally extracted using the post-processing rules to obtain the recognition result of the user ticket image. Generating and encapsulating corresponding post-processing rules based on the template reference area and template recognition area allows business users to automatically complete element recognition of the ticket image by calling these post-processing rules during subsequent ticket image recognition, obtaining the corresponding recognition result. This solves the technical problem of technicians repeatedly developing different types of ticket templates, reduces development and labor costs, and thus improves the efficiency of ticket recognition.
[0173] Reference Figure 10 , Figure 10 This is a flowchart illustrating a sixth exemplary embodiment of the ticket recognition method of this application. Based on the above... Figure 2 In the embodiment shown, step S210, acquiring the user ticket image, includes:
[0174] Step S1010: Convert the user ticket image to grayscale and detect its edges to obtain an edge image;
[0175] Because of the different angles at which user tickets are photographed, the user ticket images read by the OCR model have certain deformations and / or tilts, causing a shift in the relative position between the reference area and the recognition area. Therefore, this embodiment of the application employs a text image tilt correction method to correct ticket images that have deformations and / or tilts.
[0176] It should be noted that in step S310 above, when obtaining the template ticket image, if deformation and / or tilt are detected in the template ticket image, the steps of this application embodiment can also be performed to correct the image tilt.
[0177] First, the user's ticket image is read and converted to grayscale to obtain a grayscale image. Then, the edges of the grayscale image are detected using the Canny operator to obtain an edge image.
[0178] Step S1020: Detect several straight lines in the edge image and obtain the mode of the straight lines;
[0179] Then, Hough transform is performed on the edge image to detect lines, obtaining all lines in the image; then, the detected lines are sorted in descending order of their lengths, and the top 20 lines by length are retained, and the mode of the directions of these 20 lines is calculated; wherein, in this embodiment, retaining the top 20 lines by length is preferred, but in other embodiments, it can be more than 20 or less.
[0180] Step S1030: Based on the mode, rotate and correct the user ticket image to generate a corresponding black border;
[0181] Then, the initial user ticket image is rotated and corrected according to the mode of the straight line, so that the corresponding black border appears in the initial user ticket image.
[0182] Step S1040: Fill in the black borders to obtain the tilt-corrected image of the user ticket.
[0183] Finally, the black borders appearing in the rotated and corrected user ticket image are filled in to obtain the corrected user ticket image.
[0184] This embodiment, through the above-described scheme, specifically involves converting the user ticket image to grayscale and detecting edges to obtain an edge image; detecting several straight lines in the edge image to obtain the mode of the lines; rotating and correcting the user ticket image based on the mode to generate a corresponding black border; and filling the black border to obtain the tilt-corrected user ticket image. By correcting the tilt of the initial user ticket image, the technical problem of deformation and / or tilt in OCR model reading user ticket images can be solved, improving the accuracy of ticket recognition.
[0185] Reference Figure 11 , Figure 11 This is a flowchart illustrating the seventh exemplary embodiment of the ticket recognition method of this application. Based on the above... Figure 3 In the embodiment shown, after obtaining the user ticket image in step S210, the method further includes:
[0186] Step S1110: Sequentially detect whether the key fields match the user elements. The key fields correspond to a preset image type, and the key fields include at least one.
[0187] Specifically, in order for users to define the types of samples they need to identify on the platform, the platform provides a custom classification system that extracts only samples of the custom type from all samples for identification, thereby obtaining the corresponding classification and identification results.
[0188] Before detecting the type of user ticket image, users can define the ticket type and expand the keywords that will appear in each type of document. Additionally, for non-standard documents, definitions need to be based on business requirements and a knowledge base.
[0189] When detecting the type of user ticket image, OCR recognition is called to return all the text in the image. An absolute matching strategy is used to match the key fields of each type of ticket, and the matched key fields are scored. Finally, the type corresponding to the key field with the higher score is output.
[0190] Step S1120: If the key field matches the user element, then the key field is marked.
[0191] Step S1130: After traversing the key fields, count the number of times the key fields are marked to obtain the matching degree between the user ticket image and the key fields;
[0192] Step S1140: Based on the matching degree, obtain the image type of the user ticket image.
[0193] Specifically, matching is used to determine the match based on key fields, calculate the percentage of matches that hit the key fields as the match score, and finally output the match type. The detailed algorithm for this step is as follows:
[0194] First, the key fields are traversed, the number of key fields matched in the general recognition text is calculated and counted, and the matched key fields are marked.
[0195] Then, the matching degree is calculated as follows: if the key field is matched, it is marked and counted as 1. It is not accumulated. Finally, the total number of matched key fields is counted as the total number of key fields.
[0196] Finally, the type of the user ticket image is determined, and the matching degree is sorted and compared to determine the type with the highest matching degree as the type of user ticket image.
[0197] Specifically, refer to Figure 12 , Figure 12 This is a flowchart illustrating the ticket type identification process of the ticket recognition method in this application. This allows for quick and accurate filtering of user-defined sample types and automatic classification of samples that match user configurations, thereby reducing the workload of manually selecting target samples from a massive dataset.
[0198] This embodiment, through the above scheme, specifically detects whether the key fields match the user elements sequentially. Each key field corresponds to a preset image type, and each key field includes at least one. If a key field matches the user element, it is marked. After traversing the key fields, the number of times each key field is marked is counted to obtain the matching degree between the user ticket image and the key field. Based on the matching degree, the image type of the user ticket image is obtained. By configuring and hitting key fields, user ticket images are classified and recognized, achieving automated ticket classification and accurate acquisition and input of ticket information.
[0199] Furthermore, this application also proposes a ticket recognition device, which includes:
[0200] The image acquisition module is used to acquire images of user tickets;
[0201] The image recognition module is used to recognize the user ticket image and obtain the corresponding user elements;
[0202] The template invocation module is used to invoke the corresponding template from the preset template interface library according to the user elements. The template is configured based on the preset template reference area and template recognition area.
[0203] The element recognition module is used to recognize the user elements based on the template and obtain the recognition result of the user ticket image.
[0204] The principle and implementation process of ticket recognition in this embodiment are explained in the above embodiments and will not be repeated here.
[0205] Furthermore, this application also proposes a terminal device, which includes a memory, a processor, and a ticket recognition program stored in the memory and executable on the processor. When the ticket recognition program is executed by the processor, it implements the steps of the ticket recognition method described above.
[0206] Since this ticket recognition program employs all the technical solutions of all the aforementioned embodiments when executed by the processor, it possesses at least all the beneficial effects brought about by all the technical solutions of all the aforementioned embodiments, which will not be elaborated upon here.
[0207] Furthermore, embodiments of this application also propose a computer-readable storage medium storing a ticket recognition program, which, when executed by a processor, implements the steps of the ticket recognition method described above.
[0208] Since this ticket recognition program employs all the technical solutions of all the aforementioned embodiments when executed by the processor, it possesses at least all the beneficial effects brought about by all the technical solutions of all the aforementioned embodiments, which will not be elaborated upon here.
[0209] Compared to existing technologies, the ticket recognition method, apparatus, terminal device, and storage medium proposed in this application acquire user ticket images; recognize the user ticket images to obtain corresponding user elements; call corresponding templates from a preset template interface library based on the user elements, the templates being configured based on a preset template reference area and a template recognition area; and recognize the user elements based on the templates to obtain the recognition result of the user ticket images. This allows for the rapid recognition of different types of user ticket images to obtain corresponding ticket information. In other words, by configuring corresponding templates based on the reference area and recognition area, calling corresponding templates based on user ticket images, and recognizing elements, the recognized ticket information can be obtained. This effectively recognizes different types of tickets, reduces the difficulty of ticket information processing and the cost of ticket template development, and improves the efficiency of ticket recognition.
[0210] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0211] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0212] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, controlled terminal, or network device, etc.) to execute the methods of each embodiment of this application.
[0213] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A ticket recognition method, characterized in that, The ticket recognition method includes the following steps: Obtain user ticket image; Identify the user ticket image to obtain the corresponding user elements; Based on the user elements, the corresponding template is called from the preset template interface library. The template is configured based on the preset template reference area and template recognition area. The template reference area corresponds to the key fields in the template ticket image. Based on the template, the user elements are identified to obtain the recognition result of the user ticket image; The recognition result includes the content in the user ticket image; the step of recognizing the user elements based on the template to obtain the recognition result of the user ticket image includes: Based on the user elements and the template elements in the template, the scaling ratio of the text blocks in the user ticket image is obtained; Based on the scaling ratio of the text block and the user elements, locate the recognition area of the user ticket image; Filter the key fields to obtain the content in the user ticket image; The step of obtaining the text block scaling ratio of the user ticket image based on the user elements and the template elements in the template includes: Determine the elements of the template reference area and the text block of the template recognition area in the template elements; The height of a single character, the width of the text box, the height difference between each text block, and the width difference between each text block are calculated using the coordinate values of the text blocks. Based on the single character height and text box width in the template element, and the single character height and text box width in the user element, calculate the text block scaling ratio of the user ticket image. The text block scaling ratio includes the height scaling ratio and the width scaling ratio. The step of locating the recognition area of the user ticket image based on the scaling ratio of the text block and the user elements includes: Based on the height scaling ratio, the height difference between each text block, and the height of a single character in the user element, the text in the recognition area of the user ticket image is height-localized. Based on the width scaling ratio, the width difference between each text block, and the width of the text box in the user element, the text in the recognition area of the user ticket image is positioned by width. The steps for obtaining the user ticket image include: The user ticket image is converted to grayscale and edges are detected to obtain an edge image; Detect several straight lines in the edge image and obtain the mode of the straight lines; Based on the mode, the user ticket image is rotated and corrected to generate a corresponding black border; Fill in the black borders to obtain the tilt-corrected image of the user ticket. Before the step of calling the corresponding template from the preset template interface library based on the user elements, the method further includes: Obtain template ticket images; Based on the template ticket image, the template reference area and the template recognition area are obtained, and the template reference area and the template recognition area each include at least one; Based on the template reference area and the template recognition area, generate and encapsulate the corresponding post-processing rules; Based on the template reference area and the template recognition area, the key fields and template content of the template ticket image are obtained respectively, and used as template elements; Invoke the post-processing rules to return the configuration element identification results; If the detection result of the configuration element identification matches the template element, then the template is determined and stored in the template interface library based on the template element; After the step of filtering the key fields to obtain the content in the user ticket image, the method further includes: When any of the text blocks is detected to include a preset line of text, the image origin of the user ticket image is obtained; Based on the image origin, the distance between each line of text in the text block and other lines of text is detected sequentially to obtain the corresponding distance relationship; Based on the distance relationship, sort each line of text to obtain the sorted content; The steps of sequentially detecting the distance between each line of text in the text block and other lines of text based on the image origin to obtain the corresponding distance relationship, and sorting each line of text according to the distance relationship to obtain the sorted content include: Step 1: Locate the starting text block of the multi-line text block and define the text block as the first text block in the first line; Step 2: Create three new list lists. One list, List1, is used as a global variable to store the list. The other two lists, List2 and List3, are used as temporary variables to store the text blocks of the current line and other lines, respectively. Step 3: Calculate the maximum vertical distance from the bottom of the first text block to the image origin, denoted as Y1; compare the ordinate of the top left corner of other text blocks with Y1 to obtain the distance relationship, denoted as Y2; if Y2 is less than Y1, it is determined that it is in the same row as the first text block, and the text block is stored in the list List2 of the current row; if Y2 is greater than Y1, it is determined that it does not belong to the same row, the text block is stored in the list List3 of other rows, and the next text block is processed. Step 4: Loop through the text blocks in the same line until the top left corner of the text block is less than Y1. Store the contents of the current line of list List2 in the global variable storage list, and clear the contents of list List2 and list List3. Step 5: Recursively run Steps 3 and 4 above to sort the last N lines of text blocks until every multi-line text block has been traversed, and then end the recursive run. Step six: After the recursive operation ends, sort the text blocks left and right by the horizontal coordinate values of each line in the global variable storage list to obtain the sorted content.
2. The ticket recognition method as described in claim 1, characterized in that, The recognition result also includes key fields in the user ticket image; the step of recognizing the user elements based on the template to obtain the recognition result of the user ticket image further includes: Based on the template, the user elements of the text block are extracted in a structured manner using the post-processing rules to obtain the key fields of the user ticket image.
3. The ticket recognition method as described in claim 1, characterized in that, After the step of identifying the user ticket image and obtaining the corresponding user elements, the method further includes: The key fields are sequentially checked to see if they match the user elements. The key fields correspond to a preset image type and include at least one key field. If the key field matches the user element, then the key field is marked; After traversing the key fields, the number of times the key fields are marked is counted to obtain the matching degree between the user ticket image and the key fields; Based on the matching degree, the image type of the user ticket image is obtained.
4. A ticket recognition device, characterized in that, The ticket recognition device includes: The image acquisition module is used to acquire images of user tickets; The image recognition module is used to recognize the user ticket image and obtain the corresponding user elements; The template invocation module is used to invoke the corresponding template from the preset template interface library according to the user elements. The template is configured based on the preset template reference area and template recognition area. The template reference area corresponds to the key fields in the template ticket image. The element recognition module is used to recognize the user elements based on the template and obtain the recognition result of the user ticket image; The recognition result includes the content in the user's ticket image; The process of identifying the user elements based on the template and obtaining the recognition result of the user ticket image includes: Based on the user elements and the template elements in the template, the scaling ratio of the text blocks in the user ticket image is obtained; Based on the scaling ratio of the text block and the user elements, locate the recognition area of the user ticket image; Filter the key fields to obtain the content in the user ticket image; The step of obtaining the text block scaling ratio of the user ticket image based on the user elements and the template elements in the template includes: Determine the elements of the template reference area and the text block of the template recognition area in the template elements; The height of a single character, the width of the text box, the height difference between each text block, and the width difference between each text block are calculated using the coordinate values of the text blocks. Based on the single character height and text box width in the template element, and the single character height and text box width in the user element, calculate the text block scaling ratio of the user ticket image. The text block scaling ratio includes the height scaling ratio and the width scaling ratio. The step of locating the recognition area of the user ticket image based on the scaling ratio of the text block and the user elements includes: Based on the height scaling ratio, the height difference between each text block, and the height of a single character in the user element, the text in the recognition area of the user ticket image is height-localized. Based on the width scaling ratio, the width difference between each text block, and the width of the text box in the user element, the text in the recognition area of the user ticket image is positioned by width. The acquisition of the user ticket image includes: The user ticket image is converted to grayscale and edges are detected to obtain an edge image; Detect several straight lines in the edge image and obtain the mode of the straight lines; Based on the mode, the user ticket image is rotated and corrected to generate a corresponding black border; Fill in the black borders to obtain the tilt-corrected image of the user ticket. Before calling the corresponding template from the preset template interface library based on the user elements, the method further includes: Obtain template ticket images; Based on the template ticket image, the template reference area and the template recognition area are obtained, and the template reference area and the template recognition area each include at least one; Based on the template reference area and the template recognition area, generate and encapsulate the corresponding post-processing rules; Based on the template reference area and the template recognition area, the key fields and template content of the template ticket image are obtained respectively, and used as template elements; Invoke the post-processing rules to return the configuration element identification results; If the detection result of the configuration element identification matches the template element, then the template is determined and stored in the template interface library based on the template element; After filtering the key fields to obtain the content in the user ticket image, the process further includes: When any of the text blocks is detected to include a preset line of text, the image origin of the user ticket image is obtained; Based on the image origin, the distance between each line of text in the text block and other lines of text is detected sequentially to obtain the corresponding distance relationship; Based on the distance relationship, sort each line of text to obtain the sorted content; Based on the image origin, the distance between each line of text in the text block and other lines of text is detected sequentially to obtain the corresponding distance relationship; according to the distance relationship, each line of text is sorted to obtain the sorted content, including: Step 1: Locate the starting text block of the multi-line text block and define the text block as the first text block in the first line; Step 2: Create three new list lists. One list, List1, is used as a global variable to store the list. The other two lists, List2 and List3, are used as temporary variables to store the text blocks of the current line and other lines, respectively. Step 3: Calculate the maximum vertical distance from the bottom of the first text block to the image origin, denoted as Y1; compare the ordinate of the top left corner of other text blocks with Y1 to obtain the distance relationship, denoted as Y2; if Y2 is less than Y1, it is determined that it is in the same row as the first text block, and the text block is stored in the list List2 of the current row; if Y2 is greater than Y1, it is determined that it does not belong to the same row, the text block is stored in the list List3 of other rows, and the next text block is processed. Step 4: Loop through the text blocks in the same line until the top left corner of the text block is less than Y1. Store the contents of the current line of list List2 in the global variable storage list, and clear the contents of list List2 and list List3. Step 5: Recursively run Steps 3 and 4 above to sort the last N lines of text blocks until every multi-line text block has been traversed, and then end the recursive run. Step six: After the recursive operation ends, sort the text blocks left and right by the horizontal coordinate values of each line in the global variable storage list to obtain the sorted content.
5. A terminal device, characterized in that, The terminal device includes a memory, a processor, and a ticket recognition program stored in the memory and executable on the processor. When the ticket recognition program is executed by the processor, it implements the steps of the ticket recognition method as described in any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a ticket recognition program, which, when executed by a processor, implements the steps of the ticket recognition method as described in any one of claims 1-3.
Citation Information
Patent Citations
Self-defined bill recognition method and device, and medium
CN113989817A