Barcode detection and recognition method and device and electronic equipment
By using lightweight convolutional neural networks for fast barcode detection and precise recognition and decoding, and combining image brightness detection and blurred evaluation, the imaging parameters are automatically adjusted, and the problem of low success rate of barcode detection in the prior art is solved, achieving efficient recognition effect in complex scenarios.
Patent Information
- Application Number
- CN202411664553.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-03-11
AI Technical Summary
When detecting barcodes with different codes, the existing barcode recognition methods have a low detection success rate. Especially in complex scenarios such as high noise, too small barcode size, out-of-focus blur, and special forms, it is difficult to quickly and accurately decode different types of barcodes.
Lightweight convolutional neural network is used to perform fast barcode detection, reducing the demand for computing resources, and accurately identifying and decoding the barcodes, reducing the computing burden of the overall system. At the same time, through image brightness detection and blur evaluation, the imaging parameters of the camera are automatically adjusted to optimize image quality.
It improves the success rate and efficiency of barcode detection, can operate efficiently on devices with limited hardware resources, and enhances the recognition rate in complex scenarios.
Smart Images

Figure CN119599042A_ABST
Abstract
Description
Technical Field
[0001] The present application mainly relates to the field of computer vision technology, and in particular to a method, device and electronic equipment for barcode detection and recognition. Background Art
[0002] In recent years, deep learning technology, especially object detection and recognition methods based on convolutional neural networks (CNNs), have shown excellent performance in complex and ever-changing scenarios. Compared with traditional hand-designed features or template matching methods, CNNs have stronger generalization capabilities. However, despite the advantages of CNNs in generalization ability and detection accuracy, their high computing resource requirements and the detection results presented in the form of confidence probability make them limited in certain scenarios that require 100% accurate recognition (such as barcode recognition). Barcode recognition requires detecting and locating the barcode position and identifying the barcode content. Due to the variability and version diversity of barcode encoding, CNNs have limited performance in the barcode recognition part and are usually only used for barcode detection.
[0003] Traditional barcode recognition methods need to design and detect multiple feature templates when detecting barcodes of different code systems. The detection success rate is low in complex scenarios such as high noise, small barcode size, out-of-focus blur, special forms such as dot-matrix printed two-dimensional codes and DPM (Direct Part Marks). In addition, the efficiency is low when recognizing multiple and multiple code barcodes, and it is difficult to quickly and accurately decode different types of barcodes. Summary of the invention
[0004] The purpose of the present application is to provide a method, device and electronic device for barcode detection and recognition, so as to solve the problem that the existing barcode recognition method has a low detection success rate when detecting barcodes of different code systems.
[0005] In a first aspect, the present application provides a method for barcode detection and recognition, the method comprising:
[0006] Based on the image collector, obtain the target format data of the preview image;
[0007] Inputting the target format data into a pre-trained barcode detection model to obtain a detection result;
[0008] When a barcode exists in the detection result, a positioning image of the barcode is obtained according to the position of the barcode in the detection result, and a category identifier of the barcode is obtained from the detection result;
[0009] The barcode is decoded according to the positioning image and the category identifier.
[0010] This application uses a lightweight convolutional neural network for fast barcode detection, reducing the need for complex calculations; then, by accurately identifying and decoding the barcode, the computational burden of the overall system is reduced, enabling it to run efficiently on devices with limited hardware resources.
[0011] Optionally, before the image collector is used to obtain the target format data of the preview image, the method further includes: collecting multiple barcode sample images of multiple code systems; marking the barcode position in each barcode sample image, and processing the coordinates of each barcode position according to a set format to obtain each barcode marked image; adding corresponding category identifiers to the barcodes in each barcode marked image according to preset classification rules to obtain each barcode classification image; aggregating the barcode classification images of each code system into a training set and a verification set according to a set ratio; and training a convolutional neural network model based on the training set and the verification set to obtain the barcode detection model.
[0012] Optionally, the barcodes in each barcode annotated image are respectively added with corresponding category identifiers according to preset classification rules to obtain each barcode classification image, including: dividing all barcode annotated images into one-dimensional code images and two-dimensional code images according to the type of the barcodes in each barcode annotated image; adding a first category identifier to the one-dimensional code image to obtain a one-dimensional code sample; dividing the two-dimensional code image into N categories according to the encoding structure of the barcodes in each two-dimensional code image, and adding different category identifiers to each category of two-dimensional code image to obtain a two-dimensional code sample, wherein N is an integer greater than 1; and using the one-dimensional code sample and the two-dimensional code sample as the barcode classification image.
[0013] The barcode detection model is trained by classifying all one-dimensional codes into one category and two-dimensional codes into multiple categories according to the coding structure, which improves the training speed and detection efficiency of the model.
[0014] Optionally, the method also includes: when there is no barcode in the detection result, performing image brightness detection on the preview image; if the image brightness of the preview image does not meet preset requirements, turning on the fill light of the image collector or adjusting the exposure parameters of the image collector; and re-obtaining the target format data of the preview image based on the image collector.
[0015] Optionally, the method further includes: when there are multiple barcodes in the detection result, sorting the barcodes from small to large according to the distance between the center position of each barcode and the center position of the preview image to obtain a positioning image of each barcode; and decoding the barcodes in each positioning image in the order from small to large.
[0016] Optionally, after decoding the barcode according to the positioning image and the category identifier, it also includes: when the barcode decoding fails, detecting whether the preview image is blurred; if the preview image is blurred, triggering the image collector to refocus and re-acquire the target format data of the preview image; if the preview image is not blurred, acquiring the size of the barcode from the positioning image; when the size is less than a preset value, triggering the image collector to enlarge the preview image and acquire the target format data of the enlarged preview image; when the size is greater than or equal to the preset value, triggering the image collector to re-acquire the target format data of the preset image.
[0017] This application automatically adjusts the camera's imaging parameters such as optical zoom, exposure parameters, refocusing and fill light based on brightness detection and blur assessment, optimizes image quality, enhances recognition distance and depth of field, and improves recognition rate in complex scenes.
[0018] Optionally, the convolutional neural network model is trained based on the training set and the validation set to obtain the barcode detection model, including: changing the RGB three-channel color data of the training set into single-channel grayscale image data to obtain a target training set; based on the target training set and the validation set, the convolutional neural network model is trained to obtain the barcode detection model.
[0019] The training of the barcode detection model reduces the amount of calculation and improves the training efficiency by changing the RGB three-channel of the training image to a single-channel grayscale image data.
[0020] In a second aspect, the present application provides a barcode detection and recognition device, the device comprising:
[0021] The acquisition module is used to acquire the target format data of the preview image based on the image collector;
[0022] A detection module, used for inputting the target format data into a pre-trained barcode detection model to obtain a detection result;
[0023] An acquisition module, for obtaining a positioning image of the barcode according to the position of the barcode in the detection result when there is a barcode in the detection result, and obtaining a category identifier of the barcode from the detection result;
[0024] A decoding module is used to decode the barcode according to the positioning image and the category identifier.
[0025] Optionally, the device is also used to: collect multiple barcode sample images of multiple code systems; mark the barcode position in each barcode sample image, and process the coordinates of each barcode position according to a set format to obtain each barcode marked image; add corresponding category identifiers to the barcodes in each barcode marked image according to preset classification rules to obtain each barcode classification image; summarize the barcode classification images of each code system into a training set and a verification set according to a set ratio; based on the training set and the verification set, train the convolutional neural network model to obtain the barcode detection model.
[0026] Optionally, the device is also used to: divide all barcode annotated images into one-dimensional code images and two-dimensional code images according to the type of barcode in each barcode annotated image; add a first category identifier to the one-dimensional code image to obtain a one-dimensional code sample; divide the two-dimensional code image into N categories according to the encoding structure of the barcode in each two-dimensional code image, and add different category identifiers to each category of two-dimensional code image to obtain a two-dimensional code sample, wherein N is an integer greater than 1; and use the one-dimensional code sample and the two-dimensional code sample as the barcode classification image.
[0027] Optionally, the device is also used to: when there is no barcode in the detection result, perform image brightness detection on the preview image; if the image brightness of the preview image does not meet preset requirements, turn on the fill light of the image collector or adjust the exposure parameters of the image collector; and re-acquire the target format data of the preview image based on the image collector.
[0028] Optionally, the device is also used to: when there are multiple barcodes in the detection result, sort the barcodes from small to large according to the distance between the center position of each barcode and the center position of the preview image to obtain the positioning image of each barcode; and decode the barcodes in each positioning image in the order from small to large.
[0029] Optionally, the device is also used to: when the barcode decoding fails, detect whether the preview image is blurred; if the preview image is blurred, trigger the image collector to refocus and re-acquire the target format data of the preview image; if the preview image is not blurred, obtain the size of the barcode from the positioning image; when the size is less than a preset value, trigger the image collector to enlarge the preview image and obtain the target format data of the enlarged preview image; when the size is greater than or equal to the preset value, trigger the image collector to re-acquire the target format data of the preset image.
[0030] Optionally, the device is also used to: change the color RGB three-channel data of the training set into single-channel grayscale image data to obtain a target training set; based on the target training set and the verification set, train a convolutional neural network model to obtain the barcode detection model.
[0031] In a third aspect, the present application provides an electronic device, the electronic device comprising:
[0032] Memory, used to store computer programs;
[0033] The processor is used to implement the above-mentioned barcode detection and recognition method steps when executing the computer program stored in the memory.
[0034] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned barcode detection and recognition method steps are implemented.
[0035] For each aspect from the second to the fourth aspect and the technical effects that may be achieved by each aspect, please refer to the technical effects that can be achieved by the first aspect or the various possible solutions in the first aspect, and no further details will be given here. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings are included to provide a further understanding of the present application. They are included and constitute a part of the present application. The accompanying drawings illustrate embodiments of the present application and together with the present specification serve to explain the principles of the present application. In the accompanying drawings:
[0037] Figure 1 It is a flow chart of a training method of a barcode detection model provided by the present application;
[0038] Figure 2 It is a flow chart of a barcode detection and recognition method provided by the present application;
[0039] Figure 3 It is a schematic diagram of a barcode detection and recognition device provided by the present application;
[0040] Figure 4 It is a schematic diagram of the structure of an electronic device provided by the present application. DETAILED DESCRIPTION
[0041] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for the description of the embodiments. Obviously, the drawings described below are only some examples or embodiments of the present application. For ordinary technicians in this field, the present application can also be applied to other similar scenarios based on these drawings without creative work. Unless it is obvious from the language environment or otherwise explained, the same reference numerals in the figures represent the same structure or operation.
[0042] As shown in this application and claims, unless the context clearly indicates an exception, the words "a", "an", "an" and / or "the" do not refer to the singular and may also include the plural. Generally speaking, the terms "include" and "comprise" only indicate the inclusion of the steps and elements that have been clearly identified, and these steps and elements do not constitute an exclusive list. The method or device may also include other steps or elements.
[0043] Unless otherwise specifically stated, the relative arrangement, numerical expressions and numerical values of the parts and steps set forth in these embodiments do not limit the scope of the present application. At the same time, it should be understood that, for ease of description, the sizes of the various parts shown in the accompanying drawings are not drawn according to the actual proportional relationship. The technology, method and equipment known to those of ordinary skill in the relevant field may not be discussed in detail, but in appropriate cases, the technology, method and equipment should be considered as a part of the authorization specification. In all examples shown and discussed here, any specific value should be interpreted as being merely exemplary, rather than as a limitation. Therefore, other examples of exemplary embodiments may have different values. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so that once a certain item is defined in an accompanying drawing, it does not need to be further discussed in subsequent drawings.
[0044] Flowcharts are used in the present application to illustrate the operations performed by the system according to the embodiments of the present application. It should be understood that the preceding or following operations are not necessarily performed accurately in order. On the contrary, various steps may be processed in reverse order or simultaneously. At the same time, other operations may be added to these processes, or one or more operations may be removed from these processes.
[0045] Some of the terms used in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.
[0046] YOLOv5n: YOLOv5 is a popular object detection algorithm and the fifth generation of the YOLO (You Only Look Once) series. YOLOv5 is known for its speed and efficiency, and is particularly suitable for real-time object detection tasks. YOLOv5n is a lightweight version of the YOLOv5 series, which achieves efficient object detection capabilities by reducing the number of model parameters and computing resource requirements.
[0047] YUV: YUV is a color encoding method that separates brightness information (Y) from chrominance information (U and V). "Y" stands for brightness (Luminance or Luma), and "U" and "V" stand for chrominance (Chrominance or Chroma), which are used to describe the color and saturation of the image. This separation makes the YUV format particularly suitable for video compression and transmission because it allows subsampling of chrominance information, thereby reducing the amount of data.
[0048] ROI (Region of Interest): In machine vision and image processing, it refers to the area to be processed that is outlined in the image being processed in the form of a box, circle, ellipse, irregular polygon, etc. ROI is an important concept in image processing and is used to specify a specific part of an image that requires special attention or processing.
[0049] See also Figure 1 As shown, the embodiment of the present application provides a method for training a barcode detection model, and the specific process is as follows:
[0050] Step 101: collecting multiple barcode sample images of multiple code systems;
[0051] Specifically, the multiple code systems include about 30 mainstream code systems, including one-dimensional codes: EAN-8, EAN-13, UPC-A, UPC-E, Codabar, Code39, Code93, Code128, ISBN10, ISBN13, ISSN, GS1 DataBar, GS1DataBar Expanded, Interleaved 2of 5, etc., and two-dimensional codes: QR Code, MicroQR, PDF417, MicroPDF417, DataMatrix, AZTEC, Hanxin, Grid Matri, Maxicode, DotCode, etc.
[0052] Multiple barcode sample images of each code system are collected. In the embodiment of the present application, a total of 10W barcode sample images are collected.
[0053] Step 102: marking the barcode position in each barcode sample image, and processing the coordinates of each barcode position according to a set format to obtain each barcode marked image;
[0054] Use the annotation tool to annotate the position of the barcode in each barcode sample image, and normalize the coordinates of each barcode position relative to the width and height of the image to a floating point number between 0 and 1 according to a set format, such as the format required by YOLOv5, to obtain each barcode annotated image after processing.
[0055] Step 103: adding corresponding category identifiers to the barcodes in each barcode annotation image according to a preset classification rule to obtain each barcode classification image;
[0056] First, according to the type of barcode in each barcode annotated image, all barcode annotated images are divided into one-dimensional code images and two-dimensional code images. Since the structural features of one-dimensional codes are similar, all one-dimensional code images are divided into the same category, and a first category identifier is added to the one-dimensional code image, which is represented by ID number 0.
[0057] For the remaining two-dimensional code images, the two-dimensional code images are divided into N categories according to the coding structure of the barcode in each two-dimensional code image, where N is an integer greater than 1, and different category identifiers are added to each category of two-dimensional code images to obtain two-dimensional code samples. For example, the two-dimensional code images of the above-mentioned multiple code systems can be divided into 8 categories, namely ID No. 1: QR Code and MicroQR; ID No. 2: PDF417 and MicroPDF417; ID No. 3: DataMatrix; ID No. 4: AZTEC; ID No. 5: Hanxin; ID No. 6: GridMatri; ID No. 7: Maxicode; ID No. 8: DotCode.
[0058] The one-dimensional code samples and two-dimensional code samples with added category identification are used as barcode classification images.
[0059] Step 104: The barcode classification images of each code system are aggregated into a training set and a validation set according to a set ratio;
[0060] The number of barcode classification images of various symbol systems is counted respectively, and the barcode classification images of each symbol system are aggregated into the training set and the validation set according to a preset ratio, such as 8:2. The number of barcode classification images of different symbol systems may be different, but they are all allocated to the training set and the validation set according to the same ratio.
[0061] Step 105: Based on the training set and the validation set, the convolutional neural network model is trained to obtain a barcode detection model.
[0062] Based on the training set and the validation set, the convolutional neural network model is trained. In the embodiment of the present application, the convolutional neural network model adopts the YOLOv5n model, and the image size of the training set is set to 320. In order to reduce the amount of calculation, the color RGB three-channel data of the training set image (i.e., RGB three-channel input) is changed to single-channel grayscale image data (i.e., 256-color grayscale image data) to obtain the target training set.
[0063] The convolutional neural network model is trained using the target training set and validation set. When the training results reach the expected results, such as the overall average accuracy of the validation set exceeds 90%, the barcode detection model is obtained. It should be noted that the barcode detection model can be converted into a format suitable for other frameworks such as NCNN (Neural Network Computation Library), ONNX (Open Neural Network Exchange), TensorRT (Turing Tensor R-Engine, deep learning inference optimizer), etc. as needed.
[0064] The training of the above barcode detection model reduces the amount of calculation by changing the RGB three channels of the training image to single-channel grayscale image data, and divides all one-dimensional codes into one category, and divides two-dimensional codes into multiple categories according to the coding structure, thereby improving the training speed and detection efficiency of the model.
[0065] Based on the above barcode detection model, this application implements a method for barcode detection and recognition, see Figure 2 As shown, the specific process is as follows:
[0066] Step 201: Based on the image collector, obtain the target format data of the preview image;
[0067] The image collector can be, but is not limited to, a camera. When the image collector is a camera, the camera resolution is preset according to the support of different devices, such as 1280×720 or 640×480. The target format data of the preview image is obtained through the image collector. In this application, the target format data is YUV format data. In order to reduce the amount of calculation, only the Y component data is used to input the barcode detection model.
[0068] Step 202: input the target format data into the pre-trained barcode detection model to obtain the detection result;
[0069] The target format data is input into the trained barcode detection model to obtain the detection result. In the embodiment of the present application, the detection result includes the number of detected barcodes, the category identification of the barcode, the position coordinates of the four corner points of the barcode, and the confidence of the barcode.
[0070] Step 203: When there is a barcode in the detection result, obtain the positioning image of the barcode based on the barcode position in the detection result, and obtain the category identifier of the barcode from the detection result;
[0071] In a possible implementation manner, when there is a barcode in the detection result, that is, when the barcode is detected, based on the barcode position in the detection result, that is, the coordinate positions of the four corner points of the barcode, obtain the positioning image of the barcode. The positioning image is the ROI region containing the barcode. And obtain the category identifier of the barcode from the detection result, that is, the ID number.
[0072] Step 204: Decode the barcode according to the positioning image and the category identifier.
[0073] According to the detected ROI region containing the barcode and the category identifier of the barcode, the decoding module can be directly called to decode the barcode. For the decoding of two-dimensional codes, first detect the positioning image, such as the three "回" - shaped graphics of QR codes, and detect the "L" - shaped for DataMatrix codes, etc. Then accurately locate the position of each module of the barcode and sample (the value corresponding to each unit module is black or white, represented by 0 and 1). Finally, obtain the codeword stream data according to the coding rules for error correction and decoding. For one - dimensional codes, since the barcode detection model classifies one - dimensional codes of different code systems into the same category, the post - process needs to confirm the decoding. The bar - space direction of the current barcode region can be judged according to the feature of gradient consistency, and then the bar - space information of the barcode is extracted. Whether it conforms to a specific code system is judged according to different barcode coding rules and decoded.
[0074] In a possible implementation manner, when there is no barcode in the detection result, perform image brightness detection on the preview image, and judge whether the image brightness meets the preset requirements. If the image brightness of the preview image does not meet the preset requirements, turn on the fill light of the image collector or adjust the exposure parameters of the image collector to increase the image brightness of the preview image. For example, the average gray value AG of the image data sampled at 1 / 4 of the original image (sampling every other row or column) can be used as the judgment standard for image brightness. When AG is less than the preset value TB (default 64), it indicates that the image brightness does not meet the preset requirements. At this time, the fill light can be turned on or the exposure parameters can be adjusted according to the need to increase the image brightness. Then, based on the image collector with the fill light turned on or the exposure parameters adjusted, re - obtain the target format data of the preview image.
[0075] In a possible implementation manner, when there are multiple barcodes in the detection result, sort them in ascending order according to the distance between the center position of each barcode and the center position of the preview image to obtain the positioning images of each barcode, that is, the ROI regions of each barcode. Decode the barcodes in each positioning graphic in this ascending order.
[0076] This application optimizes the use of computing resources and reduces the reliance on high-performance hardware by combining convolutional neural networks (CNNs) with traditional methods. Fast barcode detection using lightweight CNNs reduces the need for complex calculations; accurate recognition is then performed using traditional methods, reducing the overall system's computing burden and enabling it to run efficiently on devices with limited hardware resources.
[0077] Further, after decoding the barcode according to the positioning image and the category identifier, it is determined whether the decoding is successful. If the decoding is successful, the process ends. If the decoding fails, it is detected whether the preview image is blurred.
[0078] To check whether the preview image is blurred, you can apply Laplace transform to the preview image and calculate the variance LD of the transform result. The larger the variance, the clearer the image, and the smaller the variance, the blurrier the image. Set the preset value LT according to your needs. When LD is less than the preset value LT, it indicates that the preview image is blurred.
[0079] If the preview image is blurred, the image collector is triggered to refocus, with the focus position being the center position of the first barcode (when multiple barcodes are detected), and the target format data of the preview image is reacquired.
[0080] If the preview image is not blurred and LD is greater than or equal to the preset value LT, the size of the barcode is obtained from the positioning image, for example, the width W and height H of the barcode area size are obtained according to the ROI area position, and it is determined whether the size is less than the preset value, such as whether W×H is less than the preset value AT.
[0081] When the size is smaller than the preset value, the image collector is triggered to enlarge the preview image and obtain the target format data of the enlarged preview image. It is worth noting that the enlargement process is different according to the hardware and software of different devices. If the device supports optical zoom or digital zoom, the preview image can be enlarged using the corresponding interface. If it is a fixed-focus camera, the RIO area image needs to be interpolated. The magnification can be adjusted as needed, generally 2 times or 4 times. It should be noted that the magnification must not exceed the boundary of the preview image, otherwise it will not be enlarged or the magnification will be reduced.
[0082] When the size is greater than or equal to the preset value, the image collector is triggered to re-acquire the target format data of the preset image.
[0083] This application automatically adjusts the camera's imaging parameters such as optical zoom, exposure parameters, refocusing and fill light based on brightness detection and blur assessment, optimizes image quality, enhances recognition distance and depth of field, and improves recognition rate in complex scenes.
[0084] Furthermore, in order to improve the efficiency of the entire recognition process, the present application can use multi-threaded processing of barcode detection, ROI area prediction and imaging parameter adjustment and barcode decoding to improve the efficiency of the entire recognition process and reduce processing time.
[0085] Based on the same inventive concept, the present application also provides a barcode detection and recognition device to improve the barcode detection efficiency and barcode recognition accuracy, see Figure 3 As shown, the device comprises:
[0086] The acquisition module 301 is used to acquire the target format data of the preview image based on the image collector;
[0087] The detection module 302 is used to input the target format data into a pre-trained barcode detection model to obtain a detection result;
[0088] The acquisition module 303 is used to obtain a positioning image of the barcode according to the position of the barcode in the detection result when there is a barcode in the detection result, and obtain the category identification of the barcode from the detection result;
[0089] The decoding module 304 is used to decode the barcode according to the positioning image and the category identifier.
[0090] Optionally, the device is also used to: collect multiple barcode sample images of multiple code systems; mark the barcode position in each barcode sample image, and process the coordinates of each barcode position according to a set format to obtain each barcode marked image; add corresponding category identifiers to the barcodes in each barcode marked image according to preset classification rules to obtain each barcode classification image; summarize the barcode classification images of each code system into a training set and a verification set according to a set ratio; based on the training set and the verification set, train the convolutional neural network model to obtain a barcode detection model.
[0091] Optionally, the device is also used to: divide all barcode annotated images into one-dimensional code images and two-dimensional code images according to the type of barcode in each barcode annotated image; add a first category identifier to the one-dimensional code image to obtain a one-dimensional code sample; divide the two-dimensional code image into N categories according to the encoding structure of the barcode in each two-dimensional code image, and add different category identifiers to each category of two-dimensional code image to obtain a two-dimensional code sample, wherein N is an integer greater than 1; and use the one-dimensional code sample and the two-dimensional code sample as barcode classification images.
[0092] Optionally, the device is also used to: when there is no barcode in the detection result, perform image brightness detection on the preview image; if the image brightness of the preview image does not meet preset requirements, turn on the fill light of the image collector or adjust the exposure parameters of the image collector; and re-acquire the target format data of the preview image based on the image collector.
[0093] Optionally, the device is also used to: when there are multiple barcodes in the detection results, sort the barcodes from small to large according to the distance between the center position of each barcode and the center position of the preview image to obtain the positioning image of each barcode; and decode the barcodes in each positioning image in order from small to large.
[0094] Optionally, the device is also used to: when barcode decoding fails, detect whether the preview image is blurred; if the preview image is blurred, trigger the image collector to refocus and re-acquire the target format data of the preview image; if the preview image is not blurred, obtain the size of the barcode from the positioning image; when the size is less than a preset value, trigger the image collector to enlarge the preview image and obtain the target format data of the enlarged preview image; when the size is greater than or equal to the preset value, trigger the image collector to re-acquire the target format data of the preset image.
[0095] Optionally, the device is also used to: change the color RGB three-channel data of the training set into single-channel grayscale image data to obtain a target training set; based on the target training set and the verification set, train the convolutional neural network model to obtain a barcode detection model.
[0096] Based on the same inventive concept, an electronic device is also provided in the embodiment of the present application, and the electronic device can realize the functions of the aforementioned barcode detection and recognition device, referring to Figure 4 , the electronic device comprises:
[0097] At least one processor 401, and a memory 402 connected to the at least one processor 401. The specific connection medium between the processor 401 and the memory 402 is not limited in the embodiment of the present application. Figure 4 In the example, the processor 401 and the memory 402 are connected via the bus 400. The bus 400 is Figure 4 The connection between other components is shown by bold lines, and is not intended to be limiting. The bus 400 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. Alternatively, the processor 401 can also be called a controller, and there is no limitation on the name.
[0098] In the embodiment of the present application, the memory 402 stores instructions that can be executed by at least one processor 401. The at least one processor 401 can execute the barcode detection and recognition method discussed above by executing the instructions stored in the memory 402. The processor 401 can implement Figure 3 The functions of each module in the device shown.
[0099] Among them, the processor 401 is the control center of the device, and can use various interfaces and lines to connect the various parts of the entire control device. By running or executing instructions stored in the memory 402 and calling the data stored in the memory 402, the various functions of the device and process data, the device can be monitored as a whole.
[0100] In one possible design, the processor 401 may include one or more processing units, and the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 401. In some embodiments, the processor 401 and the memory 402 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.
[0101] Processor 401 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method for barcode detection and recognition disclosed in the embodiments of the present application can be directly embodied as a hardware processor to be executed, or a combination of hardware and software modules in the processor can be executed.
[0102] The memory 402 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 402 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 402 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 402 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0103] By programming the processor 401, the code corresponding to the barcode detection and recognition method described in the above embodiment can be fixed into the chip, so that the chip can execute the code when running. Figure 2 The steps of the barcode detection and recognition method of the embodiment shown are as follows: How to design and program the processor 401 is a technique known to those skilled in the art and will not be described in detail here.
[0104] Based on the same inventive concept, an embodiment of the present application further provides a storage medium, which stores computer instructions. When the computer instructions are executed on a computer, the computer executes the barcode detection and recognition method discussed above.
[0105] In some possible implementations, various aspects of the barcode detection and identification method provided in the present application can also be implemented in the form of a program product, which includes program code. When the program product is run on an apparatus, the program code is used to enable the control device to execute the steps of the barcode detection and identification method according to various exemplary embodiments of the present application described above in this specification.
[0106] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0107] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0108] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0109] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0110] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for barcode detection and recognition, characterized in that: The method comprises: Based on the image collector, obtain the target format data of the preview image; Inputting the target format data into a pre-trained barcode detection model to obtain a detection result; When a barcode exists in the detection result, a positioning image of the barcode is obtained according to the position of the barcode in the detection result, and a category identifier of the barcode is obtained from the detection result; The barcode is decoded according to the positioning image and the category identifier.
2. The method according to claim 1, characterized in that Before obtaining the target format data of the preview image based on the image collector, the method further includes: Collect multiple barcode sample images of various symbologies; Marking the barcode position in each barcode sample image, and processing the coordinates of each barcode position according to a set format to obtain each barcode marked image; For each barcode in the barcode annotation image, add corresponding category identifiers according to preset classification rules to obtain each barcode classification image; The barcode classification images of each code system are aggregated into training sets and validation sets according to the set ratio; Based on the training set and the validation set, a convolutional neural network model is trained to obtain the barcode detection model.
3. The method according to claim 2, characterized in that The barcodes in each barcode annotation image are respectively added with corresponding category identifiers according to preset classification rules to obtain each barcode classification image, including: According to the type of barcode in each barcode annotated image, all barcode annotated images are divided into one-dimensional code images and two-dimensional code images; Adding a first category identifier to the one-dimensional code image to obtain a one-dimensional code sample; According to the coding structure of the barcode in each two-dimensional code image, the two-dimensional code image is divided into N categories, and a different category identifier is added to each category of the two-dimensional code image to obtain a two-dimensional code sample, wherein N is an integer greater than 1; The one-dimensional code sample and the two-dimensional code sample are used as the barcode classification image.
4. The method according to claim 1, characterized in that The method further comprises: When there is no barcode in the detection result, performing image brightness detection on the preview image; If the image brightness of the preview image does not meet the preset requirement, turning on the fill light of the image collector or adjusting the exposure parameters of the image collector; Based on the image collector, target format data of the preview image is acquired again.
5. The method according to claim 1, characterized in that The method further comprises: When there are multiple barcodes in the detection result, the barcodes are sorted in ascending order according to the distance between the center position of each barcode and the center position of the preview image, to obtain a positioning image of each barcode; The barcodes in each positioning image are decoded in the order from small to large.
6. The method according to claim 1, characterized in that After decoding the barcode according to the positioning image and the category identifier, the method further includes: When the barcode decoding fails, detecting whether the preview image is blurred; If the preview image is blurred, triggering the image collector to refocus and reacquire the target format data of the preview image; If the preview image is not blurred, obtaining the size of the barcode from the positioning image; When the size is smaller than a preset value, the image collector is triggered to enlarge the preview image and obtain target format data of the enlarged preview image; When the size is greater than or equal to the preset value, the image collector is triggered to reacquire the target format data of the preset image.
7. The method according to claim 2, characterized in that The convolutional neural network model is trained based on the training set and the verification set to obtain the barcode detection model, including: The color RGB three-channel data of the training set is changed into single-channel grayscale image data to obtain a target training set; Based on the target training set and the verification set, a convolutional neural network model is trained to obtain the barcode detection model.
8. A barcode detection and recognition device, characterized in that: The device comprises: The acquisition module is used to acquire the target format data of the preview image based on the image collector; A detection module, used for inputting the target format data into a pre-trained barcode detection model to obtain a detection result; An acquisition module, for obtaining a positioning image of the barcode according to the position of the barcode in the detection result when there is a barcode in the detection result, and obtaining a category identifier of the barcode from the detection result; A decoding module is used to decode the barcode according to the positioning image and the category identifier.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to implement the method steps of any one of claims 1 to 7 when executing the computer program stored in the memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 7 are implemented.