A one-dimensional code recognition method and device
By combining the identifier prediction network model and the one-dimensional barcode empty positioning algorithm, the problem of high error rate in one-dimensional barcode recognition is solved, and high-accuracy recognition is achieved under the conditions of dirt and light spot interference.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
- Filing Date
- 2021-09-07
- Publication Date
- 2026-05-01
AI Technical Summary
In existing technologies, barcode recognition is easily affected by dirt and light spots, resulting in a high probability of recognition errors.
A method combining a marker prediction network model and a one-dimensional bar code empty localization algorithm is adopted. The image region is obtained through ROI detection, the marker prediction network model is used to identify the code element markers, and the width ratio of the bar unit and the empty unit is determined by the one-dimensional bar code empty localization algorithm. Finally, the recognition results of the two methods are verified to reduce the error probability.
It effectively reduces the probability of barcode recognition errors and improves recognition accuracy, especially when the image quality is poor.
Smart Images

Figure CN115775004B_ABST
Abstract
Description
A method and apparatus for recognizing one-dimensional barcodes Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a one-dimensional barcode recognition method and apparatus. Background Technology
[0002] As an information carrier, barcodes enable rapid, accurate, and reliable information collection and identification. For example, in the logistics industry, fixed scanning devices can automatically scan barcodes on express packaging, thereby saving significant manpower and reducing costs for logistics companies. Summary of the Invention
[0003] The purpose of this application is to provide a one-dimensional barcode recognition method and apparatus, which can reduce the probability of one-dimensional barcode recognition errors. The specific technical solution is as follows:
[0004] Firstly, in order to achieve the above objectives, embodiments of this application disclose a one-dimensional barcode recognition method, the method comprising:
[0005] The original image containing the one-dimensional barcode is processed based on the Region of Interest (ROI) detection algorithm to obtain the image region corresponding to the one-dimensional barcode, which is used as the image to be identified.
[0006] The image to be identified is input into a pre-trained identifier prediction network model to obtain the identifier of each code element contained in the one-dimensional barcode in the image to be identified, which is used as the predicted identifier; wherein, the identifier prediction network model is used to identify the code elements contained in the one-dimensional barcode in the image; the identifier prediction network model is trained based on a first sample image containing a one-dimensional barcode and the identifier of each code element contained in the one-dimensional barcode in the first sample image; the identifier of a code element is used to uniquely represent the code element.
[0007] Based on the predicted identifier and the preset correspondence between the identifier and the decoding result, the first recognition result of the image to be recognized is obtained;
[0008] If the predicted identifier satisfies the first condition but not the second condition, then based on the one-dimensional bar code empty positioning algorithm, the width ratio of the bar units and empty units contained in the one-dimensional bar code in the image to be identified is determined; wherein, the first condition includes: the number of predicted identifiers with a confidence level less than a first confidence threshold is not greater than a preset number corresponding to the first confidence threshold; the second condition includes: the confidence level of the predicted identifier of the start code element contained in the one-dimensional bar code in the image to be identified is greater than a second confidence threshold, and the confidence level of the predicted identifier of the end code element is greater than a third confidence threshold;
[0009] A second recognition result of the image to be recognized is obtained based on the width ratio;
[0010] Based on the first recognition result and the second recognition result, the final recognition result of the image to be recognized is obtained.
[0011] Optionally, determining the width ratio of bar units to empty units in the one-dimensional barcode in the image to be identified, based on the one-dimensional barcode and space localization algorithm, includes:
[0012] The image to be identified is input into a pre-trained image restoration network model to obtain a restored image in which the width of each unit in the one-dimensional barcode conforms to the standard width ratio.
[0013] The image restoration network model is trained based on a second sample image containing a one-dimensional barcode and an image corresponding to the second sample image in which the width of each unit in the one-dimensional barcode conforms to a standard width ratio.
[0014] The restored image is processed based on a barcode and space localization algorithm to obtain the width ratio of bar cells and space cells contained in the barcode in the restored image, which is used as the width ratio of bar cells and space cells contained in the barcode in the image to be identified.
[0015] Optionally, the method further includes:
[0016] If the predicted identifier satisfies the first and second conditions, then the first recognition result is determined as the final recognition result of the image to be recognized.
[0017] Optionally, obtaining the second recognition result of the image to be recognized based on the width ratio includes:
[0018] Based on the width ratio, each code element contained in the one-dimensional code in the image to be identified is determined as the target code element;
[0019] Based on the decoding results corresponding to each target code element, the second recognition result of the image to be recognized is obtained.
[0020] Optionally, obtaining the final recognition result of the image to be recognized based on the first recognition result and the second recognition result includes:
[0021] If the first recognition result is consistent with the second recognition result, then the first recognition result is determined as the final recognition result of the image to be recognized.
[0022] Secondly, in order to achieve the above objectives, embodiments of this application disclose a one-dimensional barcode recognition device, the device comprising:
[0023] The image acquisition module is used to process the original image containing the one-dimensional code based on the region of interest (ROI) detection algorithm to obtain the image region corresponding to the one-dimensional code as the image to be identified.
[0024] The predictive identifier acquisition module is used to input the image to be identified into a pre-trained identifier prediction network model to obtain the identifier of each code element contained in the one-dimensional barcode in the image to be identified, which is used as the predicted identifier; wherein, the identifier prediction network model is used to identify the code elements contained in the one-dimensional barcode in the image; the identifier prediction network model is trained based on a first sample image containing a one-dimensional barcode and the identifier of each code element contained in the one-dimensional barcode in the first sample image; the identifier of a code element is used to uniquely represent the code element.
[0025] The first recognition result acquisition module is used to obtain the first recognition result of the image to be recognized based on the predicted identifier and the preset correspondence between the identifier and the decoding result;
[0026] The width ratio acquisition module is used to determine the width ratio of bar units and empty units contained in the one-dimensional barcode in the image to be identified based on a one-dimensional barcode empty positioning algorithm if the predicted identifier satisfies a first condition and does not satisfy a second condition. The first condition includes: the number of predicted identifiers with a confidence level less than a first confidence threshold is not greater than a preset number corresponding to the first confidence threshold; the second condition includes: the confidence level of the predicted identifier of the starting code element contained in the one-dimensional barcode in the image to be identified is greater than a second confidence threshold, and the confidence level of the predicted identifier of the ending code element is greater than a third confidence threshold.
[0027] The second recognition result acquisition module is used to obtain the second recognition result of the image to be recognized based on the width ratio;
[0028] The first final recognition result acquisition module is used to obtain the final recognition result of the image to be recognized based on the first recognition result and the second recognition result.
[0029] Optionally, the width ratio acquisition module is specifically used to input the image to be recognized into a pre-trained image restoration network model to obtain a restored image in which the width of each unit in the one-dimensional barcode conforms to the standard width ratio.
[0030] The image restoration network model is trained based on a second sample image containing a one-dimensional barcode and an image corresponding to the second sample image in which the width of each unit in the one-dimensional barcode conforms to a standard width ratio.
[0031] The restored image is processed based on a barcode and space localization algorithm to obtain the width ratio of bar cells and space cells contained in the barcode in the restored image, which is used as the width ratio of bar cells and space cells contained in the barcode in the image to be identified.
[0032] Optionally, the device further includes:
[0033] The second final recognition result acquisition module is used to determine the first recognition result as the final recognition result of the image to be recognized if the predicted identifier satisfies the first condition and the second condition.
[0034] Optionally, the second recognition result acquisition module is specifically used to determine, based on the width ratio, each code element contained in the one-dimensional code in the image to be recognized as the target code element;
[0035] Based on the decoding results corresponding to each target code element, the second recognition result of the image to be recognized is obtained.
[0036] Optionally, the first final recognition result acquisition module is specifically used to determine the first recognition result as the final recognition result of the image to be recognized if the first recognition result is consistent with the second recognition result.
[0037] In another aspect of this application, in order to achieve the above objectives, an embodiment of this application also discloses an electronic device, which includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0038] The memory is used to store computer programs;
[0039] When the processor executes the program stored in the memory, it implements the one-dimensional code recognition method as described above.
[0040] In another aspect of this application, a computer-readable storage medium is provided, wherein a computer program is stored therein, and when executed by a processor, the computer program implements the one-dimensional code recognition method as described above.
[0041] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the one-dimensional code recognition methods described above.
[0042] Beneficial effects of the embodiments in this application:
[0043] The one-dimensional barcode recognition method provided in this application can process the original image containing the one-dimensional barcode based on the ROI detection algorithm to obtain the image region corresponding to the one-dimensional barcode, which is used as the image to be recognized. The image to be recognized is input into a pre-trained label prediction network model to obtain the label of each code element contained in the one-dimensional barcode in the image to be recognized, which is used as the predicted label. The label prediction network model is used to recognize the code elements contained in the one-dimensional barcode in the image. The label prediction network model is trained based on a first sample image containing the one-dimensional barcode and the label of each code element contained in the one-dimensional barcode in the first sample image. The label of a code element is used to uniquely represent the code element. Based on the predicted label and the preset correspondence between the label and the decoding result, The process involves obtaining a first recognition result for the image to be recognized; if the predicted identifier satisfies the first condition but not the second condition, then based on the one-dimensional barcode space localization algorithm, determining the width ratio of the bar units and space units contained in the one-dimensional barcode in the image to be recognized; wherein, the first condition includes: the number of predicted identifiers with a confidence level less than the first confidence threshold is not greater than a preset number corresponding to the first confidence threshold; the second condition includes: the confidence level of the predicted identifier of the start code element contained in the one-dimensional barcode in the image to be recognized is greater than the second confidence threshold, and the confidence level of the predicted identifier of the end code element is greater than the third confidence threshold; a second recognition result for the image to be recognized is obtained based on the width ratio; and a final recognition result for the image to be recognized is obtained based on the first recognition result and the second recognition result.
[0044] Based on the above processing, since the identifier prediction network model focuses more on the overall features of the code elements, when the image to be identified is damaged or interfered with by light spots, causing the width of the units in the one-dimensional code to change, the identifier prediction network model tends to identify the combination of the changed units as similar code elements. This will result in a certain probability of recognition error in the code element dimension. However, the one-dimensional code bar-space localization algorithm determines the width ratio of bar units to space units for decoding, focusing more on the features of each unit itself. Therefore, when the image to be identified is damaged or interfered with by light spots, causing the width of the units in the one-dimensional code to change, it will obtain the changed width of the units. Thus, after unit combination, the corresponding decoding result may not be matched, i.e., a certain probability of recognition error will occur in the unit dimension. Accordingly, this application combines the recognition results obtained by the above two methods to determine the final recognition result, enabling mutual verification between the two methods, thereby reducing the probability of one-dimensional code recognition errors.
[0045] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0047] Figure 1 is a flowchart of a one-dimensional barcode recognition method provided in an embodiment of this application;
[0048] Figure 2 is a schematic diagram of a one-dimensional code provided in an embodiment of this application;
[0049] Figure 3 is a flowchart of another barcode recognition method provided in an embodiment of this application;
[0050] Figure 4 is a flowchart of another barcode recognition method provided in an embodiment of this application;
[0051] Figure 5 is a flowchart of an example of a barcode recognition method provided in an embodiment of this application;
[0052] Figure 6 is a structural diagram of a barcode recognition device provided in an embodiment of this application;
[0053] Figure 7 is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0054] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0055] This application provides a one-dimensional barcode recognition method, which can be applied to an electronic device. The electronic device can acquire an original image containing a one-dimensional barcode and perform recognition. For example, the electronic device can acquire an original image containing a one-dimensional barcode for recognition, or it can acquire an original image containing a one-dimensional barcode acquired by another device and perform recognition.
[0056] In one implementation, the electronic device for scanning the barcode on the express delivery packaging can be a scanning device located near the conveyor belt. This electronic device can scan the express delivery packages being transported on the conveyor belt, obtain the original image of the barcode on the packaging, and then recognize it.
[0057] Referring to Figure 1, which is a flowchart of a one-dimensional barcode recognition method provided in an embodiment of this application, the method may include the following steps:
[0058] S101: The original image containing the one-dimensional code is processed based on the ROI detection algorithm to obtain the image region corresponding to the one-dimensional code, which is used as the image to be identified.
[0059] S102: Input the image to be recognized into a pre-trained label prediction network model to obtain the label of each symbol contained in the one-dimensional code in the image to be recognized, which is used as the predicted label.
[0060] The identifier prediction network model is used to identify the code elements contained in the one-dimensional code in the image. The identifier prediction network model is trained based on a first sample image containing a one-dimensional code and the identifier of each code element contained in the one-dimensional code in the first sample image. The identifier of a code element is used to uniquely represent the code element.
[0061] S103: Based on the predicted identifier and the pre-defined correspondence between the identifier and the decoding result, the first recognition result of the image to be recognized is obtained.
[0062] S104: If the predicted identifier satisfies the first condition but not the second condition, then based on the one-dimensional barcode and space positioning algorithm, determine the width ratio of the bar cells and space cells contained in the one-dimensional barcode in the image to be identified.
[0063] The first condition includes: the number of predicted identifiers with a confidence level less than a first confidence threshold is not greater than a preset number corresponding to the first confidence threshold. The second condition includes: the confidence level of the predicted identifier of the start symbol contained in the one-dimensional code in the image to be recognized is greater than a second confidence threshold, and the confidence level of the predicted identifier of the end symbol is greater than a third confidence threshold.
[0064] S105: Obtain the second recognition result of the image to be recognized based on the width ratio.
[0065] S106: Based on the first recognition result and the second recognition result, the final recognition result of the image to be recognized is obtained.
[0066] The one-dimensional barcode recognition method provided in this application focuses more on the overall features of the code elements because the identifier prediction network model pays more attention to the features of the code elements as a whole. Therefore, when the image to be recognized is damaged or interfered with by light spots, and the width of the units in the one-dimensional barcode changes, the identifier prediction network model tends to identify the combination of the changed units as similar code elements. Thus, a certain probability of recognition error will occur in the dimension of the code elements. In contrast, the one-dimensional bar code bar-space localization algorithm determines the width ratio of bar units to space units for decoding, focusing more on the features of each unit itself. Therefore, when the image to be recognized is damaged or interfered with by light spots, and the width of the units in the one-dimensional barcode changes, it will obtain the changed width of the units. Thus, after the units are combined, the corresponding decoding result may not be matched, that is, a certain probability of recognition error will occur in the dimension of the units. Accordingly, this application embodiment combines the recognition results obtained by the above two methods to determine the final recognition result, which can achieve mutual verification between the two methods, thereby reducing the probability of one-dimensional barcode recognition errors.
[0067] Regarding step S101, the barcode in this application embodiment can be a different type of barcode, for example, it can be a Code128 barcode, or it can be a Code39 barcode, or it can be an EAN (European Article Number) barcode, but it is not limited to these.
[0068] Regarding step S102, the prediction network model can be a deep learning model, such as a CNN (Convolutional Neural Networks) model or an RNN (Recurrent Neural Network) model, but is not limited to these.
[0069] A barcode can contain multiple units. For example, see Figure 2, which is a schematic diagram of a barcode provided in an embodiment of this application.
[0070] The one-dimensional code shown in Figure 2 contains multiple black bars and white spaces, each of which can be called a unit. In the embodiments of this application, they can be referred to as bar units and space units, respectively. Multiple black bars and white spaces can constitute a code element. The composition of code elements differs for different types of one-dimensional codes. For example, for the Code128 one-dimensional code, except for the terminator (i.e., the terminator code element), all other code elements consist of three black bars and three white spaces, and the terminator consists of four black bars and three white spaces.
[0071] In one implementation, the identifiers of different code elements can be predetermined. For example, in Figure 2, the identifier of the code element consisting of the first three black bars and three white spaces can be determined as 0, the identifier of the code element consisting of the next three black bars and three white spaces can be determined as 1, and the identifier of the code element consisting of the next three black bars and three white spaces can be determined as 2. Then, for each identifier, the decoding result of the code element corresponding to that identifier can be determined, thus obtaining the correspondence between the identifiers and decoding results predetermined in step S103. This correspondence can be represented by a decoding table, that is, the decoding table records the correspondence between the identifiers of the code elements and the decoding results.
[0072] In one implementation, the identifiers corresponding to the code elements differ across different types of one-dimensional codes. For example, the identifiers corresponding to the code elements in Code 128 one-dimensional codes range from 0 to 100, while those in Code 39 one-dimensional codes range from 101 to 200, but are not limited to these ranges. In practice, the range of identifiers corresponding to the code elements in each type of one-dimensional code can be determined according to requirements.
[0073] In one embodiment, if the corresponding decoding result cannot be determined based on the predicted identifier and the above correspondence, for example, if the obtained predicted identifier contains identifiers corresponding to different types of one-dimensional barcodes, it can be determined that the identification based on the identifier prediction network model has failed. To avoid incorrect identification, the user can be reminded to manually scan and identify the barcode using a barcode scanning device (e.g., a barcode scanner).
[0074] In one implementation, the image to be recognized is input into a label prediction network model. For each symbol contained in the one-dimensional code in the image, multiple labels can be obtained, and each label corresponds to a confidence level. The confidence level corresponding to a label represents the probability that the symbol corresponds to that label. Therefore, the label with the highest confidence level can be used as the predicted label for that symbol.
[0075] In one embodiment, identifying the training process of a prediction network model may include the following steps:
[0076] Step 1: Obtain the first sample image and the identifier (which can be called the first identifier) of each symbol contained in the one-dimensional code in the first sample image.
[0077] Step 2: Input the first sample image into the label prediction network model to be trained to obtain the predicted label (which can be called the second label).
[0078] Step 3: Based on the first and second labels, adjust the model parameters of the label prediction network model and continue training until the label prediction network model converges.
[0079] In one implementation, a loss function value between the first and second identifiers can be calculated based on a preset loss function. Based on this loss function value, the model parameters of the identifier prediction network model can be adjusted according to the gradient descent algorithm until the identifier prediction network model converges.
[0080] For step S104, the first confidence threshold can be one, or multiple.
[0081] In one implementation, there are multiple first confidence thresholds, and each first confidence threshold can correspond to a preset number. The start symbol is the start symbol in the one-dimensional code, and the stop symbol is the stop symbol in the one-dimensional code.
[0082] For example, the first confidence thresholds include 0.7, 0.5, and 0.3, with corresponding preset numbers of 3, 2, and 1, respectively. That is, the first condition means that the number of predicted labels with a confidence level less than 0.7 is no greater than 3, the number of predicted labels with a confidence level less than 0.5 is no greater than 2, and the number of predicted labels with a confidence level less than 0.3 is no greater than 1.
[0083] The second confidence threshold and the third confidence threshold can be the same or different. For example, both the second confidence threshold and the third confidence threshold can be 0.95.
[0084] If the predicted identifier satisfies the first condition but not the second condition, it indicates that the accuracy of the predicted identifier is not high. Therefore, based on the one-dimensional barcode space positioning algorithm, the width ratio of the bar cells and the space cells can be determined to obtain another recognition result (i.e., the second recognition result) of the image to be recognized. Furthermore, the first recognition result and the second recognition result can be combined to obtain the final recognition result.
[0085] In one embodiment, if the predicted identifier does not meet the first condition, it indicates that the accuracy of the predicted identifier is low. In order to avoid incorrect identification, the user can be reminded to manually scan and identify the identifier using a scanning device (e.g., a barcode scanner).
[0086] In one embodiment, referring to Figure 3, based on Figure 1, the method may further include the following steps:
[0087] S107: If the predicted identifier satisfies the first condition and the second condition, then the first recognition result is determined as the final recognition result of the image to be recognized.
[0088] In this embodiment of the application, the predicted identifier satisfies the first condition and the second condition, indicating that the accuracy of the predicted identifier is high. Therefore, the first identification result can be directly determined as the final identification result.
[0089] In one embodiment, to further improve the accuracy of recognition based on the one-dimensional barcode spatial positioning algorithm, the image to be recognized can be restored before determining the width ratio.
[0090] In one embodiment, referring to FIG4, based on FIG1, step S104 above may include the following steps:
[0091] S1041: If the predicted identifier satisfies the first condition but not the second condition, the image to be identified is input into the pre-trained image restoration network model to obtain a restored image in which the width of each unit in the one-dimensional code conforms to the standard width ratio.
[0092] S1042: The restored image is processed based on the bar and space localization algorithm of the one-dimensional bar code to obtain the width ratio of the bar units and space units contained in the one-dimensional bar code in the restored image, which is used as the width ratio of the bar units and space units contained in the one-dimensional bar code in the image to be recognized.
[0093] The image restoration network model is trained based on a second sample image containing a one-dimensional barcode and an image corresponding to the second sample image in which the width of each unit in the one-dimensional barcode conforms to the standard width ratio.
[0094] In a standard one-dimensional barcode, the ratio of the width of the black bars to the width of the white spaces within a single bar element is a preset value. For example, if a bar element contains three black bars and three white spaces, the width ratio is 2:1:1:2:1:2. However, due to factors such as low printing precision and uneven lighting in one-dimensional barcode printing equipment, the width ratio of the black bars to the white spaces within the bar elements in the image to be recognized may not conform to the standard width ratio. Therefore, to improve recognition accuracy, the image to be recognized can be restored using an image restoration network model to obtain a restored image where the width of each unit in the one-dimensional barcode conforms to the standard width ratio. Furthermore, the restored image can be processed using a one-dimensional barcode space localization algorithm, resulting in a more accurate width ratio and thus improving the accuracy of the second recognition result.
[0095] In one embodiment, the training process of an image restoration network model may include the following steps:
[0096] Step 1: Obtain the second sample image, and the corresponding image of the one-dimensional code containing the second sample image, in which the width of each unit conforms to the standard width ratio (which can be called the sample restoration image).
[0097] Step 2: Input the second sample image into the image restoration network model to be trained to obtain the predicted restored image.
[0098] Step 3: Based on the sample restored image and the predicted restored image, adjust the model parameters of the image restoration network model and continue training until the image restoration network model converges.
[0099] In one implementation, a loss function value between the sample restored image and the predicted restored image can be calculated based on a preset loss function. Based on this loss function value, the model parameters of the image restoration network model are adjusted according to the gradient descent algorithm until the image restoration network model converges.
[0100] In one embodiment, step S105 above may include the following steps:
[0101] Step 1: Based on the width ratio, determine the code elements contained in the one-dimensional code in the image to be recognized, and use them as target code elements.
[0102] Step 2: Based on the decoding results corresponding to each target code element, obtain the second recognition result of the image to be recognized.
[0103] In this embodiment, after obtaining the width ratio of bar units to empty units, the units can be combined according to the width ratio of the units contained in the standard code elements to obtain multiple code elements, i.e., target code elements. Then, each target code element can be translated based on the decoding table to obtain the decoding result (i.e., the second recognition result).
[0104] In one embodiment, if the first recognition result matches the second recognition result, it indicates that the result recognized based on the identifier prediction network model is consistent with the result recognized based on the width ratio of each unit. This result represents the true information of the one-dimensional barcode in the image to be recognized. Therefore, the first recognition result can be directly determined as the final recognition result.
[0105] In one embodiment, if the first identification result is inconsistent with the second identification result, in order to avoid incorrect identification, the user can be reminded to manually scan and identify using a scanning device (e.g., a barcode scanner).
[0106] Referring to Figure 5, Figure 5 is a flowchart of an example of a one-dimensional barcode recognition method provided in an embodiment of this application.
[0107] Input 1D barcode ROI: Extract the image region corresponding to the 1D barcode in the original image (i.e., the image to be recognized) through ROI detection.
[0108] Then, the identification is performed by decoding model 1 (i.e., the model used to identify the code elements contained in the one-dimensional code in the image): the image to be identified is input into the label prediction network model to obtain the predicted label.
[0109] Then, it can be determined whether the decoding was successful: based on the correspondence between the predicted identifier, the preset identifier and the decoding result, it can be determined whether the corresponding decoding result can be determined.
[0110] If not, it indicates that decoding failed and manual scanning is required. For example, remind the user to manually scan and identify the code using a scanning device (e.g., a barcode scanner).
[0111] If so, then it can be determined whether the first condition is met.
[0112] For example, the first condition is: the number of predicted labels with a confidence level of less than 0.7 is no more than 3, the number of predicted labels with a confidence level of less than 0.5 is no more than 2, and the number of predicted labels with a confidence level of less than 0.3 is no more than 1.
[0113] If the first condition is not met, it means that the decoding has failed and manual scanning is required.
[0114] If the first condition is met, we can continue to determine whether the second condition is met.
[0115] For example, the second condition is: the confidence level of the prediction identifier of the start symbol is greater than 0.95, and the confidence level of the prediction identifier of the stop symbol is greater than 0.95.
[0116] If the second condition is met, it means that the decoding is successful, and the first recognition result obtained by decoding model 1 can be determined as the final recognition result.
[0117] If the second condition is not met, then recognition is performed based on decoding model 2 (i.e., a model that determines the width ratio of bar units and empty units based on the one-dimensional bar and empty unit positioning algorithm and performs recognition based on the width ratio): based on the one-dimensional bar and empty unit positioning algorithm, the width ratio of bar units and empty units contained in the one-dimensional bar in the image to be recognized is determined, and the second recognition result of the image to be recognized is obtained based on the width ratio.
[0118] Then, it can be determined whether the decoding was successful. That is, it can be determined whether the corresponding decoding result can be determined based on the width ratio.
[0119] If not, it means the decoding failed and manual scanning is required.
[0120] If yes, it indicates successful decoding. Then, it can be compared with the output of Model 1. If they are the same, the result is output; otherwise, decoding failed and manual reading is required. That is, the first recognition result is compared with the second recognition result. If they match, the first recognition result is determined as the final recognition result; if they do not match, the user is prompted to manually scan and recognize using a barcode scanner (e.g., a barcode scanner).
[0121] For a one-dimensional barcode ROI, if its image quality is poor, the recognition results obtained by different models will differ, and this difference can serve as a basis for reducing misidentification. Specifically, based on the above embodiments, since decoding model 1 focuses more on the overall features of the code elements, when the image to be recognized is damaged or interfered with by light spots, causing changes in the width of the units in the one-dimensional barcode, decoding model 1 tends to identify the combination of the changed units as similar code elements. This will result in a certain probability of recognition error in the code element dimension. Decoding model 2, on the other hand, focuses more on the features of each unit itself. Therefore, when the image to be recognized is damaged or interfered with by light spots, causing changes in the width of the units in the one-dimensional barcode, it will obtain the changed width of the units. Thus, after unit combination, the corresponding decoding result may not be matched, i.e., a certain probability of recognition error will occur in the unit dimension. Accordingly, this embodiment combines the recognition results of decoding model 1 and decoding model 2 to determine the final recognition result, enabling mutual verification between the two decoding models, thereby reducing the probability of one-dimensional barcode recognition errors.
[0122] Based on the same inventive concept, this application also provides a one-dimensional barcode recognition device. Referring to Figure 6, Figure 6 is a structural diagram of a one-dimensional barcode recognition device provided in this application embodiment. The device may include:
[0123] The image acquisition module 601 is used to process the original image containing the one-dimensional code based on the ROI detection algorithm to obtain the image region corresponding to the one-dimensional code as the image to be identified.
[0124] The prediction identifier acquisition module 602 is used to input the image to be identified into a pre-trained identifier prediction network model to obtain the identifier of each code element contained in the one-dimensional barcode in the image to be identified, as the prediction identifier; wherein, the identifier prediction network model is used to identify the code elements contained in the one-dimensional barcode in the image; the identifier prediction network model is trained based on a first sample image containing a one-dimensional barcode and the identifier of each code element contained in the one-dimensional barcode in the first sample image; the identifier of a code element is used to uniquely represent the code element.
[0125] The first recognition result acquisition module 603 is used to obtain the first recognition result of the image to be recognized based on the predicted identifier and the preset correspondence between the identifier and the decoding result;
[0126] The width ratio acquisition module 604 is used to determine the width ratio of the bar units and empty units contained in the one-dimensional barcode in the image to be identified based on the one-dimensional barcode empty positioning algorithm if the predicted identifier satisfies the first condition and does not satisfy the second condition; wherein, the first condition includes: the number of predicted identifiers with a confidence level less than the first confidence threshold is not greater than a preset number corresponding to the first confidence threshold; the second condition includes: the confidence level of the predicted identifier of the start code element contained in the one-dimensional barcode in the image to be identified is greater than the second confidence threshold, and the confidence level of the predicted identifier of the end code element is greater than the third confidence threshold;
[0127] The second recognition result acquisition module 605 is used to obtain the second recognition result of the image to be recognized based on the width ratio;
[0128] The first final recognition result acquisition module 606 is used to obtain the final recognition result of the image to be recognized based on the first recognition result and the second recognition result.
[0129] Optionally, the width ratio acquisition module 604 is specifically used to input the image to be recognized into a pre-trained image restoration network model to obtain a restored image in which the width of each unit in the one-dimensional barcode conforms to the standard width ratio.
[0130] The image restoration network model is trained based on a second sample image containing a one-dimensional barcode and an image corresponding to the second sample image in which the width of each unit in the one-dimensional barcode conforms to a standard width ratio.
[0131] The restored image is processed based on a barcode and space localization algorithm to obtain the width ratio of bar cells and space cells contained in the barcode in the restored image, which is used as the width ratio of bar cells and space cells contained in the barcode in the image to be identified.
[0132] Optionally, the device further includes:
[0133] The second final recognition result acquisition module is used to determine the first recognition result as the final recognition result of the image to be recognized if the predicted identifier satisfies the first condition and the second condition.
[0134] Optionally, the second recognition result acquisition module 605 is specifically used to determine, based on the width ratio, each code element contained in the one-dimensional code in the image to be recognized as the target code element;
[0135] Based on the decoding results corresponding to each target code element, the second recognition result of the image to be recognized is obtained.
[0136] Optionally, the first final recognition result acquisition module is specifically used to determine the first recognition result as the final recognition result of the image to be recognized if the first recognition result is consistent with the second recognition result.
[0137] This application also provides an electronic device, as shown in FIG7, including a processor 701, a communication interface 702, a memory 703, and a communication bus 704, wherein the processor 701, the communication interface 702, and the memory 703 communicate with each other through the communication bus 704.
[0138] Memory 703 is used to store computer programs;
[0139] When processor 701 executes a program stored in memory 703, it performs the following steps:
[0140] The original image containing the one-dimensional barcode is processed based on the ROI detection algorithm to obtain the image region corresponding to the one-dimensional barcode, which is used as the image to be identified.
[0141] The image to be identified is input into a pre-trained identifier prediction network model to obtain the identifier of each code element contained in the one-dimensional barcode in the image to be identified, which is used as the predicted identifier; wherein, the identifier prediction network model is used to identify the code elements contained in the one-dimensional barcode in the image; the identifier prediction network model is trained based on a first sample image containing a one-dimensional barcode and the identifier of each code element contained in the one-dimensional barcode in the first sample image; the identifier of a code element is used to uniquely represent the code element.
[0142] Based on the predicted identifier and the preset correspondence between the identifier and the decoding result, the first recognition result of the image to be recognized is obtained;
[0143] If the predicted identifier satisfies the first condition but not the second condition, then based on the one-dimensional bar code empty positioning algorithm, the width ratio of the bar units and empty units contained in the one-dimensional bar code in the image to be identified is determined; wherein, the first condition includes: the number of predicted identifiers with a confidence level less than a first confidence threshold is not greater than a preset number corresponding to the first confidence threshold; the second condition includes: the confidence level of the predicted identifier of the start code element contained in the one-dimensional bar code in the image to be identified is greater than a second confidence threshold, and the confidence level of the predicted identifier of the end code element is greater than a third confidence threshold;
[0144] A second recognition result of the image to be recognized is obtained based on the width ratio;
[0145] Based on the first recognition result and the second recognition result, the final recognition result of the image to be recognized is obtained.
[0146] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0147] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0148] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0149] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0150] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described one-dimensional barcode recognition methods.
[0151] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the one-dimensional code recognition methods described above.
[0152] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0153] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0154] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0155] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A one-dimensional barcode recognition method, characterized in that, The method includes: processing an original image containing a one-dimensional barcode based on a Region of Interest (ROI) detection algorithm to obtain an image region corresponding to the one-dimensional barcode, which is used as the image to be identified; inputting the image to be identified into a pre-trained identifier prediction network model to obtain an identifier for each code element contained in the one-dimensional barcode in the image to be identified, which is used as a predicted identifier; wherein, the identifier prediction network model is used to identify the code elements contained in the one-dimensional barcode in the image; the identifier prediction network model is trained based on a first sample image containing a one-dimensional barcode and the identifier for each code element contained in the one-dimensional barcode in the first sample image; the identifier of a code element is used to uniquely represent the code element; based on the predicted identifier and a preset correspondence between the identifier and the decoding result, the image to be identified is obtained. The first recognition result of the image; if the predicted identifier satisfies the first condition but not the second condition, then based on the one-dimensional barcode empty positioning algorithm, the width ratio of the bar units and empty units contained in the one-dimensional barcode in the image to be recognized is determined; wherein, the first condition includes: the number of predicted identifiers with a confidence level less than a first confidence threshold is not greater than a preset number corresponding to the first confidence threshold; the second condition includes: the confidence level of the predicted identifier of the start code element contained in the one-dimensional barcode in the image to be recognized is greater than a second confidence threshold, and the confidence level of the predicted identifier of the end code element is greater than a third confidence threshold; the second recognition result of the image to be recognized is obtained based on the width ratio; the final recognition result of the image to be recognized is obtained based on the first recognition result and the second recognition result.
2. The method according to claim 1, characterized in that, The step of determining the width ratio of bar units and empty units in the barcode of the image to be identified based on the barcode bar and empty unit localization algorithm includes: inputting the image to be identified into a pre-trained image restoration network model to obtain a restored image in which the width of each unit in the barcode conforms to a standard width ratio; wherein, the image restoration network model is trained based on a second sample image containing the barcode and an image corresponding to the second sample image in which the width of each unit in the barcode conforms to a standard width ratio; and processing the restored image based on the barcode bar and empty unit localization algorithm to obtain the width ratio of bar units and empty units in the barcode of the restored image, which is used as the width ratio of bar units and empty units in the barcode of the image to be identified.
3. The method according to claim 1, characterized in that, The method further includes: if the predicted identifier satisfies the first condition and the second condition, then the first recognition result is determined as the final recognition result of the image to be recognized.
4. The method according to claim 1, characterized in that, The step of obtaining the second recognition result of the image to be recognized based on the width ratio includes: determining each code element contained in the one-dimensional code in the image to be recognized as a target code element based on the width ratio; and obtaining the second recognition result of the image to be recognized based on the decoding result corresponding to each target code element.
5. The method according to claim 1, characterized in that, The step of obtaining the final recognition result of the image to be recognized based on the first recognition result and the second recognition result includes: if the first recognition result is consistent with the second recognition result, then the first recognition result is determined as the final recognition result of the image to be recognized.
6. A one-dimensional barcode recognition device, characterized in that, The device includes: a target image acquisition module, used to process an original image containing a one-dimensional barcode based on a Region of Interest (ROI) detection algorithm to obtain an image region corresponding to the one-dimensional barcode, which is used as the target image; a prediction identifier acquisition module, used to input the target image into a pre-trained identifier prediction network model to obtain an identifier for each code element contained in the one-dimensional barcode in the target image, which is used as a prediction identifier; wherein, the identifier prediction network model is used to identify the code elements contained in the one-dimensional barcode in the image; the identifier prediction network model is trained based on a first sample image containing a one-dimensional barcode and the identifiers of each code element contained in the one-dimensional barcode in the first sample image; the identifier of a code element is used to uniquely represent the code element; and a first recognition result acquisition module, used to obtain the target image based on the prediction identifier and a preset correspondence between the identifier and the decoding result. The system comprises: a first recognition result; a width ratio acquisition module, configured to determine the width ratio of bar units and empty units contained in the one-dimensional barcode in the image to be recognized based on a one-dimensional barcode empty positioning algorithm if the predicted identifier satisfies a first condition and does not satisfy a second condition; wherein the first condition includes: the number of predicted identifiers with a confidence level less than a first confidence threshold is not greater than a preset number corresponding to the first confidence threshold; the second condition includes: the confidence level of the predicted identifier of the start code element contained in the one-dimensional barcode in the image to be recognized is greater than a second confidence threshold, and the confidence level of the predicted identifier of the end code element is greater than a third confidence threshold; a second recognition result acquisition module, configured to obtain a second recognition result of the image to be recognized based on the width ratio; and a first final recognition result acquisition module, configured to obtain a final recognition result of the image to be recognized based on the first recognition result and the second recognition result.
7. The apparatus according to claim 6, characterized in that, The width ratio acquisition module is specifically used to input the image to be recognized into a pre-trained image restoration network model to obtain a restored image in which the width of each unit in the included barcode conforms to a standard width ratio; wherein, the image restoration network model is trained based on a second sample image containing a barcode and an image corresponding to the second sample image in which the width of each unit in the included barcode conforms to a standard width ratio; the restored image is processed based on a barcode bar and space localization algorithm to obtain the width ratio of the bar units and space units contained in the barcode in the restored image, which is used as the width ratio of the bar units and space units contained in the barcode in the image to be recognized.
8. The apparatus according to claim 6, characterized in that, The device further includes a second final recognition result acquisition module, configured to determine the first recognition result as the final recognition result of the image to be recognized if the predicted identifier satisfies the first condition and the second condition.
9. The apparatus according to claim 6, characterized in that, The second recognition result acquisition module is specifically used to determine, based on the width ratio, each code element contained in the one-dimensional code in the image to be recognized as a target code element; and to obtain the second recognition result of the image to be recognized based on the decoding result corresponding to each target code element.
10. The apparatus according to claim 6, characterized in that, The first final recognition result acquisition module is specifically used to determine the first recognition result as the final recognition result of the image to be recognized if the first recognition result is consistent with the second recognition result.
11. An electronic device, characterized in that, The system includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus; the memory is used to store computer programs; and the processor, when executing the program stored in the memory, implements the steps of the method described in any one of claims 1-5.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-5.
Citation Information
Patent Citations
Bar code identification method and a device.
CN109388999A
Decoding method and equipment of a one-dimensional bar code
CN109657515A