Optical character verification method and device, electronic equipment and storage medium
By automatically locating character regions using a target detection model and comparing them with shape, grayscale, and layout information, this technology solves the problems of cumbersome manual operation and low detection accuracy caused by character deformation in existing technologies, achieving efficient and accurate character verification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING LUSTER LIGHTTECH
- Filing Date
- 2022-12-28
- Publication Date
- 2026-05-29
AI Technical Summary
Existing optical character verification methods require manual selection of character areas, which is cumbersome and cannot adapt to character deformation, resulting in low detection accuracy and a high risk of false character detection.
The target detection model automatically locates character regions by utilizing the shape, grayscale, and layout information of characters, and compares them with character templates to achieve character detection.
It saves manual operation, improves the efficiency and accuracy of optical character verification, can adapt to character deformation, and reduces false character detection.
Smart Images

Figure CN116109573B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of printed matter inspection technology, and in particular relates to an optical character verification method, device, electronic device and storage medium. Background Technology
[0002] Optical Character Verification (OCV) is suitable for various marking inspection and label printing verification applications, as well as online inspection. It can detect blurry, uneven, distorted, or duplicate markings, redundant or missing strokes, missing characters, inverted markings, and contrast issues. If any abnormality occurs, it can display an alarm or control the machine to stop. After inspecting workpieces that do not meet requirements, it can output a control signal to reject the defective products.
[0003] Currently, optical character verification requires manually selecting a single character area on the printed product image, repeatedly cropping images of each type of character, using the cropped images to build a model of the character, and then comparing the established character model with the character on the product to be inspected to complete the character printing quality inspection.
[0004] Manually selecting character regions is not only cumbersome and time-consuming, but also cannot adapt to character deformation due to the inability to adapt to the detection accuracy of optical character verification, which can easily lead to false detections. Summary of the Invention
[0005] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes an optical character verification method, apparatus, electronic device, and storage medium, which can save manual operation, improve the accuracy of character detection, and avoid false character detection.
[0006] In a first aspect, this application provides an optical character verification method, the method comprising:
[0007] Acquire the image to be detected;
[0008] The image to be detected is input into the target detection model to obtain the character detection result of the image to be detected output by the target detection model;
[0009] The step of inputting the image to be detected into the target detection model and obtaining the character detection result of the image to be detected output by the target detection model further includes:
[0010] The image to be detected is oriented correctly.
[0011] Based on the character shape information, character grayscale information, and character layout information of the character template in the character database of the target detection model, the target character region where the character to be detected is located in the image to be detected is determined.
[0012] The target character region and the character template are compared to determine the character detection result of the character to be detected.
[0013] According to the optical character verification method of this application, the character area can be automatically located and extracted by using the character's shape information, grayscale information and layout information. This can save manual operation, improve the efficiency of optical character verification, effectively adapt to character deformation, effectively improve the detection accuracy of optical character verification, and prevent false character detection.
[0014] According to one embodiment of this application, determining the target character region in the image to be detected based on the character shape information, character grayscale information, and character layout information of the character template in the character database of the target detection model includes:
[0015] Based on the character layout information of the character template, the character search range of the image to be detected is determined;
[0016] Based on the character shape information of the character template, the gradient histogram of the character template is obtained;
[0017] Based on the gradient histogram, a coarse bounding box for the character to be detected is determined;
[0018] Based on the grayscale information of the characters in the character template and the grayscale information in the coarse positioning box, the coarse positioning box is adjusted to determine the target character region.
[0019] According to one embodiment of this application, after obtaining the character detection result of the image to be detected output by the target detection model, the method further includes:
[0020] If the difference between the character template and the character to be detected is less than a target threshold, the character template in the character database is updated based on the character to be detected.
[0021] According to one embodiment of this application, comparing the target character region with the character template to determine the character detection result of the character to be detected includes:
[0022] The pixels of the target character region are compared with the high-value image pixels of the character template, and the pixels of the target character region are compared with the low-value image pixels of the character template to determine the first pixel and the second pixel of the target character region. The pixel value of the first pixel is not greater than the pixel value of the high-value image pixel and not less than the pixel value of the low-value image pixel. The pixel value of the second pixel is greater than the pixel value of the high-value image pixel or less than the pixel value of the low-value image pixel.
[0023] The character detection result is determined based on the first pixel and the second pixel of the target character region.
[0024] According to one embodiment of this application, the orientation correction of the image to be detected includes:
[0025] The image to be detected is binarized and morphologically processed to obtain a binarized image;
[0026] Scan the binarized image to determine the vertex coordinates of the character to be detected;
[0027] Based on the vertex coordinates, the top line of the character to be detected is extracted through Hough transform;
[0028] Based on the top line, the text arrangement angle of the character to be detected is determined;
[0029] Based on the text arrangement angle, the orientation of the image to be detected is corrected by affine transformation.
[0030] According to one embodiment of this application, the target detection model is established through the following steps:
[0031] Extract the character template region from the sample image, wherein the sample image includes the character template;
[0032] Based on the character template area, obtain the character shape information, character grayscale information, and character layout information of the character template;
[0033] The target detection model is established based on the character shape information, character grayscale information, and character layout information of the character template.
[0034] According to one embodiment of this application, the extraction of the character template region of the sample image includes:
[0035] The character template region of the sample image is extracted by using Otsu threshold image segmentation;
[0036] If the number of characters in the character template region extracted by Otsu threshold image segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted by vertical projection segmentation.
[0037] If the number of characters in the character template region extracted by vertical projection segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted based on the matching and positioning of the preset character library.
[0038] Secondly, this application provides an optical character verification device, the device comprising:
[0039] The acquisition module is used to acquire the image to be detected;
[0040] The processing module is used to input the image to be detected into the target detection model and obtain the character detection result of the image to be detected output by the target detection model;
[0041] The step of inputting the image to be detected into the target detection model and obtaining the character detection result of the image to be detected output by the target detection model further includes:
[0042] The image to be detected is oriented correctly.
[0043] Based on the character shape information, character grayscale information, and character layout information of the character template in the character database of the target detection model, the target character region where the character to be detected is located in the image to be detected is determined.
[0044] The target character region and the character template are compared to determine the character detection result of the character to be detected.
[0045] The optical character verification device according to this application automatically locates and extracts the character area by using the character's shape information, grayscale information, and layout information. This can save manual operation, improve the efficiency of optical character verification, effectively adapt to character deformation, effectively improve the detection accuracy of optical character verification, and prevent false character detection.
[0046] Thirdly, this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the optical character verification method as described in the first aspect above.
[0047] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the optical character verification method as described in the first aspect above.
[0048] Fifthly, this application provides a chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the optical character verification method as described in the first aspect.
[0049] In a sixth aspect, this application provides a computer program product, including a computer program that, when executed by a processor, implements the optical character verification method as described in the first aspect above.
[0050] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0051] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:
[0052] Figure 1 This is a flowchart illustrating the optical character verification method provided in an embodiment of this application;
[0053] Figure 2 This is a schematic diagram of the process for establishing the target detection model provided in the embodiments of this application;
[0054] Figure 3 This is a schematic diagram of the target detection model processing and updating provided in the embodiments of this application;
[0055] Figure 4 This is a schematic diagram of the character template region extraction process provided in the embodiments of this application;
[0056] Figure 5 This is a schematic diagram of the minimum point of the vertical projection of a character provided in an embodiment of this application;
[0057] Figure 6 This is a schematic diagram of the characters in the preset character library provided in the embodiments of this application;
[0058] Figure 7 This is a schematic diagram of matching based on a preset character set provided in an embodiment of this application;
[0059] Figure 8 This is a schematic diagram of the process for orientation correction of the image to be detected provided in the embodiments of this application;
[0060] Figure 9 This is a schematic diagram of the process for determining the target character region provided in an embodiment of this application;
[0061] Figure 10 This is a schematic diagram of the structure of the optical character verification device provided in the embodiments of this application;
[0062] Figure 11 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;
[0063] Figure 12 This is a hardware schematic diagram of the electronic device provided in the embodiments of this application. Detailed Implementation
[0064] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0065] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0066] The optical character verification method, optical character verification device, electronic device, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0067] Among them, the optical character verification method can be applied to the terminal, and can be executed by the hardware or software in the terminal.
[0068] The terminal includes, but is not limited to, portable communication devices such as mobile phones or tablets with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads). It should also be understood that, in some embodiments, the terminal may not be a portable communication device, but rather a desktop computer with touch-sensitive surfaces (e.g., touchscreen displays and / or touchpads).
[0069] The following embodiments describe a terminal including a display and a touch-sensitive surface. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, mouse, and joystick.
[0070] The optical character verification method provided in this application embodiment can be executed by an electronic device or a functional module or entity in an electronic device that can implement the optical character verification method. The electronic devices mentioned in this application embodiment include, but are not limited to, mobile phones, tablets, computers, cameras, and wearable devices. The optical character verification method provided in this application embodiment will be described below using an electronic device as the execution subject as an example.
[0071] like Figure 1 As shown, the optical character verification method includes steps 110 and 120.
[0072] Step 110: Obtain the image to be detected.
[0073] The image to be detected can be an image of a printed matter to be detected, on which the character to be detected is printed, and the image to be detected includes the character to be detected.
[0074] In this step, the image to be inspected is acquired. This can be done by using an industrial vision system to capture an image of the printed material to be inspected.
[0075] Step 120: Input the image to be detected into the target detection model and obtain the character detection results of the image to be detected output by the target detection model.
[0076] The object detection model is a model for detecting the printing quality of characters in an image.
[0077] Understandably, before using the object detection model to detect the character to be detected, the object detection model is built using a character template. The character template is a template for the character to be detected. By comparing the character template and the character to be detected, the printing quality of the character to be detected can be detected.
[0078] In this embodiment, information such as character shape information, character grayscale information, and character layout information of the character template are stored in the character database of the target detection model, which is used to detect the character printing quality of the character to be detected.
[0079] It should be noted that the character database of the object detection model can store various types of character templates, allowing the object detection model to detect various types of characters to be detected.
[0080] For example, the character data storage of the object detection model contains character templates of Arabic numeral type and character templates of English letter type, which are used to perform character printing quality detection of Arabic numeral type characters to be detected and English letter type characters to be detected, respectively.
[0081] In this step, the image to be detected is input into the target detection model to obtain the character detection results of the image to be detected output by the target detection model, which further includes:
[0082] Orientation correction is performed on the image to be detected;
[0083] Based on the character shape information, character grayscale information and character layout information of the character template in the character database of the target detection model, the target character region where the character to be detected is located in the image to be detected is determined;
[0084] The target character region is compared with the character template to determine the character detection result of the character to be detected.
[0085] In this embodiment, the orientation correction of the image to be detected is to correct the text orientation of the image to be detected, which can reduce the impact of the positional offset during character printing or image acquisition on the character detection results.
[0086] After correcting the text orientation of the image to be detected, the target character region where the character to be detected is located is determined from the image based on the character shape information, character grayscale information and character layout information of the character template in the character database. This realizes the automatic positioning and extraction of the character region during the optical character verification process, eliminating the need for manual selection of the character region and effectively improving the efficiency and accuracy of optical character verification.
[0087] In this embodiment, based on the character shape information, character grayscale information, and character layout information of the character template in the character database, the region whose shape information, grayscale information, and layout information match the character template is selected from the image to be detected, which is the target character region.
[0088] It should be noted that the character shape information, character grayscale information, and character layout information of the character template are analyzed and obtained during the establishment of the target detection model, and stored in the character database of the target detection model.
[0089] In this embodiment, by comparing the target character region and the character template, the degree of difference between the character to be detected in the target character region and the character template can be determined, thereby judging the character detection result of the character to be detected.
[0090] It should be noted that using target character regions and character templates for comparison, compared with the comparison based on single character modeling in related technologies, can effectively adapt to the situation of character deformation (by correcting the orientation of the image to be detected, it can also reduce the impact of character deformation), effectively improve the detection accuracy of optical character verification, and prevent false character detection.
[0091] The character detection result can be a good product or a defective product with many defects. Accordingly, the character detection result can include information such as the type and location of defects on the defective product.
[0092] According to the optical character verification method provided in the embodiments of this application, the character area can be automatically located and extracted by using the character's shape information, grayscale information and layout information. This can save manual operation, improve the efficiency of optical character verification, effectively adapt to character deformation, effectively improve the detection accuracy of optical character verification, and prevent false character detection.
[0093] In some embodiments, determining the target character region in the image to be detected based on character shape information, character grayscale information, and character layout information of character templates in the character database of the target detection model may include:
[0094] Based on the character layout information of the character template, the character search range of the image to be detected is determined;
[0095] Based on the character shape information of the character template, the gradient histogram of the character template is obtained;
[0096] Based on the gradient histogram, a coarse bounding box for the character to be detected is determined;
[0097] Based on the grayscale information of the characters in the character template and the grayscale information in the coarse positioning box, adjust the coarse positioning box to determine the target character area.
[0098] In this embodiment, the character layout information of the character template in the target detection model is first used to determine the character search range. Then, the gradient histogram of the character template is used for coarse localization. Coarse localization based on the gradient histogram ensures that even if the strokes and shapes of the character to be detected differ from the character template, the localization result still has a small localization error.
[0099] After coarse positioning, the top, bottom, left, and right borders of the coarse positioning box are adjusted based on the grayscale information to make the grayscale information in the fine positioning box after the coarse positioning box adjustment less different from the grayscale information of the characters in the character template.
[0100] In this embodiment, character region positioning adopts a method based on shape information and grayscale information, combined with character layout information, which can solve the problem of character positioning failure caused by differences between the preset font library and the actual product, which is caused by simply relying on shape or NCC method.
[0101] The following is a specific example.
[0102] like Figure 9 As shown, for the image to be detected, the target detection model first initializes the character search range based on the character layout information of the character template in the model, then uses the gradient histogram of the character template for coarse localization, and adjusts the top, bottom, left and right borders of the coarse localization box based on the grayscale information. The characters within the borders are compared with the character template to determine whether the difference between the two is less than the optimal value.
[0103] In this embodiment, when the difference is not less than the current optimal value, the border continues to be adjusted; when the difference is less than the current optimal value, the current difference is updated to a new optimal difference value.
[0104] In some embodiments, after obtaining the character detection results of the image to be detected output by the target detection model, the optical character verification method may further include:
[0105] If the difference between the character template and the character to be detected is less than the target threshold, the character template in the character database is updated based on the character to be detected.
[0106] In this embodiment, characters to be detected whose difference from the character template is less than the target threshold are saved. During the detection process, the character template in the character database is replaced and updated to continuously narrow and approximate the difference between the template character and the actual product character, thereby achieving adaptive optical character verification. The character adaptive comparison method can improve the accuracy of character detection and reduce false alarms in character detection.
[0107] The following is a specific example.
[0108] like Figure 3 As shown, the target detection model detects the image to be detected by first correcting the horizontal direction of the text, then locating the characters to determine the target character region, comparing the target character region with the character template, completing the character quality detection, and obtaining the character detection result.
[0109] Based on the target threshold, determine whether the character to be detected is a good product. When the value of the character to be detected is less than the target threshold, update the character to be detected to the character database as a new character template.
[0110] In some embodiments, comparing the target character region with the character template to determine the character detection result of the character to be detected may include:
[0111] The pixels of the target character region are compared with the high-value pixels of the character template, and the pixels of the target character region are compared with the low-value pixels of the character template to determine the first pixel and the second pixel of the target character region. The pixel value of the first pixel is not greater than the pixel value of the high-value pixel and not less than the pixel value of the low-value pixel. The pixel value of the second pixel is greater than the pixel value of the high-value pixel or less than the pixel value of the low-value pixel.
[0112] The character detection result is determined based on the first and second pixels of the target character region.
[0113] The first pixel represents a normal pixel in the target character region, and the second pixel represents an abnormal pixel in the target character region.
[0114] In this embodiment, the pixels of the target character region where the character to be detected is located are compared with the pixels of the high-value image and the low-value image of the character template, respectively. If the pixel value of a certain pixel is greater than the pixel value of the pixel in the high-value image of the character template, or less than the pixel value of the pixel in the low-value image of the character template, the pixel is characterized as an abnormal pixel; otherwise, it is a normal pixel.
[0115] Based on the number and distribution of the first and second pixels in the target character area, the character detection result of the character to be detected is determined, and the printing quality of the character to be detected is detected.
[0116] In some embodiments, orientation correction of the image to be detected may include:
[0117] The image to be detected is binarized and morphologically processed to obtain a binarized image;
[0118] Scan the binarized image to determine the vertex coordinates of the character to be detected;
[0119] Based on vertex coordinates, the top line of the character to be detected is extracted through Hough transform;
[0120] Based on the top line, determine the text arrangement angle of the characters to be detected;
[0121] Based on the text arrangement angle, affine transformation is used to correct the orientation of the image to be detected.
[0122] like Figure 8 As shown, orientation correction for the image to be detected can be achieved by binarizing the image using Otsu thresholding (OSTU), connecting adjacent characters using morphological closing operations in morphological processing to obtain a binarized image, and then scanning the binarized image sequentially from top to bottom and from left to right to determine the vertex coordinates of the characters to be detected. The Hough transform is then applied to all extracted vertex coordinates to extract the top line of the text to be detected, and the text alignment angle is calculated. Finally, affine transformation is used to complete the text orientation correction.
[0123] In some embodiments, the target detection model is established through the following steps:
[0124] Extract the character template region from the sample image, which includes the character template.
[0125] Based on the character template area, obtain the character shape information, character grayscale information, and character layout information of the character template;
[0126] A target detection model is established based on character shape information, character grayscale information, and character layout information from a character template.
[0127] When establishing the target detection model, the character template region is extracted from the sample image including the character template. The character template region is analyzed to obtain the character shape information, character grayscale information and character layout information of the character template. Based on the character shape information, character grayscale information and character layout information of the character template, the target detection model is established.
[0128] like Figure 2 As shown, an object detection model is established, character region extraction is performed, character size analysis is used to obtain character shape information, character layout analysis is used to obtain character layout information, character grayscale information analysis is used to obtain character grayscale information, and finally, an object detection model is established.
[0129] In some embodiments, extracting the character template region of a sample image may include:
[0130] Character template regions of sample images are extracted using Otsu threshold image segmentation.
[0131] When it is determined that the number of characters in the character template region extracted by Otsu threshold image segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted by vertical projection segmentation.
[0132] If the number of characters in the character template region extracted by vertical projection segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted based on the matching and localization of the preset character library.
[0133] Among them, vertical projection segmentation can divide the text into binarized projection minimum points in the vertical direction and extract the character template region.
[0134] In this embodiment, character template regions are extracted using three cascaded algorithms: image binarization segmentation extraction based on Otsu threshold, binary projection minimum point segmentation extraction based on the vertical direction of the text, and matching and positioning extraction based on a preset character library.
[0135] Among them, the image binarization segmentation extraction based on the Otsu threshold can accurately segment characters when there is no adhesion between them; the segmentation extraction based on the minimum point of the binarized projection in the vertical direction of the text can segment adjacent characters with slight adhesion by searching for the minimum point in the projection histogram; and the matching and positioning extraction based on the pre-set character library can extract the character region by matching the character template when multiple characters are adhered and the characters are arranged compactly and the adhesion is relatively serious.
[0136] The following is a specific example.
[0137] like Figure 4As shown, the image is first segmented by Otsu thresholding. When the number of characters in the extracted character template region is not equal to the number of verification characters, vertical projection segmentation is used.
[0138] Figure 5 The diagram shown is a schematic of the minimum point of the vertical projection of a character provided in an embodiment of this application. Figure 5 As shown, segmentation is performed by searching for the minimum point in the projected histogram.
[0139] When the number of characters in the character template region extracted by vertical projection segmentation is not equal to the number of verification characters, a pre-set character set is used for matching. Figure 6 The image shown is a schematic diagram of the characters in the preset character set provided in an embodiment of this application. Figure 7 The diagram shown is a schematic diagram of a pre-set character set matching provided in an embodiment of this application. It uses, for example... Figure 6 The characters shown, in such Figure 7 In the image shown, a preset character set is matched to extract the character template region.
[0140] The optical character detection in this application is completed in two stages: the target detection model establishment stage and the target detection model processing and updating stage. In the establishment stage, the character template area is located by analyzing the sample image, and then the character shape information, character grayscale information and character layout information of the character template are analyzed. In the processing and updating stage, the character is located, the character quality is detected and the character is adaptively modified by analyzing the image to be detected. This can save manual operation, improve the accuracy of character detection and avoid false character detection.
[0141] The optical character verification method provided in this application can be executed by an optical character verification device. This application uses an optical character verification device executing the optical character verification method as an example to illustrate the optical character verification device provided in this application.
[0142] This application also provides an optical character verification device.
[0143] like Figure 10 As shown, the optical character verification device includes:
[0144] The acquisition module 1010 is used to acquire the image to be detected;
[0145] The processing module 1020 is used to input the image to be detected into the target detection model and obtain the character detection result of the image to be detected output by the target detection model;
[0146] The process of inputting the image to be detected into the target detection model and obtaining the character detection results of the image output by the target detection model further includes:
[0147] Orientation correction is performed on the image to be detected;
[0148] Based on the character shape information, character grayscale information and character layout information of the character template in the character database of the target detection model, the target character region where the character to be detected is located in the image to be detected is determined.
[0149] The target character region is compared with the character template to determine the character detection result of the character to be detected.
[0150] The optical character verification device provided in the embodiments of this application can automatically locate and extract character areas by using the shape information, grayscale information and layout information of the characters. This can save manual operation, improve the efficiency of optical character verification, effectively adapt to the situation of character deformation, effectively improve the detection accuracy of optical character verification, and prevent false character detection.
[0151] In some embodiments, the processing module 1020 is used to determine the character search range of the image to be detected based on the character layout information of the character template;
[0152] Based on the character shape information of the character template, the gradient histogram of the character template is obtained;
[0153] Based on the gradient histogram, a coarse bounding box for the character to be detected is determined;
[0154] Based on the grayscale information of the characters in the character template and the grayscale information in the coarse positioning box, adjust the coarse positioning box to determine the target character area.
[0155] In some embodiments, the processing module 1020 is further configured to update the character template in the character database based on the character to be detected if the difference between the character template and the character to be detected is less than a target threshold.
[0156] In some embodiments, the processing module 1020 is used to compare the pixels of the target character region with the high-value image pixels of the character template, and compare the pixels of the target character region with the low-value image pixels of the character template to determine the first pixel and the second pixel of the target character region. The pixel value of the first pixel is not greater than the pixel value of the high-value image pixel and not less than the pixel value of the low-value image pixel, and the pixel value of the second pixel is greater than the pixel value of the high-value image pixel or less than the pixel value of the low-value image pixel.
[0157] The character detection result is determined based on the first and second pixels of the target character region.
[0158] In some embodiments, the processing module 1020 is used to perform binarization and morphological processing on the image to be detected to obtain a binarized image;
[0159] Scan the binarized image to determine the vertex coordinates of the character to be detected;
[0160] Based on vertex coordinates, the top line of the character to be detected is extracted through Hough transform;
[0161] Based on the top line, determine the text arrangement angle of the characters to be detected;
[0162] Based on the text arrangement angle, affine transformation is used to correct the orientation of the image to be detected.
[0163] In some embodiments, the processing module 1020 is configured to establish a target detection model through the following steps:
[0164] Extract the character template region from the sample image, which includes the character template.
[0165] Based on the character template area, obtain the character shape information, character grayscale information, and character layout information of the character template;
[0166] A target detection model is established based on character shape information, character grayscale information, and character layout information from a character template.
[0167] In some embodiments, the processing module 1020 is used to extract the character template region of the sample image by using Otsu threshold image segmentation;
[0168] When it is determined that the number of characters in the character template region extracted by Otsu threshold image segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted by vertical projection segmentation.
[0169] If the number of characters in the character template region extracted by vertical projection segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted based on the matching and localization of the preset character library.
[0170] The optical character verification device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.
[0171] The optical character verification device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.
[0172] The optical character verification device provided in this application embodiment can achieve... Figures 1 to 9 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0173] In some embodiments, such as Figure 11 As shown, this application embodiment also provides an electronic device 1100, including a processor 1101, a memory 1102, and a computer program stored in the memory 1102 and executable on the processor 1101. When the program is executed by the processor 1101, it implements the various processes of the above-described optical character verification method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0174] It should be noted that the electronic devices in the embodiments of this application include the aforementioned mobile electronic devices and non-mobile electronic devices.
[0175] Figure 12 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.
[0176] The electronic device 1200 includes, but is not limited to, components such as: radio frequency unit 1201, network module 1202, audio output unit 1203, input unit 1204, sensor 1205, display unit 1206, user input unit 1207, interface unit 1208, memory 1209, and processor 1210.
[0177] Those skilled in the art will understand that the electronic device 1200 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 1210 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 12 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0178] In this embodiment, the input unit 1204 is a camera used to acquire the image to be detected.
[0179] The processor 1210 is used to input the image to be detected into the target detection model and obtain the character detection result of the image to be detected output by the target detection model;
[0180] The process of inputting the image to be detected into the target detection model and obtaining the character detection results of the image output by the target detection model further includes:
[0181] Orientation correction is performed on the image to be detected;
[0182] Based on the character shape information, character grayscale information and character layout information of the character template in the character database of the target detection model, the target character region where the character to be detected is located in the image to be detected is determined.
[0183] The target character region is compared with the character template to determine the character detection result of the character to be detected.
[0184] The electronic device provided in the embodiments of this application can automatically locate and extract character areas by using the shape information, grayscale information and layout information of the characters. This can save manual operation, improve the efficiency of optical character verification, effectively adapt to the situation of character deformation, effectively improve the detection accuracy of optical character verification, and prevent false character detection.
[0185] In some embodiments, the processor 1210 is further configured to determine the character search range of the image to be detected based on the character layout information of the character template;
[0186] Based on the character shape information of the character template, the gradient histogram of the character template is obtained;
[0187] Based on the gradient histogram, a coarse bounding box for the character to be detected is determined;
[0188] Based on the grayscale information of the characters in the character template and the grayscale information in the coarse positioning box, adjust the coarse positioning box to determine the target character area.
[0189] In some embodiments, the processor 1210 is further configured to update the character template in the character database based on the character to be detected if the difference between the character template and the character to be detected is less than a target threshold.
[0190] In some embodiments, the processor 1210 is further configured to compare the pixels of the target character region with the high-value image pixels of the character template, and compare the pixels of the target character region with the low-value image pixels of the character template to determine the first pixel and the second pixel of the target character region, wherein the pixel value of the first pixel is not greater than the pixel value of the high-value image pixel and not less than the pixel value of the low-value image pixel, and the pixel value of the second pixel is greater than the pixel value of the high-value image pixel or less than the pixel value of the low-value image pixel;
[0191] The character detection result is determined based on the first and second pixels of the target character region.
[0192] In some embodiments, the processor 1210 is further configured to perform binarization and morphological processing on the image to be detected to obtain a binarized image;
[0193] Scan the binarized image to determine the vertex coordinates of the character to be detected;
[0194] Based on vertex coordinates, the top line of the character to be detected is extracted through Hough transform;
[0195] Based on the top line, determine the text arrangement angle of the characters to be detected;
[0196] Based on the text arrangement angle, affine transformation is used to correct the orientation of the image to be detected.
[0197] In some embodiments, the processor 1210 is further configured to establish a target detection model through the following steps:
[0198] Extract the character template region from the sample image, which includes the character template.
[0199] Based on the character template area, obtain the character shape information, character grayscale information, and character layout information of the character template;
[0200] A target detection model is established based on character shape information, character grayscale information, and character layout information from a character template.
[0201] In some embodiments, the processor 1210 is further configured to extract character template regions of a sample image by using Otsu threshold image segmentation;
[0202] When it is determined that the number of characters in the character template region extracted by Otsu threshold image segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted by vertical projection segmentation.
[0203] If the number of characters in the character template region extracted by vertical projection segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted based on the matching and localization of the preset character library.
[0204] It should be understood that, in this embodiment, the input unit 1204 may include a graphics processing unit (GPU) 12041 and a microphone 12042. The GPU 12041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 1206 may include a display panel 12061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 1207 includes a touch panel 12071 and at least one of other input devices 12072. The touch panel 12071 is also called a touch screen. The touch panel 12071 may include a touch detection device and a touch controller. Other input devices 12072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.
[0205] The memory 1209 can be used to store software programs and various data. The memory 1209 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 1209 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 1209 in this embodiment includes, but is not limited to, these and any other suitable types of memory.
[0206] Processor 1210 may include one or more processing units; processor 1210 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 1210.
[0207] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described optical character verification method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0208] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0209] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described optical character verification method.
[0210] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0211] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described optical character verification method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0212] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0213] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0214] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a...
[0215] The storage medium (such as ROM / RAM, magnetic disk, optical disk) includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0216] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0217] 0 In the description of this specification, reference is made to the terms "one embodiment", "some embodiments", "illustrative embodiment",
[0218] The terms "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with the embodiment or example that are included in at least one embodiment or example of this application. In this specification, illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0219] 5. Although embodiments of this application have been shown and described, those skilled in the art will understand that, without departing from the present application…
[0220] Various changes, modifications, substitutions and variations may be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
Claims
1. An optical character verification method, characterized in that, include: Acquire the image to be detected; The image to be detected is input into the target detection model to obtain the character detection result of the image to be detected output by the target detection model; The step of inputting the image to be detected into the target detection model and obtaining the character detection result of the image to be detected output by the target detection model further includes: The image to be detected is oriented correctly. Based on the character shape information, character grayscale information, and character layout information of the character template in the character database of the target detection model, the target character region where the character to be detected is located in the image to be detected is determined. The target character region is compared with the character template to determine the character detection result of the character to be detected; the target character region in the image to be detected is determined based on the character shape information, character grayscale information, and character layout information of the character template in the character database of the target detection model, including: Based on the character layout information of the character template, the character search range of the image to be detected is determined; Based on the character shape information of the character template, the gradient histogram of the character template is obtained; Based on the gradient histogram, a coarse bounding box for the character to be detected is determined; Based on the grayscale information of the characters in the character template and the grayscale information in the coarse positioning box, the coarse positioning box is adjusted to determine the target character region.
2. The optical character verification method according to claim 1, characterized in that, After obtaining the character detection results of the image to be detected output by the target detection model, the method further includes: If the difference between the character template and the character to be detected is less than a target threshold, the character template in the character database is updated based on the character to be detected.
3. The optical character verification method according to claim 1, characterized in that, The step of comparing the target character region with the character template to determine the character detection result of the character to be detected includes: The pixels of the target character region are compared with the high-value image pixels of the character template, and the pixels of the target character region are compared with the low-value image pixels of the character template to determine the first pixel and the second pixel of the target character region. The pixel value of the first pixel is not greater than the pixel value of the high-value image pixel and not less than the pixel value of the low-value image pixel. The pixel value of the second pixel is greater than the pixel value of the high-value image pixel or less than the pixel value of the low-value image pixel. The character detection result is determined based on the first pixel and the second pixel of the target character region.
4. The optical character verification method according to claim 1, characterized in that, The orientation correction of the image to be detected includes: The image to be detected is binarized and morphologically processed to obtain a binarized image; Scan the binarized image to determine the vertex coordinates of the character to be detected; Based on the vertex coordinates, the top line of the character to be detected is extracted through Hough transform; Based on the top line, the text arrangement angle of the character to be detected is determined; Based on the text arrangement angle, the orientation of the image to be detected is corrected by affine transformation.
5. The optical character verification method according to any one of claims 1-4, characterized in that, The target detection model is established through the following steps: Extract the character template region from the sample image, wherein the sample image includes the character template; Based on the character template area, obtain the character shape information, character grayscale information, and character layout information of the character template; The target detection model is established based on the character shape information, character grayscale information, and character layout information of the character template.
6. The optical character verification method according to claim 5, characterized in that, The extracted character template region of the sample image includes: The character template region of the sample image is extracted by using Otsu threshold image segmentation; If the number of characters in the character template region extracted by Otsu threshold image segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted by vertical projection segmentation. If the number of characters in the character template region extracted by vertical projection segmentation is not equal to the number of verification characters, the character template region of the sample image is extracted based on the matching and positioning of the preset character library.
7. An optical character verification device, characterized in that, include: The acquisition module is used to acquire the image to be detected; The processing module is used to input the image to be detected into the target detection model and obtain the character detection result of the image to be detected output by the target detection model; The step of inputting the image to be detected into the target detection model and obtaining the character detection result of the image to be detected output by the target detection model further includes: The image to be detected is oriented correctly. Based on the character shape information, character grayscale information, and character layout information of the character template in the character database of the target detection model, the target character region where the character to be detected is located in the image to be detected is determined. The target character region and the character template are compared to determine the character detection result of the character to be detected; The method of determining the target character region in the image to be detected by using character shape information, character grayscale information, and character layout information from character templates in the character database based on the target detection model includes: Based on the character layout information of the character template, the character search range of the image to be detected is determined; Based on the character shape information of the character template, the gradient histogram of the character template is obtained; Based on the gradient histogram, a coarse bounding box for the character to be detected is determined; Based on the grayscale information of the characters in the character template and the grayscale information in the coarse positioning box, the coarse positioning box is adjusted to determine the target character region.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the optical character verification method as described in any one of claims 1-6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the optical character verification method as described in any one of claims 1-6.