Character recognition method, character recognition device, electronic equipment and storage medium

By performing dual threshold processing and template character image generation methods for detecting images in industrial scenarios without networking, the problem of character recognition in the prior art cannot be realized without networking is solved, high-precision character recognition is achieved, and the deployment process is simplified.

CN119810845APending Publication Date: 2025-04-11BYD CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411080908.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-07
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

In industrial scenarios, it is difficult for the prior art to realize character recognition without networking, especially in environments where confidentiality and inability to be connected to the network.

Method used

Character recognition is realized by performing double threshold processing on the detected image based on the first threshold value and the second threshold value, an intermediate image is generated, and a template character image is generated based on the preset character template, the first threshold value and the second threshold value.

Benefits of technology

This method can achieve high-precision character recognition without networking, simplifying the deployment process, reducing costs, and improving recognition accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119810845A_ABST
    Figure CN119810845A_ABST
Patent Text Reader

Abstract

The invention discloses a character recognition method, a character recognition device, electronic equipment and a storage medium. The method comprises: based on a first threshold and a second threshold, performing dual-threshold processing on a gray value of a to-be-detected image to obtain an intermediate image, the dual-threshold processing being used for setting a gray value of a pixel outside the first threshold and the second threshold as a preset value; generating a template character image according to a preset character template, the first threshold value and the second threshold value, wherein any pixel gray value of the template character image is located between the first threshold value and the second threshold value; and performing character recognition on the intermediate image based on the template character image to obtain a recognition result. Therefore, each template character of the template character image is closer to the character form in the intermediate image, and the template character image can identify the character to be detected of the intermediate image more accurately. Meanwhile, each step of the method does not need to use a network, so that character recognition with relatively high precision can be realized under the condition that networking is not needed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of character recognition, and more specifically, to a character recognition method, a character recognition device, an electronic device, and a non-volatile computer-readable storage medium. Background Art

[0002] There are many optical character recognition (OCR) methods that are widely used in printed text symbols, office software font symbol sets, and mixed scenarios of text, images, and tables. OCR online cloud computing solutions can even recognize handwritings of different styles or even incomplete handwritings, and can be expanded to hundreds of languages ​​around the world. Currently, SDK interfaces such as Microsoft OCR, Hanwang OCR, and Tsinghua Unigroup OCR are usually used to achieve character recognition. Some industrial scenarios require character recognition. However, when connecting to an external SDK, it is usually necessary to connect to the Internet. Industrial scenarios often require confidentiality and cannot connect to the Internet, resulting in the inability to use the SKD interface to achieve character recognition at this time. Therefore, how to achieve character recognition without connecting to the Internet has become an urgent problem that needs to be solved. Summary of the invention

[0003] Embodiments of the present application provide a character recognition method, a character recognition device, an electronic device, and a non-volatile computer-readable storage medium.

[0004] The character recognition method of the embodiment of the present application includes performing double threshold processing on the grayscale value of the image to be detected based on a first threshold and a second threshold to obtain an intermediate image, wherein the double threshold processing is used to set the grayscale value of pixels outside the first threshold and the second threshold to a preset value; generating a template character image according to a preset character template, a first threshold and a second threshold, and any pixel grayscale value of the template character image is between the first threshold and the second threshold; and performing character recognition on the intermediate image based on the template character image to obtain a recognition result.

[0005] The character recognition device of the embodiment of the present application includes a processing module, an adjustment module and a recognition module. The processing module is used to perform double threshold processing on the gray value of the image to be detected based on a first threshold and a second threshold to obtain an intermediate image, wherein the double threshold processing is used to set the gray value of pixels outside the first threshold and the second threshold to a preset value. The adjustment module is used to generate a template character image according to a preset character template, a first threshold and a second threshold, and any pixel gray value of the template character image is between the first threshold and the second threshold. The recognition module is used to perform character recognition on the intermediate image based on the template character image to obtain a recognition result.

[0006] The electronic device of the embodiment of the present application includes a processor, a memory and a computer program, wherein the computer program is stored in the memory and executed by the processor, and the computer program includes instructions for executing a character recognition method. The character recognition method includes performing double threshold processing on the grayscale value of the image to be detected based on a first threshold and a second threshold to obtain an intermediate image, wherein the double threshold processing is used to set the grayscale value of pixels outside the first threshold and the second threshold to a preset value; generating a template character image according to a preset character template, a first threshold and a second threshold, and any pixel grayscale value of the template character image is between the first threshold and the second threshold; performing character recognition on the intermediate image based on the template character image to obtain a recognition result.

[0007] The non-volatile computer-readable storage medium of the embodiment of the present application includes a computer program, and when the computer program is executed by a processor, the processor performs a character recognition method. The character recognition method includes performing double threshold processing on the grayscale value of the image to be detected based on a first threshold and a second threshold to obtain an intermediate image, wherein the double threshold processing is used to set the grayscale value of pixels outside the first threshold and the second threshold to a preset value; generating a template character image according to a preset character template, a first threshold and a second threshold, and any pixel grayscale value of the template character image is between the first threshold and the second threshold; performing character recognition on the intermediate image based on the template character image to obtain a recognition result.

[0008] The character recognition method, character recognition device, electronic device and non-volatile computer-readable storage medium of the embodiment of the present application first perform double threshold processing on the grayscale value of the image to be detected based on the first threshold and the second threshold to obtain an intermediate image. The first threshold and the second threshold can be used to reflect the grayscale value of the character to be detected and its surrounding area, so that the grayscale value of the intermediate image is closer to the grayscale value of the character to be detected and its surrounding area, ensuring that when the intermediate image is subsequently subjected to character recognition, the attention of the character recognition algorithm is focused between the first threshold and the second threshold, so as to facilitate the calculation of the difference in character morphology. Then, a template character image can be generated according to a preset character template, a first threshold and a second threshold, so that the grayscale value of any pixel of the template character image is between the first threshold and the second threshold, so that each template character of the template character image is closer to the character morphology in the intermediate image. Then, character recognition can be performed based on the intermediate image of the template character image to obtain a recognition result. It can be understood that at this time, the template character image can more accurately identify the character to be detected in the intermediate image. At the same time, each step of the present application does not require the use of a network, so the present application can achieve high-precision character recognition without the need for networking.

[0009] Additional aspects and advantages of the embodiments of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:

[0011] Figure 1 is a flowchart of a character recognition method in certain embodiments of the present application;

[0012] Figure 2 It is a scene schematic diagram of the character recognition method of certain embodiments of the present application;

[0013] Figure 3 is a curve schematic diagram corresponding to a grayscale histogram of a character recognition method in certain embodiments of the present application;

[0014] Figure 4 is a schematic diagram of a SEMI character set for a character recognition method according to certain embodiments of the present application;

[0015] Figure 5 It is a schematic diagram of an EMI font dot matrix of a character recognition method in certain embodiments of the present application;

[0016] Figure 6 is a schematic diagram of a binary matrix corresponding to the number “0” in the SEMI font of a character recognition method in certain embodiments of the present application;

[0017] Figure 7 is a flowchart of a character recognition method in certain embodiments of the present application;

[0018] Figure 8 It is a scene schematic diagram of the character recognition method of certain embodiments of the present application;

[0019] Fig. 9 is a flowchart of a character recognition method in certain embodiments of the present application;

[0020] Fig.10 is a flowchart of a character recognition method in certain embodiments of the present application;

[0021] Fig.11 is a flowchart of a character recognition method in certain embodiments of the present application;

[0022] Fig.12 is a flowchart of a character recognition method in certain embodiments of the present application;

[0023] Fig.13is a flowchart of a character recognition method in certain embodiments of the present application;

[0024] Fig.14 is a schematic diagram of a module of a character recognition device in some embodiments of the present application;

[0025] Fig.15 is a schematic diagram of the structure of an electronic device according to some embodiments of the present application;

[0026] Fig.16 It is a schematic diagram of the connection status of a non-volatile computer-readable storage medium and a processor in certain embodiments of the present application. DETAILED DESCRIPTION

[0027] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the embodiments of the present application, and cannot be understood as limiting the embodiments of the present application.

[0028] There are many optical character recognition (OCR) methods that are widely used in printed text symbols, office software font symbol sets, and mixed scenarios of text, images, and tables. OCR online cloud computing solutions can even recognize handwriting of different styles or even incomplete handwriting, and can be extended to hundreds of languages ​​around the world. Currently, software development kit (SDK) interfaces such as Microsoft OCR, Hanwang OCR, and Tsinghua Unigroup OCR are usually used to implement character recognition.

[0029] Character recognition is required in some industrial scenarios. For example, with the progress of industrial digitalization, laser coding on the surface of specific locations of workpieces for subsequent quality control and product service traceability is becoming more and more common. In many downstream process links after early coding, it is necessary to reliably and flexibly identify the upstream laser code from the workpiece. In particular, some dimension measurement and defect detection instruments have already collected images of the workpiece surface, and laser codes can be used to trace back problems when problems occur. However, when an external SDK is used, it is usually necessary to connect to the Internet, and industrial scenarios often require confidentiality and cannot be connected to the Internet, which makes it impossible to use the SKD interface to achieve character recognition at this time. At the same time, the external SDK also needs to deploy the corresponding software environment and hardware environment, which makes deployment difficult and costly.

[0030] In order to solve the above technical problems, the embodiment of the present application provides a character recognition method, which will be described in detail below:

[0031] See also Figure 1 , the embodiment of the present application provides a character recognition method, the character recognition method comprising:

[0032] Step 011: Based on the first threshold and the second threshold, double-threshold processing is performed on the grayscale value of the image to be detected to obtain an intermediate image, wherein the double-threshold processing is used to set the grayscale value of pixels outside the first threshold and the second threshold to a preset value;

[0033] Specifically, the image to be detected generally includes the workpiece to be detected, the characters to be detected on the workpiece to be detected, and in some cases, the background. Figure 2 In (a), the gray area is the workpiece to be detected, the characters on the workpiece to be detected are the characters to be detected, and the white area is the background. When character recognition is performed later, the matching degree will be calculated based on the grayscale difference. If the grayscale value of some areas in the image to be detected is significantly different from the grayscale value of the surrounding areas of the characters to be detected, then when character recognition is performed, this part of the area may have a greater impact on the matching degree calculation, thereby reducing the accuracy of character recognition.

[0034] The grayscale histogram of the image to be detected can be determined according to the grayscale value of the image to be detected. The grayscale histogram is a function of grayscale distribution and a statistic of grayscale distribution in an image. The grayscale histogram is a statistical calculation of the frequency of occurrence of all pixels in a digital image according to the size of the grayscale value. For example Figure 3 for Figure 2 (a) is a schematic diagram of the curve corresponding to the grayscale histogram. There is usually a certain difference between the grayscale value of the character to be detected and the grayscale value of the area around the character to be detected, so as to facilitate character recognition of the character to be detected. At the same time, the grayscale value of the character to be detected can form a peak in the grayscale histogram, and the grayscale value of the area around the character to be detected can also form a peak in the grayscale histogram. It can be understood that the grayscale value of the character to be detected and the grayscale value of the area around the character to be detected are local maxima in the grayscale histogram. For example Figure 3 In the figure, peak A corresponds to the light gray background around the character, peak B corresponds to the line area of ​​the character to be detected, and peak C corresponds to the background area. Of course, the magnitude relationship between the grayscale value of the character to be detected and the grayscale value of the area around the character to be detected is not certain. It is also possible that the grayscale value of the area around the character to be detected is greater than the grayscale value of the character to be detected, which is determined specifically according to the shooting environment of the image to be detected.

[0035] Therefore, the first threshold and the second threshold can be determined according to the gray value of the character to be detected and the gray value of the area around the character to be detected, so that the first threshold and the second threshold can characterize the gray value of the character to be detected and the area around it. At this time, the first threshold and the second threshold can be determined by finding the gray value of the area around the character to be detected, and the method is robust under random disturbances of the actual image.

[0036] For example, a grayscale histogram of the image to be detected can be generated according to the grayscale value of the image to be detected, and the grayscale histogram includes at least a first peak and a second peak, the first peak corresponds to the character to be detected, and the second peak corresponds to the surrounding area of ​​the character to be detected. Then, the first threshold and the second threshold are determined according to the grayscale value corresponding to the first peak and the grayscale value corresponding to the second peak. For example, when the grayscale value corresponding to the first peak is less than the grayscale value corresponding to the second peak, the first threshold is determined according to the grayscale value corresponding to the first peak, and the second threshold is determined according to the grayscale value corresponding to the second peak. When the grayscale value corresponding to the first peak is greater than the grayscale value corresponding to the second peak, the second threshold is determined according to the grayscale value corresponding to the first peak, and the first threshold is determined according to the grayscale value corresponding to the second peak.

[0037] Then, the image to be detected is subjected to double threshold processing to obtain an intermediate image. For example, the grayscale value of the first pixel whose grayscale value in the image to be detected is less than the first threshold is set to the first preset value, and the grayscale value of the second pixel whose grayscale value in the image to be detected is greater than the second threshold is set to the second preset value. Wherein, the first preset value can be determined according to the first threshold, and the first preset value can be the numerical value of the first threshold, or a numerical value close to the first threshold, for example, when the first threshold is 35, the first preset value can be 35 or 45. The second preset value can be determined according to the second threshold, and the second preset value can be the numerical value of the second threshold, or a numerical value close to the second threshold, for example, when the second threshold is 135, the second preset value can be 135 or 125.

[0038] In this way, the grayscale difference of the entire intermediate image can be reduced, so that the grayscale value of the entire intermediate image is close to the grayscale value of the character to be detected and its surrounding area, so that when the intermediate image is subsequently subjected to character recognition, the character recognition algorithm focuses on the area between the first threshold and the second threshold, thereby facilitating the calculation of the difference in character morphology, and facilitating reducing the influence of areas with a large difference in grayscale value from the character to be detected and its surrounding area on subsequent character recognition, thereby improving the accuracy of character recognition.

[0039] Step 012: Generate a template character image according to a preset character template, a first threshold value and a second threshold value, wherein the grayscale value of any pixel of the template character image is between the first threshold value and the second threshold value;

[0040] Specifically, the preset character template can be determined according to the upstream coding character set. The preset character template can be in various forms, for example, the preset character template can be a picture, or the preset character template can be a binary matrix. In this case, the resolution of the image to be detected should be more than twice that of the binary matrix to ensure the clarity of the image to be detected, so as to ensure the accuracy of subsequent character recognition. Figure 4, the characters of the upstream coding character set are SEMI characters. SEMI characters refer to a font specially designed by the International Semiconductor Industry Association for coding marks on semiconductor wafers and devices. It contains only 38 characters, namely 10 Arabic numerals and 26 uppercase English letters, as well as a hyphen and a decimal point. For example Figure 5 , one coding scheme for SEMI characters is an 18-row x 10-column dot matrix, so each character template is initialized as an 18x10 binary matrix to represent it, so as to facilitate the storage of preset character templates. Figure 6 It is the binary matrix corresponding to the dot matrix of the number "0" in the SEMI font.

[0041] Then, a template character image can be generated according to the preset character template, the first threshold value, and the second threshold value. In the case where the preset character template is a picture, the template character image can be generated by adjusting the grayscale value of the preset character template, for example, the grayscale value of the pixel whose grayscale value is lower than the first threshold value in the preset character template is changed to the first threshold value, and the grayscale value of the pixel whose grayscale value is higher than the second threshold value in the preset character template is changed to the second threshold value, so as to generate the template character image, so that any pixel grayscale value of the template character image is between the first threshold value and the second threshold value. In the case where the preset character template is a binary matrix, the first threshold value and the second threshold value can be applied to the preset character template, the pixel value corresponding to the character 0 in the binary matrix is ​​determined as the first threshold value, the pixel value corresponding to the character 1 is determined as the second threshold value, and the pixel value of the position between the two characters is determined according to the first threshold value, the second threshold value, and the Gaussian mixture formula. Then, a template character image can be generated based on the preset character template and the pixel value corresponding to each position, and at this time, any pixel grayscale value of the template character image is between the first threshold value and the second threshold value.

[0042] In this way, the character template can be adapted according to the first threshold and the second threshold, so that the grayscale value of each template character in the template character image is close to the grayscale value of the intermediate image. At this time, the template characters in the template character image can be understood as the expected appearance of each character in the preset character template, and the expected appearance is close to the actual appearance of the character, so as to facilitate the subsequent direct comparison between the template character image and the actual appearance of the character to be detected in the intermediate image.

[0043] Step 013: Perform character recognition on the intermediate image based on the template character image to obtain a recognition result.

[0044] Specifically, after obtaining the template character image, character recognition can be performed on the intermediate image based on the template character image. For example, the normalized correlation coefficient between the gray value matrix of each character to be detected in the intermediate image and the gray value matrix of each template character in the template character image can be calculated according to the following formula:

[0045]

[0046] Among them, x', y' traverse the coordinates of the template pixel point, T' represents the centralized template gray value, I' represents the centralized gray value of the region of interest, and xx', yy' represent the traversal coordinates corresponding to the region of interest.

[0047] The obtained normalized correlation coefficient can characterize the matching degree between the character to be detected and the intermediate image. Of course, other methods can also be used to determine the matching degree, which is not limited here. For example, the matching degree can be determined by calculating the correlation coefficient without normalization or the correlation without centering.

[0048] The preset matching degree threshold is the minimum matching degree when the character to be detected and the template character are the same character. At this time, the template characters with matching degrees higher than the preset matching degree threshold can be obtained, and the template character with the highest matching degree is confirmed as the target character corresponding to the character to be detected. Then, the recognition result of the intermediate image can be determined according to the target characters corresponding to all the characters to be detected.

[0049] It can be understood that the intermediate image has been processed according to the first threshold and the second threshold, so that the intermediate image can focus on reflecting the difference in character morphology, and the template character image has also been processed according to the first threshold and the second threshold, so that each template character of the template character image can be closer to the character morphology in the intermediate image. In this way, after the template character image and the intermediate image are both processed by the first threshold and the second threshold, the template character image can accurately recognize the characters in the intermediate image, thereby improving the recognition accuracy.

[0050] At the same time, the present application is a localized de novo method. In the character recognition process, it does not rely on any external large-scale character library or cloud computing resources, etc., and does not require a training process. Instead, it is directly deployed and used, so that the present application can also achieve accurate character recognition without being connected to the Internet. Compared with the existing technology that uses the SDK interface and needs to deploy the corresponding software environment and hardware environment, the deployment of the present application is relatively simple. It only needs to obtain the preset character template and the image to be detected to complete the character recognition, thereby greatly reducing the deployment difficulty and deployment cost. Different processes in the discrete manufacturing industry may be completed by different manufacturers, and the discrete manufacturing industry may set the characters to be detected on the workpiece, such as specially designed workpiece laser engraving codes. The character recognition method of the present application is relatively simple to deploy and use, so that each downstream section of the discrete manufacturing industry can use the present application more conveniently, so that each downstream section of the discrete manufacturing industry can accurately identify the characters to be detected of the object to be detected, so as to facilitate each downstream section of the discrete manufacturing industry to complete recognition and tracking according to the characters to be detected.

[0051] The character recognition method of the embodiment of the present application first performs double threshold processing on the grayscale value of the image to be detected based on the first threshold and the second threshold to obtain an intermediate image. The first threshold and the second threshold can be used to reflect the grayscale value of the character to be detected and its surrounding area, so that the grayscale value of the intermediate image is closer to the grayscale value of the character to be detected and its surrounding area, ensuring that when the intermediate image is subsequently subjected to character recognition, the attention of the character recognition algorithm is focused between the first threshold and the second threshold, so as to facilitate the calculation of the difference in character morphology. Then, a template character image can be generated according to a preset character template, a first threshold and a second threshold, so that any pixel grayscale value of the template character image is between the first threshold and the second threshold, so that each template character of the template character image is closer to the character morphology in the intermediate image. Then, character recognition can be performed based on the intermediate image of the template character image to obtain a recognition result. It can be understood that at this time, the template character image can more accurately identify the character to be detected in the intermediate image. At the same time, each step of the present application does not require the use of a network, so the present application can achieve high-precision character recognition without the need for networking.

[0052] See also Figure 7 In some implementations, step 013: performing character recognition on the intermediate image based on the template character image to obtain a recognition result includes:

[0053] Step 0131: determining a target character region of the intermediate image based on a reference region of the intermediate image;

[0054] Step 0132: Rotate the target character region according to the reference region so that the angle difference between the target character region and the template character image is less than a preset difference threshold;

[0055] Step 0133: Perform character recognition on the rotated target character area based on the template character image.

[0056] Specifically, the reference area can be a reference line or an anchor point. When the upstream process sets characters on the object to be detected, it will determine the character setting area based on the reference line or anchor point and the corresponding character setting rules. In an industrial environment, upstream process designs such as laser coding can provide reliable reference areas. For example Figure 8 In (a), the laser engraved code of the wafer substrate is located near the middle of the lower straight edge, and the flat edge is used as the reference line. Figure 8 In (b), the edge rectangle of the QR code digital code frame is easily displayed in edge detection.

[0057] Therefore, the reference area of ​​the intermediate image can be identified, and the target character area of ​​the intermediate image can be determined in combination with the character setting rules of the upstream process to achieve character positioning. At this time, the edge detection operator can also be directly used for fine positioning.

[0058] Due to workpiece placement errors and camera lens disturbances, the target character area of ​​the intermediate image may be tilted, and the tilted target character area may affect subsequent character recognition. The preset difference threshold is the maximum value of the angle difference between the target character area and the template character image when the template character image can accurately identify the characters to be detected in the target character area.

[0059] Therefore, when the target character area is identified, it can be determined whether the target character area is tilted relative to the template character image based on the reference area. When it is confirmed that the target character area is tilted relative to the template character image, the target character area can be rotated according to the reference area so that the angle difference between the target character area and the template character image is less than a preset difference threshold, for example, the template character area can be straightened according to the reference line. Figure 2 (a), to straighten the target character area, we get Figure 2 (b). Then, character recognition can be performed on the rectified target character area based on the template character image, thereby improving the speed of character recognition.

[0060] In this way, the present application can realize character positioning through the reference area on the one hand, and enhance the upstream and downstream coordination and the comprehensibility of the overall performance on the other hand. At the same time, the upstream process itself needs to design and use the reference area, so the present application can realize character positioning without increasing the workload of the upstream and downstream, thereby realizing character recognition with higher accuracy.

[0061] Furthermore, in the case of determining the first threshold and the second threshold, the first threshold and the second threshold can be determined based on the grayscale value of the character to be detected in the target character area and the grayscale value of the area surrounding the character to be detected. For example, after determining the target character area, the grayscale value of the target character area is obtained to generate a grayscale histogram of the target character area. If the grayscale value of the character to be detected cannot form a peak in the grayscale histogram, or the grayscale value of the area surrounding the character to be detected cannot form a peak in the grayscale histogram, the target character area can be reduced by adjusting the reference area, thereby ensuring that the grayscale value of the character to be detected can form a peak in the grayscale histogram, and the grayscale value of the area surrounding the character to be detected can also form a peak in the grayscale histogram, thereby ensuring that the first threshold and the second threshold can be used to reflect the grayscale value of the character to be detected and its surrounding area.

[0062] For further information, see Fig. 9 In some embodiments, step 0133: performing character recognition on the rotated target character area based on the template character image, further includes:

[0063] Step 01331: segmenting the characters in the target character area to obtain a plurality of mutually spaced characters to be detected;

[0064] Step 01332: Perform character recognition on each character to be detected based on the template character image.

[0065] Specifically, when setting characters, the upstream process will basically leave enough space between the characters on the object to be detected. Therefore, when the target character area is identified, the characters in the target character area can also be segmented, and each character can be segmented with a simple rectangular frame to obtain multiple characters to be detected that are spaced apart from each other, for example Figure 2 (b) Then, character recognition can be performed on each character to be detected based on the template character image to further improve the accuracy of character recognition.

[0066] Furthermore, due to workpiece placement errors and camera lens disturbances, the size of the characters to be detected in the intermediate image may also change. When the target character area is identified, the size of the characters to be detected and the size of the template characters can also be obtained. When the size of the characters to be detected and the size of the template characters are significantly different, the size of the intermediate image is adjusted to adjust the size of the characters to be detected so that the size difference between the size of the characters to be detected and the size of the template characters is smaller. After the size adjustment is completed, the characters in the target character area are segmented to find the optimal segmentation of the characters to be detected by adjusting the character size, thereby facilitating the improvement of the recognition accuracy of the template character image.

[0067] See also Fig.10 In some implementations, step 013: performing character recognition on the intermediate image based on the template character image to obtain a recognition result, further includes:

[0068] Step 0134: determining the matching degree between the character to be detected and each template character in the template character image according to the gray value matrix of the template character and the gray value matrix of the character to be detected, wherein the character to be detected is any character in the intermediate image, and the template character is any character in the template character image;

[0069] Step 0135: confirming the template character with the highest matching degree among the template characters whose matching degree is higher than a preset matching degree threshold as the first target character of the characters to be detected;

[0070] Step 0136: Obtain the first target character corresponding to the character to be detected according to a preset order to generate a recognition result.

[0071] Specifically, the gray value matrix of each template character in the template character image and the gray value matrix of each character to be detected in the intermediate image can be obtained. Then, the matching degree between the character to be detected and each template character in the template character image can be determined based on the gray value matrix of the template characters and the gray value matrix of the character to be detected.

[0072] The preset matching degree threshold is the minimum matching degree when the character to be detected and the template character are the same character. At this time, template characters with matching degrees higher than the preset matching degree threshold can be obtained, and the template character with the highest matching degree is confirmed as the first target character corresponding to the character to be detected.

[0073] Then, the first target character corresponding to the character to be detected is obtained according to the preset order. For example, the reading order is generally from left to right and from top to bottom. Therefore, the first target character corresponding to the character to be detected can be obtained according to the order from left to right and from top to bottom to generate the recognition result.

[0074] In this way, the first target character corresponding to each character to be detected can be accurately identified according to the gray value matrix of the template character and the gray value matrix of the character to be detected, thereby ensuring the accuracy of character recognition.

[0075] See also Fig.11 In some embodiments, the character recognition method further comprises:

[0076] Step 014: when it is confirmed that the character to be detected and the corresponding first target character are in a reverse relationship with each other, the template character image is reversed;

[0077] Step 015: determining a second target character of the character to be detected according to the gray value matrix of the flipped template character and the gray value matrix of the character to be detected;

[0078] Step 016: Obtaining a second target character corresponding to the character to be detected according to the reverse order of the preset order to generate a recognition result;

[0079] Step 017: Confirm the recognition result with the highest matching degree between the recognition result corresponding to the first target character and the recognition result corresponding to the second target character as the final recognition result.

[0080] Specifically, in some cases, the back of one side of the object to be detected with the characters to be detected faces the camera, and a back-side photographic image is obtained at this time. For example, when performing character recognition, the image to be detected corresponding to a transparent or translucent workpiece may be a back-side photographic image.

[0081] Therefore, after detecting the first target character corresponding to the character to be detected, it can be determined whether the character to be detected and the corresponding first target character are in a flip relationship with each other, that is, whether the image to be detected is a reverse photographic image. When it is confirmed that the character to be detected and the corresponding first target character are in a flip relationship with each other, the template character image is flipped, and character recognition is performed again. At this time, the second target character of the character to be detected can be determined based on the gray value matrix of the flipped template character and the gray value matrix of the character to be detected. Then, the corresponding second target character of the character to be detected is obtained according to the reverse order of the preset order to generate a recognition result. For example, when the preset order is from left to right, the second target character of the character to be detected can be obtained based on the order from right to left to generate a recognition result. Finally, the recognition result with a higher matching degree can be used as the final recognition result according to the recognition result corresponding to the first target character and the recognition result of the second target character, thereby ensuring the accuracy of the recognition result finally output.

[0082] In this way, when the image to be detected is a reverse-side photograph, the present application can perform character recognition again by flipping the template character image, and use the recognition result with the highest matching degree in the two character recognitions as the final recognition result, thereby improving the accuracy of the recognition result outputted in the end.

[0083] See also Fig.12 In some embodiments, before step 013: performing character recognition on the intermediate image based on the template character image to obtain a recognition result, the character recognition method further includes:

[0084] Step 018: Based on the resolution of the image to be detected, adjust the size of the template character image to update the template character image.

[0085] Specifically, after the template character image is generated, the size of the template character image can be adjusted based on the resolution of the image to be detected, so that the size of the template character of the template character image and the size of the character to be detected of the intermediate image match. Then, character recognition is performed on the intermediate image based on the template character image after the size adjustment. In this way, the size of the template character image matches the size of the intermediate image, and the grayscale value of the template character image matches the grayscale value of the intermediate image, so that the template character image can complete character recognition more accurately, thereby improving the accuracy of character recognition.

[0086] See also Fig.13 In some embodiments, the character recognition method further comprises:

[0087] Step 019: Determine the grayscale value of each pixel of the initial image based on the red component, green component and blue component of each pixel of the initial image; or

[0088] Step 020: determining the grayscale value of each pixel of the initial image according to the green component of each pixel of the initial image;

[0089] Step 021: Generate an image to be detected according to the grayscale value of each pixel of the initial image.

[0090] Specifically, a camera may be used to photograph the object to be detected to generate an initial image. When the initial image is a color image, the grayscale value of each pixel of the initial image may be determined based on the red component, green component, and blue component of each pixel of the initial image according to the RGB weight formula. For example, the grayscale value of each pixel may be calculated according to the following formula:

[0091] Gray=0.2989*Red+0.5870*Green+0.1140*Blue

[0092] Among them, Gray is the grayscale value, Red, Green, and Blue represent the values ​​of the red, green, and blue components of the pixel respectively.

[0093] Alternatively, since the human eye is more sensitive to green light, the value of the green component may be directly used as the grayscale value of each pixel.

[0094] After determining the grayscale value of each pixel of the initial image, the image to be detected can be generated according to the grayscale value of each pixel of the initial image to realize grayscale conversion of the color image, thereby facilitating subsequent double threshold processing of the image to be detected according to the grayscale value in the image to be detected, and generating a template character image according to the grayscale value in the image to be detected.

[0095] It should be noted that the present application also has the advantages of being error-tolerant and highly interpretable. The industrial environment is controllable, and the recognition accuracy of the present application is high. Therefore, if the final recognition result is wrong, then there is a high probability that there is a problem in the upstream process, and the problem point can be accurately reported based on the recognition result. For example, inaccurate character positioning means that the reference area is inaccurate, so that the object to be detected has quality flaws or defects in the reference area and should be excluded from the good products. Another example is inaccurate character segmentation, which means that the mapping system deviates from the normal state and needs to be reset, or there is an error in the laser coding. Another example is that when all candidate characters are recognized, the matching degree is too low, which means that unknown characters or illegal patterns are mixed in during laser coding, or there is fatal dirt at the code position, or the image is unclear or the lighting is uneven.

[0096] See also Fig.14In order to better implement the character recognition method of the embodiment of the present application, the embodiment of the present application also provides a character recognition device 10. The character recognition device 10 may include a processing module 11, an adjustment module 12 and a recognition module 13. The processing module 11 is used to perform double threshold processing on the grayscale value of the image to be detected based on a first threshold and a second threshold to obtain an intermediate image, wherein the double threshold processing is used to set the grayscale value of pixels outside the first threshold and the second threshold to a preset value. The adjustment module 12 is used to generate a template character image according to a preset character template, a first threshold and a second threshold, and the grayscale value of any pixel of the template character image is between the first threshold and the second threshold. The recognition module 13 is used to perform character recognition on the intermediate image based on the template character image to obtain a recognition result.

[0097] The character recognition device 10 also includes a threshold determination module 14. The threshold determination module 14 is used to generate a grayscale histogram of the image to be detected according to the grayscale value of the image to be detected, the grayscale histogram at least including a first peak and a second peak, the first peak corresponds to the character to be detected, and the second peak corresponds to the surrounding area of ​​the character to be detected; according to the grayscale value corresponding to the first peak and the grayscale value corresponding to the second peak, the first threshold and the second threshold are determined.

[0098] The recognition module 13 is specifically used to determine the target character area of ​​the intermediate image based on the reference area of ​​the intermediate image; rotate the target character area according to the reference area so that the angle difference between the target character area and the template character image is less than a preset difference threshold; and perform character recognition on the rotated target character area based on the template character image.

[0099] The recognition module 13 is specifically used to segment the characters in the target character area to obtain a plurality of mutually spaced characters to be detected; and perform character recognition on each character to be detected based on the template character image.

[0100] The recognition module 13 is specifically used to determine the matching degree between the character to be detected and each template character in the template character image based on the gray value matrix of the template character and the gray value matrix of the character to be detected, where the character to be detected is any character in the intermediate image, and the template character is any character in the template character image; among the template characters whose matching degree is higher than a preset matching degree threshold, the template character with the highest matching degree is confirmed as the first target character of the character to be detected; and the first target character corresponding to the character to be detected is obtained according to a preset order to generate a recognition result.

[0101] The character recognition device 10 further includes a re-recognition module 15. The re-recognition module 15 is used to flip the template character image when confirming that the character to be detected and the corresponding first target character are in a flip relationship with each other; determine the second target character of the character to be detected according to the gray value matrix of the flipped template character and the gray value matrix of the character to be detected; obtain the corresponding second target character of the character to be detected according to the reverse order of the preset sequence to generate a recognition result; and confirm the recognition result with the highest matching degree between the recognition result corresponding to the first target character and the recognition result corresponding to the second target character as the final recognition result.

[0102] The adjustment module 12 is further used to adjust the size of the template character image based on the resolution of the image to be detected, so as to update the template character image.

[0103] The character recognition device 10 further includes a generation module 16. The generation module 16 is used to determine the grayscale value of each pixel of the initial image based on the red component, green component and blue component of each pixel of the initial image; or determine the grayscale value of each pixel of the initial image according to the green component of each pixel of the initial image; and generate the image to be detected according to the grayscale value of each pixel of the initial image.

[0104] In the above text, the character recognition device 10 is described from the perspective of functional modules in conjunction with the accompanying drawings. The functional modules can be implemented in hardware form, can be implemented in software form, or can be implemented in combination with hardware and software modules. Specifically, the steps of the method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit in the processor and / or the instructions in software form. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware encoding processor for execution, or can be completed by a combination of hardware and software modules in the encoding processor. Optionally, the software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps in the above method embodiment in conjunction with its hardware.

[0105] See also Fig.15 The electronic device 100 of the embodiment of the present application includes a processor 20, a memory 30 and a computer program, wherein the computer program is stored in the memory 30 and executed by the processor 20, and the computer program includes instructions for executing the character recognition method of any of the above-mentioned embodiments.

[0106] See also Fig.16The embodiment of the present application also provides a computer-readable storage medium 300 on which a computer program 310 is stored. When the computer program 310 is executed by a processor 320, the steps of the character recognition method of any of the above-mentioned embodiments are implemented. For the sake of brevity, they are not repeated here.

[0107] In the description of this specification, the descriptions with reference to the terms "certain embodiments", "in an example", "exemplarily", etc., mean that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.

[0108] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.

[0109] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A character recognition method, characterized in that: The method comprises: Based on a first threshold and a second threshold, performing double threshold processing on the grayscale value of the image to be detected to obtain an intermediate image, wherein the double threshold processing is used to set the grayscale value of pixels outside the first threshold and the second threshold to a preset value; Generate a template character image according to a preset character template, a first threshold and a second threshold, wherein any pixel grayscale value of the template character image is between the first threshold and the second threshold; Character recognition is performed on the intermediate image based on the template character image to obtain a recognition result.

2. The character recognition method according to claim 1, characterized in that: The method further comprises: Generate a grayscale histogram of the image to be detected according to the grayscale value of the image to be detected, wherein the grayscale histogram includes at least a first peak and a second peak, wherein the first peak corresponds to the character to be detected, and the second peak corresponds to a surrounding area of ​​the character to be detected; The first threshold and the second threshold are determined according to the grayscale value corresponding to the first peak and the grayscale value corresponding to the second peak.

3. The character recognition method according to claim 1, characterized in that: The dual threshold processing is used to set the grayscale values ​​of pixels outside the first threshold and the second threshold to a preset value, including: The dual threshold processing is used to set the grayscale value of a first pixel in the image to be detected whose grayscale value is less than the first threshold to a first preset value, and to set the grayscale value of a second pixel in the image to be detected whose grayscale value is greater than the second threshold to a second preset value.

4. The character recognition method according to claim 1, characterized in that: The performing character recognition on the intermediate image based on the template character image to obtain a recognition result includes: Determining a target character region of the intermediate image based on a reference region of the intermediate image; Rotating the target character region according to the reference region so that the angle difference between the target character region and the template character image is less than a preset difference threshold; Character recognition is performed on the rotated target character area based on the template character image.

5. The character recognition method according to claim 4, characterized in that: The performing character recognition on the straightened target character area based on the template character image comprises: Segmenting the characters in the target character area to obtain a plurality of mutually spaced characters to be detected; Character recognition is performed on each of the characters to be detected based on the template character image.

6. The character recognition method according to claim 4 or 5, characterized in that: The character recognition of the segmented characters in the target character area based on the template character image includes: Determine the matching degree between the character to be detected and each template character in the template character image according to the gray value matrix of the template character and the gray value matrix of the character to be detected, wherein the character to be detected is any character in the intermediate image, and the template character is any character in the template character image; Confirming the template character with the highest matching degree among the template characters whose matching degree is higher than a preset matching degree threshold as the first target character of the character to be detected; A first target character corresponding to the character to be detected is obtained according to a preset sequence to generate a recognition result.

7. The character recognition method according to claim 6, characterized in that: The method further comprises: When it is confirmed that the character to be detected and the corresponding first target character are in a reverse relationship with each other, flipping the template character image; Determining a second target character of the character to be detected according to the flipped grayscale value matrix of the template character and the grayscale value matrix of the character to be detected; Acquire a second target character corresponding to the character to be detected according to the reverse order of the preset order to generate a recognition result; The recognition result with the highest matching degree among the recognition result corresponding to the first target character and the recognition result corresponding to the second target character is confirmed as the final recognition result.

8. The character recognition method according to claim 1, characterized in that: Before performing character recognition on the intermediate image based on the template character image to obtain a recognition result, the method further includes: Based on the resolution of the image to be detected, the size of the template character image is adjusted to update the template character image.

9. The character recognition method according to claim 1, characterized in that: The preset character template is determined according to the upstream coding character set.

10. The character recognition method according to claim 1, characterized in that: The method further comprises: Determine the grayscale value of each pixel of the initial image based on the red component, the green component and the blue component of each pixel of the initial image; or Determining a grayscale value of each pixel of the initial image according to a green component of each pixel of the initial image; The image to be detected is generated according to the grayscale value of each pixel of the initial image.

11. A character recognition device, characterized in that: The device comprises: A processing module, configured to perform double-threshold processing on the grayscale value of the image to be detected based on a first threshold value and a second threshold value to obtain an intermediate image, wherein the double-threshold processing is used to set the grayscale value of pixels outside the first threshold value and the second threshold value to a preset value; An adjustment module, used for generating a template character image according to a preset character template, a first threshold and a second threshold, wherein any pixel grayscale value of the template character image is between the first threshold and the second threshold; A recognition module is used to perform character recognition on the intermediate image based on the template character image to obtain a recognition result.

12. An electronic device, characterized in that: include: Processor, memory; and A computer program, wherein the computer program is stored in the memory and executed by the processor, and the computer program includes instructions for executing the character recognition method according to any one of claims 1 to 10.

13. A non-volatile computer-readable storage medium containing a computer program, characterized in that: When the computer program is executed by a processor, the processor executes the character recognition method according to any one of claims 1 to 10.