Character detection method and device
By establishing a benchmark character library and performing image processing, the problems of low efficiency in character defect detection and the influence of subjective judgment in existing technologies have been solved, and efficient detection of missing and multiple prints of dynamic characters has been achieved.
Patent Information
- Application Number
- CN202510822129.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-18
- Publication Date
- 2025-11-14
AI Technical Summary
Existing technologies are inefficient in character defect detection and are easily affected by subjective judgment, making it difficult to effectively detect missing or duplicate printing of dynamically variable characters such as serial numbers and International Mobile Equipment Identity codes.
By establishing a reference character library, a reference string identical to the string to be tested is extracted from the reference character library. After image processing, the difference between the reference string and the string to be tested is used to determine whether the character to be tested has missing prints and/or multiple prints.
It improves the accuracy and efficiency of character defect detection, and can effectively identify issues such as missing or duplicate printing of dynamic characters.
Smart Images

Figure CN120954005A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a character detection method and apparatus. Background Technology
[0002] In modern industrial production, character defect detection is crucial for ensuring product quality. This is especially true in the consumer electronics industry, where the accuracy and completeness of printed characters directly impact the product's appearance and functionality. However, due to limitations in processing technology and manufacturing environment, characters are prone to defects during printing, such as incompleteness, skewing, adhesion, multiple printings, misprints, omissions, and duplicate printing. Traditional manual visual inspection and machine vision-based inspection methods suffer from low efficiency and susceptibility to subjective judgment. Summary of the Invention
[0003] This application provides a character detection method and apparatus that can improve the accuracy and robustness of character defect detection.
[0004] In a first aspect, a character detection method is provided, the method comprising: identifying a string to be tested; extracting a reference string from a reference character library based on the string to be tested, the reference string and the string to be tested including the same characters; performing image processing on the reference string and the string to be tested; and detecting whether there are areas of missing and / or overprinted characters in the string to be tested based on the processed reference string and the string to be tested.
[0005] In some implementations, extracting a reference string from a reference character library based on the string to be tested includes: using a template matching algorithm, searching in the reference character library for a reference character that corresponds to the character to be tested in the string to be tested, and concatenating the reference characters to form the reference string.
[0006] In some implementations, the image processing includes: binarizing the reference string and the string to be tested to extract a binarized image of the reference string and the string to be tested, wherein the binarized image includes a character foreground.
[0007] In some implementations, the image processing further includes: dilating the reference character in the reference string and the character to be tested in the string to be tested.
[0008] In some implementations, the expansion of the base character in the base string and the character to be tested in the string to be tested includes: expanding the character to be tested in the string to be tested based on an erosion operation.
[0009] In some implementations, the image processing further includes: performing image enhancement on the reference string and the string to be tested before binarizing them; and performing smoothing on the enhanced reference string and the string to be tested.
[0010] In some implementations, the method further includes filtering out interference regions outside the baseline string and the string to be tested.
[0011] In some implementations, filtering interference regions outside the reference string and the string to be tested includes: extracting the character outlines of the reference character in the reference string and the character outlines of the character to be tested in the string to be tested; calculating the character area based on the character outlines; and determining the interference region based on the character area, wherein the interference region is a region whose area does not meet the threshold requirement.
[0012] In some implementations, determining whether there are missing and / or overprinted areas of the character to be tested in the string to be tested, based on the processed reference string and the string to be tested, includes: preprocessing the reference string or the string to be tested, wherein the preprocessing is used to improve the tolerance of the detection result of the string to be tested; and subtracting the reference character in the reference string from the character to be tested in the string to be tested to obtain the missing and / or overprinted areas of the character to be tested in the string to be tested.
[0013] In some implementations, the preprocessing includes expanding the character to be tested in the string to be tested. The step of subtracting the reference character in the reference string from the character to be tested in the string to be tested to obtain the missing and / or overprinted areas of the character to be tested in the string to be tested includes: subtracting the corresponding reference character in the reference string from the character to be tested in the string to be tested to obtain the missing area of the character to be tested in the string to be tested, wherein the missing area is an area with a grayscale value of 255.
[0014] In some implementations, the preprocessing includes expanding the reference character in the reference string. The step of subtracting the reference character in the reference string from the character to be tested in the string to be tested to obtain the missing and / or overprinted areas of the character to be tested in the string to be tested includes: subtracting the corresponding character to be tested in the string to be tested from the reference character in the reference string to obtain the overprinted areas of the character to be tested in the string to be tested, wherein the overprinted areas are areas with a grayscale value of 255.
[0015] In some implementations, the method further includes: comparing the number of characters identified in the string to be tested with a predetermined number to determine whether characters are missing and / or extra characters are printed in the string to be tested.
[0016] Secondly, a character detection device is provided, comprising: a character recognition unit for recognizing a string to be tested; a character extraction unit for extracting a reference string from a reference character library based on the string to be tested, wherein the reference string and the string to be tested include the same characters; an image processing unit for performing image processing on the reference string and the string to be tested; and a detection unit for detecting, based on the processed reference string and the string to be tested, whether there are any missing or overprinted areas of the character to be tested in the string to be tested.
[0017] Thirdly, a character detection device is provided, including a memory and a processor, wherein the memory is used to store program code, and the processor is used to call the program code in the memory to cause the character detection device to perform the method described in any one of the first aspects.
[0018] The character detection method of this application establishes a reference character library, extracts reference strings that have the same characters as the string to be tested from the reference character library, and after image processing of the reference string and the string to be tested, determines whether there are problems of overprinting and / or missing printing of the characters to be tested in the string to be tested based on the differences between the processed reference string and the string to be tested. It has high accuracy and detection efficiency. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a schematic flowchart of the character detection method according to an embodiment of this application.
[0021] Figure 2 This is a schematic diagram of the string to be tested.
[0022] Figure 3 This is a schematic diagram of the test string and the reference string at each stage in the character detection method of this application embodiment.
[0023] Figure 4 This is a schematic diagram of the test string and the reference string at each stage in the character detection method of this application embodiment.
[0024] Figure 5 yes Figure 1 The flowchart shows one possible implementation of the character detection method.
[0025] Figure 6 This is a schematic diagram of the character detection device according to an embodiment of this application.
[0026] Figure 7 This is a schematic diagram of the character detection device according to an embodiment of this application. Detailed Implementation
[0027] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. 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.
[0028] The terminology used in the embodiments of this invention is for the purpose of describing particular embodiments only and is not intended to limit the invention. The singular forms “a,” “the,” and “the” as used in the embodiments of this invention and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.
[0029] It should be understood that the term "and / or" used in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.
[0030] In modern industrial production, character defect detection is crucial for ensuring product quality, especially in the consumer electronics industry. The accuracy and integrity of printed characters directly affect the appearance and function of a product. However, due to limitations in processing technology and manufacturing environment, characters are prone to defects such as incompleteness, skewing, sticking, multiple printings, misprints, omissions, and duplicate printing during the printing process.
[0031] Traditional manual visual inspection methods, while providing intuitive feedback, are inefficient and susceptible to subjective judgment. Prolonged work can lead to operator fatigue, increasing the risk of false positives and false negatives. Therefore, manual visual inspection is not ideal in large-scale production environments with high precision requirements. Furthermore, machine vision-based inspection methods also have limitations, such as handling complex backgrounds or unclear images.
[0032] With the development of artificial intelligence technology, especially the application of neural network algorithms, the automation and intelligence level of character defect detection has been significantly improved. Nevertheless, existing technologies still have shortcomings in processing defect detection of dynamically variable characters such as serial numbers (SN) and international mobile equipment identities (IMEI).
[0033] Existing character defect detection technologies are mainly divided into two categories: one is based on traditional image processing techniques. These methods typically have a simple processing mechanism, can only detect limited defects in static character regions, and their detection performance is greatly affected by the quality of the image itself. The other category is based on semantic segmentation methods using deep learning. The effectiveness of these methods usually depends on training with a large number of negative samples, but in actual production processes, zero-defect or few-defect samples are difficult to meet the optimization conditions, resulting in mediocre training performance and difficulty in effectively solving the problems of missing and duplicate character printing.
[0034] In view of this, this application proposes a character detection method, which establishes a reference character library, extracts reference strings that have the same characters as the string to be tested from the reference character library, and after image processing of the reference string and the string to be tested, determines whether there are problems of overprinting and / or missing printing of the characters to be tested in the string to be tested based on the differences between the processed reference string and the string to be tested. It has high accuracy and detection efficiency.
[0035] The following, combined with Figures 1 to 4 The technical solutions of the embodiments of this application will be described in detail. Figure 1 This is a schematic flowchart of the character detection method provided in the embodiments of this application, such as... Figure 1 As shown, Figure 1 The method 100 shown may include some or all of the following steps.
[0036] In step S110, the string to be tested is identified. This application embodiment does not limit the method of identifying the string to be tested. For example, optical character recognition (OCR) technology can be used to identify the characters to be tested and arrange the identified characters to form the string to be tested. Specifically, OCR technology can identify each character in the image, and arranging the identified characters in sequence to form the string to be tested is equivalent to removing redundant blank areas between characters. When arranging the identified individual characters to form the string to be tested, the interval between adjacent characters can be a fixed value (hereinafter denoted as D).
[0037] The character types in the string to be tested include, but are not limited to, numbers, letters, and special symbols. For example, numbers can be 0 to 9, letters can be A to Z, and special symbols can include hyphens "-", underscores "_", forward slashes " / ", etc. The combination and use of these characters may differ in different application scenarios. For example, a serial number (SN) typically consists of numbers and letters, such as SN123456. An IMEI code is usually a 15-digit number, such as 354678012345678. A batch number typically includes numbers, letters, and hyphens, such as HITCH-12345.
[0038] In step S110, while recognizing and extracting characters such as letters, numbers, and special symbols from the image to form a string to be tested, the number of characters included in the string can be recorded. For example, such as Figure 2 The product serial number shown is CC2HAM00APA0000507, which is identified by OCR technology and has 18 characters.
[0039] After identifying the string to be tested, it can be inspected from two aspects: character-level inspection and stroke-level inspection. Character-level inspection determines whether the number of characters in the string meets the requirements, for example, whether there are extra or missing characters. Stroke-level inspection determines whether individual characters in the string have defects in their strokes, for example, whether parts of the character are missing or extra.
[0040] Since the characters included in different strings to be tested are not exactly the same, that is, the characters in the string being tested are dynamically changing each time, the character detection described in the embodiments of this application can also be called dynamic character detection.
[0041] Character-level detection For character-level detection, for example, the number of characters in the identified string to be tested can be compared with a predetermined number to determine whether the string to be tested contains missing characters and / or extra characters.
[0042] In industrial printing (e.g., printing serial numbers or IMEI codes), there are usually fixed requirements for the number of characters. For example, an IMEI code is typically required to contain 15 characters. Therefore, after identifying the specific characters and their number in the string to be tested, the identified number of characters can be compared with a predetermined number. If the identified number of characters in the string is less than the predetermined number, it can be determined that there is a character-level omission; if the identified number of characters in the string is greater than the predetermined number, it can be determined that there is a character-level overprint; if the identified number of characters in the string is equal to the predetermined number, it can be determined that there is neither a character-level omission nor an overprint.
[0043] For example, taking the IMEI code as an example, the standard number of characters in an IMEI code is 15. If the number of characters in the IMEI code to be tested is less than 15, then the IMEI code to be tested has missing characters; if the number of characters in the IMEI code to be tested is greater than 15, then the IMEI code to be tested has extra characters; if the number of characters in the IMEI code to be tested is equal to 15, then the IMEI code to be tested has neither extra characters nor missing characters.
[0044] The embodiments of this application do not limit the timing of character-level detection. For example, character-level detection can be performed after step S110; or, character-level detection can be performed after any of steps S120, S130 and S140, which will be described later.
[0045] Stroke-level detection Stroke-level detection can be achieved through Figure 1 Steps S120 to S140 are implemented as shown. First, in order to achieve stroke-level detection of the string to be tested, a reference character library needs to be established in this embodiment. The reference character library, for example, consists of all possible individual characters. As an example, for character detection of IMEI codes, the reference character library includes all characters that can be used to form IMEI codes. Assuming there are 30 possible characters for forming IMEI codes, the 15 characters in the IMEI code should be selected from these 30 characters.
[0046] See also Figure 1 In step S120, a reference string can be extracted from a reference character library based on the string to be tested. The reference string and the string to be tested contain the same characters. For example, a template matching algorithm can be used to find the reference character in the reference character library that corresponds to the character to be tested in the string to be tested, and then concatenate the reference characters to form the reference string. The template matching algorithm can be implemented using OCR technology or other computer vision processing techniques.
[0047] Specifically, based on the string to be tested, a reference character can be found in a reference character library that matches each character in the string to be tested. These reference characters are then arranged at certain intervals to form a reference string. The order of characters in the reference string is the same as that in the string to be tested, and the interval between adjacent characters is also the same, which is the aforementioned distance "D". In this way, when comparing the string to be tested and the reference string, the difference in character intervals between the two strings will not affect the detection results, thus improving the reliability of character detection.
[0048] For example, if the string to be tested identified in step S110 includes "RG520FXX-XXXDE-DEMO", the baseline string that matches the string to be tested should be "RG520FXX-XXXDE-DEMO" extracted from the baseline character library. The characters included in the baseline string and the string to be tested are the same. However, each character in the baseline string "RG520FXX-XXXDE-DEMO" is a baseline character without stroke-level defects, meaning that each character has no missing or / or overprinted areas. The string to be tested, on the other hand, may contain characters with missing and / or overprinted areas. Of course, each character in the string to be tested may also not have stroke-level defects, meaning there are no missing or / or overprinted areas. The specific character detection results need to be further determined through steps S130 and S140.
[0049] As an example, such as Figure 3 As shown, assuming the string to be tested is "RG520FXX-XXXDE-DEMO", where, Figure 3 (a1) shows the string to be tested obtained through step S110. Figure 3 (a2) shows the baseline string that matches the string to be tested, extracted from the baseline character library using a template matching algorithm. After obtaining the string to be tested and the baseline string, steps S130 and S140 can be used to process and compare the string to be tested and the baseline string to obtain the character detection result.
[0050] See also Figure 1 In step S130, image processing is performed on the reference string and the string to be tested. Here, the image processing includes, but is not limited to, image enhancement, smoothing, binarization, dilation and / or erosion operations, and interference filtering operations.
[0051] In some implementations, image processing may include binarizing a reference string and a test string to extract binary images of the reference string and the test string. The binary images obtained through binarization serve as the character foreground of the reference string and the test string. Binarization is a fundamental technique in image processing, aiming to convert a grayscale or color image into a binary image with only two gray levels, where black has a value of 0 and white has a value of 255. More specifically, binarization can separate characters and background in the test string and / or the reference string. Typically, character regions are converted to black (grayscale value 0), and background regions are converted to white (grayscale value 255), thus obtaining the character regions (i.e., the character foreground obtained through binarization). Furthermore, binarization can reduce the amount of image data and improve processing speed.
[0052] It is understandable that during the extraction of the test string, issues with the sample itself and / or factors such as lighting may lead to uneven background in the extracted string, thus affecting the binarization effect. Therefore, in some implementations, image enhancement can be performed on the reference string and the test string before binarization, followed by smoothing. This improves the contrast between the character foreground and background in the test image, enhances the character foreground, and reduces background noise interference, thereby improving the subsequent binarization effect. For example, an adaptive contrast enhancement (ACE) algorithm can be used to enhance the image of the reference string and the test string.
[0053] As an example, see further. Figure 3 ,in, Figure 3 (b1) and (b2) are the test string and the baseline string obtained after image enhancement processing, respectively, compared to... Figure 3 The test string and the reference string are shown in (a1) and (a2). Figure 3 As shown in (b1) and (b2), the foreground characters of the test string and the reference string after image enhancement are clearer, the contrast between the background and the foreground characters is more obvious, and the display effect of the characters is improved. Figure 3 In (c1) and (c2), it is... Figure 3 The test string and reference string shown in (b1) and (b2) are obtained after smoothing, compared to... Figure 3 The test string and the reference string are shown in (b1) and (b2). Figure 3The smoothed test string and reference string shown in (c1) and (c2) have less background noise. Next, for... Figure 3 The smoothed test string and the reference string shown in (c1) and (c2) are binarized to obtain the following results: Figure 3 The binarized images of the test string and the reference string are shown in (d1) and (d2). Wherein, Figure 3 In (d1) and (d2), the grayscale value of the black characters in the test string is 0, and the grayscale value of the white background is 255.
[0054] Binarization can lead to character fragmentation, where some pixels in the foreground of characters in both the test string and the reference string are incorrectly treated as background, resulting in broken characters. For example, the number "8" might be incorrectly segmented into two overlapping "0"s. This fragmentation reduces the robustness of character recognition and increases the complexity and accuracy of subsequent image processing.
[0055] Therefore, in some implementations, the image processing described in step S130 may further include dilating the reference character in the reference string and the character to be tested in the string to be tested, thereby reducing the occurrence of broken text. The dilution of characters, for example, refers to expanding the foreground of the character to fill any small holes and gaps that may exist between different areas of the character, thereby avoiding broken text.
[0056] The dilation of the base character in the reference string and the character to be tested in the test string can be achieved, for example, through an erosion operation. The erosion operation refers to the erosion of the background of the base character in the reference string and the character to be tested in the test string; that is, dilating the portion of the binary image with a grayscale value of 0. By eroding the character background, the dilation effect of the base character in the reference string and the character to be tested in the test string is achieved.
[0057] As an example, see further. Figure 3 ,in, Figure 3 (e2) is the base string after the expansion operation. Figure 3 Taking the letter "R" in (d2) as an example, in Figure 3 In (d2), the binarized "R" contains disconnected regions. After dilation, the resulting... Figure 3 The broken positions of the letter "R" in (e2) are connected.
[0058] While the aforementioned image processing steps—including image enhancement, smoothing, binarization, and dilation—can reduce interference and broken text in the image, and improve the contrast between character foreground and background, thus enhancing the robustness and accuracy of character defect detection to some extent, interference may still exist in the resulting test string and reference string after these image processing steps. Therefore, some implementations can filter out interference regions outside the reference string and test string. Here, interference regions refer to, for example, noise points, patterns, or textures that may not be completely removed, which can affect the character detection results.
[0059] Therefore, in some implementations, firstly, the character contours of the reference characters in the baseline string and the characters to be tested in the test string are extracted; secondly, the character area is calculated based on the character contours; and finally, interference regions are determined based on the character area. Interference regions are areas whose area does not meet the threshold requirement. Here, extracting the character contours of the reference characters in the baseline string and the characters to be tested in the test string can be achieved using edge detection algorithms or contour detection algorithms. For example, the `cv2.findContours()` function in OpenCV software can be used to extract character contours. The purpose of extracting character contours is to calculate the character area. Ideally, the area of each character to be tested identified in the test string and the area of each reference character in the baseline string should fall within a predetermined threshold range. Therefore, areas with an area greater than the threshold S can be identified as character regions, and areas with an area less than the threshold S can be considered interference regions. Thus, by calculating the character area, it can be determined whether interference regions exist in the test string and the baseline string, thereby filtering out these interference regions and improving the accuracy of character detection. The extracted character area is also called the discrete foreground area; areas in the discrete foreground whose area does not meet the threshold requirement can be considered interference regions.
[0060] See also Figure 1 In step S140, based on the processed reference string and the string to be tested, it is detected whether there are any missing or overprinted areas of the character to be tested in the string to be tested. That is, by comparing the reference string and the string to be tested, it is determined whether there are any missing or overprinted areas of the character to be tested in the string to be tested.
[0061] For example, the reference string or the string to be tested can be preprocessed, and the difference between the reference character in the reference string and the character to be tested in the string to be tested can be calculated to obtain the missing and / or overprinted areas of the character to be tested in the string to be tested. Here, the preprocessing is used to improve the tolerance of the detection results of the string to be tested. In some implementations, the preprocessing of the reference string or the string to be tested may include dilation operations on the foreground of the characters and / or erosion operations on the background of the characters. The detection of missing areas and overprinted areas of the character to be tested are described below.
[0062] Detection of missing areas of the character under test For detecting missing areas of a character under test, some implementations involve preprocessing the string under test by expanding the character to be tested. Then, the missing area of the character under test can be obtained by subtracting the corresponding base character from the character under test in the base string. The missing area, for example, refers to a region with a grayscale value of 255. As mentioned earlier, the expansion effect of the character under test can be achieved by expanding the foreground of the character and / or eroding the background of the character. Then, by subtracting the corresponding base character from the character under test in the base string, the resulting region with a grayscale value of 255 (i.e., the white region) is the missing area.
[0063] Tolerance, for example, refers to the ability to withstand various disturbances and changes. In this embodiment, after the character to be tested is dilated, the foreground characters near the missing printing area will also dilate. In this case, by subtracting the reference character in the reference string from the character to be tested in the character to be tested, if a region with a grayscale value of 255 (i.e., a white region) is still obtained, then the character to be tested in the character to be tested is considered to have a missing printing area. After subtracting the corresponding reference character in the reference string from the character to be tested in the character to be tested, a binary image between the character to be tested and the reference string can be obtained, hereinafter also referred to as the difference image. Optionally, the grayscale values of the regions with grayscale values of 0 and 255 in the difference image are swapped, that is, the grayscale value at the position with a grayscale value of 255 is changed from 255 to 0, and the grayscale value at the position with a grayscale value of 0 is changed to 255. The resulting binary image is the image of the missing printing area (i.e., the black region) of the character to be tested.
[0064] As an example, see further. Figure 3 (g1), (g2), and (g3), where (g1) is the string to be tested obtained after image processing in step S130. Figure 3(g2) is the reference string obtained after image processing in step S130. When it is necessary to detect the missing area of the character to be tested, the missing area of the character to be tested can be obtained by subtracting the character to be tested from the reference string, that is, missing area = expanded character to be tested - reference string. Figure 3 The string to be tested shown in (g1) is... Figure 3 When subtracting the reference string shown in (g2), the difference results of the gray values at the same position may include: (1) "0" - "0" = "0", the position where "0" - "0" = "0" is black in both the test string and the reference string, that is, the overlapping black area; (2) "0" - "255" = "-255", the position where "0" - "255" = "-255" is the part of the test string that is more than the reference string, which can be temporarily ignored when detecting missing prints; (3) "255" - "255" = "0", the position where "255" - "255" = "0" is white in both the test string and the reference string, that is, the overlapping white area; (4) "255" - "0" = "255", the position where "255" - "0" = "255" is the part of the test string that is less than the reference string, which is the missing print area. In other words, when performing missing print detection, the area with a grayscale value of "255" obtained by subtracting the test string from the reference string can be defined as the missing print area. To more clearly illustrate the missing print area, optionally, such as... Figure 3 As shown in (g3), the position with a grayscale value of 255 can be changed from white to black with a grayscale value of 0, that is, Figure 3 The black area shown in (g3) is the missing area.
[0065] Detection of multiple printed regions of the character under test For multi-print region detection of a character under test, some implementations involve preprocessing the string under test by expanding the base character in the base string. Then, the multi-print region of the character under test can be obtained by subtracting the corresponding character from the base character in the base string. This multi-print region, for example, refers to a region with a grayscale value of 255. As mentioned earlier, the expansion effect of the character under test can be achieved by expanding the foreground of the character and / or eroding the background. Then, by subtracting the corresponding character from the base character in the base string, the resulting region with a grayscale value of 255 (i.e., the white region) is the multi-print region.
[0066] In this embodiment, after dilution of the reference character, the character to be tested in the test string is subtracted from the reference character in the reference string. If a region with a grayscale value of 255 (i.e., a white region) is still obtained, it is considered that the character to be tested in the test string has a multi-printed region. After subtracting the corresponding reference character in the reference string from the character to be tested in the test string, a binary image between the test string and the reference string can be obtained, hereinafter also referred to as the difference image. Optionally, the grayscale values of the regions with grayscale values of 0 and 255 in the difference image are swapped, that is, the grayscale value at the position with a grayscale value of 255 is changed from 255 to 0, and the grayscale value at the position with a grayscale value of 0 is changed to 255. The resulting binary image is the image of the multi-printed region (i.e., the black region) of the character to be tested.
[0067] As an example, see Figure 4 ,in, Figure 4 The image processing steps involved in (a1), (a2), (b1), (b2), (c1), (c2), (d1), (d2), (e1), (e2), (f1), and (f2) can be referenced for [the relevant documentation / reference]. Figure 3 The descriptions of (a1), (a2), (b1), (b2), (c1), (c2), (d1), (d2), (e1), (e2), (f1), and (f2) will not be repeated here for the sake of brevity.
[0068] See also Figure 4 , Figure 4 (g1) is the string to be tested after image processing in step S130. Figure 4 (g2) is the reference string after image processing in step S130. When it is necessary to detect the multi-printed region of the character to be tested, the difference between the reference string and the string to be tested can be used to obtain the multi-printed region of the string to be tested, that is, multi-printed region = expanded reference string - string to be tested. Figure 4 The string to be tested shown in (g1) is... Figure 4When the reference string shown in (g2) is subtracted, the difference results of the gray values at the same position may include: (1) "0" - "0" = "0", the position that satisfies "0" - "0" = "0" is black in both the test string and the reference string, that is, the overlapping black area; (2) "0" - "255" = "-255", the position that satisfies "0" - "255" = "-255" is the part that the reference string has more than the test string, which can be temporarily ignored in the multiprint detection; (3) "255" - "255" = "0", the position that satisfies "255" - "255" = "0" is white in both the test string and the reference string, that is, the overlapping white area; (4) "255" - "0" = "255", the area that satisfies "255" - "0" = "255" is the part that the reference string has less than the test string, that is, the part that the test string has more than the reference string, and this part is the multiprint area. In other words, when performing multi-print detection, the difference between the reference string and the string to be tested can be calculated, and the area with a grayscale value of "255" can be identified as the multi-print area. To more clearly display the missing print area, optionally, such as... Figure 4 As shown in (g3), the position with a grayscale value of "255" can be changed from white to black with a grayscale value of 0, that is, Figure 4 The black area shown in (g3) is the multiprint area.
[0069] It should be understood that when detecting missing and / or overprinted areas in the string under test, it may be unclear whether such areas exist. If the missing print detection steps are performed only on the string under test and the reference string, only the possible missing print areas of the characters under test in the string under test can be detected, and it is impossible to determine the overprinted cases. Similarly, if the overprint detection steps are performed only on the string under test and the reference string, only the possible overprinted areas of the characters under test in the string under test can be detected, and it is impossible to determine the missing print cases. Therefore, when performing step S140, both missing and / or overprint detection can be performed on the characters under test in the string under test simultaneously.
[0070] In addition to the aforementioned baseline character library, optionally, when establishing the baseline character library, the library may also include a set of baseline characters after image processing; that is, all possible characters are processed and stored to form the baseline character library. Image processing of the baseline characters includes one or more operations such as image enhancement, image smoothing, binarization, dilation of the baseline characters, and filtering of interference regions. Thus, the baseline string extracted in step S120 is the baseline string after image processing. Therefore, in step S130, image processing can be performed only on the string to be tested, without further image processing of the baseline string. For example, Figure 3 and Figure 4 The process shown may no longer include Figure 3 and Figure 4 The image processing steps involved in (b2), (c2), (d2), (e2), and (f2) reduce the processing time for character detection, simplify the processing flow, and thus improve detection efficiency. It is important to note that the image processing procedures performed on the string to be detected should be the same as those performed on the reference characters when establishing the reference character library. For example, the same type of image processing operations should be used, the order of image processing operations should be the same, and the same parameters should be used during image processing.
[0071] The above describes how to perform character-level and stroke-level detection. On one hand, by determining whether the number of characters in the identified test string meets a predetermined number, it is determined whether there are any overprints or omissions at the character level in the test string. On the other hand, through the above steps S120 to S140, a reference string matching the test string is extracted from the reference character library. Image processing is performed on the reference string and the test string, and the processed reference string and the test string are compared to detect whether there are any overprints and / or omissions at the stroke level in the test string. This application embodiment does not limit the execution order of character-level and stroke-level detection. In practical applications, the character detection results of this application embodiment can be used to guide the printing process of the test string, provide feedback to the printing process, thereby correcting links in the printing process that may lead to character defects, improving the printing effect of the string, and increasing the success rate of character printing.
[0072] The following is combined with Figure 5 The specific examples shown illustrate the detection of missing and multiple printing areas in the embodiments of this application in more detail. In the examples below, the image recognition technology used to identify the reference string is OCR. When extracting the corresponding reference string from the reference character library based on the string to be tested, a template matching algorithm can be used. The image processing techniques involved in image processing of the string to be tested and the reference string may include, for example, image enhancement technology based on the ACE algorithm, erosion operation for dilating characters, and the cv2.findContours() function in OpenCV for extracting character contours and areas. It should be noted that... Figure 5 The examples shown are merely to help those skilled in the art understand the embodiments of this application, and are not intended to limit the embodiments of this application to the specific values or scenarios illustrated. Those skilled in the art will obviously be able to make various equivalent modifications or variations based on the examples given below, and such modifications or variations also fall within the scope of the embodiments of this application.
[0073] like Figure 5 As shown, in step S5010, the string to be tested is identified by OCR technology, and the number of characters to be tested included in the string to be tested is recorded.
[0074] In step S5020, a reference character corresponding to the character to be tested in the string to be tested is found in the reference character library to form a reference string.
[0075] In step S5030, the reference string and the string to be tested are image enhanced using the ACE algorithm, and the enhanced reference string and the string to be tested are smoothed.
[0076] In step S5040, the baseline string and the string to be tested obtained in step S5030 are binarized to extract the character foreground of the string to be tested and the baseline string.
[0077] In step S5050, the expansion of the test character in the test string and the reference character in the reference string is achieved by eroding the character background.
[0078] In step S5060, the character contour of the character to be tested is calculated using the cv2.findContours() function, and then the character area of each character is obtained. Interference areas are filtered out by comparing the character area with the corresponding threshold.
[0079] Steps S5030-S5060 involve image processing of the test string and the reference string to obtain higher quality binarized images of the test string and the reference string, which helps improve the accuracy of subsequent steps S5072 and S5074.
[0080] In step S5072, the character to be tested in the string to be tested is subjected to an erosion operation. The corresponding base character in the base string is subtracted from the character to be tested in the string to be tested to obtain the missing area of the character to be tested in the string to be tested.
[0081] In step S5074, the reference character in the reference string to be tested is eroded. The reference character in the reference string is subtracted from the corresponding character to be tested in the string to be tested to obtain the multiprinted region of the character to be tested in the string to be tested.
[0082] Through steps S5072 and S5074, the stroke-level missing and / or overprinted areas of the characters to be tested in the string to be tested can be obtained.
[0083] In step S5080, based on the number of characters recorded in step S5010, it is determined whether there are character-level overprints and / or missing prints in the string to be tested.
[0084] It is understood that step S5080 can be executed after step S5010, or after steps S5072-S5074. Alternatively, in this embodiment of the application, step S5080 may not be executed, but character-level multiple printing and / or omission printing may be achieved through steps S5072 and S5074.
[0085] In step S5090, the results of the aforementioned steps S5082, S5084 and S5090 are integrated to output the final character detection result.
[0086] The above text combined Figures 1 to 5 The method embodiments of this application are described in detail below, in conjunction with... Figures 6 to 7 The present application provides a detailed description of the apparatus embodiments. It should be understood that the descriptions of the method embodiments correspond to the descriptions of the apparatus embodiments; therefore, any parts not described in detail can be found in the foregoing method embodiments.
[0087] Figure 6 This is a schematic diagram of the character detection device provided in an embodiment of this application. Figure 6 As shown, the device 600 includes a character recognition unit 610, a character extraction unit 620, an image processing unit 630, and a detection unit 640. The character recognition unit 610 is used to recognize the string to be tested; the character extraction unit 620 is used to extract a reference string from a reference character library based on the string to be tested, the reference string and the string to be tested containing the same characters; the image processing unit 630 is used to perform image processing on the reference string and the string to be tested; the detection unit 640 is used to detect whether there are any missing or overprinted areas of the characters to be tested in the string to be tested, based on the processed reference string and the string to be tested.
[0088] In some implementations, the character extraction unit 620 is further configured to: extract a reference string from a reference character library based on the string to be tested, including: searching for a reference character in the reference character library that corresponds to the character to be tested in the string to be tested based on a template matching algorithm, and concatenating the reference characters to form the reference string.
[0089] In some implementations, the image processing unit 630 is further configured to: perform binarization processing on the reference string and the string to be tested to extract a binarized image of the reference string and the string to be tested, wherein the binarized image includes a character foreground.
[0090] In some implementations, the image processing unit 630 is further configured to: expand the reference character in the reference string and the test character in the test string.
[0091] In some implementations, the expansion of the base character in the base string and the character to be tested in the string to be tested includes: expanding the character to be tested in the string to be tested based on an erosion operation.
[0092] In some implementations, the image processing unit 630 is further configured to: perform image enhancement on the reference string and the string to be tested before binarizing the reference string and the string to be tested; and perform smoothing on the reference string and the string to be tested after image enhancement.
[0093] In some implementations, the image processing unit 630 is further configured to: filter out interference regions outside the reference string and the string to be tested.
[0094] In some implementations, the image processing unit 630 is further configured to: filter interference regions outside the reference string and the test string, including: extracting the character outlines of the reference character in the reference string and the test character in the test string; calculating the character area based on the character outlines; and determining the interference region based on the character area, wherein the interference region is a region whose area does not meet the threshold requirement.
[0095] In some implementations, the detection unit 640 is further configured to: determine whether there are areas of missing or overprinted characters in the string to be tested based on the processed reference string and the string to be tested, including: preprocessing the reference string or the string to be tested, wherein the preprocessing is used to improve the tolerance of the detection result of the string to be tested; and subtracting the reference character in the reference string from the character to be tested in the string to be tested to obtain the areas of missing or overprinted characters in the string to be tested.
[0096] In some implementations, the detection unit 640 is further configured to: preprocessing includes expanding the character to be tested in the string to be tested; the step of subtracting the reference character in the reference string from the character to be tested in the string to be tested to obtain the missing and / or overprinted area of the character to be tested in the string to be tested includes: subtracting the corresponding reference character in the reference string from the character to be tested in the string to be tested to obtain the missing area of the character to be tested in the string to be tested, wherein the missing area is an area with a grayscale value of 255.
[0097] In some implementations, the detection unit 640 is further configured to: preprocessing includes expanding the reference character in the reference string; the step of subtracting the reference character in the reference string from the character to be tested in the string to be tested to obtain the missing and / or overprinted areas of the character to be tested in the string to be tested includes: subtracting the corresponding character to be tested in the string to be tested from the reference character in the reference string to obtain the overprinted areas of the character to be tested in the string to be tested, wherein the overprinted areas are areas with a grayscale value of 255.
[0098] In some implementations, the detection unit 640 is further configured to: compare the number of characters included in the identified string to be tested with a predetermined number to determine whether any characters are missing in the string to be tested.
[0099] This application also provides a character detection device, such as... Figure 7 As shown, the device 700 includes a memory 710 and a processor 720. The memory 710 is used to store program code, and the processor 720 is used to call the program code in the memory 710 so that the device 700 executes the method described in any of the foregoing embodiments.
[0100] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0101] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0102] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0103] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can read or a data storage device such as a server or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital video discs (DVDs)), or semiconductor media (e.g., solid-state disks (SSDs)).
[0104] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A character detection method, characterized in that, include: Identify the string to be tested; Based on the string to be tested, a benchmark string is extracted from the benchmark character library, and the benchmark string and the string to be tested contain the same characters. Image processing is performed on the baseline string and the string to be tested; Based on the processed baseline string and the test string, detect whether there are areas of missing or overprinted characters in the test string.
2. The method according to claim 1, characterized in that, The step of extracting a benchmark string from a benchmark character library based on the string to be tested includes: Based on the template matching algorithm, a reference character corresponding to the character to be tested in the string to be tested is found in the reference character library, and the reference characters are concatenated to form the reference string.
3. The method according to claim 1, characterized in that, The image processing includes: The reference string and the string to be tested are binarized to extract binarized images of the reference string and the string to be tested, the binarized images including character foregrounds.
4. The method according to claim 3, characterized in that, The image processing further includes: The base character in the base string and the character to be tested in the string to be tested are expanded.
5. The method according to claim 4, characterized in that, The expansion of the base character in the base string and the character to be tested in the character to be tested includes: Based on the erosion operation, the characters to be tested in the string to be tested are expanded.
6. The method according to claim 3, characterized in that, The image processing further includes: Before binarizing the reference string and the test string, image enhancement is performed on the reference string and the test string; and, The baseline string and the string to be tested, after image enhancement, are smoothed.
7. The method according to claim 1, characterized in that, The method further includes: Filter out interference regions outside of the baseline string and the string to be tested.
8. The method according to claim 7, characterized in that, The filtering of interference regions outside the reference string and the string to be tested includes: Extract the base character of the base string and the character outline of the character to be tested in the string to be tested; Calculate the character area based on the character outline; The interference region is determined based on the character area, wherein the interference region is the region whose area does not meet the threshold requirement.
9. The method according to claim 1, characterized in that, The step of detecting whether there are missing and / or overprinted areas of the character to be tested in the character to be tested in the character to be tested, based on the processed base string and the character to be tested, includes: The baseline string or the string to be tested is preprocessed, and the preprocessing is used to improve the tolerance of the detection result of the string to be tested; The difference between the reference character in the reference string and the character to be tested in the string to be tested is used to obtain the areas of missing and / or overprinted characters in the string to be tested.
10. The method according to claim 9, characterized in that, The preprocessing includes expanding the characters to be tested in the string to be tested, and subtracting the reference character in the reference string from the characters to be tested in the string to be tested to obtain the areas of missing and / or overprinted characters in the string to be tested, including: By subtracting the corresponding reference character from the reference string from the character to be tested in the string to be tested, the missing printing area of the character to be tested in the string to be tested is obtained, wherein the missing printing area is an area with a grayscale value of 255.
11. The method according to claim 9, characterized in that, The preprocessing includes expanding the reference characters in the reference string, and subtracting the reference characters in the reference string from the characters to be tested in the string to be tested to obtain the areas of missing and / or overprinted characters in the string to be tested, including: By subtracting the corresponding character to be tested from the base character in the base string, a multi-print region of the character to be tested in the test string is obtained, wherein the multi-print region is a region with a grayscale value of 255.
12. The method according to any one of claims 1 to 11, characterized in that, The method further includes: The number of characters in the identified string to be tested is compared with a predetermined number to determine whether there are missing characters and / or extra characters in the string to be tested.
13. A character detection device, characterized in that, include: The character recognition unit is used to recognize the string to be tested. A character extraction unit is used to extract a reference string from a reference character library based on the string to be tested, wherein the reference string and the string to be tested contain the same characters; An image processing unit is used to perform image processing on the reference string and the string to be tested; The detection unit is used to detect, based on the processed reference string and the string to be tested, whether there are areas of missing or overprinted characters in the string to be tested.
14. A character detection device, characterized in that, The device includes a memory and a processor, the memory being used to store program code, and the processor being used to invoke the program code in the memory to cause the character detection device to perform the method of any one of claims 1 to 12.
Citation Information
Patent Citations
Character defect automatic detection method and system
CN108416765A
Character defect detection method and device
CN111060527A
Defect detection method and device for characters at bearing end
CN117173709A
Character defect detection method and device, electronic equipment and storage medium
CN117727052A