Barcode information recognition method and electronic device
By extracting and repairing the character's circumscribed rectangle from the one-dimensional code character image, the problem of low decoding success rate of traditional methods when the image quality is poor and the barcode is incomplete is solved, and efficient barcode information recognition is achieved.
Patent Information
- Application Number
- CN202111256684.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-27
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2041-10-27
AI Technical Summary
The traditional one-dimensional code information extraction method has a low decoding success rate when the image quality is poor, the barcode is incomplete or blocked, and it cannot effectively improve the recognition accuracy.
By obtaining the barcode character image, extract the character circumscribed rectangle of each character, and perform character quality inspection on it. If defects are found, character repair is performed until the number of black connected domains within the circumscribed rectangle of each character is one, and the target character is obtained by merging After stringing, OCR technology is used for identification.
Significantly improves the decoding success rate under special circumstances such as poor image quality and incomplete barcodes, ensuring the accuracy and reliability of barcode information recognition.
Smart Images

Figure CN114169352B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a barcode information recognition method and an electronic device. Background Art
[0002] In traditional one-dimensional code information extraction methods, the corresponding decoding algorithm is used to directly extract information from the barcode part, which requires high image quality of the one-dimensional code. At the same time, if the one-dimensional code is partially incomplete or blocked, it will cause decoding failure. Especially in some special cases, such as poor image quality, incomplete barcode, blocked barcode, etc., the traditional one-dimensional code information extraction method often has a low decoding success rate.
[0003] In the related art, a patent document with publication number CN111738031B provides a one-dimensional barcode recognition method, the steps of which include: detecting and identifying a barcode image, if the barcode content and the check digit are correct, outputting the barcode content, if there is an error, using OCR recognition to identify the barcode image to obtain the text content, and then outputting the recognition result based on the barcode content; if the barcode content only recognizes the starting character, scoring the OCR recognition result, and outputting the recognition result based on the scoring result.
[0004] Although the above scheme uses the method of scoring the OCR recognition results to improve the accuracy of character recognition, the score of the OCR recognition result is not high for situations such as incomplete barcodes and barcode occlusion. Although it can ensure the reliability of the barcode recognition output results, that is, the accuracy of the barcode information finally recognized, the decoding success rate in special situations such as poor image quality and incomplete barcodes cannot be guaranteed. Summary of the invention
[0005] In order to overcome the problems existing in the related art, the present application provides a barcode information recognition method, which can improve the decoding success rate in special circumstances such as poor image quality and incomplete barcodes.
[0006] The first aspect of the present application provides a barcode information recognition method, comprising:
[0007] Get barcode character image;
[0008] Obtaining a character circumscribed rectangle of each character based on the barcode character image;
[0009] Performing character quality detection on each character in turn according to the character circumscribed rectangle to obtain a target character; the character quality detection includes: extracting a black connected domain within the character circumscribed rectangle of the current character; calculating the number of black connected domains within the character circumscribed rectangle of the current character; judging whether the number of black connected domains is greater than one, if so, performing character repair on the current character to obtain a target character; if not, taking the current character as the target character;
[0010] Merge the target characters to obtain a target character string;
[0011] The target character string is identified by using OCR technology to obtain barcode information.
[0012] In one implementation, obtaining a character circumscribed rectangle of each character based on the barcode character image includes:
[0013] Discretizing the barcode character image to obtain a plurality of black areas;
[0014] Generating a plurality of area circumscribed rectangles based on the plurality of black areas;
[0015] Performing rectangular expansion on the circumscribed rectangles of the plurality of regions;
[0016] The circumscribed rectangles of several regions after the rectangular expansion are discretized to obtain the character circumscribed rectangle of each character.
[0017] In one implementation, performing character repair on the current character to obtain the target character includes:
[0018] Expanding each black connected region within the character circumscribed rectangle in a neighborhood growth manner;
[0019] The step of extracting the black connected domains within the character circumscribed rectangle of the current character is re-executed until the number of the black connected domains is less than or equal to one.
[0020] In one implementation, the step of expanding each black connected domain within the character circumscribed rectangle in a neighborhood growing manner includes:
[0021] Calculate and obtain the adjacent connected domain of the current black connected domain; the adjacent connected domain is the black connected domain within the character circumscribed rectangle and having the shortest distance from the boundary of the current black connected domain;
[0022] The current black connected domain is expanded along the growth direction with a growth step; the growth step is equal to the boundary distance between the adjacent connected domain and the current black connected domain; the growth direction is the connection direction of the two pixel points with the shortest pixel distance between the current black connected domain and the adjacent connected domain.
[0023] In one implementation, after extracting the black connected domain within the character circumscribed rectangle of the current character, the method includes:
[0024] Performing morphological judgment on the black connected domain within the character circumscribed rectangle of the current character, if there is a black connected domain that satisfies the preset morphological condition, segmenting the black connected domain that satisfies the preset morphological condition, and after obtaining the target character, merging it into the target character as a supplementary character; if there is no black connected domain that satisfies the preset morphological condition, executing the step of obtaining the number of black connected domains within the character circumscribed rectangle based on the black connected domain, until the target character is obtained;
[0025] The preset morphological conditions include: the roundness of the black connected domain ranges from 0.9 to 1.1.
[0026] In one implementation, the acquiring of the barcode character image includes:
[0027] Get barcode recognition image;
[0028] Calculate and obtain a barcode graphic area based on the barcode recognition image;
[0029] Performing expansion processing on the barcode graphic area to obtain a full barcode area;
[0030] Obtaining a barcode character area using the barcode graphic area and the full barcode area;
[0031] The black area is extracted based on the barcode character area to obtain the barcode character image.
[0032] In one embodiment, the step of calculating the barcode graphic area based on the barcode recognition image includes:
[0033] The barcode recognition image is subjected to feature comparison based on the bar morphological features to obtain a barcode graphic area.
[0034] In one embodiment, the step of obtaining the barcode character area by using the barcode graphic area and the full barcode area includes:
[0035] The halcon area operation algorithm is used to subtract the barcode graphic area from the full barcode area to obtain the barcode character area.
[0036] In one implementation, before acquiring the barcode character image, the process includes:
[0037] The barcode information is extracted from the barcode graphic using a decoding algorithm. If the decoding is successful, the barcode information is identified;
[0038] Otherwise, the barcode characters are recognized by using OCR technology. If the recognition is successful, the barcode information is obtained.
[0039] Otherwise, execute the step of obtaining the barcode character image.
[0040] A second aspect of the present application provides an electronic device, including:
[0041] Processor; and
[0042] A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute any of the methods described above.
[0043] The technical solution provided by this application may have the following beneficial effects:
[0044] The present application discretizes the barcode character image according to the characters in advance to obtain the character circumscribed rectangle of a single character, and then the character quality detection of the single character can be performed based on the character circumscribed rectangle. Since the barcode information content of the one-dimensional code is composed of Arabic numerals or English characters, the common feature is that the character strokes are all coherent. Therefore, the number of black connected domains in the character circumscribed rectangle of a character that meets the barcode recognition quality requirements, that is, a complete character, should be one. After the present application uses discretization to divide the barcode character image into several character circumscribed rectangles, the black connected domains in each character circumscribed rectangle are extracted and counted. If the number of black connected domains is greater than one, it means that the character in the character circumscribed rectangle is defective, and the character is repaired until the number of black connected domains in the character circumscribed rectangle is one. At this time, the defective character is completely repaired, that is, the target character is obtained. The target characters corresponding to each character circumscribed rectangle are merged to obtain the repaired target character string. At this time, the OCR technology is used for barcode recognition, which can greatly improve the decoding success rate.
[0045] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The above and other objects, features and advantages of the present application will become more apparent through a more detailed description of exemplary embodiments of the present application in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the present application.
[0047] Figure 1 It is a flowchart of a barcode information recognition method shown in an embodiment of the present application;
[0048] Figure 2 is a flow chart of a character circumscribed rectangle extraction method shown in an embodiment of the present application;
[0049] Figure 3 is a flow chart of a character repair method shown in an embodiment of the present application;
[0050] Figure 4 It is a flowchart of a method for identifying barcode information with lowercase letters shown in an embodiment of the present application;
[0051] Figure 5 is another flowchart of the barcode information recognition method shown in the embodiment of the present application;
[0052] Figure 6 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The preferred embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0054] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0055] It should be understood that although the terms "first", "second", "third", etc. may be used in this application to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.
[0056] Embodiment 1
[0057] Although the patent document with publication number CN111738031B adopts a method of scoring OCR recognition results to improve the accuracy of character recognition, the score of the OCR recognition result is not high for situations such as incomplete barcodes and barcode occlusion. Although it can ensure the reliability of the barcode recognition output results, that is, the accuracy of the barcode information finally recognized, the decoding success rate in special situations such as poor image quality and incomplete barcodes cannot be guaranteed.
[0058] In response to the above problems, an embodiment of the present application provides a barcode information recognition method, which can improve the decoding success rate in special circumstances such as poor image quality and incomplete barcodes.
[0059] The technical solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.
[0060] Figure 1 It is a flowchart of the barcode information recognition method shown in the embodiment of the present application.
[0061] See also Figure 1 , the barcode information recognition method comprises:
[0062] 101. Obtain a barcode character image;
[0063] In the embodiment of the present application, a CCD camera or a CMOS camera may be used to capture barcode character images, which is not limited here.
[0064] In actual application, in order to improve the image quality of the barcode character image, the acquired barcode character image may be subjected to image preprocessing, including but not limited to: image equalization, image illumination compensation or image filtering.
[0065] 102. Obtaining a character circumscribed rectangle of each character based on the barcode character image;
[0066] In the embodiment of the present application, since the size of each character in the barcode character is relatively uniform, an average segmentation algorithm can be used to calculate the interval point between two adjacent characters on average according to the number of characters in the verification code, and after vertical segmentation along the interval point, the character circumscribed rectangle of each character is obtained according to the uniform character size;
[0067] Or use the projection segmentation algorithm to count the number of black pixels that appear in the horizontal or vertical direction of the binarized image, and make a corresponding histogram based on the statistical value. The point with a trough value of zero in the histogram is the interval point between two characters. Then use the K-means clustering algorithm for classification, and classify the segmented areas belonging to the same character into the same cluster, and then get the circumscribed rectangle of each character.
[0068] In actual application, other algorithms may be used to calculate the character circumscribed rectangle of each character. For example, after obtaining the circumscribed rectangle of each connected domain by discretization, the character circumscribed rectangle of each character is obtained by combining rectangle expansion.
[0069] It is understandable that the embodiment of the present application does not have strict limitations on the algorithm used for the character circumscribed rectangle, that is, the above description of the algorithm for the character circumscribed rectangle does not have to be the only limitation on the present application.
[0070] 103. Perform character quality detection on each character in turn according to the character circumscribed rectangle to obtain the target character;
[0071] Exemplarily, character quality detection includes:
[0072] Extract the black connected domain within the character circumscribed rectangle of the current character;
[0073] Calculate the number of black connected domains within the character circumscribed rectangle of the current character;
[0074] It is determined whether the number of black connected domains is greater than one. If so, character repair is performed on the current character to obtain a target character; if not, the current character is used as the target character.
[0075] In the embodiment of the present application, since the barcode character part of the one-dimensional code is composed of Arabic numerals or English characters, their common feature is that the character strokes are all coherent, that is, a single character corresponds to a connected domain. Therefore, after the barcode characters are segmented into single characters, the number of black connected domains of the circumscribed rectangle of each character can be determined to determine whether the character is complete. If the number of black connected domains is greater than one, it can be determined that the character is missing, resulting in incoherent characters; if the number of black connected domains is equal to one, the character is a complete character.
[0076] When the above-mentioned character quality detection is performed on the character circumscribed rectangle of each character, and each character circumscribed rectangle satisfies the condition that there is only one black connected domain, each character in the barcode character can be considered to be a complete character, that is, the target character, and then the barcode information recognition is completed through the following steps 104 and 105.
[0077] 104. Merge the target characters to obtain a target string;
[0078] In the embodiment of the present application, a regional operation algorithm is used to perform a union operation on the above-mentioned target characters to obtain a character string composed of the above-mentioned target characters, that is, the barcode character part of the barcode.
[0079] It should be noted that other algorithms that can realize the target character union operation are also applicable to this solution and will not be described in detail here.
[0080] 105. Use OCR technology to identify the target character string and obtain barcode information.
[0081] In the embodiments of the present application, OCR refers to optical character recognition (OCR), which is the process of using an electronic device (such as a scanner or a digital camera) to check the characters on an image, determine their shapes by detecting dark and light patterns, and then translate the shapes into computer text using a character recognition method. Therefore, for OCR technology, the quality of characters will affect the reliability of the recognition results and the success rate of decoding.
[0082] In the embodiment of the present application, through the above steps 101 to 104, the quality of the original barcode characters can be detected, and the damaged characters can be repaired, thereby improving the quality of the barcode characters used for recognition, thereby ensuring the success rate and accuracy of the OCR recognition results.
[0083] In actual application, any one or more of the following OCR technologies can be used to recognize barcode character information: End-to-End Text Spotting and PSENet text detection algorithm.
[0084] It is understandable that other OCR technologies besides the above may also be used in this solution, which will not be described in detail here.
[0085] The embodiment of the present application discretizes the barcode character image according to the characters in advance to obtain the character circumscribed rectangle of a single character, and then the character quality detection of the single character can be performed based on the character circumscribed rectangle. Since the barcode information content of the one-dimensional code is composed of Arabic numerals or English characters, the common feature is that the character strokes are all coherent. Therefore, the number of black connected domains in the character circumscribed rectangle of a character that meets the barcode recognition quality requirements, that is, a complete character, should be one. After the present application uses discretization to divide the barcode character image into a number of character circumscribed rectangles, the black connected domains in each character circumscribed rectangle are extracted and counted. If the number of black connected domains is greater than one, it means that the character in the character circumscribed rectangle is defective, and the character is repaired until the number of black connected domains in the character circumscribed rectangle is one. At this time, the defective character is completely repaired, that is, the target character is obtained. The target characters corresponding to each character circumscribed rectangle are merged to obtain a repaired target character string. At this time, the OCR technology is used for barcode recognition, which can greatly improve the decoding success rate.
[0086] Embodiment 2
[0087] The embodiment of the present application designs step 102 in the above-mentioned embodiment 1, and obtains the character circumscribed rectangle of each character through discretization processing, so as to facilitate accurate character repair of a single character area and improve the reliability of character repair.
[0088] The technical solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.
[0089] Figure 2 It is a flowchart of a method for extracting a character circumscribed rectangle shown in an embodiment of the present application.
[0090] The character circumscribed rectangle extraction method comprises:
[0091] 201. Discretize the barcode character image to obtain a plurality of black areas;
[0092] In the embodiment of the present application, since there are gaps between the characters, several black areas can be obtained after the barcode character image is discretized; and for a single missing character, the separated character parts will also be divided into several black areas after the discretization process.
[0093] 202. Generate a plurality of area circumscribed rectangles based on a plurality of black areas;
[0094] In actual application, the minimum bounding rectangle of several black areas, that is, the bounding rectangle of the above area, can be obtained by calling the minAreaRect function or the boundingRect function of Opencv.
[0095] 203. Expand the circumscribed rectangles of several regions;
[0096] In an embodiment of the present application, for several black areas belonging to the same character, the circumscribed rectangles of the areas are rectangularly expanded so that the circumscribed rectangles of the areas with intervals less than the interval threshold are connected to each other, thereby framed in the same rectangular area.
[0097] 204. Discretize the plurality of area circumscribed rectangles after the rectangle is expanded to obtain a character circumscribed rectangle of each character.
[0098] In order to avoid the situation in the above step 203 where the area circumscribed rectangles of black areas that do not belong to the same character are connected and the shapes of the area circumscribed rectangles of several black areas of the same character after being connected are irregular, it is necessary to discretize the several area circumscribed rectangles after the rectangles are expanded to obtain the character circumscribed rectangle of each character.
[0099] In the embodiment of the present application, the method for calculating the minimum circumscribed rectangle has been described in step 202 and will not be repeated here.
[0100] The embodiment of the present application utilizes discretization processing combined with rectangular expansion to segment individual characters in a barcode character image and obtain the character circumscribed rectangle of each character, so as to extract and count the black connected domains within the circumscribed rectangle of each character, and then judge whether the character is complete by the number of black connected domains within the circumscribed rectangle of each character, thereby determining whether the character needs to be repaired to ensure the accuracy and success rate of subsequent barcode character recognition.
[0101] Embodiment 3
[0102] The embodiment of the present application designs step 103 in the first embodiment, and uses a neighborhood growing method to repair the defective characters to obtain the target characters.
[0103] The technical solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.
[0104] Figure 3 It is a flow chart of the character repair method shown in the embodiment of the present application.
[0105] The character repair method comprises:
[0106] 301. Extract the black connected domain within the character circumscribed rectangle of the current character;
[0107] In an embodiment of the present application, an image is traversed using a depth-first search or a breadth-first search, and connected domains are marked for pixel points whose grayscale values have not changed among adjacent pixels, thereby forming a connected domain, wherein the adjacency relationship of adjacent pixels can adopt either 4-adjacency or 8-adjacency.
[0108] In an embodiment of the present application, marking determination can be made based on the grayscale value difference of adjacent pixels; or marking determination can be made directly based on the grayscale value of the pixel point, specifically: if the grayscale value of the current pixel point is 0, the current pixel point is marked.
[0109] 302. Calculate the number of black connected domains within the character circumscribed rectangle of the current character;
[0110] 303. Determine whether the number of black connected domains is greater than one;
[0111] If yes, execute step 304 and then return to step 301;
[0112] If not, execute step 305.
[0113] Since the barcode character part of the one-dimensional code is composed of Arabic numerals or English characters, their common feature is that the character strokes are continuous, that is, a single character corresponds to a connected domain. Therefore, by judging the number of black connected domains in the circumscribed rectangle of each character, it is possible to determine whether the character is complete. If the number of black connected domains is greater than one, the character is incomplete; if the number of black connected domains is equal to one, the character is complete.
[0114] 304. Expand each black connected domain within the character circumscribed rectangle in a neighborhood growth manner;
[0115] In the embodiment of the present application, taking the expansion of a black connected domain by neighborhood growth as an example:
[0116] Calculate the adjacent connected domains of the current black connected domain;
[0117] Dilate the current black connected domain along the growth direction with the growth step size.
[0118] Among them, the adjacent connected domain is the black connected domain within the character circumscribed rectangle with the shortest distance from the boundary of the current black connected domain; the growth step is equal to the boundary distance between the adjacent connected domain and the current black connected domain; the growth direction is the direction of the connection between the two pixel points with the shortest pixel distance between the current black connected domain and the adjacent connected domain.
[0119] In the embodiment of the present application, the boundary distance can be set to the shortest pixel distance between two black connected domains or the shortest distance between the rectangular boundaries of the minimum circumscribed rectangles of two black connected domains.
[0120] In actual application, the growth step can also be adjusted according to actual conditions.
[0121] In an embodiment of the present application, after character repair is performed in the neighborhood growing manner as described above, that is, after executing step 304, the step of extracting the black connected domain within the character circumscribed rectangle of the current character, that is, step 301, is re-executed until the number of black connected domains is less than or equal to one.
[0122] 305. Use the current character as the target character.
[0123] In the embodiment of the present application, when the number of black connected domains in all character circumscribed rectangles is less than or equal to one, the target characters corresponding to all characters can be obtained, and a target character string that is easy to identify can be obtained through these target characters.
[0124] The target character refers to a complete character.
[0125] The embodiment of the present application provides a character repair method, which expands each black connected domain within the character's circumscribed rectangle in a neighborhood growth manner along the growth direction according to the growth step size until there is only one black connected domain within the character's circumscribed rectangle, thereby ensuring the integrity of each character, and obtaining a target character string with high recognition accuracy based on the complete target character, thereby improving the accuracy and success rate of barcode information recognition.
[0126] Embodiment 4
[0127] In the actual barcode recognition process, since the barcode is mostly composed of Arabic numerals and uppercase English letters, and Arabic numerals and uppercase English letters are all composed of a single connected domain, when the number of black connected domains of the character's circumscribed rectangle is one, the character can be considered complete; but for the special case of using lowercase letters to construct the barcode, the embodiment of the present application provides a barcode recognition method to solve the barcode recognition problem of characters "i" and "j" in lowercase letters that have two connected domains.
[0128] The technical solution of the embodiments of the present application is described in detail below with reference to the accompanying drawings.
[0129] Figure 4 It is a flowchart of a method for identifying barcode information with lowercase letters shown in an embodiment of the present application.
[0130] The method for identifying barcode information with lowercase letters comprises:
[0131] 401. Obtain a barcode character image;
[0132] In the embodiment of the present application, the content of step 401 is consistent with step 101 in the above-mentioned embodiment 1 and will not be repeated here.
[0133] 402. Obtaining a character circumscribed rectangle of each character based on the barcode character image;
[0134] In the embodiment of the present application, the content of step 402 is consistent with step 102 in the above-mentioned embodiment 1 and will not be repeated here.
[0135] 403. Extract the black connected domain within the character circumscribed rectangle of the current character;
[0136] In the embodiment of the present application, the content of step 401 is consistent with step 301 in the above-mentioned embodiment 3, and will not be repeated here.
[0137] 404, performing morphological judgment on the black connected domain within the character circumscribed rectangle of the current character to determine whether there is a black connected domain that meets a preset morphological condition;
[0138] Specific:
[0139] If there is a black connected domain that meets the preset morphological condition, then step 405, step 406, step 407 and step 408 are executed in sequence;
[0140] If there is no black connected domain that meets the preset morphological condition, step 406 and step 407 are performed in sequence.
[0141] In an embodiment of the present application, if there is a black connected domain that meets the preset morphological conditions, it means that the characters "i" and "j" exist in the barcode character. In order to avoid misjudgment of character quality detection caused by the above two special characters, it is necessary to pre-process them and then execute the step of judging the number of black connected domains; if there is no black connected domain that meets the preset morphological conditions, it means that the characters "i" and "j" do not exist in the barcode character. Therefore, the barcode character can be processed according to the normal character quality detection steps.
[0142] Among them, the preset morphological conditions include: the roundness of the black connected domain ranges from 0.9 to 1.1.
[0143] Since the character features of the letters "i" and "j" both contain black dot parts, after extracting the black connected domain within the circumscribed rectangle of the character, each black connected domain is judged. If there is a nearly circular black connected domain, specifically, the roundness of the black connected domain can be judged to determine whether it is a nearly circular black connected domain. In this case, it can be considered that the black dot parts of the letters "i" and "j" are detected, and the character is judged to be the characters "i" and "j" with two black connected domains.
[0144] 405. Segment the black connected domain that meets the preset morphological conditions;
[0145] Since the nearly circular black connected domain is not connected to other black connected domains belonging to the same character, it will affect the subsequent character quality detection process and cause the system to misjudge it as an incomplete character. Therefore, the black dot part is segmented in advance and only the non-dot part is judged to avoid misjudgment.
[0146] 406. Calculate the number of black connected domains within the character circumscribed rectangle of the current character;
[0147] 407. Determine whether the number of black connected domains is greater than one; if so, perform character repair on the current character to obtain a target character; if not, use the current character as the target character.
[0148] The content of character repair has been described in detail in Example 3 and will not be repeated here.
[0149] 408. Update the target character.
[0150] Specifically, the black connected region segmented in step 405 is merged into the target character as a supplementary character to serve as an updated target character.
[0151] The embodiment of the present application designs a barcode information recognition method for a barcode with lowercase letters, and especially improves the barcode information recognition method for the two characteristic characters "i" and "j". First, a morphological judgment is made on the black connected domain within the character circumscribed rectangle of the current character to identify whether there is a black dot part, thereby judging whether the barcode character contains the character "i" or "j". For the barcode characters with the characters "i" or "j", the black dot part is first segmented out, and the number of connected domains is detected for the non-dot part to avoid errors introduced by the black dot part, thereby avoiding misjudgment of character quality detection, and effectively solving the problem of barcode information recognition with lowercase letters.
[0152] Embodiment 5
[0153] In the actual barcode information recognition process, not all barcodes are damaged or dirty. For a complete barcode, it can be successfully recognized without repairing it. Therefore, in order to improve the recognition efficiency and avoid unnecessary processing, before performing the processing shown in Example 1 on the barcode information, the decoding algorithm and OCR technology are first used to determine whether the barcode is a complete barcode.
[0154] Figure 5 It is another flowchart of the barcode information recognition method shown in an embodiment of the present application.
[0155] See also Figure 5 The barcode information recognition method shown in the embodiment of the present application includes:
[0156] 501. Extracting barcode information from the barcode graphic using a decoding algorithm;
[0157] If the decoding is successful, execute step 505;
[0158] If the decoding fails, execute step 502.
[0159] In the embodiments of the present application, the decoding algorithm used is not unique and can be adjusted according to actual conditions.
[0160] 502. Using OCR technology to recognize barcode information from barcode characters;
[0161] If the recognition is successful, execute step 505;
[0162] If the recognition fails, execute step 503.
[0163] In the embodiments of the present application, the OCR technology used is not unique and can be adjusted according to actual conditions, for example: end-to-end text recognition (End-to-End Text Spotting) or PSENet text detection algorithm.
[0164] 503. Obtain a barcode character image;
[0165] Exemplary:
[0166] Get barcode recognition image;
[0167] Calculate and obtain a barcode graphic area based on the barcode recognition image;
[0168] Performing expansion processing on the barcode graphic area to obtain a full barcode area;
[0169] Obtaining a barcode character area using the barcode graphic area and the full barcode area;
[0170] The black area is extracted based on the barcode character area to obtain the barcode character image.
[0171] In an embodiment of the present application, the barcode graphic area can be extracted from the barcode recognition image through a feature comparison algorithm. Since the barcode graphic area of the one-dimensional code has obvious bar morphological features, in an embodiment of the present application, feature comparison is performed on the barcode recognition image based on the bar morphological features to obtain the barcode graphic area.
[0172] Since the barcode pattern of a one-dimensional code is composed of several black vertical lines of different widths, it appears in form as multiple bar-shaped black areas, namely bar-shaped morphological features. Therefore, based on the bar-shaped features, the barcode pattern area can be obtained in the barcode recognition image through feature comparison.
[0173] In an embodiment of the present application, the barcode character area is obtained by using the barcode graphic area and the full barcode area, which specifically includes: using the halcon area operation algorithm to subtract the barcode graphic area from the full barcode area to obtain the barcode character area.
[0174] It should be noted that the above-mentioned specific process of obtaining the barcode character image is only an example given in the embodiment of the present application and does not necessarily constitute the sole limitation of the present application.
[0175] 504. Obtain a target character string based on the barcode character image;
[0176] In the embodiment of the present application, the content of step 504 has been described in detail in the above embodiments 1 to 4 and will not be repeated here.
[0177] 505. Obtain the barcode information by using OCR technology.
[0178] In the embodiment of the present application, the content of step 505 is consistent with step 105 in the above-mentioned embodiment 1 and will not be repeated here.
[0179] The embodiment of the present application first uses a decoding algorithm and OCR technology to identify the barcode information. When the decoding algorithm and OCR technology cannot successfully decode, indicating that the barcode has problems such as poor image quality or incomplete barcodes, the barcode information recognition method shown in the above-mentioned embodiment 1 is used to recognize the barcode information, thereby improving the efficiency of barcode information recognition, avoiding character quality detection of high-quality barcodes, and reducing the recognition efficiency of barcode information.
[0180] Embodiment 6
[0181] Corresponding to the aforementioned application function implementation method embodiment, the present application also provides an electronic device and corresponding embodiments.
[0182] Figure 6 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application.
[0183] See also Figure 6 , the electronic device 1000 includes a memory 1010 and a processor 1020 .
[0184] The processor 1020 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0185] The memory 1010 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 1020 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 1010 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 1010 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0186] The memory 1010 stores executable codes, and when the executable codes are processed by the processor 1020 , the processor 1020 can execute part or all of the methods described above.
[0187] The scheme of the present application has been described in detail above with reference to the accompanying drawings. In the above embodiments, the description of each embodiment has its own emphasis. For the part that is not described in detail in a certain embodiment, refer to the relevant description of other embodiments. Those skilled in the art should also know that the actions and modules involved in the description are not necessarily required for the present application. In addition, it can be understood that the steps in the method of the embodiment of the present application can be adjusted in order, merged and deleted according to actual needs, and the modules in the device of the embodiment of the present application can be merged, divided and deleted according to actual needs.
[0188] In addition, the method according to the present application may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above method of the present application.
[0189] Alternatively, the present application can also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or electronic device, server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present application.
[0190] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the application herein may be implemented as electronic hardware, computer software, or combinations of both.
[0191] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system and method according to multiple embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a part of a module, a program segment or a code, and the part of the module, the program segment or the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or the flow chart, and the combination of the square boxes in the block diagram and / or the flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0192] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A barcode information recognition method, It is characterized in that include: Get barcode character image; Obtaining a character circumscribed rectangle of each character based on the barcode character image; Performing character quality detection on each character in turn according to the character circumscribed rectangle to obtain a target character; The character quality detection includes: extracting the black connected domain within the character circumscribed rectangle of the current character; calculating the number of black connected domains within the character circumscribed rectangle of the current character; judging whether the number of black connected domains is greater than one, if so, performing character repair on the current character to obtain a target character; if not, taking the current character as the target character; Merge the target characters to obtain a target character string; Using OCR technology to identify the target character string and obtain barcode information; Wherein, after extracting the black connected domain within the character circumscribed rectangle of the current character, the method further comprises: Performing morphological judgment on the black connected domain within the character circumscribed rectangle of the current character, if there is a black connected domain that satisfies the preset morphological condition, segmenting the black connected domain that satisfies the preset morphological condition, and after obtaining the target character, merging it into the target character as a supplementary character; if there is no black connected domain that satisfies the preset morphological condition, executing the step of obtaining the number of black connected domains within the character circumscribed rectangle based on the black connected domain, until the target character is obtained; The preset morphological conditions include: the roundness of the black connected domain ranges from 0.9 to 1.
1.
2. The barcode information recognition method according to claim 1, It is characterized in that The step of obtaining a character circumscribed rectangle of each character based on the barcode character image includes: Discretizing the barcode character image to obtain a plurality of black areas; Generating a plurality of area circumscribed rectangles based on the plurality of black areas; Performing rectangular expansion on the circumscribed rectangles of the plurality of regions; The circumscribed rectangles of several regions after the rectangular expansion are discretized to obtain the character circumscribed rectangle of each character.
3. The barcode information recognition method according to claim 1, It is characterized in that The performing character repair on the current character to obtain the target character includes: Expanding each black connected region within the character circumscribed rectangle in a neighborhood growth manner; The step of extracting the black connected domains within the character circumscribed rectangle of the current character is re-executed until the number of the black connected domains is less than or equal to one.
4. The barcode information recognition method according to claim 3, It is characterized in that The step of expanding each black connected domain within the character circumscribed rectangle in a neighborhood growing manner includes: Calculate and obtain the adjacent connected domain of the current black connected domain; the adjacent connected domain is the black connected domain within the character circumscribed rectangle and having the shortest distance from the boundary of the current black connected domain; The current black connected domain is expanded along the growth direction with a growth step; the growth step is equal to the boundary distance between the adjacent connected domain and the current black connected domain; the growth direction is the connection direction of the two pixel points with the shortest pixel distance between the current black connected domain and the adjacent connected domain.
5. The barcode information recognition method according to claim 1, It is characterized in that The step of obtaining a barcode character image comprises: Get barcode recognition image; Calculate and obtain a barcode graphic area based on the barcode recognition image; Performing expansion processing on the barcode graphic area to obtain a full barcode area; Obtaining a barcode character area using the barcode graphic area and the full barcode area; The black area is extracted based on the barcode character area to obtain the barcode character image.
6. The barcode information recognition method according to claim 5, It is characterized in that The step of calculating the barcode graphic area based on the barcode recognition image includes: The barcode recognition image is subjected to feature comparison based on the bar morphological features to obtain a barcode graphic area.
7. The barcode information recognition method according to claim 5, It is characterized in that The method of obtaining the barcode character area by using the barcode graphic area and the full barcode area includes: The halcon area operation algorithm is used to subtract the barcode graphic area from the full barcode area to obtain the barcode character area.
8. The barcode information recognition method according to claim 1, It is characterized in that Before obtaining the barcode character image, the method includes: The barcode information is extracted from the barcode graphic using a decoding algorithm. If the decoding is successful, the barcode information is identified; Otherwise, the barcode characters are recognized by using OCR technology. If the recognition is successful, the barcode information is obtained. Otherwise, execute the step of obtaining the barcode character image.
9. An electronic device, It is characterized in that include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 8.
