Barcode recognition method and device, terminal equipment and computer program product
The barcode is decoded through various decoding schemes and similarity detection models, which solves the problem of low barcode recognition accuracy with low image quality, and achieves higher recognition accuracy and fault tolerance.
Patent Information
- Application Number
- CN202510436337.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-08
- Publication Date
- 2025-07-08
AI Technical Summary
In the prior art, in scenarios with low image quality, the problem of low barcode recognition accuracy has not been effectively solved.
通过多种解码方案对待识别条码进行解码,得到多个解码结果,并计算每个解码结果与目标图像之间的相似度,基于相似度确定最终的识别结果。
It improves the accuracy of barcode recognition in scenarios with low image quality, and enhances the fault tolerance and robustness of barcode decoding.
Smart Images

Figure CN120278175A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of image processing, and particularly relates to a barcode recognition method, device, terminal device, and computer program product. Background Art
[0002] A barcode (also known as a bar code) is a graphical identifier that arranges multiple black bars and white spaces of unequal widths according to a certain coding rule to express a set of information. Due to its characteristic of being able to carry high-density information, barcodes are widely used in fields such as coding management, warehousing logistics, and industrial manufacturing.
[0003] Currently, the detection and recognition of barcodes often involve identifying the width ratio of each black bar / white space; reading multiple groups of character strings based on the width ratio of each black bar / white space; and determining the character corresponding to each group of character strings by querying the corresponding character table. However, this recognition method is greatly affected by the image quality. Once there are breaks, blurs, etc. at the edges of some barcodes, it will cause errors in reading the character strings, and further cause decoding errors.
[0004] Currently, for the problem of low recognition accuracy of barcodes in scenarios with low image quality in related technologies, no effective solution has been proposed. Summary of the Invention
[0005] Embodiments of this application provide a barcode recognition method, device, terminal device, and computer program product to at least solve the problem of low recognition accuracy of barcodes in scenarios with low image quality in related technologies.
[0006] In a first aspect, embodiments of this application provide a barcode recognition method, including: decoding a target image including a barcode to be recognized through multiple decoding schemes to obtain a decoding result corresponding to each decoding scheme; calculating the similarity between each decoding result and the target image in the case where at least two of the decoding results are different; and determining the recognition result of the barcode to be recognized based on the similarity between each decoding result and the target image.
[0007] In some embodiments, the similarity includes cosine similarity; calculating the similarity between each decoding result and the target image includes: inputting the target image and each decoding result into a trained similarity detection model; extracting, by the similarity detection model, an image feature vector of the target image and a text feature vector of each decoding result; and calculating, by the similarity detection model, the cosine similarity between each text feature vector and the image feature vector.
[0008] In some embodiments, determining the recognition result of the barcode to be recognized based on the similarity between each decoding result and the target image includes: using the decoding result corresponding to the text feature vector with the largest cosine similarity to the image feature vector as the recognition result of the barcode to be recognized.
[0009] In some embodiments, the similarity detection model includes an image encoder and a text encoder; extracting the image feature vector of the target image and the text feature vector of each decoding result by the similarity detection model includes: extracting the image feature vector of the target image by the image encoder; extracting the text feature vector of each decoding result by the text encoder.
[0010] In some embodiments, before inputting the target image and each decoding result into the trained similarity detection model, the method further includes: obtaining a sample image and a text label corresponding to the sample image; inputting the sample image and the text label into the initial BarCredNet model, and extracting the image feature vector of the sample image and the text feature vector of the text label by the initial BarCredNet model; training the initial BarCredNet model by contrastive learning based on the image feature vector of the sample image and the text feature vector of the text label to obtain the trained similarity detection model.
[0011] In some embodiments, the decoding scheme includes at least two of the following schemes: performing barcode decoding based on the grayscale image of the target image, performing barcode decoding based on the binary image of the target image, and inputting the target image into the trained decoding model for barcode decoding.
[0012] In some embodiments, after decoding the target image including the barcode to be recognized by multiple decoding schemes to obtain the decoding result corresponding to each decoding scheme, the method further includes: when all the decoding results are the same, using the decoding result as the recognition result of the barcode to be recognized.
[0013] In a second aspect, an embodiment of the present application provides a barcode recognition device, including: a decoding module, configured to decode a target image including a barcode to be recognized by multiple decoding schemes to obtain a decoding result corresponding to each decoding scheme; a calculation module, configured to calculate the similarity between each decoding result and the target image when at least two of the decoding results are different; and an identification module, configured to determine the recognition result of the barcode to be recognized based on the similarity between each decoding result and the target image.
[0014] In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the barcode recognition method according to any one of the above first aspects is implemented.
[0015] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is run, the barcode recognition method according to any one of the above first aspects is executed.
[0016] Compared with the related art, the barcode recognition method, device, terminal device, and computer program product provided by the embodiments of the present application decode the barcode to be recognized through multiple decoding methods to obtain multiple decoding results; when at least two decoding results are different, calculate the similarity between each decoding result and the target image including the barcode to be recognized respectively; finally, determine the recognition result of the barcode to be recognized based on the similarity between each decoding result and the target image. In this way, by decoding the barcode through multiple decoding schemes and selecting the recognition result corresponding to the barcode based on the similarity, compared with using a single scheme for barcode decoding, the accuracy of barcode decoding in scenarios with low image quality can be effectively improved; in addition, through the redundant design of multiple decoding schemes and similarity verification, the fault tolerance and robustness of barcode decoding can also be enhanced. Through the present application, the problem of low recognition accuracy of barcodes in scenarios with low image quality in the related art is solved, and the technical effect of improving the recognition accuracy of barcodes is achieved.
[0017] The details of one or more embodiments of the present application are set forth in the following drawings and description to make the other features, objects, and advantages of the present application more comprehensible. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] To more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the following drawings are only some embodiments of the present application, and those of ordinary skill in the art can also obtain other drawings based on these drawings without creative efforts.
[0019] Figure 1 is a flowchart of a barcode recognition method according to an embodiment of the present application;
[0020] Figure 2 is an application schematic diagram of a similarity detection model according to an embodiment of the present application;
[0021] Figure 3 is a schematic diagram of the convolutional kernel structure of a similarity detection model according to an embodiment of the present application;
[0022] Figure 4 It is a schematic structural diagram of a bar code recognition device according to an embodiment of the present application;
[0023] Figure 5 It is a schematic structural diagram of a terminal device according to an embodiment of the present application. Detailed implementation manners
[0024] In the following description, specific details such as specific system architectures and technologies are proposed for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0025] It should be understood that when used in the specification and appended claims of the present application, the term "comprising" indicates the presence of the described features, wholes, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.
[0026] It should also be understood that the term "and / or" used in the specification and appended claims of the present application refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0027] As used in the specification and appended claims of the present application, the term "if" can be interpreted as "when", "once", "in response to determining", or "in response to detecting" depending on the context. Similarly, the phrase "if determined" or "if [the described condition or event] is detected" can be interpreted as meaning "once determined", "in response to determining", "once [the described condition or event] is detected", or "in response to detecting [the described condition or event]" depending on the context.
[0028] In addition, in the description of the specification and appended claims of the present application, the terms "first", "second", "third", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.
[0029] Reference to "one embodiment" or "some embodiments" etc. described in the specification of this application means that a specific feature, structure, or characteristic described in connection with that embodiment is included in one or more embodiments of this application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized. The terms "comprising", "including", "having" and their variants all mean "including but not limited to", unless otherwise specifically emphasized.
[0030] A bar code (also known as a bar code) is a graphical identifier that arranges multiple black bars and white spaces of unequal widths in a certain coding rule to express a set of information. Compared with other images, the bar code area has the following two important characteristics: First, the bars and spaces in the bar code area are arranged in parallel and tend to have the same direction; Second, for the readability of the bar code, there is a large reflectivity difference between the black bars and white spaces when the bar code is made, so that the gray-scale contrast in the bar code area is large and the edge information is rich. Due to its characteristic of being able to carry high-density information, bar codes are widely used in fields such as coding management, warehousing logistics, and industrial manufacturing.
[0031] The technology of one-dimensional bar codes is increasingly widely used in industrial and civilian fields. By scanning a one-dimensional bar code with a handheld device such as a barcode reader, detailed information about the commodity corresponding to the one-dimensional bar code can be obtained. One-dimensional bar codes improve the information transparency of commodities, enabling commodity information to be circulated, exchanged, and confirmed more efficiently.
[0032] Currently, the detection and recognition of bar codes often involve identifying the width ratios of each black bar / white space; reading multiple groups of character strings based on the width ratios of each black bar / white space; and determining the characters corresponding to each group of character strings by querying the corresponding character table. However, this recognition method is greatly affected by the image quality. Once there are breaks, blurs at the edges of some bar codes or the printing quality of the bar codes is low, etc., it will cause errors in reading the character strings, and further cause decoding errors.
[0033] Currently, for the problem of low recognition accuracy of bar codes in scenarios with low image quality in the related art, no effective solution has been proposed.
[0034] In view of this, an embodiment of the present application provides a barcode recognition method, which decodes a barcode to be recognized through multiple decoding methods to obtain multiple decoding results; when at least two decoding results are different, calculates the similarity between each decoding result and a target image including the barcode to be recognized respectively; and finally determines the recognition result of the barcode to be recognized based on the similarity between each decoding result and the target image. In this way, by decoding the barcode through multiple decoding schemes and selecting the recognition result corresponding to the barcode based on the similarity, compared with using a single scheme for barcode decoding, the accuracy of barcode decoding in a scenario with low image quality can be effectively improved; in addition, through the redundant design of multiple decoding schemes and similarity verification, the fault tolerance and robustness of barcode decoding can also be enhanced. Through the present application, the problem of low recognition accuracy of barcodes in a scenario with low image quality in the related art is solved, and the technical effect of improving the recognition accuracy of barcodes is achieved.
[0035] Next, a barcode recognition method provided by an embodiment of the present application will be described in conjunction with Figure 1 Please refer to Figure 1 , Figure 1 which is a flowchart of a barcode recognition method according to an embodiment of the present application. As shown in Figure 1 , the method includes:
[0036] Step S101, decode a target image including a barcode to be recognized through multiple decoding schemes to obtain a decoding result corresponding to each decoding scheme.
[0037] In this embodiment, since the target image may be blurred, defective, etc., multiple decoding schemes can be set to decode the target image including the barcode to be recognized respectively, and the fault tolerance and robustness of barcode decoding are enhanced based on the redundant design of multiple decoding schemes.
[0038] In one embodiment, the decoding scheme includes at least two of the following schemes: decoding the barcode based on the grayscale image of the target image, decoding the barcode based on the binary image of the target image, and inputting the target image into a trained decoding model for barcode decoding.
[0039] In this embodiment, decoding the barcode based on the grayscale image of the target image directly analyzes the grayscale image of the target image without binarization processing, uses pixel brightness gradient or local contrast features to locate the barcode area. The boundary between black bars and white spaces is recognized by calculating the continuous change of grayscale values, and the accuracy is improved by combining sub-pixel interpolation technology. Finally, the encoding rule is matched according to the bar-width sequence to complete the decoding operation of the barcode to be recognized. This decoding scheme can avoid the loss of details caused by the selection of binarization threshold and adapt to scenarios with uneven illumination or low contrast.
[0040] Barcode decoding based on the binary image of the target image is to convert the grayscale image of the target image into a binary image, determine the bar and space boundary points through global thresholding or local adaptive thresholding segmentation, then extract the barcode area through connected component analysis or projection method, and finally match the encoding rules according to the obtained bar and space width sequence to complete the decoding operation of the barcode to be recognized.
[0041] The trained decoding model can be trained based on the Convolutional Neural Networks (CNN) or Transformer model architecture, and the above decoding model can be used to identify the barcode end-to-end. The target image is directly input into the decoding model, and the barcode area is located and the encoded content is parsed through the feature extraction network, or combined with traditional image processing (such as edge detection) for hybrid decoding. This decoding scheme has strong robustness and has certain advantages in complex background, distortion, occlusion or low-quality image scenarios.
[0042] In addition, the decoding scheme can also include barcode decoding based on super-resolution technology. The target image is input into the trained super-resolution network model to obtain the high-resolution image output by the trained super-resolution network model, and then the decoding operation is performed on the high-resolution image. This decoding scheme has advantages in scenarios such as low-resolution and blurred images.
[0043] Alternatively, the decoding scheme can also include barcode decoding based on template matching. The actual waveform of the codeword contained in the barcode is matched with the template waveform, and barcode decoding is performed based on pixel intensity. This decoding scheme has advantages in scenarios where the image is defective.
[0044] In this way, using decoding schemes with respective advantages in different scenarios to decode the barcode to be recognized can improve the fault tolerance and robustness of barcode decoding in different scenarios (such as blurred images, low printing quality, defects, etc.), and thus improve the recognition accuracy of the barcode.
[0045] Step S102, in the case where at least two decoding results are different, calculate the similarity between each decoding result and the target image.
[0046] In one embodiment, after step S101, the method further includes: in the case where all decoding results are the same, using the decoding result as the recognition result of the barcode to be recognized.
[0047] In this embodiment, in the case where the decoding results corresponding to each decoding scheme are the same, it can indicate that the decoding result is highly credible, and then the decoding result can be directly used as the recognition result of the barcode to be recognized and output.
[0048] In one embodiment, the similarity includes cosine similarity; the step of "calculating the similarity between each decoding result and the target image" in step S102 includes the following steps:
[0049] Step 1, input the target image and each decoding result into a trained similarity detection model.
[0050] Step 2, the similarity detection model extracts the image feature vector of the target image and the text feature vector of each decoding result.
[0051] Step 3, the similarity detection model calculates the cosine similarity between each text feature vector and the image feature vector.
[0052] An exemplary application structure of the similarity detection model can refer to Figure 2 , Figure 2 which is a schematic diagram of the application of the similarity detection model according to an embodiment of the present application. As shown in Figure 2 , the similarity detection model includes an image encoder and a text encoder; the step of the similarity detection model extracting the image feature vector of the target image and the text feature vector of each decoding result includes: the image encoder extracts the image feature vector of the target image; the text encoder extracts the text feature vector of each decoding result.
[0053] In this embodiment, the backbone network of the image encoder (ImageEncoder) can be ResNet50 or MobileNetV3, which is used to convert a picture into a numerical vector; the backbone network of the text encoder (TextEncoder) can be constructed based on the Transformer architecture and is used to convert text into a numerical representation.
[0054] As an example, as shown in Figure 2 , input multiple decoding results such as "1234567890005", "6973072010212", "4003683453244" into the text encoder of the similarity detection model. The text encoder converts them into text feature vectors "T1, T2,..., Tn". "1234567890005" corresponds to "T1", "6973072010212" corresponds to "T2", "4003683453244" corresponds to "T3", and so on.
[0055] Input the target image containing the code to be recognized into the image encoder of the similarity detection model, and the image encoder converts it into an image feature vector "I1". Then, the similarity detection model can calculate the cosine similarities "I1.T1, I2.T2, I3.T3,..., In.Tn" between "I1" and each text feature vector "T1, T2,..., Tn".
[0056] In one embodiment, the above similarity detection model can be obtained by performing contrastive learning training on the BarCredNet model. During the training process of the BarCredNet model, the model will perform matching training on thousands of pairs of images and texts, making the numerical vectors of relevant image and text pairs closer and those of irrelevant pairs farther apart. In this way, the BarCredNet model can understand the meanings of texts and pictures and perform matching, such that the distance between texts and pictures with high matching degree is closer, and the distance between those with low matching degree is farther.
[0057] In this embodiment, before inputting the target image and each decoding result into the trained similarity detection model, the method further includes the following steps:
[0058] Step 1, obtain a sample image and a text label corresponding to the sample image.
[0059] Step 2, input the sample image and the text label into the initial BarCredNet model, and the initial BarCredNet model extracts the image feature vector of the sample image and the text feature vector of the text label.
[0060] Step 3, based on the image feature vector of the sample image and the text feature vector of the text label, perform contrastive learning to train the initial BarCredNet model to obtain the trained similarity detection model.
[0061] The sample image and the text label can form a positive sample or a negative sample. Specifically, the positive sample includes the sample image and the text label corresponding to the sample image, that is, the text label is the actual decoding result of the barcode included in the sample image; the negative sample includes the sample image and the text label not corresponding to the sample image, that is, the text label is not the same as the actual decoding result of the barcode included in the sample image.
[0062] By inputting the sample image and the text label into the initial BarCredNet model, the initial BarCredNet model extracts the image feature vector of the sample image and the text feature vector of the text label, and based on the image feature vector of the sample image and the text feature vector of the text label, perform contrastive learning to train the initial BarCredNet model, which can enable the initial BarCredNet model to understand the meanings of texts and pictures and perform matching, and make the distance between texts and pictures with high matching degree closer and the distance between those with low matching degree farther, thereby obtaining the similarity detection model. The similarity detection model can accurately detect the similarity between the input barcode image and the decoded text, thereby providing a basis for barcode recognition.
[0063] In one embodiment, the convolutional kernel in the above similarity detection model is different from the conventional convolutional kernel "Conv-3×3" in the BarCredNet model and includes five parts.
[0064] As an example, see Figure 3 , Figure 3 which is a schematic diagram of the convolutional kernel structure of the similarity detection model according to an embodiment of the present application. As Figure 3 shown, the first part of the convolutional kernel in the similarity detection model provided by the embodiment of the present application includes an ordinary Conv-3×3 convolution, which is used to ensure the basic model performance; the second part includes an expansion and squeeze convolution, which is composed of a Conv-1×1 convolution layer and a Conv-3×3 convolution layer. The Conv-1×1 convolution is used to expand the feature map dimension (number of channels), and the Conv-3×3 convolution then reduces and squeezes the feature map dimension to finally obtain a feature map with richer feature information.
[0065] The third and fourth parts in the similarity detection model provided by the embodiment of the present application are used for first-order edge information extraction. Among them, the branch represented by the third part is used to extract horizontal edge information. The feature passes through a Conv-1×1 convolution, and then through a Sobel-Dx convolutional kernel with a learnable scale factor and a preset value. The other branch represented by the fourth part is used to extract vertical edge information. The feature passes through a Conv-1×1 convolution, and then through a Sobel-Dy convolutional kernel with a learnable scale factor and a preset value. Among them, the two preset convolutional kernels are as follows:
[0066] and
[0067] The third and fourth parts as a whole can be represented by the following expression:
[0068]
[0069] The fifth part in the similarity detection model provided by the embodiment of the present application uses Conv-1×3 convolution and Conv-3×1 convolution to replace the calculation of Conv-3×3 convolution, reducing the calculation amount and memory requirements, thereby improving the efficiency of the model.
[0070] In the similarity detection model provided by the embodiment of the present application, more than 80% of the conventional convolutional kernels "Conv-3×3" can be replaced by the above specific convolutional kernel structure, so as to ensure that the similarity detection model can improve the feature information more beneficial to barcode decoding.
[0071] Step S103, based on the similarity between each decoding result and the target image, determine the recognition result of the barcode to be recognized.
[0072] In this embodiment, the above similarity detection model may use the decoding result corresponding to the text feature vector with the largest cosine similarity to the image feature vector as the recognition result of the barcode to be recognized.
[0073] As an example, see Figure 2 , after the similarity detection model calculates the cosine similarities "I1.T1, I2.T2, I3.T3,..., In.Tn" between the image feature vector "I1" and each text feature vector "T1, T2,..., Tn", it selects the decoding result "4003683453244" corresponding to the highest cosine similarity "I3.T3" as the recognition result of the barcode to be recognized and outputs this recognition result.
[0074] In other embodiments, the similarity detection model may also compare the cosine similarity between each decoding result and the target image with a preset threshold (for example, this preset threshold can be adjusted based on the application scenario and user expectations and can be set to 0.9, 0.95, etc.). If the cosine similarity between the decoding result and the target image is lower than this preset threshold, it is directly discarded without subsequent similarity comparison. If there is no decoding result with a cosine similarity higher than this preset threshold to the target image, a prompt message is sent to prompt the user that there is a risk that all decoding results are incorrect.
[0075] In this embodiment, by using a multi-modal deep learning model (i.e., the similarity detection model) to calculate the similarity between each decoding result and the target image, the decoding result is judged. The feature information of two modalities, image features and text features, is used to evaluate the similarity between the decoding result and the target image, and the decoding result with the largest similarity is selected as the recognition result of the barcode to be recognized. The decoding accuracy is higher, and the stability and environmental adaptability are good, and a high decoding efficiency and decoding accuracy can be ensured in scenarios such as blurred images, low printing quality, and defects.
[0076] It should be noted that the barcode recognition method provided in the embodiments of this application can be applied not only to the recognition of one-dimensional barcodes but also to the recognition of two-dimensional barcodes. In addition, the barcode recognition method provided in the embodiments of this application can also be accelerated using a Graphics Processing Unit (GPU) / Central Processing Unit (CPU) / Neural network Processing Unit (NPU) to decode and recognize the barcode in real time and improve the recognition efficiency of the barcode.
[0077] Through the above steps S101 to S103, the barcodes to be recognized are decoded by multiple decoding methods to obtain multiple decoding results. In the case where at least two decoding results are different, the similarity between each decoding result and the target image including the barcode to be recognized is calculated respectively. Finally, based on the similarity between each decoding result and the target image, the recognition result of the barcode to be recognized is determined. In this way, by decoding the barcode through multiple decoding schemes and selecting the recognition result corresponding to the barcode based on the similarity, compared with using a single scheme for barcode decoding, it can effectively improve the accuracy of barcode decoding in scenarios with low image quality. In addition, through the redundant design of multiple decoding schemes and similarity verification, the fault tolerance and robustness of barcode decoding can also be enhanced. Through this application, the problem of low recognition accuracy of barcodes in scenarios with low image quality in the related art is solved, and the technical effect of improving the recognition accuracy of barcodes is achieved.
[0078] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not imply the order of execution. The order of execution of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0079] Corresponding to the barcode recognition method described in the above embodiments, Figure 4 FIG. shows a schematic structural diagram of a barcode recognition device according to an embodiment of the present application. For the sake of convenience of description, only the parts related to the embodiments of the present application are shown.
[0080] Please refer to Figure 4 , the barcode recognition device 4 includes: a decoding module 40, configured to decode a target image including a barcode to be recognized through multiple decoding schemes to obtain a decoding result corresponding to each decoding scheme; a calculation module 41, configured to calculate the similarity between each decoding result and the target image in the case where at least two decoding results are different; and a recognition module 42, configured to determine the recognition result of the barcode to be recognized based on the similarity between each decoding result and the target image.
[0081] In one embodiment, the similarity includes cosine similarity; the calculation module 41 is further configured to input the target image and each decoding result into a trained similarity detection model; the similarity detection model extracts the image feature vector of the target image and the text feature vector of each decoding result; and the similarity detection model calculates the cosine similarity between each text feature vector and the image feature vector.
[0082] In one embodiment, the recognition module 42 is further configured to use the decoding result corresponding to the text feature vector with the largest cosine similarity to the image feature vector as the recognition result of the barcode to be recognized.
[0083] In one embodiment, the similarity detection model includes an image encoder and a text encoder; the calculation module 41 is further configured to extract an image feature vector of the target image by the image encoder; and extract a text feature vector of each decoding result by the text encoder.
[0084] In one embodiment, the barcode recognition device 4 further includes a training module, configured to obtain a sample image and a text label corresponding to the sample image; input the sample image and the text label into the initial BarCredNet model, and extract an image feature vector of the sample image and a text feature vector of the text label by the initial BarCredNet model; and train the initial BarCredNet model by contrast learning based on the image feature vector of the sample image and the text feature vector of the text label to obtain a trained similarity detection model.
[0085] In one embodiment, the decoding scheme includes at least two of the following schemes: performing barcode decoding based on the grayscale image of the target image, performing barcode decoding based on the binary image of the target image, and inputting the target image into a trained decoding model for barcode decoding.
[0086] In one embodiment, the recognition module 42 is further configured to, when all the decoding results are the same, use the decoding result as the recognition result of the barcode to be recognized.
[0087] It should be noted that, for the information interaction, execution process, etc. between the above-mentioned device / units, since they are based on the same concept as the method embodiment of the present application, for their specific functions and the technical effects brought, reference can be specifically made to the method embodiment part, and details are not described herein again.
[0088] Those skilled in the art can clearly understand that, for the convenience and conciseness of description, only the above-mentioned division of each functional unit and module is used as an example. In actual applications, the above-mentioned functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of the present application. The specific working process of the units and modules in the above system can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
[0089] Figure 5 is a schematic structural diagram of a terminal device according to an embodiment of the present application. As Figure 5As shown, the terminal device 5 includes: at least one processor 50 ( Figure 5 only one is shown in the figure), a processor, a memory 51, and a computer program 52 stored in the memory 51 and executable on at least one processor 50. When the processor 50 executes the computer program 52, the steps in any of the above barcode recognition method embodiments are implemented.
[0090] The terminal device 5 can be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The terminal device 5 may include but is not limited to a processor 50 and a memory 51. Those skilled in the art can understand that Figure 5 merely examples of the terminal device 5, which do not constitute a limitation on the terminal device 5, may include more or fewer components than shown in the figure, or combine certain components, or different components. For example, it may also include input / output devices, network access devices, etc.
[0091] The processor 50 may be a central processing unit (CPU), and the processor 50 may also be other general-purpose processors, 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, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0092] The memory 51 may be an internal storage unit of the terminal device 5 in some embodiments, such as the hard disk or memory of the terminal device 5. The memory 51 may also be an external storage device of the terminal device 5 in other embodiments, such as a plug-in hard disk equipped on the terminal device 5, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. In other embodiments, the memory 51 may also include both an internal storage unit and an external storage device of the terminal device 5. The memory 51 is used to store an operating system, application programs, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program 52. The memory 51 may also be used to temporarily store data that has been output or will be output.
[0093] The embodiments of the present application also provide a computer-readable storage medium storing a computer program, which when executed by a processor, can implement the steps in the above-described embodiments of various barcode recognition methods.
[0094] The embodiments of the present application provide a computer program product, which when running on a mobile terminal, enables the mobile terminal to implement the steps in the above-described embodiments of various barcode recognition methods when executed.
[0095] All or part of the processes in the above-described embodiment methods of the present application can be completed by instructing relevant hardware through a computer program. This computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above-described various method embodiments can be implemented. Among them, the computer program includes computer program code, which can be in the form of source code, object code, executable file, or some intermediate form, etc. The computer-readable medium can at least include: any entity or device capable of carrying the computer program code to the terminal device, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk, or an optical disc, etc.
[0096] In the above embodiments, the descriptions of the various embodiments each have their own focuses. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0097] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be implemented by electronic hardware, or by a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.
[0098] In the embodiments provided in the present application, it should be understood that the disclosed device / network device and method can be implemented in other ways. For example, the device / network device embodiments described above are only illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in electrical, mechanical or other forms.
[0099] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0100] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A bar code recognition method, characterized in that, Including: Decoding a target image including a barcode to be recognized through multiple decoding schemes to obtain a decoding result corresponding to each decoding scheme; When at least two of the decoding results are different, calculating the similarity between each decoding result and the target image; Based on the similarity between each decoding result and the target image, determining the recognition result of the barcode to be recognized.
2. The method according to claim 1, wherein The similarity includes cosine similarity; calculating the similarity between each decoding result and the target image includes: Inputting the target image and each decoding result into a trained similarity detection model; Extracting, by the similarity detection model, an image feature vector of the target image and a text feature vector of each decoding result; Calculating, by the similarity detection model, the cosine similarity between each text feature vector and the image feature vector.
3. The method according to claim 2, wherein Based on the similarity between each decoding result and the target image, determining the recognition result of the barcode to be recognized includes: Taking the decoding result corresponding to the text feature vector with the largest cosine similarity to the image feature vector as the recognition result of the barcode to be recognized.
4. The method according to claim 2, characterized in that, The similarity detection model includes an image encoder and a text encoder; extracting, by the similarity detection model, an image feature vector of the target image and a text feature vector of each decoding result includes: Extracting, by the image encoder, the image feature vector of the target image; Extracting, by the text encoder, the text feature vector of each decoding result.
5. The method according to claim 2, characterized in that, Before inputting the target image and each decoding result into a trained similarity detection model, the method further includes: Obtaining a sample image and a text label corresponding to the sample image; Inputting the sample image and the text label into an initial BarCredNet model, and extracting, by the initial BarCredNet model, an image feature vector of the sample image and a text feature vector of the text label; Training the initial BarCredNet model by contrastive learning based on the image feature vector of the sample image and the text feature vector of the text label to obtain the trained similarity detection model.
6. The method according to any one of claims 1 to 5, characterized in that, The decoding scheme includes at least two of the following schemes: barcode decoding based on the grayscale image of the target image, barcode decoding based on the binary image of the target image, and barcode decoding by inputting the target image into a trained decoding model.
7. The method according to any one of claims 1 to 5, characterized in that, After decoding a target image including a barcode to be recognized through multiple decoding schemes to obtain a decoding result corresponding to each decoding scheme, the method further includes: When all the decoding results are the same, taking the decoding result as the recognition result of the barcode to be recognized.
8. A bar code recognition device, characterized in that, Including: A decoding module, configured to decode a target image including a barcode to be recognized through multiple decoding schemes to obtain a decoding result corresponding to each decoding scheme; A calculation module, configured to calculate the similarity between each decoding result and the target image when at least two of the decoding results are different; An identification module, configured to determine an identification result of the barcode to be identified based on a similarity between each of the decoding results and the target image.
9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, the barcode identification method according to any one of claims 1 to 7 is implemented.
10. A computer program product, characterized in that, It includes a computer program which, when run, causes the barcode identification method according to any one of claims 1 to 7 to be executed.