CN115376136A - Character recognition method, device, equipment and storage medium - Google Patents

Character recognition method, device, equipment and storage medium Download PDF

Info

Publication number
CN115376136A
CN115376136A CN202210994137.8A CN202210994137A CN115376136A CN 115376136 A CN115376136 A CN 115376136A CN 202210994137 A CN202210994137 A CN 202210994137A CN 115376136 A CN115376136 A CN 115376136A
Authority
CN
China
Prior art keywords
character
dimensional code
image
rotation angle
recognition result
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210994137.8A
Other languages
Chinese (zh)
Inventor
周相如
孙宇君
李睿宇
吕江波
沈小勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Smartmore Technology Co Ltd
Original Assignee
Shenzhen Smartmore Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Smartmore Technology Co Ltd filed Critical Shenzhen Smartmore Technology Co Ltd
Priority to CN202210994137.8A priority Critical patent/CN115376136A/en
Publication of CN115376136A publication Critical patent/CN115376136A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition
    • G06V30/14Image acquisition
    • G06V30/146Aligning or centring of the image pick-up or image-field
    • G06V30/1463Orientation detection or correction, e.g. rotation of multiples of 90 degrees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition
    • G06V30/14Image acquisition
    • G06V30/146Aligning or centring of the image pick-up or image-field
    • G06V30/1465Aligning or centring of the image pick-up or image-field by locating a pattern
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition
    • G06V30/16Image preprocessing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition
    • G06V30/18Extraction of features or characteristics of the image
    • G06V30/1801Detecting partial patterns, e.g. edges or contours, or configurations, e.g. loops, corners, strokes or intersections
    • G06V30/18076Detecting partial patterns, e.g. edges or contours, or configurations, e.g. loops, corners, strokes or intersections by analysing connectivity, e.g. edge linking, connected component analysis or slices

Abstract

The application discloses a character recognition method, a character recognition device, a character recognition equipment and a storage medium, and relates to the technical field of image processing. The method comprises the following steps: acquiring an original image, wherein the original image comprises a first two-dimensional code and a first character to be recognized; determining a first rotation angle according to the first two-dimensional code; correcting the original image according to the first rotation angle to obtain a first image; based on the first image, a first recognition result of the first character is obtained. By the aid of the method and the device, accuracy of the identification result can be improved.

Description

Character recognition method, device, equipment and storage medium
Technical Field
The present application relates to the field of image processing technologies, and in particular, to a character recognition method, device, apparatus, and storage medium.
Background
Character recognition refers to a technique of recognizing characters contained in an image. For example, when a certificate number is input, after a certificate image is obtained by shooting an entity certificate, the computing device can automatically identify the certificate number contained in the certificate image through a character identification technology, so that a user does not need to manually input the certificate number.
In the related art, a user sets a fixed angle on a computing device. After obtaining an original image, the computing equipment rotates the original image according to a preset angle, and performs character recognition based on the rotated image to obtain a recognition result.
However, in practice, it has been found that when the character recognition is performed by the above method, the accuracy of the recognition result is low.
Disclosure of Invention
The application provides a character recognition method, a character recognition device, a character recognition equipment and a storage medium, which can improve the accuracy of a recognition result.
In a first aspect, the present application provides a character recognition method, including:
acquiring an original image, wherein the original image comprises a first two-dimensional code and a first character to be recognized;
determining a first rotation angle according to the first two-dimensional code;
correcting the original image according to the first rotation angle to obtain a first image;
based on the first image, a first recognition result of the first character is obtained.
In some embodiments, the determining a first rotation angle according to the first two-dimensional code includes:
and determining the first rotation angle according to the position relation between the first two-dimensional code and the first character.
In some embodiments, the determining the first rotation angle according to the position relationship between the first two-dimensional code and the first character includes:
and determining the first rotation angle according to the angle between a first edge of the connected domain corresponding to the first two-dimensional code and the horizontal direction, wherein the first edge is parallel to a second edge of the connected domain corresponding to the first character, and the second edge is the longest edge in the connected domain corresponding to the first character.
In some embodiments, the determining the first rotation angle according to the position relationship between the first two-dimensional code and the first character includes:
and determining the first rotation angle according to the angle between the diagonal line of the connected domain corresponding to the first two-dimensional code and the horizontal direction.
In some embodiments, the determining the first rotation angle according to the position relationship between the first two-dimensional code and the first character includes:
and determining the first rotation angle according to the position relation between the connected domain corresponding to the first two-dimensional code and the connected domain corresponding to the first character.
In some embodiments, the determining a first rotation angle according to the first two-dimensional code includes:
and determining a first rotation angle according to the positioning information included in the first two-dimensional code.
In some embodiments, the first two-dimensional code is a quick response QR code, and the positioning information is a glyph positioning point included in the QR code; alternatively, the first and second electrodes may be,
the first two-dimensional code is a data matrix DM code, and the positioning information is an L-shaped boundary included by the DM code.
In some embodiments, the original image further includes a second two-dimensional code and a second character to be recognized, and the method further includes:
under the condition that the second two-dimensional code is determined to be not parallel to the first two-dimensional code or the second character is determined to be not parallel to the first character, determining a second rotation angle according to the second two-dimensional code;
correcting the original image according to the second rotation angle to obtain a second image;
and obtaining a recognition result of the second character based on the second image.
In some embodiments, the original image further includes a second two-dimensional code and a second character to be recognized, and the method further includes:
and under the condition that the second two-dimensional code is determined to be parallel to the first two-dimensional code and the second character is determined to be parallel to the first character, obtaining a recognition result of the second character based on the first image.
In some embodiments, the original image includes a first area and a second area, the first two-dimensional code and the first character are both located in the first area, and the second two-dimensional code and the second character are both located in the second area.
In some embodiments, after obtaining the first recognition result of the first character based on the first image, the method further comprises:
in a case where it is determined that the first recognition result is the desired result, the first recognition result is output.
In some embodiments, after obtaining the first recognition result of the first character based on the first image, the method further comprises:
under the condition that the first recognition result is determined not to be the expected result, rotating the first image by 180 degrees to obtain a third image;
and obtaining a second recognition result of the first character based on the third image.
In some embodiments, after obtaining the first recognition result of the first character based on the first image, the method further comprises:
and in the case that the first recognition result is determined not to be an expected result, inputting the first image into a character recognition model, processing the first image through the character recognition model, and outputting a third recognition result of the first character, wherein the character recognition model is used for recognizing the character with the rotation angle of 180 degrees.
In a second aspect, the present application provides a character recognition apparatus comprising:
the device comprises an acquisition module, a recognition module and a recognition module, wherein the acquisition module is used for acquiring an original image, and the original image comprises a first two-dimensional code and a first character to be recognized;
the determining module is used for determining a first rotating angle according to the first two-dimensional code;
the correction module is used for correcting the original image according to the first rotation angle to obtain a first image;
the obtaining module is further configured to obtain a first recognition result of the first character based on the first image.
In a third aspect, the present application provides a computer device comprising a processor and a memory, the memory having stored therein computer program instructions, the processor implementing the steps of the method of the first aspect when executing the computer program instructions.
In a fourth aspect, the present application provides a computer readable storage medium having stored therein computer program instructions which, when executed by a processor, implement the steps in the method of the first aspect described above.
In a fifth aspect, the present application provides a computer program product comprising computer program instructions which, when executed by a processor, implement the steps in the method of the first aspect described above.
Therefore, the application has the following beneficial effects:
the rotation angle of the original image is determined by using the two-dimensional code contained in the original image as auxiliary information, so that the determined rotation angle is more accurate, the original image can be corrected more accurately according to the rotation angle, and a more accurate character recognition result is obtained.
Drawings
Fig. 1 is a flowchart of a character recognition method according to an embodiment of the present application;
fig. 2 is a flowchart of a character recognition method according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a character recognition apparatus 300 according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of a computer device 400 according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of a computer-readable storage medium 500 according to an embodiment of the present application.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, embodiments accompanying the present application are described in further detail below with reference to the drawings and the detailed description.
The inventors of the present application have found that the existing Optical Character Recognition (OCR) technology can generally only recognize forward characters. For tilted or inverted characters, existing OCR techniques typically recognize with poor accuracy. In view of this, after an original image to be subjected to OCR is acquired, the image needs to be corrected first, so that characters in the image are rotated from an oblique direction to a forward direction, and then the characters in the image are recognized, thereby improving recognition accuracy. In order to correct an image, in the conventional technology, a fixed angle is usually manually set, and OCR recognition is performed by rotating an original image by a fixed angle. However, the fixed angle needs to be manually set, and in an actual industrial scene, the rotation angle of the original image is not fixed, and after the original image is rotated by using the fixed angle, characters in the rotated image may not be recognized by the OCR model, or the accuracy of the characters after OCR recognition is low. In addition, in the conventional technology, when there are a plurality of original images, it is necessary that the directions of the original images are consistent, that is, the rotation angles of the original images are consistent, so that a good character recognition effect can be obtained. However, for a plurality of original images with different rotation angles, the conventional scheme cannot perform OCR recognition or the accuracy of characters after OCR recognition is low.
Based on this, in some embodiments of the present application, the two-dimensional code is used to assist in rotating the image based on the relative positional relationship between the two-dimensional code and the character. In other embodiments of the present application, it is considered that the two-dimensional code generally includes positioning information, for example, a Quick Response (QR) code includes a glyph positioning point, and a Data Matrix (DM) code includes an outer frame formed by a solid line L and a dotted line L, so that the positioning information included in the two-dimensional code is utilized to assist in rotating the image. According to the method provided by the embodiment of the application, due to the fact that the two-dimensional code is used as the auxiliary information, the rotation angle used in the image correction process is more accurate, and therefore the problem that in an actual industrial scene, due to the fact that the rotation angle of an original image cannot be fixed, and due to the fact that the method for manually setting the fixed angle is low in accuracy, characters in the original image are difficult to be recognized by an OCR model is solved, the success rate of processing the image is improved, and the effect that the character recognition is more accurate is achieved. In addition, the problem that characters in original images with different rotation angles are difficult to be recognized by an OCR model even if the rotation angles of the original images are not completely the same is solved.
Fig. 1 is a flowchart of a character recognition method according to an embodiment of the present application. Some embodiments of the present application relate to a case where one original image includes a plurality of two-dimensional codes. In order to distinguish different two-dimension codes, a plurality of different two-dimension codes are distinguished and described by a first two-dimension code and a second two-dimension code.
Some embodiments of the present application relate to a case where one original image includes a plurality of characters. In order to distinguish different characters, a plurality of different characters are described with "first character" and "second character" distinctively. The first character may be a character or a string of characters.
The method shown in fig. 1 includes the following steps S101 to S104.
Step S101, computer equipment acquires an original image, wherein the original image comprises a first two-dimensional code and a first character to be recognized.
In some embodiments, after the computer device obtains the original image, the computer device performs a pre-processing of the original image before performing the subsequent steps. The pre-processing includes, but is not limited to, gaussian filtering, contrast enhancement, median filtering, mean filtering, or morphological processing. Morphological processing includes, but is not limited to, open-close computation, dilation, erosion, and the like. By preprocessing, noise in the original image can be filtered out, so that the success rate of image processing in subsequent steps is improved. The process of pre-processing is an optional step. In other embodiments, in the case that the original image is clearer or is easy to be subsequently processed, the computer device may perform the step of subsequently determining the rotation angle based on the acquired original image directly without preprocessing the original image.
Step S102, the computer equipment determines a first rotation angle according to the first two-dimensional code.
And S103, correcting the original image by the computer equipment according to the first rotation angle to obtain a first image.
Step S104, the computer equipment obtains a first recognition result of the first character based on the first image.
In some embodiments, the computing device inputs the first image into an OCR model, OCR processes the first image through the OCR model, and outputs the first recognition result. The OCR model is, for example, a deep learning model or other type of machine learning model. Since the first image is a rectified image, the direction of the character in the first image is a direction recognizable by the OCR model, for example, the character recognizable by the OCR model is a horizontal character, and the direction of the first character in the first image is a horizontal direction.
In some embodiments, after the computer device obtains the first recognition result for the first character, the computer device outputs the first recognition result. Outputting the first recognition result may be displaying the first recognition result on a display screen of the computer device, or may be storing the first recognition result in a memory in the computer device, or may be transmitting the first recognition result to another device.
In the method provided by the embodiment, the two-dimensional code in the original image is used as the auxiliary information to determine the rotation angle of the original image, so that the determined rotation angle is more accurate, and the original image can be corrected more accurately according to the rotation angle, so that a more accurate character recognition result is obtained.
Some embodiments of the present application provide various implementations as to how to determine the rotation angle from the two-dimensional code. The following two implementation manners are exemplified by taking the process of determining the rotation angle according to the first two-dimensional code as an example.
In the first implementation manner, the computer device determines the first rotation angle according to the position relationship between the first two-dimensional code and the first character.
The present embodiment provides various implementations for how to determine the position relationship between the first two-dimensional code and the first character. In some embodiments, the computer device determines a position of the first two-dimensional code and a position of the first character using an OCR model, and determines a positional relationship between the first two-dimensional code and the first character based on the position of the first two-dimensional code and the position of the first character. In other embodiments, the computer device determines, from the original image, a connected component corresponding to the two-dimensional code and a connected component corresponding to the character. The computer device determines a positional relationship between the connected component corresponding to the two-dimensional code and the connected component corresponding to the character as a positional relationship between the first two-dimensional code and the first character.
In some embodiments, the computer device determines the first rotation angle according to an angle of a first side of the connected domain corresponding to the first two-dimensional code with a horizontal direction. The first edge is parallel to a second edge of the connected component corresponding to the first character, and the second edge is the longest edge of the connected component corresponding to the first character.
Because at least one side of the two-dimensional code and the character is generally parallel, the angle between the long side of the character and the horizontal direction can be estimated according to the angle between the two-dimensional code and the horizontal direction, and the character can be corrected by rotating the long side of the character to be attached to the horizontal direction. In other words, rotating the two-dimensional code in the forward direction can rotate the character in the forward direction as well or rotate the character in the reverse direction. In particular, since the image and the two-dimensional code are also generally parallel on at least one side, in this way, the original image can be rotated into a "rectangle" in which the longer side of the original image is rotationally attached to the horizontal direction. The image thus rotated has only two states, one positive and one negative, and the original image can be rectified by rotating the image again by 180 degrees.
In some embodiments, the computer device determines the first rotation angle according to an angle between a diagonal line of the connected domain corresponding to the first two-dimensional code and a horizontal direction. Specifically, according to the angle between the diagonal line of the two-dimensional code and the horizontal direction, the angle at which the two-dimensional code is inclined with respect to the horizontal direction can be determined, so that the two-dimensional code is rotated to the forward direction. Since the two-dimensional code and the character are generally parallel to each other on at least one side, by rotating the two-dimensional code in the forward direction, the character can be rotated in the forward direction as well or in the reverse direction. Further, considering that in some scenes, the long side of the two-dimensional code in the image has missing or interference, in this way, the diagonal line is used to align the horizontal line instead of the long side, and some specific scenes are more stable.
In some embodiments, the computer device determines the first rotation angle according to a positional relationship between a connected component corresponding to the first two-dimensional code and a connected component corresponding to the first character.
In some embodiments, if the connected component corresponding to the first two-dimensional code in the original image is located at the left side of the connected component corresponding to the first character, it may be determined that the first rotation angle is 90 °, and the original image is rotated counterclockwise with respect to the rotation direction of the forward image, that is, the original image needs to be rotated clockwise when corrected. And after the original image is rotated by 90 degrees clockwise, the first two-dimensional code in the obtained image is positioned above the first character. As another example, if the first two-dimensional code is located above the first character in the original image, it is determined that rotation is not required. As another example, if the first two-dimensional code is located below the first character in the original image, the first rotation angle is determined to be 180 °.
In some embodiments, the process of determining the connected component corresponding to the two-dimensional code includes the following steps a to c.
And a, carrying out binarization processing on the original image by using computer equipment to obtain a binarized image. The binarization processing of the original image may be to set a pixel value of the original image, which is greater than a first preset threshold, to 1, and set a pixel value of the original image, which is less than the first preset threshold, to 0.
And step b, the computer equipment performs expansion operation on the binary image to determine N connected domains in the original image. The expansion matrix used when the expansion operation is performed on the binarized image may be a preset matrix. N is a positive integer greater than or equal to 1.
And step c, the computer equipment determines the connected domains corresponding to the two-dimensional code according to the N connected domains in the original image. Specifically, the computer device may determine whether the nth connected component is rectangular or square according to the positions of four vertices of the nth connected component in the original image. If the nth connected domain is not rectangular or square, the computer device determines if the (n + 1) th connected domain is rectangular or square. If the nth connected domain is rectangular or square, the computer device determines the length and width of the nth connected domain according to the positions of four vertexes or two vertexes (the two vertexes are diagonal vertexes) of the nth connected domain. If the difference between the length of the nth connected domain and the preset length is smaller than a second preset threshold, and the difference between the width of the nth connected domain and the preset width is smaller than a third preset threshold, the nth connected domain may be determined as the connected domain corresponding to the two-dimensional code. The second preset threshold may be the same as or different from the third preset threshold, and this embodiment is not limited.
Because the length and the width of the two-dimensional code are usually within a certain range, whether the connected domain is the connected domain corresponding to the two-dimensional code can be judged by judging whether the length and the width meet the conditions. In view of this, in the implementation manner of determining the connected component corresponding to the two-dimensional code, two threshold values (a second preset threshold value and a third preset threshold value) are set, and the two threshold values are used to determine whether the length and the width of the connected component meet the conditions, so as to find the connected component corresponding to the two-dimensional code.
If the difference between the length of the nth connected domain and the preset length is greater than or equal to a third preset threshold, or the difference between the width of the nth connected domain and the preset width is greater than or equal to a fourth preset threshold, the computer device may determine the nth connected domain as the connected domain corresponding to the character.
Similar to the implementation manner of determining the two-dimensional code connected domain, since the length and the width of the character connected domain are usually within a certain range, whether the connected domain is the connected domain corresponding to the character can be determined by whether the length and the width meet the conditions. In view of this, in the implementation manner of determining the connected component corresponding to the character, two threshold values (a third preset threshold value and a fourth preset threshold value) are set, and the two threshold values are used to determine whether the length and the width of the connected component meet the conditions, so as to find the connected component corresponding to the character.
In a second implementation manner, the computer device determines the first rotation angle according to the positioning information included in the first two-dimensional code.
The positioning information refers to positioning marks contained in the two-dimensional code, and the two-dimensional code can be correctly analyzed through the positioning information, so that the two-dimensional code can be identified no matter from which direction the two-dimensional code is read. For example, the first two-dimensional code is a QR code, and the positioning information is a glyph positioning point included in the QR code. The QR code comprises three clip-shaped positioning points, and the first rotation angle can be determined based on the three clip-shaped positioning points. Specifically, since the QR two-dimensional code has one characteristic: after three zigzag positioning points in the QR two-dimensional code are connected, an L shape can be obtained, and the inclination angle of the two-dimensional code can be known by utilizing the L shape. Since the two-dimensional code is usually positive with respect to the image, the image can be rotated in the forward direction by rotating the two-dimensional code in the forward direction, taking the inclination angle of the two-dimensional code as the inclination angle of the image. For another example, the first two-dimensional code is a DM code, and the positioning information is an L-shaped boundary included in the DM code.
The embodiment shown in fig. 1 described above describes how the first character is recognized based on the first two-dimensional code. In some embodiments, if an original image includes a plurality of two-dimensional codes and a plurality of characters to be recognized, the computer device may determine recognition results of the characters according to each two-dimensional code.
In some embodiments, the computer device divides the original image into a plurality of regions, each region including the two-dimensional code and the character to be recognized, obtains a rotation angle of each region according to the two-dimensional code in each region, and obtains a recognition result of the character in each region based on the rotation angle of each region, respectively.
For any two areas in the same original image, if the two-dimensional codes in the two areas are parallel and the characters in the two areas are parallel, the computer equipment determines that the rotation angles of the two areas are the same; if the two-dimensional codes in the two areas are not parallel or the characters in the two areas are not parallel, the computer device determines that the rotation angles of the two areas are different.
For example, the original image includes a first area and a second area, which are two different areas. The first area comprises the first two-dimensional code and the first character, and the second area comprises the second two-dimensional code and the second character. For this example, the process of character recognition includes the following cases a to B.
In case a, the rotation angles corresponding to the two regions are the same.
For example, the computer device determines a first rotation angle according to the first two-dimensional code; the computer equipment corrects the original image according to the first rotation angle to obtain a first image; the computer device obtains a first recognition result of the first character based on the first image. Under the condition that the computer equipment determines that the second two-dimensional code is parallel to the first two-dimensional code and the second character is parallel to the first character (namely that the two-dimensional codes of the first area and the second area are parallel and the characters of the first area and the second area are parallel), the computer equipment determines the rotation angle of the first area (namely the first rotation angle) according to the position relation between the first two-dimensional code and the first character or according to the positioning information included in the first two-dimensional code; the computer equipment corrects the first area according to the first rotation angle to obtain a first image; the computer device obtains a first recognition result of the first character based on the first image. Since the rotation angle of the second region is the same as the rotation angle of the first region, the computer device does not need to repeatedly determine the rotation angle for the second region, and corrects the second region according to the first rotation angle to obtain a second image; the computer device obtains a recognition result of the second character based on the second image.
In case B, the rotation angles corresponding to the two regions are different.
For example, the computer device determines a first rotation angle according to the first two-dimensional code; the computer equipment corrects the original image according to the first rotation angle to obtain a first image; the computer device obtains a first recognition result of the first character based on the first image. Under the condition that the computer equipment determines that the second two-dimensional code is parallel to the first two-dimensional code or the second character is parallel to the first character (namely that the two-dimensional codes of the first area and the second area are parallel or the characters of the first area and the second area are parallel), the computer equipment determines the rotation angle of the first area (namely the first rotation angle) according to the position relation between the first two-dimensional code and the first character or according to the positioning information included in the first two-dimensional code; the computer equipment corrects the first area according to the first rotation angle to obtain a first image; the computer device obtains a first recognition result of the first character based on the first image. In addition, the computer device determines a rotation angle of the second region (i.e. the second rotation angle) according to the position relationship between the second two-dimensional code and the second character, or according to positioning information included in the second two-dimensional code itself; the computer equipment corrects the second area according to the second rotation angle to obtain a second image; the computer device obtains a recognition result of the second character based on the second image.
In some embodiments, the computer device determines whether the two-dimensional codes are parallel according to whether the long sides of the two-dimensional codes are parallel. In some embodiments, the computer device obtains an included angle between the long sides of the two-dimensional codes, and determines whether the long sides of the two-dimensional codes are parallel according to a relationship between the included angle and a threshold. Exemplarily, the computer device acquires an included angle between a long edge of the second two-dimensional code and a long edge of the first two-dimensional code; and if the included angle between the long edge of the second two-dimensional code and the long edge of the first two-dimensional code is smaller than the first angle threshold value, determining that the second two-dimensional code is parallel to the first two-dimensional code. And if the included angle between the long edge of the second two-dimensional code and the long edge of the first two-dimensional code is greater than or equal to the first angle threshold value, determining that the second two-dimensional code is not parallel to the first two-dimensional code.
With respect to how two characters are determined to be parallel, in some embodiments, the computer device determines whether two characters are parallel based on whether the long edges of the two characters are parallel. In some embodiments, the computer device obtains an included angle between the long sides of the two characters, and determines whether the long sides of the two characters are parallel according to a relationship between the included angle and a threshold. Illustratively, the computer device acquires an included angle between a long edge of the second character and a long edge of the first character; and if the included angle between the long edge of the second character and the long edge of the first character is smaller than a second angle threshold value, determining that the second character is parallel to the first character. And if the included angle between the long side of the second character and the long side of the first character is larger than or equal to a second angle threshold value, determining that the second character is not parallel to the first character.
In this embodiment, the order of character recognition in different regions is not limited, for example, a processing order of a front-to-back operation is adopted, such as a concurrent process. For example, the computer device may obtain a recognition result of a first character based on the first image and then obtain a recognition result of a second character based on the second image; as another example, the computer device may obtain a recognition result of a second character based on the second image while obtaining a recognition result of the first character based on the first image.
Fig. 2 is a flowchart of a character recognition method according to an embodiment of the present application. The method shown in fig. 2 is based on the method shown in fig. 1, and further includes the following steps S105 to S108. Reference may be made to the description of fig. 1 for steps S101 to S104 in the method of fig. 2.
Step S105, the computer device determines whether the first recognition result is an expected result.
For example, the computer device determines whether the format of the first recognition result meets a preset condition, and if the format of the first recognition result meets the preset condition, the computer device determines that the first recognition result is an expected result; if the format of the first recognition result does not satisfy the preset condition, the computer device determines that the first recognition result is not an expected result.
The format of the recognition result is, for example, the type of character, the number of types of characters, and the number of characters in the recognition result. The predetermined condition is, for example, that the recognition result includes a combination of capital letters, lowercase letters, numbers and symbols, or, for example, that the number of characters in the recognition result is between 8-bit characters and 20-bit characters. For another example, in the case of identifying a product number, if the format of the identification result is batch-production week-model-date, it is determined that the format of the identification result satisfies the preset condition.
For example, the computer device determines whether the format of the first recognition result appears repeatedly, and if the format of the first recognition result does not appear repeatedly, the computer device determines that the first recognition result is an expected result; if the format of the first recognition result is repeated, the computer device determines that the first recognition result is not an expected result.
For example, the computer device determines whether the format of the first recognition result is recorded in a preset database and has not repeatedly appeared, and if the format of the first recognition result is recorded in the preset database and has not repeatedly appeared, the computer device determines that the first recognition result is an expected result; if the format of the first recognition result is not recorded in the preset database, or the format of the first recognition result is recorded in the preset database but the format of the first recognition result appears repeatedly, the computer device determines that the first recognition result is not the desired result.
And S106, the computer equipment outputs the first identification result under the condition that the computer equipment determines that the first identification result is an expected result.
And S107, under the condition that the computer equipment determines that the first recognition result is not an expected result, the computer equipment rotates the first image by 180 degrees to obtain a third image.
If the first recognition result is not the expected result, it indicates that the rotation angle determined according to the position of the two-dimensional code and the position of the character is wrong, that is, the character direction after rotation according to the rotation angle is opposite to the actual character direction. Thus, the computer device may rotate the first image 180 degrees clockwise or counterclockwise, obtaining a third image. The orientation of the characters in the third image is the same as the actual character orientation.
And S108, the computer equipment obtains a second recognition result of the first character based on the third image.
In the method provided by this embodiment, by determining whether the character recognition result (the first recognition result) recognized for the first time is the expected result, and performing 180-degree rotation on the image (the first image) after the first rotation again when the character recognition result is not the expected result, the direction of the character in the image (the second image) after the rotation again is the same as the direction of the character, and the character recognition result in the original image is obtained through the image after the rotation again, thereby avoiding that the recognition result is inaccurate due to an error in the rotation angle determined according to the two-dimensional code, and thus improving the accuracy of character recognition.
Alternatively, in the above embodiment, instead of rotating the first image by 180 degrees to obtain the third image, the OCR model capable of recognizing the character rotated by 180 degrees may be directly used to recognize the first character. For example, if it is determined that the first recognition result is not the desired result, the computer device inputs the first image into a character recognition model, processes the first image through the character recognition model, and outputs a third recognition result of the first character, the character recognition model being used for recognizing a character rotated by an angle of 180 degrees.
The above-described embodiment takes as an example a flow of obtaining a character recognition result for one original image. In other embodiments, the computer device obtains a plurality of original images, and in a case that the rotation angles of the plurality of original images are not identical, the computer device may adaptively determine the rotation angle of each original image according to the positions of the two-dimensional code and the character region in each original image, so as to obtain a more accurate character recognition result of each original image.
Fig. 3 is a schematic structural diagram of a character recognition apparatus 300 according to an embodiment of the present application. Referring to fig. 3, the apparatus 300 includes:
an obtaining module 301, configured to obtain an original image, where the original image includes a first two-dimensional code and a first character to be recognized;
a determining module 302, configured to determine a first rotation angle according to the first two-dimensional code;
a correcting module 303, configured to correct the original image according to the first rotation angle to obtain a first image;
the obtaining module 301 is further configured to obtain a first recognition result of the first character based on the first image.
In some embodiments, the determining module 302 is configured to determine the first rotation angle according to a position relationship between the first two-dimensional code and the first character.
In some embodiments, the determining module 302 is configured to determine the first rotation angle according to an angle between a first edge of the connected component corresponding to the first two-dimensional code and a horizontal direction, where the first edge is parallel to a second edge of the connected component corresponding to the first character, and the second edge is the longest edge of the connected component corresponding to the first character.
In some embodiments, the determining module 302 is configured to determine the first rotation angle according to an angle between a diagonal line of the connected component corresponding to the first two-dimensional code and a horizontal direction.
In some embodiments, the determining module 302 is configured to determine the first rotation angle according to a position relationship between a connected component corresponding to the first two-dimensional code and a connected component corresponding to the first character.
In some embodiments, the determining module 302 is configured to determine the first rotation angle according to the positioning information included in the first two-dimensional code.
In some embodiments, the first two-dimensional code is a quick response QR code, and the positioning information is a glyph positioning point included in the QR code; alternatively, the first and second electrodes may be,
the first two-dimensional code is a data matrix DM code, and the positioning information is an L-shaped boundary included by the DM code.
In some embodiments, the original image further includes a second two-dimensional code and a second character to be recognized, and the determining module 302 is further configured to determine a second rotation angle according to the second two-dimensional code when it is determined that the second two-dimensional code is not parallel to the first two-dimensional code or the second character is not parallel to the first character;
the correcting module 303 is further configured to correct the original image according to the second rotation angle to obtain a second image;
the obtaining module 301 is further configured to obtain a recognition result of the second character based on the second image.
In some embodiments, the original image further includes a second two-dimensional code and a second character to be recognized, and the obtaining module 301 is further configured to, when it is determined that the second two-dimensional code is parallel to the first two-dimensional code and the second character is parallel to the first character, obtain a recognition result of the second character based on the first image.
In some embodiments, the original image includes a first area and a second area, the first two-dimensional code and the first character are both located in the first area, and the second two-dimensional code and the second character are both located in the second area.
In some embodiments, the apparatus further comprises:
and the output module is used for outputting the first recognition result under the condition that the first recognition result is determined to be an expected result.
In some embodiments, the rectification module 303 is further configured to rotate the first image by 180 degrees to obtain a third image if it is determined that the first recognition result is not the expected result;
the obtaining module 301 is further configured to obtain a second recognition result of the first character based on the third image.
In some embodiments, the obtaining module 301 is further configured to, in a case that it is determined that the first recognition result is not an expected result, input the first image into a character recognition model, process the first image through the character recognition model, and output a third recognition result of the first character, where the character recognition model is configured to recognize a character with a rotation angle of 180 degrees.
All the above optional technical solutions may be combined arbitrarily to form optional embodiments of the present application, and are not described herein again.
It should be noted that: in the character recognition device provided in the above embodiment, only the division of the above functional modules is used for illustration in character recognition, and in practical applications, the above function distribution may be completed by different functional modules according to needs, that is, the internal structure of the character recognition device is divided into different functional modules to complete all or part of the above described functions. In addition, the character recognition device and the character recognition method provided by the above embodiments belong to the same concept, and specific implementation processes thereof are described in the method embodiments in detail and are not described herein again.
Fig. 4 is a schematic structural diagram of a computer device 400 according to an embodiment of the present application.
The computer device 400 includes at least one processor 401, memory 402, and at least one network interface 403.
The processor 401 is, for example, a Central Processing Unit (CPU), a Network Processor (NP), a Graphics Processing Unit (GPU), a neural-Network Processing Unit (NPU), a Data Processing Unit (DPU), a microprocessor, or one or more integrated circuits for implementing the present disclosure. For example, the processor 401 may include an application-specific integrated circuit (ASIC), a Programmable Logic Device (PLD), or a combination thereof. PLDs are, for example, complex Programmable Logic Devices (CPLDs), field-programmable gate arrays (FPGAs), general Array Logic (GALs), or any combination thereof.
The Memory 402 is, for example, but not limited to, a read-only Memory (ROM) or other type of static storage device that can store static information and instructions, a Random Access Memory (RAM) or other type of dynamic storage device that can store information and instructions, an electrically erasable programmable read-only Memory (EEPROM), a compact disc read-only Memory (CD-ROM) or other optical disc storage, optical disc storage (including compact disc, laser disc, optical disc, digital versatile disc, blu-ray disc, etc.), a magnetic disc storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer. Optionally, the memory 402 is separate and coupled to the processor 401 through an internal connection 404. Alternatively, the memory 402 and the processor 401 may alternatively be integrated.
The network interface 403 uses any transceiver or the like for communicating with other devices or communication networks. The network interface 403 includes, for example, at least one of a wired network interface or a wireless network interface. The wired network interface is, for example, an ethernet interface. The ethernet interface is for example an optical interface, an electrical interface or a combination thereof. The wireless network interface is, for example, a Wireless Local Area Network (WLAN) interface, a cellular network interface, or a combination thereof.
In some embodiments, processor 401 includes one or more CPUs, such as CPU0 and CPU1 shown in FIG. 4.
In some embodiments, computer device 400 optionally includes multiple processors, such as processor 401 and processor 405 shown in fig. 4. Each of these processors is, for example, a single-core processor (single-CPU) or, for example, a multi-core processor (multi-CPU). A processor herein may alternatively refer to one or more devices, circuits, and/or processing cores that may be configured to process data, such as computer program instructions.
In some embodiments, computer device 400 also includes internal connections 404. The processor 401, the memory 402 and the at least one network interface 403 are connected by an internal connection 404. Internal connections 404 include pathways that convey information between the aforementioned components. Optionally, internal connection 404 is a single board or bus. Optionally, internal connections 404 are divided into address buses, data buses, control buses, and the like.
In some embodiments, computer device 400 also includes input-output interface 406. The input/output interface 406 is connected to the internal connection 404.
Alternatively, the processor 401 may implement the method in the above-described embodiment by reading the program code stored in the memory 402, or the processor 401 may implement the method in the above-described embodiment by the program code stored internally. In the case where the processor 401 implements the method in the above-described embodiment by reading the program code stored in the memory 402, the program code 410 implementing the character recognition method provided in the embodiment of the present application is stored in the memory 402.
For more details of the processor 401 to implement the above functions, reference is made to the description of the foregoing method embodiments, which are not repeated here.
Fig. 5 is a schematic structural diagram of a computer-readable storage medium 500 provided in an embodiment of the present application, where computer program instructions 501 are stored in the computer-readable storage medium, and when executed by a processor, the computer program instructions 501 implement the steps in the method shown in the embodiment of fig. 1.
Embodiments of the present application further provide a computer program product, which includes computer program instructions, and when executed by a processor, the computer program instructions implement the steps in the method shown in the embodiment of fig. 1.
It should be noted that, in the present specification, the embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the system or the device disclosed by the embodiment, the description is simple because the system or the device corresponds to the method disclosed by the embodiment, and the relevant points can be referred to the method part for description.
It should be understood that in the present application, "at least one" means one or more, "a plurality" means two or more. "and/or" for describing an association relationship of associated objects, indicating that there may be three relationships, e.g., "a and/or B" may indicate: only A, only B and both A and B are present, wherein A and B may be singular or plural. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. "at least one of the following" or similar expressions refer to any combination of these items, including any combination of single item(s) or plural items. For example, at least one (one) of a, b, or c, may represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", wherein a, b, c may be single or plural.
It is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising a … …" does not exclude the presence of another identical element in a process, method, article, or apparatus that comprises the element.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (15)

1. A character recognition method, comprising:
acquiring an original image, wherein the original image comprises a first two-dimensional code and a first character to be recognized;
determining a first rotation angle according to the first two-dimensional code;
correcting the original image according to the first rotation angle to obtain a first image;
based on the first image, a first recognition result of the first character is obtained.
2. The method of claim 1, wherein determining the first rotation angle according to the first two-dimensional code comprises:
and determining the first rotation angle according to the position relation between the first two-dimensional code and the first character.
3. The method according to claim 2, wherein the determining the first rotation angle according to the position relationship between the first two-dimensional code and the first character comprises:
and determining the first rotation angle according to an angle between a first edge of the connected domain corresponding to the first two-dimensional code and the horizontal direction, wherein the first edge is parallel to a second edge of the connected domain corresponding to the first character, and the second edge is the longest edge in the connected domain corresponding to the first character.
4. The method according to claim 2, wherein the determining the first rotation angle according to the position relationship between the first two-dimensional code and the first character comprises:
and determining the first rotation angle according to the angle between the diagonal line of the connected domain corresponding to the first two-dimensional code and the horizontal direction.
5. The method according to claim 2, wherein the determining the first rotation angle according to the position relationship between the first two-dimensional code and the first character comprises:
and determining the first rotation angle according to the position relation between the connected domain corresponding to the first two-dimensional code and the connected domain corresponding to the first character.
6. The method of claim 1, wherein determining a first rotation angle according to the first two-dimensional code comprises:
and determining a first rotation angle according to the positioning information included in the first two-dimensional code.
7. The method according to claim 6, wherein the first two-dimensional code is a Quick Response (QR) code, and the positioning information is a glyph positioning point included in the QR code; alternatively, the first and second electrodes may be,
the first two-dimensional code is a data matrix DM code, and the positioning information is an L-shaped boundary included by the DM code.
8. The method of claim 1, wherein the original image further comprises a second two-dimensional code and a second character to be recognized, the method further comprising:
under the condition that the second two-dimensional code is determined not to be parallel to the first two-dimensional code or the second character is determined not to be parallel to the first character, determining a second rotation angle according to the second two-dimensional code;
correcting the original image according to the second rotation angle to obtain a second image;
and obtaining a recognition result of the second character based on the second image.
9. The method of claim 1, wherein the original image further comprises a second two-dimensional code and a second character to be recognized, the method further comprising:
and under the condition that the second two-dimensional code is determined to be parallel to the first two-dimensional code and the second character is determined to be parallel to the first character, obtaining a recognition result of the second character based on the first image.
10. The method of claim 1, wherein after obtaining the first recognition result for the first character based on the first image, the method further comprises:
in a case where it is determined that the first recognition result is an expected result, the first recognition result is output.
11. The method of claim 1, wherein after obtaining the first recognition result for the first character based on the first image, the method further comprises:
under the condition that the first recognition result is determined not to be an expected result, rotating the first image by 180 degrees to obtain a third image;
and obtaining a second recognition result of the first character based on the third image.
12. The method of claim 1, wherein after obtaining the first recognition result for the first character based on the first image, the method further comprises:
and under the condition that the first recognition result is determined not to be an expected result, inputting the first image into a character recognition model, processing the first image through the character recognition model, and outputting a third recognition result of the first character, wherein the character recognition model is used for recognizing the character with the rotation angle of 180 degrees.
13. A character recognition apparatus, comprising:
the device comprises an acquisition module, a recognition module and a recognition module, wherein the acquisition module is used for acquiring an original image, and the original image comprises a first two-dimensional code and a first character to be recognized;
the determining module is used for determining a first rotating angle according to the first two-dimensional code;
the correction module is used for correcting the original image according to the first rotation angle to obtain a first image;
the obtaining module is further configured to obtain a first recognition result of the first character based on the first image.
14. A computer device, characterized in that the computer device comprises a processor and a memory, in which computer program instructions are stored, which computer program instructions, when executed by the processor, carry out the steps in the method according to any one of claims 1-12.
15. A computer-readable storage medium, having stored thereon computer program instructions, which, when executed by a processor, implement the steps in the method according to any one of claims 1-12.
CN202210994137.8A 2022-08-18 2022-08-18 Character recognition method, device, equipment and storage medium Pending CN115376136A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210994137.8A CN115376136A (en) 2022-08-18 2022-08-18 Character recognition method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210994137.8A CN115376136A (en) 2022-08-18 2022-08-18 Character recognition method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115376136A true CN115376136A (en) 2022-11-22

Family

ID=84065532

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210994137.8A Pending CN115376136A (en) 2022-08-18 2022-08-18 Character recognition method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115376136A (en)

Similar Documents

Publication Publication Date Title
CN110046529B (en) Two-dimensional code identification method, device and equipment
CN110309687B (en) Correction method and correction device for two-dimensional code image
EP3309704B1 (en) Two-dimensional code partitioning and decoding method and system
CN107633192B (en) Bar code segmentation and reading method based on machine vision under complex background
CN111079772B (en) Image edge extraction processing method, device and storage medium
US20140247470A1 (en) Camera-based document imaging
US20110069890A1 (en) Fast line linking
CN109784250B (en) Positioning method and device of automatic guide trolley
EP2974261A2 (en) Systems and methods for classifying objects in digital images captured using mobile devices
CN111860489A (en) Certificate image correction method, device, equipment and storage medium
EP3067858B1 (en) Image noise reduction
CN110647882A (en) Image correction method, device, equipment and storage medium
CN107545223B (en) Image recognition method and electronic equipment
CN113449534B (en) Two-dimensional code image processing method and device
US20220398716A1 (en) Method of detecting product defects, electronic device, and storage medium
CN111311497A (en) Bar code image angle correction method and device
CN112767412B (en) Vehicle part classification method and device and electronic equipment
CN112507938A (en) Geometric feature calculation method, geometric feature recognition method and geometric feature recognition device for text primitives
US11190684B2 (en) Image processing apparatus, image processing method, and storage medium
CN112699704A (en) Method, device, equipment and storage device for detecting bar code
CN116976372A (en) Picture identification method, device, equipment and medium based on square reference code
CN115376136A (en) Character recognition method, device, equipment and storage medium
CN112800824B (en) Method, device, equipment and storage medium for processing scanned file
CN111753573B (en) Two-dimensional code image recognition method and device, electronic equipment and readable storage medium
JP4869365B2 (en) Image processing apparatus and image processing method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination