Text recognition method, device, computer equipment and storage medium

Through the combination of YOLO model, generative adversarial network and line detection model, combined with the optical character recognition model, the problem of low text recognition efficiency caused by poor image quality in electronic documents is solved, and higher text recognition accuracy is achieved.

CN113807343BActive Publication Date: 2024-10-18PING AN TECH (SHENZHEN) CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202111106567.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-22
Publication Date
2024-10-18
Estimated Expiration
2041-09-22

AI Technical Summary

Technical Problem

In the existing technology, when the image quality in electronic documents is poor, the text recognition efficiency is low, and it is difficult to accurately identify the text information in the image.

Method used

The YOLO model is used to obtain the reference rectangular image of the text to be recognized, and the image is enhanced through the generative adversarial network to obtain the target rectangular image; based on the straight line detection model, the reference straight line is selected from the target rectangular image, the virtual underline is obtained, and the tilt angle of the line text image is determined. ; Finally, the optical character recognition model is used to recognize the line text image corresponding to the tilt angle.

Benefits of technology

It improves the accuracy of text recognition, enhances the ability to recognize text in low-quality images, and improves the efficiency of text detection in electronic documents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113807343B_ABST
    Figure CN113807343B_ABST
Patent Text Reader

Abstract

The present application relates to the field of artificial intelligence technology, and proposes a text recognition method, device, computer equipment and storage medium, wherein the method includes: obtaining a reference rectangular image corresponding to the text to be recognized based on a YOLO model; performing image enhancement on the reference rectangular image based on a generative adversarial network to obtain a target rectangular image; selecting a reference straight line from the target rectangular image based on a straight line detection model; obtaining a virtual underline of each line of text image in the target rectangular image; determining the inclination angle of the line of text image based on the virtual underline and the reference straight line; and performing text recognition on the line of text image corresponding to the inclination angle based on an optical character recognition model. The present application can improve the accuracy of text recognition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and mainly to a text recognition method, device, computer equipment and storage medium. Background Art

[0002] Currently, there is a need to detect text in images in many occasions. For example, images containing ID cards, vehicle registration certificates, driver's licenses or business cards are collected to detect text information such as names, numbers or positions in the images. However, the image quality corresponding to some electronic documents (such as Portable Document Format (PDF) documents, etc.) is poor, resulting in low text recognition efficiency. Summary of the invention

[0003] The embodiments of the present application provide a text recognition method, apparatus, computer device and storage medium, which can improve the accuracy of text recognition.

[0004] In a first aspect, an embodiment of the present application provides a method for character recognition, wherein:

[0005] Obtain a reference rectangular image corresponding to the text to be recognized based on the YOLO model;

[0006] Performing image enhancement on the reference rectangular image based on a generative adversarial network to obtain a target rectangular image;

[0007] Selecting a reference straight line from the target rectangular image based on a straight line detection model; obtaining a virtual underline of each line of text image in the target rectangular image;

[0008] Determining the tilt angle of the line text image based on the virtual underline and the reference straight line;

[0009] The text line image corresponding to the tilt angle is subjected to text recognition based on an optical character recognition model.

[0010] In a second aspect, an embodiment of the present application provides a text recognition device, wherein:

[0011] A processing unit is used to obtain a reference rectangular image corresponding to the text to be recognized based on the YOLO model; perform image enhancement on the reference rectangular image based on a generative adversarial network to obtain a target rectangular image; select a reference straight line from the target rectangular image based on a straight line detection model; obtain a virtual underline of each line of text image in the target rectangular image; and determine a tilt angle of the line of text image based on the virtual underline and the reference straight line;

[0012] A recognition unit is used to perform character recognition on the line text image corresponding to the tilt angle based on the optical character recognition model.

[0013] In a third aspect, an embodiment of the present application provides a computer device, comprising a processor, a memory, a communication interface, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the program includes instructions for some or all of the steps described in the first aspect.

[0014] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program enables a computer to execute to implement some or all of the steps described in the first aspect.

[0015] Implementing the embodiments of the present application will have the following beneficial effects:

[0016] After adopting the above-mentioned text recognition method, device, computer equipment and storage medium, first obtain the reference rectangular image corresponding to the text to be recognized based on the YOLO model. Then, based on the generative adversarial network, the reference rectangular image is enhanced to obtain the target rectangular image. Then, based on the straight line detection model, a reference straight line is selected from the target rectangular image, and a virtual underline of each line of text image in the target rectangular image is obtained. Then, based on the virtual underline and the reference straight line, the inclination angle of the line text image is determined. Finally, based on the optical character recognition model, text recognition is performed on the line text image corresponding to the inclination angle. In this way, the accuracy of text recognition can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] in:

[0019] Figure 1 A flowchart of a text recognition method provided in an embodiment of the present application;

[0020] Figure 2 A structural schematic diagram of a text recognition device provided in an embodiment of the present application;

[0021] Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0022] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. According to the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0023] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0024] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0025] The network architecture used in the embodiment of the present application includes a server and an electronic device. The embodiment of the present application does not limit the number of electronic devices and servers, and the server can provide services for multiple electronic devices at the same time. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms. The server may be implemented by a server cluster consisting of multiple servers.

[0026] The electronic device may be a personal computer (PC), a laptop or a smart phone, or an all-in-one machine, a handheld computer, a tablet computer (pad), a smart TV player terminal, a vehicle-mounted terminal or a portable device. The operating system of the electronic device on the PC side, such as an all-in-one machine, may include but is not limited to Linux system, Unix system, Windows series system (such as Windows XP, Windows 7, etc.), Mac OS X system (Apple computer operating system) and other operating systems. The operating system of the electronic device on the mobile side, such as a smart phone, may include but is not limited to Android system, IOS (Apple mobile phone operating system), Window system and other operating systems.

[0027] The electronic device can install and run applications, and the server can be a server corresponding to the application installed in the electronic device, providing application services for the application. Among them, the application can be a separately integrated application software, or a small program embedded in other applications, or a system on a web page, etc., which is not limited here. In an embodiment of the present application, the application can be a text recognition application, or an application with a text recognition function. The text recognition method provided in this application can be used in application scenarios such as image-to-text conversion, identity image authentication, intelligent diagnosis and treatment, or case reading for remote consultation.

[0028] For example, if a user uploads a target image through a text recognition application on an electronic device, the electronic device can recognize the text in the target image. Alternatively, the electronic device uploads the target image to a server, receives the recognition result transmitted by the server, and then displays the text corresponding to the recognition result on the electronic device.

[0029] For another example, when the server is reviewing a file, if it determines that there is an image of text to be recognized in the review file, the server will perform text recognition on the image to obtain the text in the image, and then review the review file based on the text.

[0030] The embodiment of the present application provides a method for character recognition, which can be performed by a character recognition device. The device can be implemented by software and / or hardware, and can generally be integrated in an electronic device, which can improve the accuracy of character recognition.

[0031] Please refer to Figure 1 , Figure 1 This is a flowchart of a text recognition method provided by the present application. Taking the method applied in a server as an example, it includes the following steps S101 to S106, wherein:

[0032] S101: Obtain a reference rectangular image corresponding to the text to be recognized based on the YOLO model.

[0033] The present application does not limit the text to be recognized, and the text to be recognized can be text in any image, or text involved in an electronic document, etc. The reference rectangular image is an image containing the text to be recognized, and can contain part of the text to be recognized. In a possible example, before step S101, the text recognition method can also include step S100: receiving a text recognition instruction of a target area sent by a user.

[0034] In the embodiment of the present application, the text recognition instruction is used to indicate the text at the target position for recognition. The text recognition instruction can be generated by the user selecting the target area and selecting the functional component of text recognition (for example, the "Convert to Text" tab, etc.). The target area can be a rectangle corresponding to the position from the position where the user drags the mouse to the position corresponding to the release of the mouse, or it can be the page area corresponding to the mouse or the entire area of ​​the current page.

[0035] Based on this, step S101 may include: locating the target area based on the YOLO model to obtain a reference rectangular image of the text to be recognized.

[0036] It can be understood that when browsing an electronic document, the user can send a text recognition instruction of the target area to the server so that the server can recognize the text in the target area. Before recognition, the target area can be located based on the YOLO model to obtain a reference rectangular image of the text to be recognized. In this way, the text in the target area specified in the text recognition instruction sent by the user can be recognized, which can improve the efficiency of YOLO positioning. After step S106 is executed, the step of sending the result of text recognition to the user can also be included.

[0037] The YOLO (You Only Look Once: Unified, Real-Time Object Detection) model is an end-to-end convolutional neural network that can predict the location and category of multiple objects at once. The advantages of the YOLO model are fast detection speed, lower background false detection rate than Region-Convolutional Neural Networks (R-CNN), and support for detection of non-natural images.

[0038] In an embodiment of the present application, the YOLO model is used to detect the position of the text to be recognized. Specifically, the image to be detected corresponding to the text to be recognized can be divided into images of uniform scale, for example, divided into S×S grids. B bounding boxes and confidence scores are predicted in each grid, as well as the probability values ​​of belonging to C categories. The confidence value represents the overlap (Intersection over Union, IOU) between the predicted bounding box and the actual bounding box, reflecting the confidence of the YOLO model in whether the box contains the target and the accuracy of its prediction of the box. If there is no target, the confidence value is zero. Each bounding box contains 4-dimensional coordinate information (x, y, w, h) and 1-dimensional confidence, and each grid outputs a 5×B+C dimensional vector. Among them, the (x, y) coordinate represents the center of the bounding box relative to the grid unit bounding box. (w, h) is predicted relative to the entire image.

[0039] In a possible example, before step S101, the following steps are also included: determining scene information of the text to be recognized; determining the size of the reference rectangular image and the recognition accuracy of the text to be recognized based on the scene information; and determining the YOLO model based on the size and the recognition accuracy.

[0040] In the embodiment of the present application, the scene information may include the title corresponding to the text to be recognized, or the file name of the text to be detected, or the font size (or font size) of the text to be recognized, etc. The scene information may also include the application scenario of the text to be recognized, such as information extraction, identity authentication, case reading, etc. The size of the reference rectangular image may be determined based on the size of the text to be recognized and / or the size of the image to be detected occupied by the text to be recognized.

[0041] It can be understood that the reference rectangular image must contain the text to be recognized, and different scene information may require text with different recognition accuracy. In this example, the YOLO model is determined based on the size of the reference rectangular image determined based on the scene information of the text to be recognized and the recognition accuracy of the text to be recognized, which can improve the detection accuracy of the YOLO model and facilitate improving the accuracy of text positioning.

[0042] S102: Perform image enhancement on the reference rectangular image based on a generative adversarial network to obtain a target rectangular image.

[0043] In the embodiment of the present application, the target rectangular image is an image obtained after image enhancement of the reference rectangular image. In this way, the efficiency of text recognition can be improved by denoising. The present application does not limit the method of image enhancement, which may include noise reduction processing, such as detecting straight lines in the reference rectangular image. If all the straight lines are focused on one area, it can be determined that the area is a shadow, and the image corresponding to the shadow can be removed.

[0044] Image enhancement can also include noise perturbation processing, color processing, contrast transformation, etc. Among them, noise perturbation processing refers to random perturbation of the RGB color mode of each pixel on the image. Commonly used noise modes are salt and pepper noise and Gaussian noise. Color processing refers to adding random perturbations to the RGB channels of the text image. Contrast transformation refers to changing the saturation S and V brightness components in the color space composed of hue (Hue, H), saturation (Saturation, S) and value (Value, V), keeping the hue H unchanged, performing exponential operations on the S and V components of each pixel, increasing lighting changes, etc. The above methods can achieve image enhancement and weakening through different processing. In this way, image enhancement can strengthen the detailed features of the text image, reduce the impact of objective factors such as ambient light and electronic equipment on the text image, and help improve the accuracy of text recognition. Generative Adversarial Networks (GAN) is a deep learning model that includes a generator (Generator, G) and a discriminator (Discriminator, D). G and D can use a convolutional layer, followed by a BatchNorm layer and a Rectified Linear Unit (ReLU) activation function. G and D can also include a dropout layer, which is set to 0.5 to prevent overfitting. The encoding module and the decoding module of G are skipped, so that feature maps of corresponding sizes are connected by channels to fuse more feature information.

[0045] In the embodiment of the present application, the GAN can be trained in advance based on an image containing text to obtain a blurred image and a high-definition image corresponding to the image. After the training is completed, the reference rectangular image to be recognized is input into the GAN to obtain a high-definition target rectangular image. In this way, the reference rectangular image is enhanced by the trained GAN, which is conducive to improving the accuracy of text recognition in the target rectangular image.

[0046] The present application does not limit the training method of GAN. In a possible example, the following steps may also be included: performing image processing on the text image to be trained by the generator to obtain an image pair of the text image; determining the recognition rate of the image pair by the discriminator; judging whether the recognition rate is less than a preset threshold; if the recognition rate is less than the preset threshold, updating the generator based on the recognition rate, and then performing the step of performing image processing on the text image to be trained by the generator to obtain an image pair of the text image, until the number of training times is equal to the preset number of times. If the recognition rate is greater than or equal to the preset threshold, updating the discriminator based on the recognition rate, and then performing the step of performing image processing on the text image to be trained by the generator to obtain an image pair of the text image, until the number of training times is equal to the preset number of times.

[0047] In an embodiment of the present application, an image pair of a text image may include a blurred image and a high-definition image corresponding to the text image. Image processing may refer to the above-mentioned image enhancement method, which will not be described in detail here. The recognition rate of the image pair is used to describe the quality of the text image in the image pair. The recognition rate may be an average value or a minimum value between the quality of the high-definition image and the quality of the blurred image, or may be the quality of the blurred image, etc., which is not limited here.

[0048] The present application does not limit the preset threshold and the preset number of times. The preset threshold can be a specified value, such as 80%. The preset threshold can also be determined based on the number of training times and the number of training samples. For example, the greater the number of training times, the greater the preset threshold. Or the greater the number of training samples, the greater the preset threshold. The preset number of times is the maximum number of training times, which can be a specified value, such as 20. The preset number of times can also be determined based on the number of training samples. For example, if the number of training samples is 20, the preset number of times is 40, that is, the number of training times for each training sample is 2.

[0049] It can be understood that the image pair of the text image is obtained by performing image processing on the text image to be trained through the generator. Then the recognition rate of the image pair is determined. If the recognition rate is less than the preset threshold, it means that the image quality does not meet the requirements, and the generator can be updated based on the recognition rate. If the recognition rate is greater than or equal to the preset threshold, it means that the image quality meets the requirements, but in order to improve the recognition accuracy, the discriminator can be updated based on the recognition rate. In this way, after multiple trainings, the training is completed when the number of trainings is equal to the preset number. After the reference rectangular image is input into the trained generative adversarial network, the target rectangular image can be output.

[0050] S103: Selecting a reference straight line from the target rectangular image based on a straight line detection model.

[0051] In an embodiment of the present application, the reference straight line is a line segment in the target rectangular image, which can be used to determine the offset angle of the target rectangular image. The present application does not limit the number of reference straight lines, and the number of reference straight lines can be the number of edges of the outer contour corresponding to the text to be recognized. For example, the outer contour corresponding to the text to be recognized is a book, and the reference straight line can be the spine of the book or a straight line in the bounding box, and the number of reference straight lines can be a positive integer less than or equal to 4. Optionally, the reference straight lines can be the two longest straight lines in the target rectangular image, or can be two intersecting straight lines in the target rectangular image.

[0052] The line detection model is used to identify the straight lines in the target rectangular image and the reference straight lines in the straight lines. The line detection model can be based on the Line Segment Detector (LSD) algorithm. The LSD algorithm mainly uses the gradient of the image to detect the straight line segment. Compared with the Hough line detection algorithm, it has an overwhelming advantage in speed. Before using the LSD algorithm, the target rectangular image can be converted into a grayscale image to improve the detection accuracy.

[0053] In a possible example, the method further includes: determining the language of the text to be recognized; and selecting a line detection model corresponding to the language from a preset line detection model library.

[0054] In the embodiment of the present application, the language may be Chinese, English, Japanese, etc., which is not limited here. It is understood that different languages ​​may have different strokes and fonts corresponding to the text. Therefore, the language is determined based on the stroke composition and font form of the text to be recognized. Or, common characters in texts of different languages ​​are used to match the text to be recognized. If the match is successful, the language corresponding to the text is determined to be the language of the text to be recognized, etc., which is not limited here.

[0055] The preset line detection model library stores line detection models of different languages. It can be understood that in this example, selecting a line detection model corresponding to a language from the preset line detection model library can improve the accuracy of obtaining reference lines, which is conducive to improving the accuracy of text recognition.

[0056] The present application does not limit the method for obtaining the reference straight line. In a possible example, step S103 may include the following steps A1 to A3, wherein:

[0057] A1: Acquire a plurality of first straight lines in the target rectangular image based on a straight line detection model.

[0058] In the embodiment of the present application, the first straight line may be a straight line in the target rectangular image. Taking the target rectangular image as a book spine as an example, the first straight line may include a straight line corresponding to the spine or a bounding box in the book spine, a straight line stroke of a character in the image, and a straight line corresponding to a light shadow, etc. There are multiple first straight lines, that is, there are at least 3 first straight lines.

[0059] A2: Select a second straight line from the plurality of first straight lines.

[0060] In the embodiment of the present application, the second straight line can be a straight line selected from the first straight line. It is understandable that there may be some shadows in the first straight line, resulting in misidentified straight lines. For example, the straight line corresponding to the shadow and the straight strokes in the text, etc. By selecting the first straight line, the interference of these noise straight lines can be reduced, which is convenient for improving the accuracy of text positioning.

[0061] In a possible example, step A2 may include the following steps A21 to A23, wherein:

[0062] A21: Establishing the coordinate system of the target rectangular image.

[0063] In the embodiment of the present application, the center point of the coordinate axis may be the geometric center point of the target rectangular image. The coordinate axis includes an x-coordinate axis and a y-coordinate axis, and the x-coordinate axis and the y-coordinate axis may be determined based on the geometric center point and the sides of the target rectangular image, for example, the side of the parallel lines corresponding to the long side that intersects with the center point is used as the x-axis, and the side of the parallel lines corresponding to the short side that intersects with the center point is used as the y-axis, etc.

[0064] A2: Obtain the length and angle of the first straight line based on the coordinate system.

[0065] In the embodiment of the present application, the length of the first straight line can be understood as the length of the first straight line projected to the x direction, that is, the difference in x coordinates at both ends of the straight line segment. The angle of the first straight line segment can be the angle between the first straight line and the coordinate axis, for example, the angle between the first straight line and the x axis.

[0066] A23: Select a first straight line whose length is greater than a preset length and whose angle falls within a preset angle range from the first straight lines to obtain a second straight line.

[0067] The present application does not limit the preset length and the preset angle range. The preset length can be 10 cm, and the preset angle range can be greater than 0 and less than 20 degrees. The preset length can be determined based on the size of the target rectangular image. For example, if the size of the target rectangular image is 20 cm, the preset length can be 15 cm. The preset length can also be determined based on the font size of the text to be recognized. For example, the preset length is equal to the length of one character corresponding to the font size of the text to be recognized. The preset angle range can be determined based on the deviation angle of the target rectangular image. The deviation angle can be determined by the angle between the border of the text corresponding to the text to be recognized and the border of the target rectangular image.

[0068] It can be understood that if the length of a straight line is less than a preset length, or the angle of the straight line deviates from a preset angle range, it indicates that the straight line may be noise. In this way, by obtaining the length and angle of the first straight line based on the coordinate axis of the target rectangular image to filter the second straight line in the first straight line, the interference of these noise straight lines can be reduced, thereby improving the accuracy of text recognition.

[0069] A3: Clustering the second straight lines to obtain reference straight lines in the target rectangular image.

[0070] In the embodiment of the present application, the second straight line can be classified by clustering based on the mean shift algorithm, or the line segments on two nearly overlapping straight lines can be merged into one straight line based on the position and angle of the second straight line, or different line segments on the same straight line can be connected into one straight line.

[0071] It can be understood that in steps A1 to A3, a plurality of first straight lines in the target rectangular image are obtained based on the straight line detection model. Second straight lines are then selected from the plurality of first straight lines. The second straight lines are then clustered to obtain reference straight lines in the target rectangular image, which is conducive to improving the accuracy of determining the tilt angle of the text in the target rectangular image by the reference straight line.

[0072] S104: Obtain a virtual underline for each line of text image in the target rectangular image.

[0073] In the embodiment of the present application, the virtual underline is not a line segment in the target rectangular image, but a straight line segment constructed based on the text direction of each line of text image in the target rectangular image. It should be noted that the present application does not limit the execution order between step S103 and step S104, and step S103 can be executed first, and then step S104. Alternatively, step S104 can be executed first, and then step S103. Alternatively, step S103 and step S104 can be executed simultaneously.

[0074] In a possible example, step S104 may include the following steps B1 to B5, wherein:

[0075] B1: Determine the language of the text to be recognized.

[0076] As mentioned above, the language may include Chinese, English, Japanese, etc. The language may be determined based on the stroke composition and font form of the character to be recognized; or common characters in characters of different languages ​​may be matched with the character to be recognized. If the match is successful, the language corresponding to the character is determined to be the language of the character to be recognized, etc., which will not be described in detail here.

[0077] B2: Acquire the coordinate information of each character in the target rectangular image based on the coordinate system.

[0078] The coordinate information can be determined based on the aforementioned coordinate system to describe the position of the text in the target rectangular image. The coordinate information can also be used to determine the size of the text. Further, the average size of the text can be determined based on the coordinate information of all the texts in the text to be recognized.

[0079] It should be noted that the present application does not limit the execution order between step B1 and step B2. Step B1 may be executed first, and then step B2. Alternatively, step B2 may be executed first, and then step B1. Alternatively, step B1 and step B2 may be executed simultaneously.

[0080] B3: Determine a preset interval of the text based on the coordinate information and the language.

[0081] In an embodiment of the present application, a mapping relationship between a language and a line spacing may be pre-stored. After the language is determined, the line spacing corresponding to the language may be determined. The preset spacing of each line of text may be the same or different. In this example, the size information of the text in the target rectangular image may be determined based on the coordinate information of the text, thereby determining the preset spacing between the text and the underline based on the line spacing and size information, and the size information of the target rectangular image.

[0082] B4: Draw a sub-line segment below the text based on the preset interval and the coordinate information.

[0083] In the embodiment of the present application, a sub-line segment may be included below each character to describe the direction of the character. The position of the lower boundary of the character may be determined based on the coordinate information of the character, and the position of the sub-line segment may be determined based on the preset interval and the position of the lower boundary, thereby drawing the sub-line segment.

[0084] B5: Adjust the sub-line segments to obtain a virtual underline for each line of text image in the target rectangular image.

[0085] In the embodiment of the present application, the sub-line segments of each character in the line text image can be fine-tuned so that the sub-line segments are connected to form a straight line or a curve with a small amplitude change.

[0086] It can be understood that in steps B1 to B5, the preset interval of the text is determined based on the language of the text to be recognized and the coordinate information of each text in the target rectangular image. Then, based on the preset interval and coordinate information of the text, a line segment is drawn below the text to obtain a sub-segment. Then, the sub-segment is adjusted to obtain a virtual underline of each line of text image in the target rectangular image. In this way, the accuracy of the virtual underline in describing the direction of the text can be improved, which is conducive to improving the accuracy of the virtual underline in determining the inclination angle of the text line in the target rectangular image.

[0087] S105: Determine the inclination angle of the line text image based on the virtual underline and the reference straight line.

[0088] In an embodiment of the present application, the tilt angle of a line text image can be understood as the tilt angle of a text line corresponding to the line text image. The present application does not limit the method for determining the tilt angle. In one possible example, if the reference straight line intersects with the virtual underline, the angle between the reference straight line and the virtual underline can be directly obtained as the tilt angle of the line text image. If the reference straight line does not intersect with the virtual underline, the angles between the reference straight line and the virtual underline and the x-axis can be obtained respectively, and then the average value of the angles can be obtained; or the reference straight line can be translated so as to intersect with the virtual underline, and then the angle of intersection is used as the tilt angle.

[0089] If there are multiple reference lines, a target reference line can be selected, and then the tilt angle of the line text image can be determined based on the target reference line and the virtual underline. In the embodiment of the present application, the longest reference line among the reference lines can be selected as the target reference line, or a reference line intersecting the virtual underline can be selected as the target reference line, etc.

[0090] Or if there are multiple reference lines, the angle between each reference line and the virtual underline can be obtained to obtain multiple angles, and then the inclination angle of the line text image can be determined based on the average value of the multiple angles.

[0091] S106: Performing character recognition on the line text image corresponding to the tilt angle based on an optical character recognition model.

[0092] The Optical Character Recognition (OCR) model is a model based on OCR technology. OCR technology refers to the process in which an electronic device (such as a scanner or digital camera) examines characters printed on paper and determines their shapes by detecting dark and light patterns. The shapes are then translated into computer text using character recognition methods. That is, for printed characters, the text in a paper document is converted into a black and white dot matrix image file using an optical method, and the text in the image is converted into a text format through recognition software for further editing and processing by word processing software.

[0093] In the embodiment of the present application, the OCR model is used to perform text recognition on the target image to identify the text to be recognized. In a possible example, before step S106, the following steps are also included: determining the scene information of the text to be recognized; determining the recognition accuracy of the text to be recognized based on the scene information; and selecting the optical character recognition model corresponding to the language, the recognition accuracy and the tilt angle from a preset optical character recognition model library.

[0094] Among them, the scene information can refer to the description of step S101, and the language can refer to the description of step B1, which will not be repeated here. It can be understood that different scene information requires different recognition accuracy. For example, the recognition accuracy in the identity authentication scenario is greater than the recognition accuracy in the ordinary text recognition scenario, and the recognition accuracy in the case reading scenario is greater than the recognition accuracy in the identity authentication scenario, etc. In an embodiment of the present application, the recognition accuracy corresponding to different scene information can be pre-stored, so as to determine the recognition accuracy of the text to be recognized after determining the scene information of the text to be recognized.

[0095] Different types of OCR models are stored in the preset optical character recognition model. It can be understood that in this example, selecting an OCR model corresponding to the language, recognition accuracy and tilt angle from the preset optical character recognition model can further improve the accuracy of text recognition.

[0096] exist Figure 1 In the method shown, a reference rectangular image corresponding to the text to be recognized is first obtained based on the YOLO model. Then, the reference rectangular image is enhanced based on the generative adversarial network to obtain a target rectangular image. Then, a reference straight line is selected from the target rectangular image based on the straight line detection model, and a virtual underline of each line of text image in the target rectangular image is obtained. Then, the inclination angle of the line text image is determined based on the virtual underline and the reference straight line. Finally, text recognition is performed on the line text image corresponding to the inclination angle based on the optical character recognition model. In this way, the accuracy of text recognition can be improved.

[0097] In a possible example, after step S105, the target rectangular image is adjusted based on the tilt angle to obtain an image to be recognized; and text recognition is performed on the image to be recognized based on an OCR model.

[0098] The target rectangular image can be adjusted based on the average value of the tilt angles, or based on the angles that the OCR model is good at recognizing, or each line of text image can be adjusted according to its corresponding tilt angle, etc. In this way, multiple text recognition methods can be improved for text recognition.

[0099] After performing text recognition on the image to be recognized based on the OCR model, and performing text recognition on the line text image corresponding to the tilt angle based on the optical character recognition model, a fusion decision can be made based on the recognition results obtained by the two methods. For example, if the recognized text is the same, it is confirmed. Otherwise, the accuracy is calculated based on the same text and semantics, and the one with the larger accuracy is taken as the result.

[0100] The method of the embodiment of the present application is described in detail above, and the device of the embodiment of the present application is provided below.

[0101] and Figure 1 The embodiment shown is consistent with that shown in FIG. Figure 2 , Figure 2 is a structural diagram of a text recognition device proposed in this application, such as Figure 2 As shown, the above-mentioned text recognition device 200 includes:

[0102] The processing unit 201 is used to obtain a reference rectangular image corresponding to the text to be recognized based on the YOLO model; perform image enhancement on the reference rectangular image based on the generative adversarial network to obtain a target rectangular image; select a reference straight line from the target rectangular image based on the straight line detection model; obtain a virtual underline of each line of text image in the target rectangular image; determine the inclination angle of the line of text image based on the virtual underline and the reference straight line;

[0103] The recognition unit 202 is used to perform text recognition on the line text image corresponding to the tilt angle based on the optical character recognition model.

[0104] In a possible example, the processing unit 201 is specifically used to obtain multiple first straight lines in the target rectangular image based on a straight line detection model; select second straight lines from the multiple first straight lines; and cluster the second straight lines to obtain reference straight lines in the target rectangular image.

[0105] In a possible example, the processing unit 201 is specifically used to establish a coordinate system of the target rectangular image; obtain the length and angle of the first straight line based on the coordinate system; and filter out from the first straight lines the first straight lines whose length is greater than a preset length and whose angle falls within a preset angle range to obtain a second straight line.

[0106] In a possible example, the processing unit 201 is specifically used to determine the language of the text to be recognized; obtain the coordinate information of each text in the target rectangular image based on the coordinate system; determine the preset interval of the text based on the coordinate information and the language; draw a sub-line segment under the text based on the preset interval and the coordinate information; and adjust the sub-line segment to obtain a virtual underline for each line of text image in the target rectangular image.

[0107] In a possible example, the processing unit 201 is also used to determine the scene information of the text to be recognized; determine the recognition accuracy of the text to be recognized based on the scene information; and select the optical character recognition model corresponding to the language, the recognition accuracy and the tilt angle from a preset optical character recognition model library.

[0108] In a possible example, the processing unit 201 is specifically used to determine the inclination angle of the line of text image as the angle between the reference straight line and the virtual underline if the reference straight line intersects the virtual underline; or if the reference straight line does not intersect the virtual underline, determine the inclination angle of the line of text image as the average value of the angle between the reference straight line and the reference axis, and the angle between the virtual underline and the reference axis; or if the number of reference straight lines is greater than or equal to 2, select a target reference straight line from the reference straight lines, and determine the inclination angle of the line of text image based on the target reference straight line and the virtual underline.

[0109] In a possible example, the device 200 further includes a communication unit 203 for receiving a text recognition instruction of a target area sent by a user; the processing unit 201 is specifically used to locate the target area based on a YOLO model to obtain a reference rectangular image of the text to be recognized.

[0110] In a possible example, the communication unit 203 is further configured to send the text recognition result to the user.

[0111] The detailed execution process of each unit in the text recognition device 200 can refer to the execution steps in the aforementioned method embodiment, which will not be repeated here.

[0112] and Figure 1 For details, please refer to Figure 3 , Figure 3 Schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 3 As shown, the computer device 300 includes a processor 310, a memory 320, a communication interface 330, and one or more programs 340. The processor 310, the memory 320, and the communication interface 330 are interconnected via a bus 320. Figure 2 The related functions implemented by the communication unit 203 shown can be implemented through the communication interface 330. Figure 2 The related functions implemented by the processing unit 201 and the identification unit 202 shown can be implemented by the processor 310 .

[0113] The one or more programs 340 are stored in the memory 320 and are configured to be executed by the processor 310. The program 340 includes instructions for executing the following steps:

[0114] Obtain a reference rectangular image corresponding to the text to be recognized based on the YOLO model;

[0115] Performing image enhancement on the reference rectangular image based on a generative adversarial network to obtain a target rectangular image;

[0116] Selecting a reference straight line from the target rectangular image based on a straight line detection model;

[0117] Obtaining a virtual underline of each line of text image in the target rectangular image;

[0118] Determining the tilt angle of the line text image based on the virtual underline and the reference straight line;

[0119] The text line image corresponding to the tilt angle is subjected to text recognition based on an optical character recognition model.

[0120] In a possible example, in the aspect of selecting a reference straight line from the target rectangular image based on the straight line detection model, the program 340 is specifically used to execute instructions of the following steps:

[0121] Acquire a plurality of first straight lines in the target rectangular image based on a straight line detection model;

[0122] Selecting a second straight line from the plurality of first straight lines;

[0123] The second straight lines are clustered to obtain reference straight lines in the target rectangular image.

[0124] In a possible example, in the aspect of selecting the second straight line from the plurality of first straight lines, the program 340 is specifically used to execute instructions of the following steps:

[0125] Establishing a coordinate system of the target rectangular image;

[0126] Acquire the length and angle of the first straight line based on the coordinate system;

[0127] A first straight line whose length is greater than a preset length and whose angle falls within a preset angle range is selected from the first straight lines to obtain a second straight line.

[0128] In a possible example, in the aspect of obtaining the virtual underline of each line of text image in the target rectangular image, the program 340 is specifically used to execute the following steps:

[0129] Determining the language of the text to be recognized;

[0130] Acquire coordinate information of each character in the target rectangular image based on the coordinate system;

[0131] Determining a preset interval of the text based on the coordinate information and the language;

[0132] Drawing a sub-line segment below the text based on the preset interval and the coordinate information;

[0133] The sub-line segments are adjusted to obtain a virtual underline for each line of text image in the target rectangular image.

[0134] In a possible example, before performing text recognition on the line text image corresponding to the tilt angle based on the optical character recognition model, the program 340 is further used to execute instructions for the following steps:

[0135] Determining scene information of the text to be recognized;

[0136] Determining the recognition accuracy of the to-be-recognized text based on the scene information;

[0137] The optical character recognition model corresponding to the language, the recognition accuracy and the tilt angle is selected from a preset optical character recognition model library.

[0138] In a possible example, in determining the tilt angle of the text line image based on the virtual underline and the reference straight line, the program 340 is specifically used to execute the following steps:

[0139] If the reference straight line intersects with the virtual underline, then determining the inclination angle of the line text image as the angle between the reference straight line and the virtual underline; or

[0140] If the reference straight line does not intersect the virtual underline, the inclination angle of the line text image is determined to be the average of the angle between the reference straight line and the reference axis and the angle between the virtual underline and the reference axis; or

[0141] If the number of the reference straight lines is greater than or equal to 2, a target reference straight line is selected from the reference straight lines, and the inclination angle of the line text image is determined based on the target reference straight line and the virtual underline.

[0142] In a possible example, before obtaining the reference rectangular image corresponding to the to-be-recognized text based on the YOLO model, the program 340 is further used to execute instructions for the following steps:

[0143] Receive a text recognition instruction of a target area sent by a user;

[0144] In the aspect of obtaining the reference rectangular image corresponding to the text to be recognized based on the YOLO model, the program 340 is specifically used to execute the following steps:

[0145] The target area is located based on the YOLO model to obtain a reference rectangular image of the text to be recognized.

[0146] An embodiment of the present application also provides a computer storage medium, wherein the computer storage medium stores a computer program, which enables a computer to execute part or all of the steps of any method recorded in the method embodiment, and the computer includes an electronic device and a server.

[0147] The present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute to implement some or all steps of any method described in the method embodiment. The computer program product can be a software installation package, and the computer includes an electronic device and a server.

[0148] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modes involved are not necessarily required by the present application.

[0149] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0150] In the several embodiments provided in the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as at least one unit or component can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.

[0151] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on at least one network unit. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0152] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software program mode.

[0153] If the integrated unit is implemented in the form of a software program model and sold or used as an independent product, it can be stored in a computer-readable memory. According to this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, magnetic disk or optical disk, etc., and other media that can store program codes.

[0154] The embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A method for character recognition, characterized in that: include: Obtain a reference rectangular image corresponding to the text to be recognized based on the YOLO model; Performing image enhancement on the reference rectangular image based on a generative adversarial network to obtain a target rectangular image; Selecting a reference straight line from the target rectangular image based on a straight line detection model; Obtaining a virtual underline of each line of text image in the target rectangular image; Determining the tilt angle of the line text image based on the virtual underline and the reference straight line; Performing character recognition on the line text image corresponding to the tilt angle based on an optical character recognition model; Establishing a coordinate system of the target rectangular image; The step of obtaining a virtual underline of each line of text image in the target rectangular image includes: Determining the language of the text to be recognized; Acquire coordinate information of each character in the target rectangular image based on the coordinate system; Determining a preset interval of the text based on the coordinate information and the language; Drawing a sub-line segment below the text based on the preset interval and the coordinate information; Adjusting the sub-line segments to obtain a virtual underline for each line of text image in the target rectangular image; Before performing character recognition on the line text image corresponding to the tilt angle based on the optical character recognition model, the method further includes: Determining scene information of the text to be recognized; Determining the recognition accuracy of the to-be-recognized text based on the scene information; The optical character recognition model corresponding to the language, the recognition accuracy and the tilt angle is selected from a preset optical character recognition model library.

2. The method according to claim 1, characterized in that: The selecting a reference straight line from the target rectangular image based on a straight line detection model includes: Acquire a plurality of first straight lines in the target rectangular image based on a straight line detection model; Selecting a second straight line from the plurality of first straight lines; The second straight lines are clustered to obtain reference straight lines in the target rectangular image.

3. The method according to claim 2, characterized in that The selecting a second straight line from the plurality of first straight lines comprises: Acquire the length and angle of the first straight line based on the coordinate system; A first straight line whose length is greater than a preset length and whose angle falls within a preset angle range is selected from the first straight lines to obtain a second straight line.

4. The method according to any one of claims 1 to 3, characterized in that The step of determining the tilt angle of the text line image based on the virtual underline and the reference straight line includes: If the reference straight line intersects with the virtual underline, then determining the inclination angle of the line text image as the angle between the reference straight line and the virtual underline; or If the reference straight line does not intersect the virtual underline, the inclination angle of the line text image is determined to be the average of the angle between the reference straight line and the reference axis and the angle between the virtual underline and the reference axis; or If the number of the reference straight lines is greater than or equal to 2, a target reference straight line is selected from the reference straight lines, and the inclination angle of the line text image is determined based on the target reference straight line and the virtual underline.

5. The method according to any one of claims 1 to 3, characterized in that Before obtaining the reference rectangular image corresponding to the text to be recognized based on the YOLO model, the method further includes: Receive a text recognition instruction of a target area sent by a user; The method of obtaining a reference rectangular image corresponding to the text to be recognized based on the YOLO model includes: The target area is located based on the YOLO model to obtain a reference rectangular image of the text to be recognized.

6. A text recognition device, characterized in that: The method comprises a unit for executing the method according to any one of claims 1 to 5.

7. A computer device, characterized in that: The method comprises a processor, a memory, a communication interface and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the processor, and the programs include instructions for executing the steps in any one of the methods of claims 1-5.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which enables a computer to execute to implement the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Inclination character judgment and identification method based on pixel tracking

    CN105184294A

  • Image quality detection method and device, computer equipment and medium

    CN113256583A

  • Formation device of underline and sideline

    JP1985231275A

  • Document recognizing method

    JP1997319824A