Disclosure of Invention
Accordingly, it is necessary to provide a character recognition method, a device, a computer device, and a computer-readable storage medium, which can perform overall recognition on a character image and improve the accuracy of character recognition, for the problem of low accuracy of character recognition in the conventional technology.
A character recognition method comprising the steps of:
acquiring a character image to be recognized, and carrying out gray processing on the character image to be recognized to obtain a preprocessed character image;
inputting the preprocessed character image as a whole into a preset character recognition model, and calculating a first character recognition result of the preprocessed character image by using the character recognition model, wherein the character recognition model is generated by training a set neural network model by using a training sample set of the character image;
rotating the preprocessed character image for a plurality of times, inputting the preprocessed character image after each rotation as a whole into the character recognition model, and calculating a second character recognition result of the preprocessed character image after each rotation by the character recognition model;
and obtaining characters in the character image to be recognized according to the first character recognition result and the second character recognition result.
According to the character recognition method, the character recognition model is preset, then the character image to be recognized is processed and then is integrally input into the character recognition model, the character image is integrally recognized through the character recognition model, character segmentation is not needed any more, therefore, false recognition caused by character adhesion during character segmentation is avoided, the character recognition accuracy is improved, the method is effective and robust, and the method has a great application value.
In one embodiment, deriving the character in the character image to be recognized according to the first character recognition result and the second character recognition result includes: if the first character recognition result is the same as each second character recognition result, calculating the length-width ratio of the preprocessed character image before rotation and the length-width ratio of the preprocessed character image after each rotation; calculating the total character length of the first character recognition result or the second character recognition result; and if all the length-width ratios are larger than the product of the total length of the characters and a first ratio and smaller than the product of the total length of the characters and a second ratio, taking the first character recognition result or the second character recognition result as the character recognition result of the character image to be recognized. Considering that when the pixel points of the character image are symmetrical, the identification results are easy to be consistent, if the wrong identification occurs, the wrong result is taken as the final output, and the problem can be effectively avoided by comparing the length-width ratio with the total length of the character, so that the correct identification result is further screened out.
In one embodiment, after the graying processing is performed on the character image to be recognized and before the preprocessed character image is obtained, the method further includes the steps of: carrying out image binarization on the grayed character image to be recognized to obtain a binary image; and carrying out image normalization on the binary image.
In one embodiment, image normalizing the binary image comprises: and adjusting the binary image into a pattern of black bottom white characters.
In one embodiment, adjusting the binary image to a pattern of black bottom white characters comprises: acquiring a first contour of a white part in the binary image; performing black-white overturning processing on the binary image to obtain a second outline of a white part in the overturned binary image; calculating the maximum width of the first contour and the maximum width of the second contour respectively; if the maximum width of the first contour is smaller than the maximum width of the second contour, the binary image before black-white inversion is reserved, otherwise, the binary image after black-white inversion is reserved.
In one embodiment, image normalizing the binary image further comprises: and removing the boundary of the binary image, and scaling the binary image with the boundary removed to a preset size.
In one embodiment, removing the boundary of the binary image comprises: respectively carrying out horizontal integral projection and vertical integral projection on the binary image; traversing the row pixels of the binary image after horizontal integral projection, and acquiring the starting row number and the ending row number in the row pixels; traversing the column pixels of the binary image after vertical integral projection, and acquiring the initial column number and the ending column number in the column pixels; and setting an interested region in the binary image according to the starting line number, the ending line number, the starting column number and the ending column number, and removing the boundary except the interested region in the binary image.
A character recognition apparatus comprising:
the character image preprocessing module is used for acquiring a character image to be recognized, and carrying out graying processing on the character image to be recognized to obtain a preprocessed character image;
the first character recognition module is used for inputting the preprocessed character images into a preset character recognition model as a whole, and calculating a first character recognition result of the preprocessed character images by the character recognition model, wherein the character recognition model is generated by training a set neural network model by a training sample set of the character images;
the second character recognition module is used for rotating the preprocessed character image for a plurality of times, inputting the preprocessed character image after each rotation as a whole into the character recognition model, and calculating a second character recognition result of the preprocessed character image after each rotation by the character recognition model;
and the character recognition result determining module is used for obtaining characters in the character image to be recognized according to the first character recognition result and the second character recognition result.
The character recognition device is provided with the character recognition model in advance, then the character recognition model is input integrally after the character image to be recognized is processed, the character image is recognized integrally through the character recognition model, character segmentation is not needed any more, and therefore mistaken recognition caused by character adhesion during character segmentation is avoided, accuracy of character recognition is improved, the character recognition device is effective in robustness, and the character recognition device has great application value.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of any of the methods described above when executing the program.
The computer equipment is characterized in that a character recognition model is preset, then the character recognition model is input integrally after the character image to be recognized is processed, the character image is recognized integrally through the character recognition model, character segmentation is not needed any more, and therefore misrecognition caused by character adhesion during character segmentation is avoided, accuracy of character recognition is improved, and the computer equipment is effective in robustness and has great application value.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any of the above.
The computer readable storage medium is provided with the character recognition model in advance, then the character image to be recognized is input into the character recognition model in an integral mode after being processed, the character image is recognized in an integral mode through the character recognition model, character segmentation is not needed any more, therefore, false recognition caused by character adhesion during character segmentation is avoided, character recognition accuracy is improved, and the computer readable storage medium is effective in robustness and has a high application value.
Detailed Description
In order to further explain the technical means and effects of the present invention, the following description of the present invention with reference to the accompanying drawings and preferred embodiments will be made for clarity and completeness.
As shown in fig. 1, in one embodiment, there is provided a character recognition method including the steps of:
s110, acquiring a character image to be recognized, and carrying out gray processing on the character image to be recognized to obtain a preprocessed character image;
the character image to be recognized is the image needing character recognition. The graying processing of the image to be recognized can be realized according to the existing mode in the prior art, and the preprocessed character image of the character image to be recognized is obtained after the graying processing of the image.
S120, inputting the preprocessed character image as a whole into a preset character recognition model, and calculating a first character recognition result of the preprocessed character image by using the character recognition model, wherein the character recognition model is generated by training a set neural network model by using a training sample set of the character image;
the preset character recognition model is a model generated by training a set neural network model by a training sample set, and the character recognition model is used for performing character recognition on a character image to be recognized. There are various types of neural network models, and optionally, the neural network model is set as a Back Propagation (BP) neural network model. The training sample set comprises a plurality of character image training samples, and optionally, after an original character image is obtained, a series of processing such as graying, binarization, normalization and the like is performed on the original character image to obtain the character image training samples. The character image is input as a whole, namely the character segmentation is not needed to be carried out on the preprocessed character image, and the character image is directly used as a whole for character recognition. And after the preprocessed character image is taken as a whole to be input into the character recognition model, the character recognition result A is obtained by the character recognition model.
S130, rotating the preprocessed character image for a plurality of times, inputting the preprocessed character image after each rotation into the character recognition model as a whole, and calculating a second character recognition result of the preprocessed character image after each rotation by the character recognition model;
the number of times of rotating the preprocessed character image can be determined according to actual needs, the preprocessed character image after each rotation is input into the character recognition model, and a character recognition result of the preprocessed character image after each rotation is obtained. For example, since the pre-processed character image may be placed in the front or in the back, and therefore the direction of the character cannot be determined, in one embodiment, as shown in fig. 2, the pre-processed character image may be rotated three times: and rotating the preprocessed character image A clockwise by 90 degrees to obtain a preprocessed character image B, rotating the preprocessed character image A clockwise by 180 degrees to obtain a preprocessed character image C, and rotating the preprocessed character image C clockwise by 90 degrees to obtain a preprocessed character image D, wherein the preprocessed character image A is the preprocessed character image in S120. And respectively inputting the preprocessed character images after the three rotations into the character recognition model to obtain a character recognition result B, a character recognition result C and a character recognition result D.
S140, obtaining characters in the character image to be recognized according to the first character recognition result and the second character recognition result.
The character recognition method provided by the embodiment can be implemented by a corresponding program, and the program runs in a terminal, such as a mobile phone, a tablet computer or a computer. The method carries out integral identification on the character image area, omits the step of character segmentation, avoids false identification caused by character adhesion during character segmentation, is effective and robust, and has great application value. In addition, the method effectively avoids the error of character recognition caused by different terminal placement modes by comparing the recognition results of all characters after the image is rotated, and improves the accurate probability of actual recognition.
In order to further improve the accuracy of character recognition, in an embodiment, after performing graying processing on the character image to be recognized and before obtaining a preprocessed character image, the method further includes the steps of: carrying out image binarization on the grayed character image to be recognized to obtain a binary image; and carrying out image normalization on the binary image. It should be noted that the present invention is not limited to this, and may perform only the operation of image binarization, perform only the operation of image normalization, or perform other image processing besides the image binarization and the image normalization.
The image binarization is to set the gray value of a pixel point on an image to be 0 or 255, that is, the whole image presents an obvious black and white effect. The binarization of the image is beneficial to further processing of the image, so that the image is simple, the data volume is reduced, and the outline of an interested target can be highlighted. The image binarization has various implementation modes, and optionally, the image binarization is implemented by adopting an Otsu algorithm.
The image normalization is to convert the original image to be processed into a corresponding unique standard form (the standard form has invariant characteristics to affine transformations such as translation, rotation, scaling and the like) through a series of transformations (namely, a set of parameters is found by using invariant moment of the image so that the influence of other transformation functions on image transformation can be eliminated). Image normalization makes the image resistant to attacks by geometric transformations. There are various implementations of image normalization, for example, in one embodiment, image normalization of the binary image includes S1101: and adjusting the binary image into a pattern of black bottom white characters.
As shown in fig. 3, in one embodiment, adjusting the binary image into a pattern of black bottom white characters comprises:
s1101a, acquiring a first outline A of a white part in the binary image;
there are various implementations for extracting the contour of the white portion of the binary image, for example, the contour a is extracted using the function cvFindContours.
S1101B, performing black and white inversion processing on the binary image to obtain a second outline B of a white part in the inverted binary image;
the black-white turning processing is carried out on the binary image, namely, white pixel points in the binary image are changed into black pixel points, and meanwhile, the black pixel points are changed into white pixel points. After the black-and-white flip, the contour B can be extracted by the function cvFindContours.
S1101c, respectively calculating the maximum width maxw _ a of the outline A and the maximum width maxw _ B of the outline B;
calculating the maximum width of the contour can be done according to methods known in the art.
And S1101d, if the maximum width maxw _ a of the outline A is smaller than the maximum width maxw _ B of the outline B, retaining the binary image before black-white inversion, otherwise, retaining the binary image after black-white inversion.
The binary image before the inversion is the binary image in S1101 a. Because the maximum width of the outline of the white part when the picture is in the black background and white characters is smaller than the maximum width of the outline of the white part when the picture is in the white background and black characters, whether the original picture is in the pattern of the black background and white characters can be judged according to the rule, and adjustment is made.
In another embodiment, image normalizing the binary image comprises S1102: the image normalization of the binary image further comprises: and removing the boundary of the binary image, and scaling the binary image with the boundary removed to a preset size. Step S1102 and step S1101 may be executed simultaneously or alternatively. The preset size may be determined according to actual needs, for example, scaling the binary image to a height of 50 pixels.
As shown in fig. 4, in one embodiment, removing the boundary of the binary image includes:
s1102a, respectively carrying out horizontal integral projection and vertical integral projection on the binary image;
s1102b, traversing the line pixels of the binary image after horizontal integral projection, and acquiring the starting line number and the ending line number in the line pixels;
s1102c, traversing the column pixels of the binary image after vertical integral projection, and acquiring the initial column number and the ending column number in the column pixels;
s1102d, setting a region of interest (ROI) in the binary image according to the starting row number, the ending row number, the starting column number, and the ending column number, and removing a boundary except the region of interest in the binary image. The area enclosed by the starting row number, the ending row number, the starting column number and the ending column number is the region of interest.
It should be noted that the above process of processing the character image to be recognized is also applicable to obtaining a training sample set in the character recognition model, that is, after obtaining a plurality of original character images, the above method may be adopted to perform graying processing, image binarization and image normalization on the plurality of original character images, then train the set neural network model through the character images of the plurality of image normalization, and retain the network model parameters to obtain the character recognition model.
As shown in fig. 5, in one embodiment, deriving the character in the character image to be recognized according to the first character recognition result and the second character recognition result includes:
s1401, if the first character recognition result is the same as each second character recognition result, calculating the aspect ratio of the preprocessed character image before rotation and the aspect ratio of the preprocessed character image after each rotation; calculating the total character length of the first character recognition result or the second character recognition result;
since the requirement for the accuracy of character recognition is relatively strict in practical commercial applications, it is necessary to confirm that the character recognition results in step S120 and step S130 are consistent, so as to increase the probability of the accuracy of actual recognition. Therefore, in this step, the obtained character recognition results need to be compared, if the character recognition results are consistent, the character recognition result is retained, and if the character recognition results are inconsistent, the character recognition result is discarded. For example, four character recognition results are obtained by the recognition method shown in fig. 2: the character recognition method comprises the steps of obtaining a character recognition result A, a character recognition result B, a character recognition result C and a character recognition result D, reserving the character recognition result A, the character recognition result B, the character recognition result C and the character recognition result D if the character recognition result A is equal to the character recognition result B, the character recognition result C is equal to the character recognition result D, and discarding the character recognition result if the four character recognition results are inconsistent.
The pre-processed character image before rotation is the pre-processed character image in step S120. For example, as shown in fig. 2, this step calculates four aspect Ratio ratios of the pre-processed character image a, the pre-processed character image B, the pre-processed character image C, and the pre-processed character image D, respectively.
Since the respective character recognition results are the same, the total character length Str L en only needs to be calculated from the character recognition results of any one of them.
S1402, if all the length-width ratios are larger than the product of the total length of the characters and the first ratio and smaller than the product of the total length of the characters and the second ratio, taking the first character recognition result or the second character recognition result as the character recognition result of the character image to be recognized.
For example, a is set to 1/2, B is set to 3/2, whether Ratio ∈ ((1/2) × Str L en, (3/2) × Str L en) is established or not is respectively judged, if each Ratio value belongs to the range, the character recognition result is determined as the final recognition result, and if part of the Ratio values does not belong to the range, the character recognition result is discarded.
When the pixel points or contents of the character images are symmetrical, the character recognition results are easy to be consistent, if the character images are recognized by mistake, the wrong character recognition results are taken as final output, and the problem can be effectively solved through the embodiment shown in fig. 5, so that the correct character recognition results can be further screened out.
For a better understanding of the present invention, reference is made to the following detailed description taken in conjunction with a specific embodiment.
As shown in fig. 6, a character recognition method includes a training phase and a testing phase:
s1, training:
s11, acquiring a training sample set containing a plurality of character images, and graying the training sample set;
s12, carrying out image binarization on the grayed training sample set by utilizing an Otsu algorithm to obtain a binary image;
s13, carrying out image normalization on the binary image, wherein the image normalization comprises the following steps: adjusting the binary image into a pattern of black bottom white characters; removing the boundary of the binary image, and unifying the size; wherein adjusting the pattern and removing the border may be performed according to the above-described manner;
and S14, training a BP neural network model by taking the normalized binary image, and storing parameters of the neural network model to obtain a trained character recognition model.
S2, testing:
s21, acquiring a character image to be recognized, and graying the character image to be recognized;
s22, carrying out image binarization on the grayed character image to be recognized by utilizing an Otsu algorithm to obtain a binary image;
s23, carrying out image normalization on the binary image, wherein the image normalization comprises the following steps: adjusting the binary image into a pattern of black bottom white characters; removing the boundary of the binary image, and unifying the size; wherein adjusting the pattern and removing the border may be performed according to the above-described manner;
s24, taking the normalized binary image, recognizing the normalized binary image by using a trained BP neural network model (character recognition model) to obtain a recognition result A, then clockwise rotating the normalized binary image by 90 degrees, recognizing the normalized binary image by using the trained BP neural network model to obtain a recognition result B, clockwise rotating the normalized binary image by 180 degrees, recognizing the normalized binary image by using the trained BP neural network model to obtain a recognition result C, clockwise rotating the normalized binary image by 90 degrees, recognizing the normalized binary image by using the trained BP neural network model to obtain a recognition result D, and ensuring that the character images in four directions are respectively recognized once to obtain four recognition results to be determined next step;
s25, determining whether the recognition result a, B, C, D is true, if the four recognition results are the same, retaining the recognition result, proceeding to the next step, and if the four recognition results are not the same, discarding the result;
s26, calculating the aspect Ratio of the four character images to be recognized and the total character length Str L en. of the obtained recognition result, respectively, determines whether Ratio ∈ ((1/2) × Str L en, (3/2) × Str L en) is true, if all Ratio values are within the range, the result is determined as the final recognition result, and if the condition is not true, the result is discarded.
Based on the same inventive concept, the invention also provides a character recognition device, and the following detailed description is provided for the specific implementation mode of the character recognition device in combination with the accompanying drawings.
As shown in fig. 7, a character recognition apparatus includes:
the character image preprocessing module 110 is configured to obtain a character image to be recognized, perform graying processing on the character image to be recognized, and obtain a preprocessed character image;
a first character recognition module 120, configured to input the preprocessed character images as a whole into a preset character recognition model, and calculate a first character recognition result of the preprocessed character images from the character recognition model, where the character recognition model is generated by training a set neural network model by using a training sample set of the character images;
a second character recognition module 130, configured to rotate the preprocessed character image for multiple times, input the preprocessed character image after each rotation as a whole into the character recognition model, and calculate, by the character recognition model, a second character recognition result of the preprocessed character image after each rotation;
and a character recognition result determining module 140, configured to obtain characters in the character image to be recognized according to the first character recognition result and the second character recognition result.
The character recognition device (character classifier) provided by the embodiment can be operated in a terminal, such as a mobile phone, a tablet computer or a computer. The device carries out integral identification on the character image area, omits the step of character segmentation, avoids false identification caused by character adhesion during character segmentation, is effective and robust, and has great application value. In addition, the device effectively avoids the error of character recognition caused by different terminal placing modes through the comparison of the recognition results of all characters after the image is rotated, and improves the accurate probability of actual recognition.
In one embodiment, the character recognition result determining module 140 calculates an aspect ratio of the pre-processed character image before rotation and an aspect ratio of the pre-processed character image after each rotation when the first character recognition result and each second character recognition result are the same; calculating the total character length of the first character recognition result or the second character recognition result; and if all the length-width ratios are larger than the product of the total length of the characters and a first ratio and smaller than the product of the total length of the characters and a second ratio, taking the first character recognition result or the second character recognition result as the character recognition result of the character image to be recognized. When the pixel points or the contents of the character images are symmetrical, the character recognition results are easy to be consistent, if the wrong recognition occurs, the wrong result is taken as the final output, and the embodiment can effectively solve the problem and further screen out the correct character recognition result.
In order to further improve the accuracy of character recognition, in an embodiment, the character image preprocessing module 110 is further configured to perform image binarization on the grayed character image to be recognized to obtain a binary image, and perform image normalization on the binary image, after performing graying processing on the character image to be recognized and before obtaining the preprocessed character image.
In one embodiment, the character image pre-processing module 110 image normalizes the binary image by adjusting the binary image to a pattern of black bottom white characters. Optionally, the character image preprocessing module 110 obtains a first contour of a white portion in the binary image; performing black-white overturning processing on the binary image to obtain a second outline of a white part in the overturned binary image; calculating the maximum width of the first contour and the maximum width of the second contour respectively; if the maximum width of the first contour is smaller than the maximum width of the second contour, the binary image before black-white inversion is reserved, otherwise, the binary image after black-white inversion is reserved.
In one embodiment, the character image preprocessing module 110 further performs image normalization on the binary image by removing a boundary of the binary image and scaling the boundary-removed binary image to a preset size. Optionally, the character image preprocessing module 110 performs horizontal integral projection and vertical integral projection on the binary image respectively; traversing the row pixels of the binary image after horizontal integral projection, and acquiring the starting row number and the ending row number in the row pixels; traversing the column pixels of the binary image after vertical integral projection, and acquiring the initial column number and the ending column number in the column pixels; and setting an interested region in the binary image according to the starting line number, the ending line number, the starting column number and the ending column number, and removing the boundary except the interested region in the binary image.
Other technical features of the character recognition apparatus are the same as those of the character recognition method, and are not described herein again.
As shown in fig. 8, in one embodiment, there is provided a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the program:
acquiring a character image to be recognized, and carrying out gray processing on the character image to be recognized to obtain a preprocessed character image;
inputting the preprocessed character image as a whole into a preset character recognition model, and calculating a first character recognition result of the preprocessed character image by using the character recognition model, wherein the character recognition model is generated by training a set neural network model by using a training sample set of the character image;
rotating the preprocessed character image for a plurality of times, inputting the preprocessed character image after each rotation as a whole into the character recognition model, and calculating a second character recognition result of the preprocessed character image after each rotation by the character recognition model;
and obtaining characters in the character image to be recognized according to the first character recognition result and the second character recognition result.
In another embodiment, the processor, when executing the program, further performs the steps of: obtaining characters in the character image to be recognized according to the first character recognition result and the second character recognition result comprises: if the first character recognition result is the same as each second character recognition result, calculating the length-width ratio of the preprocessed character image before rotation and the length-width ratio of the preprocessed character image after each rotation; calculating the total character length of the first character recognition result or the second character recognition result; and if all the length-width ratios are larger than the product of the total length of the characters and a first ratio and smaller than the product of the total length of the characters and a second ratio, taking the first character recognition result or the second character recognition result as the character recognition result of the character image to be recognized.
In another embodiment, the processor, when executing the program, further performs the steps of: after the graying processing is carried out on the character image to be recognized and before the preprocessed character image is obtained, the method further comprises the following steps: carrying out image binarization on the grayed character image to be recognized to obtain a binary image; and carrying out image normalization on the binary image.
In another embodiment, the processor, when executing the program, further performs the steps of: the image normalization of the binary image comprises: and adjusting the binary image into a pattern of black bottom white characters.
In another embodiment, the processor, when executing the program, further performs the steps of: adjusting the binary image into a pattern of black bottom white characters comprises: acquiring a first contour of a white part in the binary image; performing black-white overturning processing on the binary image to obtain a second outline of a white part in the overturned binary image; calculating the maximum width of the first contour and the maximum width of the second contour respectively; if the maximum width of the first contour is smaller than the maximum width of the second contour, the binary image before black-white inversion is reserved, otherwise, the binary image after black-white inversion is reserved.
In another embodiment, the processor, when executing the program, further performs the steps of: the image normalization of the binary image further comprises: and removing the boundary of the binary image, and scaling the binary image with the boundary removed to a preset size.
In another embodiment, the processor, when executing the program, further performs the steps of: removing the boundary of the binary image comprises: respectively carrying out horizontal integral projection and vertical integral projection on the binary image; traversing the row pixels of the binary image after horizontal integral projection, and acquiring the starting row number and the ending row number in the row pixels; traversing the column pixels of the binary image after vertical integral projection, and acquiring the initial column number and the ending column number in the column pixels; and setting an interested region in the binary image according to the starting line number, the ending line number, the starting column number and the ending column number, and removing the boundary except the interested region in the binary image.
Other technical features of the computer device are the same as those of the character recognition method, and are not described herein again.
In one embodiment, a computer-readable storage medium is provided, having stored thereon a computer program which, when executed by a processor, performs the steps of:
acquiring a character image to be recognized, and carrying out gray processing on the character image to be recognized to obtain a preprocessed character image;
inputting the preprocessed character image as a whole into a preset character recognition model, and calculating a first character recognition result of the preprocessed character image by using the character recognition model, wherein the character recognition model is generated by training a set neural network model by using a training sample set of the character image;
rotating the preprocessed character image for a plurality of times, inputting the preprocessed character image after each rotation as a whole into the character recognition model, and calculating a second character recognition result of the preprocessed character image after each rotation by the character recognition model;
and obtaining characters in the character image to be recognized according to the first character recognition result and the second character recognition result.
In another embodiment, the computer program when executed by the processor further performs the following steps of deriving a character in the character image to be recognized from the first character recognition result and the second character recognition result includes: if the first character recognition result is the same as each second character recognition result, calculating the length-width ratio of the preprocessed character image before rotation and the length-width ratio of the preprocessed character image after each rotation; calculating the total character length of the first character recognition result or the second character recognition result; and if all the length-width ratios are larger than the product of the total length of the characters and a first ratio and smaller than the product of the total length of the characters and a second ratio, taking the first character recognition result or the second character recognition result as the character recognition result of the character image to be recognized.
In another embodiment, the computer program when executed by the processor further performs the steps of: after the graying processing is carried out on the character image to be recognized and before the preprocessed character image is obtained, the method further comprises the following steps: carrying out image binarization on the grayed character image to be recognized to obtain a binary image; and carrying out image normalization on the binary image.
In another embodiment, the computer program when executed by the processor further performs the steps of: the image normalization of the binary image comprises: and adjusting the binary image into a pattern of black bottom white characters.
In another embodiment, the computer program when executed by the processor further performs the steps of: adjusting the binary image into a pattern of black bottom white characters comprises: acquiring a first contour of a white part in the binary image; performing black-white overturning processing on the binary image to obtain a second outline of a white part in the overturned binary image; calculating the maximum width of the first contour and the maximum width of the second contour respectively; if the maximum width of the first contour is smaller than the maximum width of the second contour, the binary image before black-white inversion is reserved, otherwise, the binary image after black-white inversion is reserved.
In another embodiment, the computer program when executed by the processor further performs the steps of: the image normalization of the binary image further comprises: and removing the boundary of the binary image, and scaling the binary image with the boundary removed to a preset size.
In another embodiment, the computer program when executed by the processor further performs the steps of: removing the boundary of the binary image comprises: respectively carrying out horizontal integral projection and vertical integral projection on the binary image; traversing the row pixels of the binary image after horizontal integral projection, and acquiring the starting row number and the ending row number in the row pixels; traversing the column pixels of the binary image after vertical integral projection, and acquiring the initial column number and the ending column number in the column pixels; and setting an interested region in the binary image according to the starting line number, the ending line number, the starting column number and the ending column number, and removing the boundary except the interested region in the binary image.
Other technical features of the computer-readable storage medium are the same as those of the character recognition method, and are not described herein again.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.