Bar code identification method, terminal and system in low-quality image scene
By detecting and enhancing barcode images in low-quality images, and combining the confidence ranking of atomic data and reference data, the problem of low barcode recognition rate in low-quality image scenarios is solved, and the recognition accuracy rate is significantly improved.
Patent Information
- Application Number
- CN202411045502.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-08-01
AI Technical Summary
The barcode recognition rate of the existing technology is not high in low-quality image scenarios, especially when the image is damaged, incomplete, dirty, blurred or distorted, which affects the recognition efficiency.
By reading the image data, detecting the barcode coordinate information, performing grayscale image enhancement, edge extraction and abnormal data elimination, combining atomic data and reference data to generate 'bar-space' data with confidence, determining the character encoding and decoding, and finally based on Confidence ranking to obtain recognition results.
The accuracy of barcode recognition in low-quality image scenarios is improved, and high-quality barcode data can be obtained from low-quality images and given confidence, thereby improving the accuracy of the recognition results.
Smart Images

Figure CN118569285A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image information processing, and in particular relates to a barcode recognition method, terminal and system. Background Art
[0002] As a way of encoding information, barcodes represent different data information through a specific combination of bars and spaces, and have the advantages of large encoding capacity, high reliability, and low cost. With the development of the economy and the trend of globalization, barcodes have become an indispensable part of modern business activities and are widely used in many fields such as commodity circulation, logistics management, and identity recognition.
[0003] With the popularization of barcode applications, the accuracy and efficiency of its detection and recognition technology have become particularly important. In practical applications, barcode recognition technology can be divided into two categories: photoelectric scanning and image recognition. Photoelectric scanning technology uses the difference in the reflection of light by the "bars" and "spaces" on the barcode, obtains the data of the "bars" and "spaces" after photoelectric conversion, and finally parses it according to the coding rules to complete the recognition and reading of the barcode content. However, photoelectric scanning technology must scan the area of the barcode. When there are multiple densely arranged barcodes to be identified on a label sticker, it is necessary to manually hold a handheld scanner to align and identify them one by one, and the overall efficiency is not high. Image recognition technology uses a camera to take a photo of the area where the barcode to be identified is located, then detects the barcodes in it, and finally parses the detected barcodes. This method can recognize multiple barcodes at one time, eliminating the step of manually scanning one by one with a handheld scanner. However, in scenarios where high-quality images cannot be obtained, the barcode recognition rate still faces huge challenges. For example, when the image is damaged, incomplete, dirty, blurred or distorted, the barcode recognition accuracy rate is not high, which affects the barcode recognition efficiency and usually reduces the overall production efficiency of the factory. Summary of the invention
[0004] In view of this, on the one hand, some embodiments disclose a barcode recognition method in a low-quality image scenario, comprising the steps of: S1, reading the image data containing the barcode, and detecting and obtaining the barcode image data and coordinate information corresponding to the barcode; S2, converting the obtained barcode image into a grayscale image, calculating the pixel average, setting an image enhancement scale factor according to the pixel average, performing image enhancement according to the image enhancement scale factor, increasing the contrast of the grayscale image, and obtaining a first preprocessed image; S3, extracting "edge" data from the first preprocessed image, removing abnormal "edge" data, obtaining atomic data of "bars" and "spaces", and generating a second preprocessed image based on the atomic data of "bars" and "spaces"; S4, performing edge detection on the second preprocessed image to obtain reference "edge" data; obtaining reference atomic data of "bars" and "spaces" according to the reference "edge" data; S5, combining the atomic data of the "bar" and "space" with the reference atomic data to obtain the atomic data of the "bar space" with confidence; S6, obtaining the final module width data according to the "strip space" atomic data with confidence; S7, determining a character encoding data list according to the final module width data; S8, decoding the character encoding data list to obtain a final string list; S9, sorting the strings in the final string list in descending order of confidence; S10. The character string with the highest confidence in the final character string list is used as the final barcode recognition result.
[0005] On the other hand, some embodiments disclose a barcode recognition terminal for executing a barcode recognition method in a low-quality image scenario.
[0006] In yet another aspect, some embodiments disclose a barcode recognition system, including a barcode recognition terminal.
[0007] The barcode recognition method in a low-quality image scenario disclosed in an embodiment of the present invention recognizes a low-quality barcode image based on an atomic parsing method of "bars" and "spaces" of a barcode, and can obtain high-quality barcode data from a low-quality original image. It further assigns corresponding confidences to possible combinations of "bars" and "spaces", obtains the confidence of character data composed of a combination of bars and spaces, sorts the character data according to the confidences, and obtains the character combination with the highest confidence as a barcode parsing result, which greatly improves the accuracy of barcode recognition in low-quality image scenarios and has good application prospects in the barcode field. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 A flow chart of a barcode recognition method in a low-quality image scenario disclosed in some embodiments; Figure 2 Some embodiments disclose a flow chart of detecting image data to obtain barcode coordinates; Figure 3 A flowchart of a neural network model training for image segmentation disclosed in some embodiments; Figure 4 Some embodiments disclose a flow chart for re-determining the left and right boundaries of a barcode according to a coordinate frame corresponding to the barcode; Figure 5 Step S3 disclosed in some embodiments generates a second pre-processed image flow chart; Figure 6 Step S4 disclosed in some embodiments obtains a reference atomic data flow chart of "bar" and "space"; Figure 7 Step S5 disclosed in some embodiments obtains a "bar-space" atomic data flow chart with confidence; Figure 8 Step S6 disclosed in some embodiments obtains the final module width data flow chart; Fig. 9 Step S7 of some embodiments disclosed herein determines a character encoding data list flow chart; Fig.10 , one Step S8 disclosed in some embodiments obtains the final string list flow chart. DETAILED DESCRIPTION
[0009] The word "embodiment" used herein as an "exemplary" does not necessarily mean that any embodiment described is superior or better than other embodiments. Performance index tests in the embodiments of the present invention are performed using conventional test methods in the art unless otherwise specified. It should be understood that the terms described in the embodiments of the present invention are only used to describe specific implementation methods and are not intended to limit the contents disclosed in the embodiments of the present invention.
[0010] Unless otherwise specified, the technical and scientific terms used herein have the same meanings as commonly understood by ordinary technicians in the technical field to which the embodiments of the present invention belong; other experimental methods and technical means not specifically specified in the embodiments of the present invention refer to experimental methods and technical means commonly used by ordinary technicians in the field.
[0011] In this document, including in the claims, transitional words such as "comprises," "includes," "with," "having," "containing," "involving," "accommodating," etc. are understood to be open-ended, i.e., meaning "including but not limited to." Only the transitional words "consisting of" and "composed of" are closed transitional words.
[0012] In order to better illustrate the present invention, numerous specific details are provided in the specific examples below. It should be understood by those skilled in the art that the present invention can be implemented without certain specific details. In the embodiments, some methods, means, instruments, equipment, etc. well known to those skilled in the art are not described in detail in order to highlight the gist of the present invention.
[0013] Under the premise of no conflict, the technical features disclosed in the embodiments of the present invention may be arbitrarily combined, and the resulting technical solutions belong to the contents disclosed in the embodiments of the present invention.
[0014] In some embodiments, Figure 1 As shown, the barcode recognition method in a low-quality image scene includes the steps of: S1, reading the image data containing the barcode, and detecting and obtaining the barcode image data and coordinate information corresponding to the barcode; S2, converting the obtained barcode image into a grayscale image, calculating the pixel average, setting an image enhancement scale factor according to the pixel average, performing image enhancement according to the image enhancement scale factor, increasing the contrast of the grayscale image, and obtaining a first preprocessed image; S3, extracting "edge" data from the first preprocessed image, removing abnormal "edge" data, obtaining atomic data of "bars" and "spaces", and generating a second preprocessed image based on the atomic data of "bars" and "spaces"; S4, performing edge detection on the second preprocessed image to obtain reference "edge" data; obtaining reference atomic data of "bars" and "spaces" according to the reference "edge" data; S5, combining the atomic data of the "bar" and "space" with the reference atomic data to obtain the atomic data of the "bar space" with confidence; S6, obtaining the final module width data according to the "strip space" atomic data with confidence; S7, determining a character encoding data list according to the final module width data; S8, decoding the character encoding data list to obtain a final string list; S9, sorting the strings in the final string list in descending order of confidence; S10. The character string with the highest confidence in the final character string list is used as the final barcode recognition result.
[0015] Some embodiments disclose a barcode recognition method in a low-quality image scenario, wherein step S1 specifically includes: reading image data containing a barcode, detecting the image data to obtain a barcode coordinate frame, using the barcode coordinate frame to crop an image of a valid area of the barcode, and obtaining barcode image data and coordinates corresponding to the barcode.
[0016] The barcode recognition method in a low-quality image scenario disclosed in an embodiment of the present invention reads an image containing a barcode, detects the barcode in the image using a barcode detector, extracts a valid area, further performs image prediction in the valid area, obtains the approximate position of the barcode, further processes the approximate area containing the barcode, obtains an accurate valid area coordinate frame containing the barcode, obtains valid barcode data, further processes and parses the valid barcode data using a barcode recognizer, recognizes the low-quality barcode image based on an atomic parsing method of "bars" and "spaces" of the barcode, and obtains high-quality barcode data from the low-quality original image, further assigns corresponding confidences to possible combinations of "bars" and "spaces", obtains the confidence of character data composed of a combination of "bars" and "spaces", sorts the character data according to the confidences, obtains the character combination with the highest confidence as the barcode parsing result, and finally obtains the encoded content of the barcode.
[0017] Some embodiments disclose a barcode recognition method, such as Figure 2 As shown, in step S1, the process of detecting image data to obtain a barcode coordinate frame specifically includes: S101, sending the image data to the barcode segmentation model for prediction to obtain model output data; S102, parsing the model output data, and obtaining the barcode mask image predicted by the model; S103, converting the barcode mask image into a binary grayscale image, wherein the background is black and the barcode valid area is pure white; S104, performing contour extraction on the binary grayscale image; usually, before contour extraction, the binary grayscale image may be eroded and closed to fill holes and remove some scattered points, and contour extraction is then performed on the eroded and closed binary image; S105, traversing the extracted contour and calculating the area of the contour; S106. If the area of the contour is not greater than the preset threshold, it is ignored. Taking Code128 barcode as an example, a complete barcode usually contains at least 4 characters, namely, a start character, a data character, a check character and an end character, and the 4 characters have a total of 46 modules. If the minimum width of the module is 1 pixel, then the minimum width of the barcode is 46 pixels. If the height of the barcode is not less than 30 pixels, then the preset threshold of the area is determined to be 46×30=1380. S107, if the area of the contour is greater than a preset threshold, the contour is put into a valid contour list; S108, traversing the valid contour list, drawing an outer approximate polygon for each valid contour, and generating a new barcode mask image; S109, detecting all straight lines of the new barcode mask image, selecting the longest straight line and calculating its inclination; S110, performing rotation correction on the new barcode mask image according to the inclination angle so that the barcode remains horizontal; S111, re-extracting the contour of the rotated barcode mask image and drawing a circumscribed rectangle; S112, obtaining a coordinate frame corresponding to each barcode according to the circumscribed rectangle of each contour; S113, re-determining the left and right boundaries of the barcode according to the coordinate frame corresponding to the barcode; S114. Obtain the final barcode coordinate frame according to the newly determined left and right boundaries.
[0018] In the barcode recognition method in a low-quality image scene disclosed in some embodiments, in step S101, the image data is sent to the barcode segmentation model for prediction to obtain model output data, which also includes a training step for the image segmentation neural network model, such as Figure 3 As shown, the specific methods include: S1011 uses the camera to collect N images of the production line environment and stores them in the background library; S1012, compiling a character dictionary according to the data content of the barcode, and generating a list of character strings of varying lengths within a preset range according to the character dictionary; S1013, generating a barcode image according to the string list, wherein a plurality of barcode images with different module widths and heights are generated for each string; S1014, setting the white part of the barcode image to be transparent; S1015, randomly selecting an image from the background image library as a background image; S1016, randomly placing multiple barcode transparent images at a certain position of the background image; S1017, generating a training image and a corresponding label mask image to obtain a barcode image segmentation data set; S1018, using the prepared barcode image segmentation data set to train an image segmentation neural network model; Generally, the image segmentation neural network model can be selected according to the task requirements and model performance; from the perspective of task requirements, it includes semantic segmentation, instance segmentation, interactive segmentation, panoramic segmentation, etc.; the task requirement in this article is semantic segmentation, you can first find out the currently available semantic segmentation model, the optional models are: PP-LiteSeg, PP-MobileSeg, DeepLabV3P, MobileSeg, BiSeNetV2, DeepLabV3, Fast-SCNN, UNet++, ESPNetV2, etc.; you can also freely match various models in various combinations; from the perspective of model performance, including model prediction accuracy, model inference speed and model size, comprehensively consider the space occupied by memory, video memory and hard disk; generally, you can consider choosing a model with faster inference speed and smaller resource occupation as much as possible under the premise of meeting the prediction accuracy requirements; S1019, training is completed, and the barcode segmentation neural network model file is output.
[0019] In the barcode recognition method disclosed in some embodiments, step S113 re-determines the left and right boundaries of the barcode according to the coordinate frame corresponding to the barcode, such as Figure 4 As shown, the specific methods include: S1131, cutting out an image of a corresponding area on the original image according to the coordinate frame of the barcode; S1132, converting the cropped image into a grayscale image and performing binarization processing to obtain binarized image data, and converting the binarized image data into a two-dimensional array; S1133, traverse the two-dimensional array row by row, and find the total number of pixels contained in the black and white bars of the first M characters in combination with the barcode encoding rules, and store them in a list; usually, the list can also be processed to remove abnormal data according to the standard deviation; usually, the barcode encoding rules include EAN-8, EAN-13, UPC-A, UPC-E, Code39, Code128, etc.; taking Code128 as an example, except for the end character, each character contains 3 "bars" and 3 "spaces". For intuitive understanding, in this article, we regard "bars" as black and "spaces" as white; usually, the M characters of the black and white bars can be judged in combination with the task requirements. Taking the Code128 barcode as an example, a complete barcode contains at least 4 characters, namely the start character, data character, check character, and end character. If the data character is at least 1 in the specific task, M can be set to 4; S1134, calculate the average value of the data in the list, and then divide it by the number of modules represented by M characters to obtain module width data; usually the module width data is recorded as module-width; S1135, searching for black bars from the leftmost side of the coordinate frame to the left; if no black bars are found after exceeding the distance of five module widths, the position of the previous black bar is determined to be the leftmost boundary, otherwise, continue to search for black bars to the left; usually, the distance of five module widths is recorded as 5×module-width; S1136, searching for black bars from the rightmost side of the coordinate frame to the right; if no black bars are found after exceeding the distance of five module widths, the position of the previous black bar is determined to be the rightmost boundary, otherwise, continue searching for black bars to the right; S1137. Use the obtained leftmost boundary and rightmost boundary as boundary data of the newly determined coordinate frame.
[0020] In some embodiments, the barcode recognition method in a low-quality image scenario disclosed in step S2 includes: converting the obtained barcode image into a grayscale image, calculating the pixel average value, recorded as P_av; setting the image enhancement scale factor according to the pixel average value P_av, recorded as α; performing image enhancement according to the image enhancement scale factor α to increase the contrast of the grayscale image, and obtaining a first preprocessed image, recorded as pre_image_1.
[0021] In some embodiments, the image enhancement scale factor α may be calculated as follows: If the value of P_av is in the range of (0, 60], the value of α is 3; if the value of P_av is in the range of (60, 70], the value of α is 2.5; if the value of P_av is in the range of (70, 105], the value of α is 2; otherwise, the value of α is 1.5.
[0022] Some embodiments disclose a barcode recognition method in a low-quality image scenario, such as Figure 5 As shown, step S3 specifically includes: S301, read the first preprocessed image, and calculate the pixel average value; usually the first preprocessed image is a grayscale image after image enhancement, and the pixel average value of the grayscale image is calculated, which is recorded as P_av1.
[0023] S302, processing the first pre-processed image data line by line, obtaining "edge" data, and forming an "edge" data list. Generally, the "edge" in the barcode image data refers to the edge of the "bar" of the barcode, and the edge of the "space", which generally refers to the boundary position between the "bar" and the "space"; Generally, the barcode grayscale image is a two-dimensional image with H rows and W columns, where H is the height of the image and W is the width of the image. When processing the first preprocessed image, the same method is usually used to process row by row. The process of processing one row of image data includes: Take a row of image data, where the number of pixels is equal to W, and then traverse point by point, taking the pixel values of four points forward from the current position, recorded as: y0_0, y0_1, y0_2, y0_3; Calculate the first-order difference based on these four points, recorded as: y1_1, y1_2, where: y1_1 = y0_1 - y0_2, y1_2 = y0_2 - y0_3; If the absolute value of y1_1 is less than the absolute value of y1_2, and both y1_1 and y1_2 are greater than 0, then set the value of y1_1 to the value of y1_2; Calculate the second-order difference, recorded as: y2_1, y2_2; where: y2_1 = (y0_0 - y0_1) - (y0_1 - y0_2), y2_2 = (y0_1 - y0_2) - (y0_2 -y0_3); According to the above data, whether the current point is an edge or not can be determined as follows: If y2_1, y2_2, y0_0, y0_2, y0_3, P_av1 satisfy the following two relations at the same time: (y2_1>=0 and y2_2<0) or (y2_1>0 and y2_2<=0); y0_0<(P_av1×1.2) , and max(y0_2, y0_3)>(P_av1×0.6); Among them, max(y0_2, y0_3) represents the maximum value of y0_2 and y0_3. If the value of y0_3 is the largest, the value of max(y0_2, y0_3) is the value of y0_3, otherwise it is the value of y0_2. Then set the current point as an edge with the type of EdgeType.WTB, which means an edge from white to black, and then add the edge point to the line_edges list; If y2_1, y2_2, y0_0, y0_2, y0_3, and P_av1 do not satisfy the above relationship, continue to judge whether they satisfy the following two relationships: (y2_1<=0 and y2_2>0) or (y2_1<0 and y2_2>=0); y0_0>(P_av1×0.6) and min(y0_2, y0_3)<(P_av1×1.2); Among them, min(y0_2, y0_3) represents the minimum value of y0_2 and y0_3. If the value of y0_3 is the smallest, the value of min(y0_2, y0_3) is the value of y0_3, otherwise it is the value of y0_2; The current point is set as an edge with the type EdgeType.BTW, indicating an edge from black to white), and then the edge point is added to the line_edges list.
[0024] After the single-line point-by-point traversal is completed, line_edges is added to the edges list, that is, the "edge" data list.
[0025] S303, obtaining the X coordinate values of the edge elements in the first column of the "edge" data list, storing them in the first column of the edge element x coordinate list, and calculating the mean and standard deviation of the x coordinates of the first column of the edge element list.
[0026] Usually, after receiving the edge data list, the x-coordinate value of the first column of edge data is obtained and stored in the first column of edge element x-coordinate list, recorded as X1_list; the mean and standard deviation of the x-coordinate value are further calculated, recorded as X1_av and X1_std.
[0027] S304 , according to the mean and standard deviation of the x-coordinate list of the edge elements in the first column, process the data in a loop and remove abnormal data.
[0028] Usually, the judgment is made based on X1_av and X1_std, and the loop processing is performed; In some embodiments, the loop processing process includes: If X1_std ≥ X1_av, remove the element with the largest deviation in X1_list and remove the row data in the edges of the corresponding position; Finally, recalculate the mean and standard deviation of X1_list until X1_std≤X1_av, otherwise repeat the above process; If X1_std<X1_av, traverse edges and remove the row data corresponding to the elements in the first column whose x coordinates are greater than 1.5 times the standard deviation.
[0029] S305. Traverse the "edge" data row by row after removing abnormal data, determine the width value, type and x-coordinate of the "bar" and the width value, type and x-coordinate of the "space" in each row of data as the atomic data of the "bar" and "space" in each row of data, and store them in the row atomic data list; after traversing all row data, store all row atomic data in the "bar" and "space" atomic data lists, and obtain the "bar" and "space" atomic data lists.
[0030] Typically, after receiving the generated "edge" data edges after removing abnormal data, the "edge" data list is traversed line by line; the edges data list is traversed line by line, and each line of data is processed in the same way; Generally speaking, the processing of a row of data includes: Read a row of data, traverse each element one by one, and determine whether the current element is the first element; If yes, then record the x coordinate of the current element as X_off, and set the previous element as the current element; if no, then judge the previous element and the current element. The element refers to the "edge" data, and the judgment method is as follows: If the type of the previous element is EdgeType.WTB and the type of the current element is EdgeType.BTW, then get the atomic data of the "bar", set its x coordinate to X_last-X_off, type to ElementType.BLACK, width to X-X_last; where X_last is the x coordinate of the previous element, and X is the x coordinate of the current element.
[0031] Otherwise, continue to judge: If the type of the previous element is EdgeType.BTW and the type of the edge of the current element is EdgeType.WTB, then get the "empty" atomic data, set its x coordinate to X_last-X_off, type to ElementType.WHITE, width to X-X_last; where X_last is the x coordinate of the previous element, and X is the x coordinate of the current element; Store the atomic data of "bar" and "blank" into the line atomic data list, i.e. line_element_list; After processing a row of data, store the row atomic data list into the "bar" and "empty" atomic data lists, i.e., element_list; After traversing line by line, we get the atomic data list of "bar" and "space", namely element_list.
[0032] S306 , based on the atomic data lists of “bar” and “space”, create a row array with the same length as the width of the barcode image, and all the values in the row array are set to 255.
[0033] Typically, based on the generated atomic data lists of "bars" and "spaces", a line array with the same length as the width of the barcode image is created, recorded as line_array, where all the values in the array are set to 255.
[0034] S307, traverse the atomic data lists of "bar" and "space" row by row, process the atomic data therein, if the type of the atomic data is "bar", reduce the value within the width range of the "bar" in the row array by 1, if the type of the atomic data is "space", increase the value within the width range of the "space" in the row array by 1.
[0035] Usually, the atomic data lists of "bars" and "spaces" are traversed line by line to process the atomic data therein. The processing method for each line of data is the same; generally, the processing process of a line of data includes: Take a row of data and judge each element in it: If the type of the current element is ElementType.BLACK, which means the current element is a "bar", then the value in the range [X:X+W] in the line_array array is reduced by 1; If the type of the current element is ElementType.WHITE, which means the current element is "empty", then the value in the range [X:X+W] in the line_array array is reduced by 1; Among them, X is the x coordinate of the current element, and W is the width value of the current element.
[0036] S308. After the traversal is completed, the row array is corrected. If the value in the row array is less than 0, it is set to 0. If the value in the row array is greater than 255, it is set to 255 to obtain a corrected row array.
[0037] S309, creating a blank image with the same size as the barcode image, traversing the blank image, and filling each row of data with the data in the corrected row array to obtain a second pre-processed image.
[0038] Some embodiments disclose a barcode recognition method in a low-quality image scenario, such as Figure 6 As shown, step S4 specifically includes: S401, using the Canny algorithm to perform edge detection on the second preprocessed image to obtain reference "edge" data; calculating the pixel average value of the corrected row array; Typically, the data of the generated second preprocessed image is received; a row of data is taken, recorded as canny_line; and the pixel average value of the corrected row array is calculated, recorded as P_av2; S402, taking any row of data in the reference "edge" data, and determining the demarcation threshold between "strip" and "space" according to the pixel average value of the corrected row array, wherein the demarcation threshold of "strip" is set to 0.8 times the pixel average value, and the demarcation threshold of "space" is set to 1.2 times the pixel average value; generally, the demarcation threshold of "strip" is set to P_av2×0.8, and the demarcation threshold of "space" is set to P_av2×1.2; S403, traverse the row data point by point, determine the point that can be used as an edge element, store the "edge" data of the point in the "edge" data list, and obtain the final reference "edge" data; wherein the "edge" data includes an x-coordinate, an edge type, and a pixel value. If the edge type is from "empty" to "strip", the pixel value of the point is 0, and if the edge type is from "strip" to "empty", the pixel value of the point is 255; Usually, the row data is traversed point by point, and the pixel value of each point is judged to determine whether it can be used as an edge element point; if the pixel value of the current point is equal to 255, the values of some variables are set: pre_pixel = image_line[max(last_edge.x, idx-2):idx]; cur_pixel = image_line[idx]; next_value = image_line[idx:min(len(canny_line)-1, idx+3)]; max_pre_pixel = max(pre_pixel); min_pre_pixel = min(pre_pixel); min_next_value = min(next_value); max_next_value = max(next_value); wtb_diff_value = int(max_pre_pixel) - int(min_next_value); btw_diff_value = int(max_next_value) - int(min_pre_pixel); Then judge the type of the previous point last_edge.type, pre_pixel, white_value_threshold, pre_pixel, next_value, and btw_diff_value; If the following relational expressions are satisfied simultaneously: last_edge.type == EdgeType.WTB; min(pre_pixel) < white_value_threshold; min(pre_pixel) < min(next_value); max(next_value) > white_value_threshold or btw_diff_value > 40; where min(next_value) represents the minimum value in the next_value list, max(next_value) represents the maximum value in the next_value list, last_edge.type represents the type of the previous point, and EdgeType.WTB represents an edge from white to black or from "empty" to "bar"; then set the current point as an edge element point, with the type EdgeType.BTW and the value 255, and at the same time add this point to the canny_line_edges list.
[0039] If the following relational expressions are satisfied: last_edge.type == EdgeType.BTW; max(pre_pixel) > black_value_threshold; max(pre_pixel) > max(next_value); (min(next_value) < white_value_threshold or wtb_diff_value > 40; where min(next_value) represents the minimum value in the next_value list, max(next_value) represents the maximum value in the next_value list, last_edge.type represents the type of the previous element, and EdgeType.BTW represents an edge from black to white or from "bar" to "empty"; then set this point as an edge element point, with the type EdgeType.WTB and the value 0, and at the same time add this point to the canny_line_edges list, that is, refer to the "edge" data list; After traversing each line, the final reference edge data canny_line_edges is obtained.
[0040] S404, traverse the final reference "edge" data and make a judgment on each data therein; If the current data is the first data, the previous data is used as the current data. If the current data is not the first data, continue to the next step. If the type of the previous data is the edge from "bar" to "space", and the type of the current data is the edge from "space" to "bar", then create "space" atomic data, where the x coordinate of the "space" atomic data is the x coordinate of the previous data, the type is "space", and the width is the x coordinate of the current data minus the x coordinate of the previous data; If the type of the previous data is an edge from "space" to "bar", and the type of the current data is an edge from "bar" to "space", then create "bar" atomic data, where the x coordinate of the "bar" atomic data is the x coordinate of the previous data, the type is "bar", and the width is the x coordinate of the current data minus the x coordinate of the previous data; S405, storing the created atomic data of the "bar" and the atomic data of the "space" into the final reference "edge" data list, and obtaining the reference atomic data lists of the "bar" and the "space".
[0041] In some embodiments, the reference "edge" data canny_line_edges is traversed, and each element therein is judged. If it is the first element, last_edge = edge is set; wherein last_edge represents the previous element, and edge represents the current element.
[0042] If the current element is not the first element, continue to judge: If the type of the previous element is EdgeType.WTB and the type of the current element is EdgeType.BTW, then create a "bar" of atomic data with the x coordinate of X_last, the type of ElementType.BLACK, and the width of X-X_last; X is the x coordinate of the current element, and X_last is the x coordinate of the previous element.
[0043] If the type of the previous element is EdgeType.BTW and the type of the current element is EdgeType.WTB, create "empty" atomic data with the x coordinate of X_last, the type of ElementType.WHITE, and the width of X-X_last; X is the x coordinate of the current element, and X_last is the x coordinate of the previous element.
[0044] The obtained "bar" and "empty" atom data are added to the canny_line_elements list; After the traversal is completed, the reference atomic data of "bars" and "spaces" are obtained, recorded as: ref_elements.
[0045] Some embodiments disclose a barcode recognition method in a low-quality image scenario, such as Figure 7 As shown, step S5 specifically includes: S501, taking an element in the reference atomic data list of "bar" and "space" as a reference element, taking its x coordinate as a reference coordinate, and its width value as a reference width value; usually, the reference coordinate can be recorded as X_ref, and the reference width can be recorded as W_ref; S502, using the reference element, traverse each element in the atomic data list of "bar" and "space"; If the absolute value of the difference between the coordinate value of the current element and the reference coordinate value is not greater than 1, and the absolute value of the difference between the width value of the current element and the reference width value is not greater than 1, the current element is determined as the selected element; the selected element is stored in the selected atomic data list; Usually, if the current element satisfies the relationship, the current element is added to the selected_elements list: abs(X -X_ref)≤1; abs(W - W_ref≤1; element.type == ref_element.type; that is, the current element type is the same as the reference element type; Where X is the x coordinate of the current element, X_ref is the reference coordinate, W is the width value of the current element, and W_ref is the reference width; S503, constructing dictionary data using the selected element; wherein the atomic data of the constructed dictionary data is the data of the selected element, the x coordinate is the reference coordinate, and the width value is the reference width; and storing the constructed dictionary data into the "bar space" atomic data list; S504, the traversal is completed, and a list of "bar space" atomic data is obtained; S505, traverse the "space" atomic data list, take out the elements therein one by one, and recalculate the confidence of the corresponding element according to the number of credible data; In some embodiments, the bw_elements list is traversed, and the elements therein are taken out one by one, and the current element traversed is recorded as element; then the dictionary data is constructed according to element: temp_dict ={"element": element, "width": element.width, "count": 1}; All elements in bw_elements with the same width data are grouped together, and "count" is incremented by 1 each time an identical data item is encountered. Calculate the confidence of the corresponding element according to the value of "count": element.score = temp_dict["count"] / len(bw_elements["elements"]); Among them, element.score represents the confidence of the current element, temp_dict["count"] represents the "count" data item in the constructed dictionary data, and len(bw_elements["elements"]) represents the data length of the "elements" data item in the bw_elements dictionary; S506. The traversal is completed, and a list of "bar space" atomic data with confidence is obtained, which is recorded as bw_elements list.
[0046] Some embodiments disclose a barcode recognition method in a low-quality image scenario, such as Figure 8 As shown, step S6 specifically includes: S601, traversing the "bar space" atomic data with confidence level row by row, and taking out the data of each row during the loop traversal process; In some embodiments, the bw_elements list is traversed row by row, and in the loop traversal, the data bw_dict of each row is taken out: that is, {"id": idx, "elements": elements, "x": ref_x, "everage_width": width_list}; S602, extract the width value of each row of data, and construct a width data list as a temporary module width data list; In some embodiments, take out data _element_list = bw_dict["elements"], traverse the _element_list list, and construct data: _temp_width_list=[{"width": elem.width, "score":elem.score},{}, ... ]; Add all _temp_width_list to _temp_bw_data list; S603, extracting data according to the barcode encoding rule; for example, for a barcode based on the Code128 encoding rule, extracting data from the temporary module width data list, with the last 7 data items as the end characters, and the remaining data as 6 as one character, to obtain the extracted data slice; S604, performing complete permutation and combination on the extracted data to obtain module width data corresponding to the characters and their confidence levels; In some embodiments, the arrangement and combination of width data includes: w1 is an item in _temp_bw_data[0][0:min(3,len(_temp_bw_data[0]))]; w2 is an item in _temp_bw_data[1][0:min(3,len(_temp_bw_data[1]))]; w3 is an item in _temp_bw_data[2][0:min(3,len(_temp_bw_data[2]))]; w4 is an item in _temp_bw_data[3][0:min(3,len(_temp_bw_data[3]))]; w5 is an item in _temp_bw_data[4][0:min(3,len(_temp_bw_data[4]))]; w6 is an item in _temp_bw_data[5][0:min(3,len(_temp_bw_data[5]))]; Further construct new data _char_code_dict: {"score": _score, "width": _width}, where: _score=round(w1["score"]*w2["score"]*w3["score"]*w4["score"]* w5["score"]* w6["score"], 4); _width=[w1["width"], w2["width"], w3["width"], w4["width"], w5["width"], w6["width"]]; S605, storing the module width data corresponding to the character and its confidence level into a character width data list; In some embodiments, the module width data _char_code_dict corresponding to the constructed single character is added to the _char_code list; S606 , sort the character width data in descending order of confidence, and store them in a final module width data list.
[0047] In some embodiments, the data items in _char_code are sorted from large to small according to confidence, and then added to the final module width data list, that is, the final_bw_data list; the bw_elements traversal is completed to obtain the final module width data final_bw_data.
[0048] Some embodiments disclose a barcode recognition method in a low-quality image scenario, such as Fig. 9 As shown, step S7 specifically includes: S701. Formulate a coding table in accordance with barcode coding rules; S702, parsing the final module width data according to the barcode encoding rules to generate character encoding; In some embodiments, the barcode encoding table is formulated as code128_charset, and the parsing of the width data includes: Traverse the final_bw_data list, where each item of data corresponds to a character; Take each item of data bw_data_list, and then traverse bw_data_list; Take each data item _dict in bw_data_list and set: _width_list = _dict["width"], score = _dict["score"]; Generate character encoding based on _width_list, the rules are as follows: B = [0] * 6; everage_width = sum(width_list) / 11.0; e1 = width_list[0] + width_list[1]; e2 = width_list[2] + width_list[3]; e3 = width_list[4] + width_list[5]; E1 = max(2, round(e1 / everage_width)); E2 = max(2, round(e2 / everage_width)); E3 = max(2, round(e3 / everage_width)); R1 = width_list[0] / (width_list[0]+ width_list[1]); R2 = width_list[2] / (width_list[2]+ width_list[3]); R3 = width_list[4] / (width_list[4]+ width_list[5]); B[0] = round(R1 * E1); B[1] = E1 - B[0]; B[2] = round(R2 * E2); B[3] = E2 - B[2]; B[4] = round(R3 * E3); B[5] = E3 - B[4]; Convert the numbers in array B into characters and concatenate them. The resulting string is the character code charcode_str.
[0049] S703, searching and matching the generated character code in the code table to obtain a list of all possible values for each character; In some embodiments, when searching and matching the generated character code in the code table, if a match is found, the character code corresponding to the character is determined to be charcode_str, otherwise the most similar character code is found in the code table and recorded as charcode_str, and the traversal of bw_data_list is completed to obtain all possible values of each character code_str_list; S704, traverse all possible value lists, construct data items, and add them to the character code list corresponding to the character; wherein the data item of the character code list corresponding to a single character includes the character code and confidence level corresponding to the barcode; In some embodiments, the code_str_list list is traversed, a data item {"code": code_str, "score": score} is constructed, and added to the _char_code list; wherein code_str is the corresponding character code in the code_str_list, and score is the corresponding confidence level; S705, sorting the data items in the character encoding list corresponding to the single character in descending order of confidence, and then adding them to the character encoding list corresponding to the barcode image; In some embodiments, the data items in _char_code are sorted from large to small according to confidence, and then added to the char_code_list list; S706: The traversal is completed, and a character encoding data list corresponding to the barcode image corresponding to the final module width is obtained, namely, char_code_list.
[0050] In some embodiments, the data format of the character encoding data list is: char_code_list = [; [{'code': '211214', 'score': 1.0}], # The first character; [{'code': '321122', 'score': 0.9998}], # The second character; [{'code': '123221', 'score': 0.9615}, {'code': '214121', 'score':0.0094}]; [{'code': '223211', 'score': 1.0}]; ...; [{'code': '2331112', 'score': 1.0}] # The last character, the termination character; ].
[0051] Some embodiments disclose a barcode recognition method in a low-quality image scenario, such as Fig.10 As shown, step S8 specifically includes: S801, completely arrange and combine all possible characters in the character encoding data list corresponding to the barcode image to obtain a list of all possible character combinations; In some embodiments, all possible characters in char_code_list are fully arranged and combined to obtain all possible character combinations code_data_all. In order to prevent the amount of data from being too large, we can set the maximum amount of data to N, for example, N is set to 3000; S802, traverse the list of all possible character combinations, combine all possible values of the barcode verification character, and verify each character combination; S803, constructing a data item for the character combination that passes the verification, wherein the data of the data item includes the character combination and the corresponding confidence level; S804, adding the constructed data items into the decoded data list, obtaining a string list that has completed decoding and passed verification as a final string list; In some embodiments, the code_data_all list is traversed, and each character combination is verified in combination with the check code; further, if the verification passes, a data item is constructed: {"content": decoded_str, "score": _score}, where: decoded_str is the character combination that passed the verification, and score is its corresponding confidence level; the data item is added to the decoded_str_list list as the final string list.
[0052] Some embodiments disclose a barcode recognition terminal for executing a barcode recognition method in a low-quality image scenario. Generally, the barcode recognition terminal is configured with a computer-readable storage medium, the computer-readable storage medium stores computer code, and the barcode recognition terminal also includes an information processor. When the information processor processes the computer program code, the barcode recognition method is executed to scan and recognize the barcode.
[0053] Some embodiments disclose a barcode recognition system, including a barcode recognition terminal.
[0054] The barcode recognition method in a low-quality image scenario disclosed in an embodiment of the present invention recognizes a low-quality barcode image based on an atomic parsing method of "bars" and "spaces" of a barcode, and can obtain high-quality barcode data from a low-quality original image. It further assigns corresponding confidences to possible combinations of "bars" and "spaces", obtains the confidence of character data composed of a combination of "bars" and "spaces", sorts the character data according to the confidences, and obtains the character combination with the highest confidence as the barcode parsing result, which greatly improves the accuracy of barcode recognition in low-quality image scenarios and has good application prospects in the barcode field.
[0055] The technical solutions disclosed in the embodiments of the present invention and the technical details disclosed in the embodiments are merely illustrative of the inventive concept of the present invention and do not constitute a limitation on the technical solutions of the embodiments of the present invention. Any conventional changes, replacements or combinations of the technical details disclosed in the embodiments of the present invention have the same inventive concept as the present invention and are within the protection scope of the claims of the present invention.
Claims
1. A barcode recognition method in a low-quality image scene, characterized in that: Includes steps: S1, reading the image data containing the barcode, and detecting and obtaining the barcode image data and coordinate information corresponding to the barcode; S2, converting the obtained barcode image into a grayscale image, calculating the pixel average, setting an image enhancement scale factor according to the pixel average, performing image enhancement according to the image enhancement scale factor, increasing the contrast of the grayscale image, and obtaining a first preprocessed image; S3, extracting "edge" data from the first preprocessed image, removing abnormal "edge" data, obtaining atomic data of "bars" and "spaces", and generating a second preprocessed image based on the atomic data of "bars" and "spaces"; S4, performing edge detection on the second preprocessed image to obtain reference "edge" data; Obtain reference atomic data of "bars" and "spaces" based on reference "edge" data; S5, combining the atomic data of "bars" and "spaces" with the reference atomic data to obtain atomic data of "bars and spaces" with confidence; S6. Obtaining final module width data according to the "space" atomic data with confidence; S7, determining a character encoding data list according to the final module width data; S8, decoding the character encoding data list to obtain a final string list; S9, sorting the strings in the final string list in descending order of confidence; S10. The character string with the highest confidence in the final character string list is used as the final barcode recognition result.
2. The barcode recognition method in low-quality image scenarios according to claim 1, characterized in that: Step S1 specifically includes: reading image data containing a barcode, detecting the image data, obtaining a barcode coordinate frame, cutting out an image of a valid area of the barcode using the barcode coordinate frame, and obtaining barcode image data and coordinates corresponding to the barcode.
3. The barcode recognition method in a low-quality image scenario according to claim 1, characterized in that: Step S3 specifically includes: S301, reading a first preprocessed image and calculating a pixel average value; S302, processing the first pre-processed image data line by line to obtain "edge" data and form an "edge" data list; S303, obtaining the X coordinate values of the edge elements in the first column of the "edge" data list, storing them in the first column of the edge element x coordinate list, and calculating the mean and standard deviation of the x coordinates of the first column of the edge element list; S304, according to the mean and standard deviation of the x-coordinate list of the edge elements in the first column, loop through the data and remove abnormal data; S305, traversing the "edge" data after removing abnormal data line by line, determining the width value, type and x-coordinate of the "bar" and the width value, type and x-coordinate of the "space" in each line of data as the atomic data of the "bar" and "space" in each line of data, and storing them in a line atomic data list; after traversing all line data, storing all line atomic data in the "bar" and "space" atomic data lists, that is, obtaining the "bar" and "space" atomic data lists; S306, according to the atomic data list of "bar" and "space", create a row array with the same length as the width of the barcode image, and all the values in the row array are set to 255; S307, traversing the atomic data lists of "bar" and "blank" row by row, processing the atomic data therein, if the type of the atomic data is "bar", then reducing the value within the width range of the "bar" in the row array by 1, if the type of the atomic data is "blank", then increasing the value within the width range of the "blank" in the row array by 1; S308, after the traversal is completed, the row array is corrected. If the value in the row array is less than 0, it is set to 0. If the value in the row array is greater than 255, it is set to 255 to obtain a corrected row array; S309, creating a blank image with the same size as the barcode image, traversing the blank image, and filling each row of data with the data in the corrected row array to obtain a second pre-processed image.
4. The barcode recognition method in a low-quality image scene according to claim 1, characterized in that: Step S4 specifically includes: S401, using the Canny algorithm to perform edge detection on the second preprocessed image to obtain reference "edge" data; and calculating the pixel average value of the corrected row array; S402, taking any row of data in the reference "edge" data, and determining the demarcation threshold between "bar" and "space" according to the pixel average value of the corrected row array, wherein the demarcation threshold of "bar" is set to 0.8 times the pixel average value, and the demarcation threshold of "space" is set to 1.2 times the pixel average value; S403, traverse the row data point by point, determine the point that can be used as an edge element, store the "edge" data of the point in the "edge" data list, and obtain the final reference "edge" data; wherein the "edge" data includes the x-coordinate, edge type, and pixel value. If the edge type is from "empty" to "strip", the pixel value of the point is 0, and if the edge type is from "strip" to "empty", the pixel value of the point is 255; S404, traverse the final reference "edge" data and make a judgment on each data therein; If the current data is the first data, the previous data is used as the current data. If the current data is not the first data, continue to the next step. If the type of the previous data is the edge from "bar" to "space", and the type of the current data is the edge from "space" to "bar", then create "space" atomic data, where the x coordinate of the "space" atomic data is the x coordinate of the previous data, the type is "space", and the width is the x coordinate of the current data minus the x coordinate of the previous data; If the type of the previous data is the edge from "space" to "bar", and the type of the current data is the edge from "bar" to "space", then create the "bar" atomic data, where the x coordinate of the "bar" atomic data is the x coordinate of the previous data, the type is "bar", and the width is the x coordinate of the current data minus the x coordinate of the previous data; S405, storing the created "bar" atomic data and "blank" atomic data into the final reference atomic data list, and obtaining the "bar" and "blank" reference atomic data lists.
5. The barcode recognition method in low-quality image scenarios according to claim 1, characterized in that: Step S5 specifically includes: S501, taking an element in the reference atomic data list of "bar" and "space" as a reference element, taking its x coordinate as a reference coordinate, and its width value as a reference width value; S502, using the reference element, traverse each element in the atomic data list of "bar" and "space"; If the absolute value of the difference between the coordinate value of the current element and the reference coordinate value is not greater than 1, and the absolute value of the difference between the width value of the current element and the reference width value is not greater than 1, the current element is determined as the selected element; the selected element is stored in the selected atomic data list; S503, constructing dictionary data using the selected element; wherein the atomic data of the constructed dictionary data is the data of the selected element, the x coordinate is the reference coordinate, and the width value is the reference width; and storing the constructed dictionary data into the "bar space" atomic data list; S504, the traversal is completed, and the "bar empty" atomic data list is obtained; S505, traverse the "space" atomic data list, take out the elements one by one, and recalculate the confidence of the corresponding element according to the number of credible data; S506. The traversal is completed, and a list of "space" atomic data with confidence is obtained.
6. The barcode recognition method in a low-quality image scenario according to claim 1, characterized in that: Step S6 specifically includes: S601, traversing the "bar space" atomic data with confidence level row by row, and taking out the data of each row during the loop traversal process; S602, extract the width value of each row of data, and construct a width data list as a temporary module width data list; S603, extracting data according to barcode encoding rules; S604, performing complete permutation and combination on the extracted data to obtain module width data corresponding to the characters and their confidence levels; S605, storing the module width data corresponding to the character and its confidence level into a character width data list; S606 , sort the character width data in descending order of confidence, and store them in a final module width data list.
7. The barcode recognition method in low-quality image scenarios according to claim 1, characterized in that: Step S7 specifically includes: S701. Formulate a coding table in accordance with barcode coding rules; S702, parsing the final module width data according to the barcode encoding rules to generate character encoding; S703, searching and matching the generated character code in the code table to obtain a list of all possible values for each character; S704, traverse all possible value lists, construct data items, and add them to the character code list corresponding to the character; wherein the data item of the character code list corresponding to a single character includes the character code and confidence level corresponding to the barcode; S705, sorting the data items in the character encoding list corresponding to the single character in descending order of confidence, and then adding them to the character encoding list corresponding to the barcode image; S706: The traversal is completed, and a character encoding data list corresponding to the barcode image corresponding to the final module width is obtained.
8. The barcode recognition method in low-quality image scenarios according to claim 1, characterized in that: Step S8 specifically includes: S801, completely arrange and combine all possible characters in the character encoding data list corresponding to the barcode image to obtain a list of all possible character combinations; S802, traverse the list of all possible character combinations, combine all possible values of the barcode verification character, and verify each character combination; S803, constructing a data item for the character combination that passes the verification, wherein the data of the data item includes the character combination and the corresponding confidence level; S804: Add the constructed data items to the decoded data list to obtain a string list that has completed decoding and passed verification as the final string list.
9. A barcode recognition terminal, characterized in that: Used to execute the barcode recognition method in a low-quality image scene as described in any one of claims 1 to 8.
10. A barcode recognition system, characterized in that: Includes the barcode recognition terminal described in claim 9.
Citation Information
Patent Citations
Method for cutting portable data file (PDF) 417 standard two-dimensional bar code image
CN102184378A
Barcode correcting method and device
CN105512595A
Decoding method of stained one-dimensional bar code
CN114298078A
Bar code demodulation system
JP2002133363A
Decoding of linear barcodes under unfavorable conditions
US20230367984A1
Cited By
Book information processing method, device and equipment
CN119538957A
Book information processing method, device and equipment
CN119538957B
