Barcode recognition method and device, electronic equipment and readable storage medium

By performing differential operations and stability assessments on frame images in captured videos, the barcode region is determined and decoded, solving the problem of low barcode recognition accuracy in complex backgrounds and achieving higher decoding accuracy and computational efficiency.

CN120493967BActive Publication Date: 2025-11-28BEIJING MYSHER TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510983751.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-16
Publication Date
2025-11-28
Estimated Expiration
2045-07-16

AI Technical Summary

Technical Problem

When the shooting background is relatively complex, the accuracy of the barcode recognition methods proposed by the relevant technologies is low.

Method used

By performing a difference operation on adjacent first and second frame images in the captured video, a difference image is obtained. The stability of the video is determined based on the connected components of the difference image, and appropriate frame images are selected for difference operation to determine the barcode region. Decoding is then performed based on the length and width of the binarized region.

Benefits of technology

It improves the decoding accuracy of barcodes in complex backgrounds, reduces the consumption of computing resources, and is independent of the shooting angle and the orientation of the items.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120493967B_ABST
    Figure CN120493967B_ABST
Patent Text Reader

Abstract

The application provides a barcode recognition method and device, electronic equipment and readable storage medium, comprising: acquiring adjacent first frame image and second frame image in a shooting video including a barcode, and performing difference operation on the first frame image and the second frame image to obtain a first difference image, acquiring all connected domains of the first difference image, if the maximum connected domain in all connected domains occupies more than a first preset value of pixels, selecting an image from the remaining frame images of the shooting video as a third frame image, and performing difference operation on the third frame image and the second frame image to obtain a binary region containing the barcode in the third frame image, acquiring the length and width of the binary region, and determining the barcode region according to the length and width of the binary region, and decoding the barcode in the barcode region to obtain the information corresponding to the barcode, which can improve the accuracy of barcode recognition.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image recognition, and in particular to a barcode recognition method and device, an electronic device, and a computer readable storage medium. BACKGROUND

[0002] ‌Barcode recognition technology is to read the information in the barcode through a scanning device, and then recognize the content represented by the barcode. One-dimensional barcodes are the common barcode types in the market at present, and are commonly used on various production and living supplies for recording product information to facilitate identification and traceability.

[0003] The related technology uses a camera or a scanner to obtain a barcode image, then performs denoising and segmentation processing on the barcode image, determines the position and size of the barcode in the image, and finally converts the barcode image into corresponding digital or alphabetical information according to the coding rules of the barcode.

[0004] In the case of a complex shooting background, the method proposed by the related technology has a low accuracy in recognizing the barcode. SUMMARY

[0005] Embodiments of the present application provide a barcode recognition method and device, an electronic device, and a computer readable storage medium to solve the problems in the related art.

[0006] In a first aspect, the embodiments of the present application provide a barcode recognition method, which includes:

[0007] Obtaining a first frame image and a second frame image adjacent in a shooting video including a barcode, and performing difference operation on the first frame image and the second frame image to obtain a first difference image; the first difference image is used to represent the difference degree between the first frame image and the second frame image;

[0008] Obtaining all connected domains of the first difference image, if the largest connected domain in all connected domains occupies more than a first preset value of pixels, selecting one image from the remaining frame images of the shooting video as a third frame image, and performing difference operation on the third frame image and the second frame image to obtain a binary region containing a barcode in the third frame image;

[0009] Obtaining the length and width of the binary region, determining a barcode region according to the length and width of the binary region, and decoding the barcode in the barcode region to obtain the information corresponding to the barcode.

[0010] In a second aspect, the embodiments of the present application provide a barcode recognition device, which includes:

[0011] The first operation module is configured to acquire a first frame image and a second frame image adjacent to each other in the photographed video comprising the barcode, and perform difference operation on the first frame image and the second frame image to obtain a first difference image; the first difference image is configured to represent a difference degree between the first frame image and the second frame image.

[0012] The second operation module is configured to acquire all connected domains of the first difference image, and if a maximum connected domain in all connected domains occupies more than a first preset value of pixels, select one image from the remaining frame images of the photographed video as a third frame image, and perform difference operation on the third frame image and the second frame image to obtain a binarization region comprising the barcode in the third frame image.

[0013] The first decoding module is configured to acquire a length and a width of the binarization region, determine a barcode region according to the length and the width of the binarization region, and decode the barcode in the barcode region to obtain information corresponding to the barcode.

[0014] In a third aspect, an electronic device is provided, comprising a processor, a memory for storing instructions executable by the processor, and wherein the processor is configured to execute the instructions to implement the method of the first aspect.

[0015] In a fourth aspect, a computer readable storage medium is provided, and when instructions in the computer readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the method of the first aspect.

[0016] In the embodiments of the present application, the first frame image and the second frame image adjacent to each other in the photographed video comprising the barcode are acquired, and difference operation is performed on the first frame image and the second frame image to obtain a first difference image. If the maximum connected domain in all connected domains of the first difference image occupies more than a first preset value of pixels, it indicates that the photographed video is relatively stable, then one image is selected from the remaining frame images of the photographed video as a third frame image, and difference operation is performed on the third frame image and the second frame image to obtain a binarization region comprising the barcode in the third frame image. By using the second frame image in the last stable video as a background frame image, repeated calculation can be avoided, and the occupancy rate of computing resources can be reduced. According to the length and the width of the binarization region, a barcode region is determined, and the barcode in the barcode region is decoded to obtain information corresponding to the barcode. The present application obtains the barcode region by performing operation on three frame images in the photographed video, so that in the case that the background of the photographed video is relatively complex, a relatively complete barcode region can be obtained without depending on the shooting angle and the placement direction of the object, thereby improving the accuracy of decoding when decoding the barcode.

[0017] The above description is only a summary of the technical solutions of the present application. In order to make the technical means of the present application more clear and complete, and in order to make the above and other purposes, characteristics and advantages of the present application more obvious and easy to understand, the following specific embodiments of the present application are described. BRIEF DESCRIPTION OF DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments description. Obviously, the drawings in the following description are only some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor.

[0019] Figure 1 is a step flow chart of a bar code recognition method provided by the embodiments of the present application;

[0020] Figure 2 is a schematic diagram of a frame image provided by the embodiments of the present application;

[0021] Figure 3 is a specific step flow chart of a bar code recognition method provided by the embodiments of the present application;

[0022] Figure 4 is a step flow chart of another bar code recognition method provided by the embodiments of the present application;

[0023] Figure 5 is a step flow chart of another bar code recognition method provided by the embodiments of the present application;

[0024] Figure 6 is a block diagram of a bar code recognition device provided by the embodiments of the present application;

[0025] Figure 7 is a block diagram of an electronic device provided by the embodiments of the present application;

[0026] Figure 8 is a block diagram of another electronic device provided by the embodiments of the present application. DETAILED DESCRIPTION

[0027] The technical solutions in the embodiments of the present application will be described clearly and completely in the following with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.

[0028] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than that illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally a class and do not limit the number of objects, for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims is used to describe the relationship between the associated objects, which means that there can be three relationships, for example, A and / or B, which means that there are three cases of A alone, A and B together, and B alone. The character " / " generally represents an "or" relationship between the associated objects. The term "multiple" in the embodiments of the present application means two or more, and other quantifiers are similar.

[0029] Figure 1 is a step flow chart of a bar code recognition method provided by the embodiments of the present application, as shown in Figure 1 , the method can include:

[0030] Step 101, acquiring adjacent first frame image and second frame image in the shooting video including bar code, and performing difference operation on the first frame image and the second frame image to obtain a first difference image; the first difference image is used to represent the difference between the first frame image and the second frame image.

[0031] In examples, the shooting video in the present application does not depend on the angle and direction of shooting, and does not depend on the direction of the bar code. For example, referring to the image 20 in Figure 2 , Figure 2 includes: article 21, article 22 and article 23. Each of the articles contains XXX, and the direction of XXX is different, and XXX represents a bar code. Article 21 contains bar code 211, which is vertical, article 22 contains bar code 221, which is horizontal, and article 23 contains bar code 231, which is inclined. The article can be a medicine box or a commodity with a bar code.

[0032] In examples, the difference operation detects the moving target by comparing the pixel difference between the adjacent frame images in the shooting video, which is simple and efficient, and is suitable for scenes with high real-time requirements. Specifically, by converting the first frame image and the second frame image into a first gray image and a second gray image, then subtracting the pixel value of the pixel point in the first gray image from the pixel value of the corresponding pixel point in the second gray image, and taking the absolute value of the subtraction result as the pixel value of the corresponding pixel point in the first difference image, the first difference image is constructed.

[0033] For example, the first difference image is used to represent the difference between the first frame image and the second frame image, and the difference is used to reflect the stability of the video. Whether the video is stable can be determined by analyzing the pixel size of the complete edge in the first difference image. If the video is stable, the edge pixels in the first difference image should be less and uniformly distributed, and if the video is not stable (such as shaking or rapid motion), the edge pixels in the first difference image will be more and concentrated. Specifically, a statistical quantity of the first difference image is calculated, and when the statistical quantity of the first difference image exceeds a threshold value, it is considered that the video is not stable, otherwise it is considered that the video is stable. For example, the statistical quantity can be the pixel size of the complete edge of the first difference image, and the threshold value is 100. If the pixel size of the complete edge of the first difference image is greater than 100, it is considered that the video is not stable, otherwise it is considered that the video is stable.

[0034] In step 102, all connected domains of the first difference image are obtained, and if the largest connected domain in all connected domains occupies more than a first preset value of pixels, one image is selected from the remaining frame images of the video as a third frame image, and the third frame image is subjected to difference operation with the second frame image to obtain a binary region containing a barcode in the third frame image.

[0035] For example, the connected domain of an image refers to a region composed of pixels with the same pixel value and adjacent positions in the image. The findContours function of OpenCV is called to obtain all connected domains of the first difference image, and then the pixel size of the largest connected domain in all connected domains, i.e. the pixel occupied by the connected domain, is obtained. Taking 100 as the first preset value, if the largest connected domain in all connected domains occupies more than 100 pixels, it is considered that the video is stable.

[0036] For example, in the case of stable video, one image is selected from the remaining frame images of the video as a third frame image. Specifically, the frame image after the second frame image can be taken as the third frame image, and the second frame image is determined as a background frame image for judging whether the video before and after the stable video is the same, which can avoid repeated calculation. By modeling the background, the current frame image is compared with the background frame image to separate the moving target.

[0037] For example, after determining the third frame image, the third frame image is subjected to difference operation with the second frame image to obtain a binary region containing a barcode in the third frame image. Specifically, the third frame image is subjected to difference operation with the second frame image to obtain a second difference image, and whether there is a difference between the third frame image and the second frame image is judged. If there is a difference, it means that there is a moving region in the video, and the moving region needs to be cropped to obtain a binary region containing a barcode. If there is no difference, it means that there is no moving target in the video, and the barcode image can be cropped.

[0038] In step 103, the length and width of the binarized region are obtained, and a barcode region is determined according to the length and width of the binarized region, and a barcode in the barcode region is decoded to obtain information corresponding to the barcode.

[0039] For example, the barcode is usually rectangular or approximately rectangular. The aspect ratio of the barcode is usually within a certain range, for example, 2:1 to 5:1. The area of the barcode depends on the image resolution and the actual size of the barcode. The edge of the barcode is usually clear and complete. Because the barcode has the above characteristics, the findContours function of OpenCV can be used to detect the binarized region. According to the shape and size of the binarized region, the region most likely representing the barcode is determined according to the geometric characteristics of the binarized region, such as area, aspect ratio, and rectangularity.

[0040] For example, after obtaining the barcode region, the barcode in the barcode region is decoded by using zbar and zxing to obtain information corresponding to the barcode. The use of zbar and zxing to decode the barcode in the barcode region can improve the accuracy of barcode recognition and can achieve more comprehensive barcode detection.

[0041] In summary, in the embodiment of the present application, the first frame image and the second frame image adjacent to the captured video including the barcode are obtained, and the first frame image and the second frame image are subjected to difference operation to obtain a first difference image. If the largest connected domain in all connected domains of the first difference image occupies more than a first preset value of pixels, it indicates that the captured video is relatively stable, then a third frame image is selected from the remaining frame images of the captured video, and the third frame image and the second frame image are subjected to difference operation to obtain a binarized region containing the barcode in the third frame image. By using the second frame image in the last stable video as a background frame image, repeated calculation can be avoided, and the occupancy rate of computing resources can be reduced. According to the length and width of the binarized region, a barcode region is determined, and a barcode in the barcode region is decoded to obtain information corresponding to the barcode. By operating three frame images in the captured video, the barcode region is obtained. In the case that the background of the captured video is relatively complex, a complete barcode region can be obtained without relying on the shooting angle and the placement direction of the object, thereby improving the accuracy of decoding when decoding the barcode.

[0042] Figure 3 is a specific step flowchart of a barcode recognition method provided by the embodiment of the present application, as shown in Figure 3 The method can include:

[0043] In step 201, adjacent first and second frame images in a video image including a barcode are obtained, and the first frame image is converted into a first gray image, and the second frame image is converted into a second gray image.

[0044] In an example, after reading the video frame image using OpenCV, the first and second frame images are obtained, and the first frame image is converted into a first gray image, and the second frame image is converted into a second gray image, which can reduce the amount of calculation.

[0045] In step 202, edge extraction is performed on the first gray image to obtain a first edge image, and edge extraction is performed on the second gray image to obtain a second edge image.

[0046] In an example, edge extraction is used to identify regions in an image where the brightness changes significantly, which usually correspond to the edges of objects. Edges are places in an image where the brightness changes significantly, usually corresponding to the boundaries or texture changes of objects. The core of edge extraction is to calculate the gradient of the image, that is, the rate of change of pixel value. Places with large gradients usually correspond to edges.

[0047] Optionally, step 202 can specifically include:

[0048] In sub-step 2021, a first convolution kernel in the horizontal direction and a second convolution kernel in the vertical direction are obtained.

[0049] In sub-step 2022, the first and second convolution kernels are respectively used to convolve the first gray image to obtain a first gradient matrix of the first gray image.

[0050] In sub-step 2023, the first and second convolution kernels are respectively used to convolve the second gray image to obtain a second gradient matrix of the second gray image.

[0051] In sub-step 2024, the first and second gradient matrices are respectively binarized to obtain the first and second edge images.

[0052] For sub-steps 2021-2024, the first convolution kernel in the horizontal direction is used to detect the horizontal edges in the image. The second convolution kernel in the vertical direction is used to detect the vertical edges in the image. By reasonably selecting the first convolution kernel in the horizontal direction and the second convolution kernel in the vertical direction for edge extraction, the edge information in the image can be effectively extracted.

[0053] For example, the first grayscale image is convolved by using the first convolution kernel and the second convolution kernel to obtain a first gradient matrix of the first grayscale image, and the second grayscale image is convolved by using the first convolution kernel and the second convolution kernel to obtain a second gradient matrix of the second grayscale image. The present application calculates the gradients of the image in the horizontal and vertical directions through convolution, which is simple and fast.

[0054] Optionally, the sub-step 2024 can specifically include:

[0055] The sub-step 20241 calculates a first average value of the gradient values in the first gradient matrix and a second average value of the gradient values in the second gradient matrix.

[0056] The sub-step 20242 modifies the gradient value in the first gradient matrix to a first pixel value representing white if the gradient value is greater than the first average value multiplied by a second preset value, and modifies the gradient value to a second pixel value representing black if the gradient value is less than or equal to the first average value multiplied by the second preset value.

[0057] The sub-step 20243 modifies the gradient value in the second gradient matrix to the first pixel value representing white if the gradient value is greater than the second average value multiplied by the second preset value, and modifies the gradient value to the second pixel value representing black if the gradient value is less than or equal to the second average value multiplied by the second preset value.

[0058] The sub-step 20244 generates the first edge image and the second edge image according to the first pixel value and the second pixel value.

[0059] For the sub-step 20241 to the sub-step 20244, the first edge image and the second edge image are both binary images, in which the pixel points are assigned two extreme gray values: 0 (black) or 255 (white). This processing method makes the image show obvious black and white effect, which is convenient for subsequent image analysis and processing. The first pixel value can be 255, and the second pixel value can be 0.

[0060] For example, the first average value is obtained by summing and averaging the gradient values in the first gradient matrix, and the second average value is obtained by summing and averaging the gradient values in the second gradient matrix.

[0061] Taking the second preset value 1.8 as an example, if the gradient value in the first gradient matrix is greater than the first average value multiplied by 1.8, the gradient value is modified to 255, and if the gradient value in the first gradient matrix is less than or equal to the first average value multiplied by 1.8, the gradient value is modified to 0. If the gradient value in the second gradient matrix is greater than the second average value multiplied by 1.8, the gradient value is modified to 255, and if the gradient value in the second gradient matrix is less than or equal to the second average value multiplied by 1.8, the gradient value is modified to 0. After the gradient values in the first gradient matrix are modified, the first edge image composed of the modified gradient values is obtained, and after the gradient values in the second gradient matrix are modified, the second edge image composed of the modified gradient values is obtained.

[0062] In step 203, a first pixel difference value of a pixel point in the first edge image and a corresponding pixel point in the second edge image is calculated, and a first difference image is constructed according to an absolute value of the first pixel difference value.

[0063] For example, after the first edge image and the second edge image are obtained, a first pixel difference value of a pixel point in the first edge image and a corresponding pixel point in the second edge image is calculated, and an absolute value of the first pixel difference value is taken as a pixel value of a corresponding pixel point in the first difference image, so as to construct the first difference image.

[0064] In step 204, all connected domains of the first difference image are obtained, and if a largest connected domain in all connected domains occupies more than a first preset value of pixels, one image is selected from the remaining frame images of the photographed video as a third frame image, and a difference operation is performed between the third frame image and the second frame image to obtain a binaryzation region containing a bar code in the third frame image.

[0065] This step can refer to the above-mentioned step 102, and will not be described in detail here.

[0066] Optionally, step 204 can specifically include:

[0067] In sub-step 2041, an image adjacent to the second frame image is taken as the third frame image, or one image is randomly selected from the remaining frame images of the photographed video as the third frame image.

[0068] For example, the image adjacent to the second frame image can be taken as the third frame image. Compared with the frame image after the second frame image, the third frame image has the shortest frame interval time difference with the second frame image.

[0069] In an example, one image can be randomly selected from the rest of the images of the video as the third image. After the video is stabilized, the barcode is detected only once. If the detected barcode is not successfully decoded, the barcode is decoded for each of the following images, which can greatly reduce the influence of the barcode reflection on the barcode recognition.

[0070] Optionally, step 204 can further include:

[0071] Sub-step 2042, performing edge extraction on the third grayscale image corresponding to the third image to obtain a third edge image, and performing edge extraction on the second grayscale image corresponding to the second image to obtain a second edge image.

[0072] Sub-step 2043, calculating a second pixel difference value of a pixel point in the third edge image and a corresponding pixel point in the second edge image, and constructing a second difference image according to an absolute value of the second pixel difference value.

[0073] Sub-step 2044, obtaining a coordinate of a pixel point of a connected domain of the second difference image, generating a minimum circumscribed rectangle of the connected domain according to the coordinate of the pixel point of the connected domain, and taking the minimum circumscribed rectangle as the binarization region containing the barcode.

[0074] For sub-step 2042 to sub-step 2044, the third image is converted into a third grayscale image, and edge extraction is performed on the third grayscale image to obtain a third edge image. The second image is converted into a second grayscale image, and edge extraction is performed on the second grayscale image to obtain a second edge image. After the third edge image and the second edge image are obtained, a second pixel difference value of a pixel point in the third edge image and a corresponding pixel point in the second edge image is calculated, and an absolute value of the second pixel difference value is taken as a pixel value of a corresponding pixel point in a second difference image to construct the second difference image.

[0075] For example, after obtaining the second difference image, it is determined whether there is a difference between the third frame image and the second frame image according to the second difference image. If there is a difference, the motion region is cropped. Specifically, the minimum circumscribed rectangle of all motion regions is calculated for the second difference image obtained by difference, and the minimum circumscribed rectangle is taken as the binarization region containing the barcode. For example, the findContours function of OpenCV is called to obtain the pixel coordinate values of all connected domains of the second difference image, the coordinates of all connected domain pixels are merged, and then the boundingRect function of OpenCV is called to calculate the coordinate values (min_x, min_y, width, height) of the motion region. The region of

min_x, min_y, width, height

[0076] Optionally, the method further comprises:

[0077] Step A, if the largest connected domain in all connected domains occupies less than the first preset value, then enter the step of obtaining the adjacent first frame image and the second frame image in the photographed video containing the barcode.

[0078] For example, taking 100 as the first preset value, if the largest connected domain in all connected domains occupies less than 100, it is considered that the photographed video is unstable. At this time, it is necessary to find the frame image again to determine the first frame image and the second frame image until the frame image that makes the photographed video stable is found.

[0079] Step 205, obtaining the length and width of the binarization region, and determining the barcode region according to the length and width of the binarization region, and decoding the barcode in the barcode region to obtain the information corresponding to the barcode.

[0080] This step can refer to the above-mentioned step 103 for details, and will not be described in detail here.

[0081] Optionally, step 205 can specifically include:

[0082] Sub-step 2051, dividing the length by the width to obtain an aspect ratio;

[0083] Sub-step 2052, calculating the area of the binarization region, and when the aspect ratio is in a first range and the area of the binarization region is in a second range, multiplying the length by the width, and dividing the area of the binarization region by the product of the length and the width to obtain a rectangular degree; the rectangular degree is used to represent the similarity degree of the binarization region and the rectangular region.

[0084] Sub-step 2053, when the rectangularity is greater than a third preset value, the binarized region is cropped to obtain the barcode region.

[0085] For sub-step 2051-sub-step 2053, after obtaining the length and width of the binarized region, the length is divided by the width to obtain the aspect ratio, and the area of the binarized region is calculated. Taking the first range of 2.0 to 5.0 as an example, and the second range of 1000 to 50000 as an example, when the aspect ratio is greater than 2.0 and less than 5.0, and the area of the binarized region is greater than 1000 and less than 50000, the length is multiplied by the width, and the area of the binarized region is divided by the product of the length and the width to obtain the rectangularity. When the rectangularity is greater than 0.7, the binarized region is cropped to obtain the barcode region. For example, the barcode region in the binarized region can be cropped by calling the warpAffine function of OpenCV.

[0086] Optionally, after step 205, the method further comprises:

[0087] Step 206, when the barcode image is incorrectly identified, the direction of the barcode image is obtained, and if the direction of the barcode image is vertical, the barcode image is adjusted to a horizontal barcode image; the direction of the barcode image is the arrangement direction of the barcodes in the barcode image.

[0088] Step 207, performing mean filtering on the horizontal barcode image to obtain a mean filtering image, and obtaining the enhanced image according to the comparison result of the pixel value of the pixel point in the mean filtering image and the pixel value of the corresponding pixel point in the horizontal barcode image.

[0089] Step 208, decoding the enhanced image to obtain information corresponding to the enhanced image.

[0090] For steps 206-208, incorrect identification means that the identified or decoded information does not conform to the drug traceability barcode specification. When the barcode image is incorrectly identified, the barcode image can be enhanced using an adaptive barcode enhancement algorithm, and then the enhanced barcode image can be decoded using zbar and zxing, which can reduce the influence of environmental factors on barcode identification and improve the accuracy of barcode image identification.

[0091] The one-dimensional barcode direction may not be horizontal, which may cause the cut-out barcode image to be vertical. Therefore, the direction of the barcode image needs to be adjusted to be horizontal to unify the direction of the barcode image. After adjusting the direction of the barcode image to be horizontal, the horizontal barcode image is subjected to mean filtering to obtain a mean filtering image. Mean filtering is to replace the value of each pixel in an image with the average value of the pixel and the pixels in the neighborhood of the pixel. Specifically, for each pixel in the image, a region (for example, a 3x3 or 5x5 region) around the pixel is taken, the average value of the pixel values is calculated, and then the average value is assigned to the center pixel. This processing makes the high-frequency information (such as edges and details) smooth, thereby achieving the effect of noise reduction and blurring.

[0092] After obtaining the mean filtering image, the enhanced image is obtained according to the comparison result of the pixel value of the pixel point in the mean filtering image and the pixel value of the corresponding pixel point in the horizontal barcode image, the enhanced image is decoded to obtain the information corresponding to the enhanced image, and the accuracy of barcode image recognition can be improved.

[0093] Optionally, step 207 can specifically include:

[0094] In sub-step 2071, if the difference between the pixel value of the pixel point of the horizontal barcode image and the pixel value of the corresponding pixel point in the mean filtering image is less than a fourth preset value, the pixel value of the corresponding pixel point of the enhanced image is modified to a second pixel value representing black.

[0095] In sub-step 2072, if the difference between the pixel value of the pixel point of the horizontal barcode image and the pixel value of the corresponding pixel point in the mean filtering image is greater than a fifth preset value, the pixel value of the corresponding pixel point of the enhanced image is modified to a first pixel value representing white.

[0096] In sub-step 2073, if the difference between the pixel value of the pixel point of the horizontal barcode image and the pixel value of the corresponding pixel point in the mean filtering image is greater than the fourth preset value and less than the fifth preset value, the difference is subjected to a division operation with the fifth preset value, and the result of the division operation is subjected to an addition operation with a sixth preset value to obtain an addition result, and the pixel value of the corresponding pixel point of the enhanced image is modified to the addition result.

[0097] For sub-step 2071-sub-step 2073, for example, the fourth preset value is -50, the fourth preset value is 50, the first pixel value is 255, and the second pixel value is 0. Referring to the following formula, if the difference between the pixel value f(x, y) of the horizontal barcode image pixel point and the pixel value s(x, y) of the corresponding pixel point in the mean filter image is less than -50, the pixel value g(x, y) of the corresponding pixel point in the enhanced image is modified to 0. If the difference between the pixel value f(x, y) of the horizontal barcode image pixel point and the pixel value s(x, y) of the corresponding pixel point in the mean filter image is greater than 50, the pixel value g(x, y) of the corresponding pixel point in the enhanced image is modified to 255. If the difference between the pixel value f(x, y) of the horizontal barcode image pixel point and the pixel value s(x, y) of the corresponding pixel point in the mean filter image is greater than -50 and less than 50, the difference is divided by 50, and the result of the division is added to 128 to obtain an addition result, and the pixel value g(x, y) of the corresponding pixel point in the enhanced image is modified to the addition result. The formula for obtaining the enhanced image from the horizontal barcode image and the mean filter image is as follows:

[0098]

[0099] wherein x represents the coordinate of the x-axis, y represents the coordinate of the y-axis, f(x, y) represents the pixel value corresponding to the pixel point with coordinates (x, y) in the horizontal barcode image, s(x, y) represents the pixel value corresponding to the pixel point with coordinates (x, y) in the mean filter image, and g(x, y) represents the pixel value corresponding to the pixel point with coordinates (x, y) in the enhanced image.

[0100] Optionally, after step 205, the method further comprises:

[0101] Step 209, when the barcode image is incorrectly identified, scaling the barcode image by a preset scaling factor to obtain a scaled barcode image;

[0102] Step 210, decoding the scaled barcode image to obtain information corresponding to the scaled barcode image.

[0103] For steps 209-210, incorrect identification refers to not identifying or decoding information that does not conform to the drug traceability barcode specification. When the barcode image is incorrectly identified, the barcode image can be scaled by a preset scaling factor to obtain a scaled barcode image, and the preset scaling factor can be [0.5:0.25:2]. Then, zbar and zxing are used to decode the scaled barcode image, which can achieve more comprehensive barcode detection and improve the accuracy of barcode image recognition.

[0104] In summary, in the embodiment of the present application, the first frame image and the second frame image adjacent in the shooting video including the bar code are obtained, and the first frame image and the second frame image are subjected to difference operation to obtain the first difference image. If the largest connected domain in all connected domains of the first difference image occupies more than the first preset value, it indicates that the shooting video is relatively stable, then one image is selected from the remaining frame images of the shooting video as the third frame image, and the third frame image and the second frame image are subjected to difference operation to obtain the binarization region containing the bar code in the third frame image. By using the second frame image in the last stable video as the background frame image, repeated calculation can be avoided, and the occupancy rate of the computing resources can be reduced. According to the length and width of the binarization region, the bar code region is determined, and the bar code in the bar code region is decoded to obtain the information corresponding to the bar code. The present application obtains the bar code region by operating three frame images in the shooting video, so that in the case of a relatively complex shooting background, a relatively complete bar code region can be obtained without depending on the shooting angle and the placement direction of the object, thereby improving the accuracy of decoding when decoding the bar code.

[0105] Figure 4 is a step flow chart of another bar code recognition method provided by the embodiment of the present application, referring to Figure 4 , the step can specifically include:

[0106] Step S1, obtaining the first frame image and the second frame image adjacent in the shooting video, and using the adjacent frame difference method for motion target detection;

[0107] Step S2, judging whether there is a motion target, if there is a motion target, jumping to step S1, otherwise jumping to step S3;

[0108] Step S3, using the background elimination method for motion target detection by taking the second frame image as a background frame image and the third frame image;

[0109] Step S4, judging whether there is a motion target, if there is a motion target, jumping to step S5, otherwise jumping to step S12;

[0110] Step S5, binarizing the image using a bar code segmentation model, and then accurately positioning the bar code image;

[0111] Step S6, judging whether the bar code image is correctly recognized, if the bar code image is correctly recognized, jumping to step S12, otherwise jumping to step S7;

[0112] Step S7, enhancing the bar code image using an adaptive bar code enhancement algorithm to obtain an enhanced image;

[0113] Step S8, using zbar and zxing to decode the enhanced image, to obtain the decoded information;

[0114] Step S9, judging whether the barcode image is recognized correctly, if the barcode image is recognized correctly, jumping to step S12, otherwise, jumping to step S10;

[0115] Step S10, using a scaling factor to scale the barcode image, to obtain the scaled barcode image;

[0116] Step S11, using zbar and zxing to decode the scaled barcode image, to obtain the decoded information;

[0117] Step S12, using zbar and zxing to decode the barcode image, to obtain the decoded information.

[0118] Figure 5 is a step flow chart of another barcode recognition method provided by the embodiment of the present application, referring to Figure 5 , the step specifically can include:

[0119] Step M1, acquiring a shooting video;

[0120] Step M2, performing motion target detection on a frame image in the shooting video, to obtain a motion region;

[0121] Step M3, detecting the motion region, to obtain a barcode region;

[0122] Step M4, cutting the barcode region, to obtain a barcode image;

[0123] Step M5, performing adaptive enhancement on the barcode image, to obtain an enhanced image, or performing scaling on the barcode image, to obtain a scaled barcode image;

[0124] Step M6, decoding the enhanced image or the scaled barcode image, to obtain information corresponding to the image.

[0125] Figure 6 is a block diagram of a barcode recognition device 30 provided by the embodiment of the present application, the device includes:

[0126] A first operation module 301 is configured to acquire a first frame image and a second frame image adjacent in a shooting video including a barcode, and perform difference operation on the first frame image and the second frame image, to obtain a first difference image; the first difference image is used to represent a difference degree between the first frame image and the second frame image;

[0127] The second operation module 302 is configured to acquire all connected domains of the first difference image, and if a largest connected domain in the all connected domains occupies more than a first preset value of pixels, select one image from the remaining frame images of the photographed video as a third frame image, and perform difference operation on the third frame image and the second frame image to obtain a binarization region containing the barcode in the third frame image.

[0128] The first decoding module 303 is configured to acquire the length and width of the binarization region, determine a barcode region according to the length and width of the binarization region, and decode the barcode in the barcode region to obtain information corresponding to the barcode.

[0129] Optionally, the first operation module comprises:

[0130] The first conversion submodule is configured to convert the first frame image into a first gray scale image and convert the second frame image into a second gray scale image.

[0131] The first edge extraction submodule is configured to perform edge extraction on the first gray scale image to obtain a first edge image and perform edge extraction on the second gray scale image to obtain a second edge image.

[0132] The first calculation submodule is configured to calculate a first pixel difference value of a pixel point in the first edge image and a corresponding pixel point in the second edge image, and construct a first difference image according to an absolute value of the first pixel difference value.

[0133] Optionally, the first edge extraction submodule comprises:

[0134] The first acquisition unit is configured to acquire a first convolution kernel in a horizontal direction and a second convolution kernel in a vertical direction.

[0135] The first convolution unit is configured to respectively perform convolution on the first gray scale image by using the first convolution kernel and the second convolution kernel to obtain a first gradient matrix of the first gray scale image.

[0136] The second convolution unit is configured to respectively perform convolution on the second gray scale image by using the first convolution kernel and the second convolution kernel to obtain a second gradient matrix of the second gray scale image.

[0137] The processing unit is configured to respectively perform binarization processing on the first gradient matrix and the second gradient matrix to obtain the first edge image and the second edge image.

[0138] Optionally, the processing unit comprises:

[0139] a calculating sub-unit, configured to calculate a first average value of gradient values in the first gradient matrix and a second average value of gradient values in the second gradient matrix;

[0140] a first modifying sub-unit, configured to modify the gradient value in the first gradient matrix to a first pixel value representing white if the gradient value is greater than the first average value multiplied by a second preset value, and modify the gradient value in the first gradient matrix to a second pixel value representing black if the gradient value is less than or equal to the first average value multiplied by the second preset value;

[0141] a second modifying sub-unit, configured to modify the gradient value in the second gradient matrix to the first pixel value representing white if the gradient value is greater than the second average value multiplied by the second preset value, and modify the gradient value in the second gradient matrix to the second pixel value representing black if the gradient value is less than or equal to the second average value multiplied by the second preset value;

[0142] a generating sub-unit, configured to generate the first edge image and the second edge image according to the first pixel value and the second pixel value.

[0143] Optionally, the second operation module comprises:

[0144] a second edge extraction sub-module, configured to perform edge extraction on a third gray-scale image corresponding to the third frame of image to obtain a third edge image, and perform edge extraction on a second gray-scale image corresponding to the second frame of image to obtain a second edge image;

[0145] a second calculating sub-module, configured to calculate a second pixel difference value between a pixel point in the third edge image and a corresponding pixel point in the second edge image, and construct a second difference image according to an absolute value of the second pixel difference value;

[0146] a generating sub-module, configured to obtain coordinates of pixel points of a connected domain of the second difference image, generate a minimum circumscribed rectangle of the connected domain according to the coordinates of the pixel points of the connected domain, and take the minimum circumscribed rectangle as the binarization region containing the barcode.

[0147] Optionally, the first decoding module comprises:

[0148] a third calculating sub-module, configured to divide the length by the width to obtain an aspect ratio;

[0149] a fourth calculating sub-module, configured to calculate an area of the binarization region, and when the length-width ratio is in a first range and the area of the binarization region is in a second range, multiply the length by the width, divide the area of the binarization region by the product of the length and the width to obtain a rectangular degree, wherein the rectangular degree is used to represent a similarity between the binarization region and a rectangular region;

[0150] a cutting sub-module, configured to cut the binarization region to obtain the barcode region when the rectangular degree is greater than a third preset value.

[0151] Optionally, the apparatus further comprises:

[0152] an adjusting module, configured to, when the barcode image is misrecognized, acquire a direction of the barcode image, and if the direction of the barcode image is vertical, adjust the barcode image into a horizontal barcode image, wherein the direction of the barcode image is an arrangement direction of a barcode in the barcode image;

[0153] a mean filtering module, configured to perform mean filtering on the horizontal barcode image to obtain a mean filtering image, and according to a comparison result of a pixel value of a pixel point in the mean filtering image and a pixel value of a corresponding pixel point in the horizontal barcode image, obtain the enhanced image;

[0154] a second decoding module, configured to decode the enhanced image to obtain information corresponding to the enhanced image.

[0155] Optionally, the mean filtering module comprises:

[0156] a first modifying sub-module, configured to, if a difference between the pixel value of the pixel point in the horizontal barcode image and the pixel value of the corresponding pixel point in the mean filtering image is less than a fourth preset value, modify the pixel value of the corresponding pixel point in the enhanced image into a second pixel value representing black;

[0157] a second modifying sub-module, configured to, if the difference between the pixel value of the pixel point in the horizontal barcode image and the pixel value of the corresponding pixel point in the mean filtering image is greater than a fifth preset value, modify the pixel value of the corresponding pixel point in the enhanced image into a first pixel value representing white;

[0158] a third modifying sub-module, configured to, if the difference between the pixel value of the pixel point in the horizontal barcode image and the pixel value of the corresponding pixel point in the mean filtering image is greater than the fourth preset value and less than the fifth preset value, perform a division operation on the difference and the fifth preset value, perform an addition operation on a result of the division operation and a sixth preset value to obtain an addition result, and modify the pixel value of the corresponding pixel point in the enhanced image into the addition result.

[0159] Optionally, the apparatus further comprises:

[0160] a scaling module, configured to scale the barcode image by a preset scaling coefficient to obtain a scaled barcode image when the barcode image is misrecognized;

[0161] a third decoding module, configured to decode the scaled barcode image to obtain information corresponding to the scaled barcode image.

[0162] Optionally, the apparatus further comprises:

[0163] a judging module, configured to enter a step of acquiring adjacent first and second frames of images in a shooting video including a barcode if a maximum connected domain in all connected domains occupies less than the first preset value of pixels.

[0164] Optionally, the second operation module comprises:

[0165] a determining sub-module, configured to take an image adjacent to the second frame of image as the third frame of image, or randomly select one image from the remaining frames of images in the shooting video as the third frame of image.

[0166] In summary, in the embodiment of the application, adjacent first and second frames of images in a shooting video including a barcode are acquired, and the first and second frames of images are subjected to difference operation to obtain a first difference image. If a maximum connected domain in all connected domains of the first difference image occupies more than a first preset value of pixels, it indicates that the shooting video is relatively stable, and then one image is selected from the remaining frames of images in the shooting video as a third frame of image, and the third frame of image is subjected to difference operation with the second frame of image to obtain a binaryzation region containing a barcode in the third frame of image. By using the second frame of image in the last stable video as a background frame of image, repeated calculation can be avoided, and the occupancy rate of computing resources can be reduced. According to the length and width of the binaryzation region, a barcode region is determined, and the barcode in the barcode region is decoded to obtain information corresponding to the barcode. The application obtains a barcode region by operating three frames of images in a shooting video, and in the case of a relatively complex shooting background, a relatively complete barcode region can be obtained without depending on the shooting angle and the placement direction of the article, so that the accuracy of decoding can be improved when the barcode is decoded.

[0167] For the apparatus embodiment, it is basically similar to the method embodiment, so the description is relatively simple, and the related parts refer to the part of the method embodiment.

[0168] Each embodiment in the specification is described in a progressive manner, and each embodiment focuses on the difference from other embodiments. The same or similar parts between embodiments can be referred to each other.

[0169] As to the apparatus in the above embodiments, the specific manner in which each module performs operations has been described in detail in the embodiments of the method. No detailed description will be given here.

[0170] Embodiments of the present application provide a barcode recognition device, comprising a memory, and one or more programs, wherein the one or more programs are stored in the memory, and the one or more processors are configured to execute the one or more programs, including the method described in one or more embodiments.

[0171] Figure 7 is a block diagram of an electronic device 400 provided by embodiments of the present application. For example, the electronic device 400 can be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0172] Referring to Figure 7 , the electronic device 400 can include one or more of the following components: a processing component 402, a memory 404, a power supply component 406, a multimedia component 408, an audio component 410, an input / output (I / O) interface 412, a sensor component 414, and a communication component 416.

[0173] The processing component 402 usually controls the overall operation of the electronic device 400, such as operations associated with displaying, making phone calls, data communications, camera operations and recording operations. The processing component 402 can include one or more processors 420 to execute instructions to complete all or part of the steps of the methods described above. In addition, the processing component 402 can include one or more modules to facilitate the interaction between the processing component 402 and other components. For example, the processing component 402 can include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.

[0174] The memory 404 is used to store various types of data to support the operation of the electronic device 400. Examples of these data include instructions for any application programs or methods operating on the electronic device 400, contact data, phonebook data, messages, pictures, multimedia, etc. The memory 404 can be implemented by any type of volatile or nonvolatile memory device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0175] The power supply component 406 supplies power for various components of the electronic device 400. The power supply component 406 can include a power management system, one or more power supplies, and other components associated with generating, managing and distributing power for the electronic device 400.

[0176] The multimedia component 408 includes a screen providing an output interface between the electronic device 400 and a user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touch, swiping and gestures on the touch panel. The touch sensors can not only sense a boundary of a touching or swiping action, but also detect duration and pressure related to the touching or swiping action. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. The front and rear cameras can receive external multimedia data when the electronic device 400 is in an operation mode, such as a photographing mode or a multimedia mode. Each of the front and rear cameras can be a fixed optical lens system or have a focal length and optical zoom capability.

[0177] The audio component 410 is configured to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC) for receiving an external audio signal when the electronic device 400 is in an operation mode, such as a call mode, a recording mode and a voice recognition mode. The received audio signal can be further stored in the memory 404 or transmitted via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting audio signals.

[0178] The input / output interface 412 provides an interface between the processing component 402 and peripheral interface modules, which can be a keypad, a click wheel, buttons, etc. These buttons can include, but are not limited to, a home button, a volume button, a start button and a lock button.

[0179] The sensor component 414 includes one or more sensors for providing status assessments for various aspects of the electronic device 400. For example, the sensor component 414 can detect an open / closed position of the electronic device 400, relative positioning of components of the electronic device 400, such as a display and a keypad of the electronic device 400, a change in position of the electronic device 400 or a component of the electronic device 400, the presence or absence of user contact with the electronic device 400, the orientation or acceleration / deceleration / g-force and a temperature change of the electronic device 400. The sensor component 414 can include a proximity sensor configured to detect presence of a nearby object without any physical touch. The sensor component 414 can also include a light sensor (e.g., a CMOS or CCD image sensor) configured to function in an imaging application. In some embodiments, the sensor component 414 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0180] The communication component 416 is configured to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a communication standard, such as WiFi, a cellular network (e.g., 2G, 3G, 4G or 5G), or a combination thereof. In an example embodiment, the communication component 416 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In an example embodiment, the communication component 416 can further include a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) techniques, infrared data association (IrDA) techniques, ultra-wideband (UWB) techniques, Bluetooth (BT) techniques and other techniques.

[0181] In an example embodiment, the electronic device 400 can be implemented with one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic elements to perform the methods provided by the present application.

[0182] In an example embodiment, a non-transitory computer-readable storage medium, such as the memory 404 including instructions stored therein, is also provided that can be executed by the processor 420 of the electronic device 400 to perform the methods described above. For example, the non-transitory storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disc, and an optical data storage device, and the like.

[0183] Figure 8is another block diagram of an electronic device 500 provided by embodiments of the present application. For example, the electronic device 500 can be provided as a server. Referring to Figure 8 The electronic device 500 includes a processing component 522, which further includes one or more processors, and a memory resource represented by a memory 532, for storing instructions executable by the processing component 522, such as an application program. The application program stored in the memory 532 can include one or more than one module each corresponding to a set of instructions. In addition, the processing component 522 is configured to execute the instructions to perform the method provided by embodiments of the present application.

[0184] The electronic device 500 can also include a power supply component 526 configured to perform power management of the electronic device 500, a wired or wireless network interface 550 configured to connect the electronic device 500 to a network, and an input / output interface 558. The electronic device 500 can operate based on an operating system stored in the memory 532, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™ or the like.

[0185] Embodiments of the present application also provide a computer program product, comprising a computer program which, when executed by a processor, implements the method described in the above embodiments.

[0186] Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. The specification and examples given are exemplary only and the true scope and spirit of the application is indicated by the following claims. It will be appreciated by persons skilled in the art that numerous variations and / or modifications can be made to the application as described above without departing from the scope or spirit of the application. It is intended that all such variations and / or modifications be included within the scope of the application. It is intended that the specification and examples be considered as exemplary only, with the true scope and spirit of the application being indicated by the following claims.

[0187] It should be understood that the application is not limited to the precise construction that has been described above and illustrated in the accompanying drawings, and that various modifications and changes can be made by those skilled in the art without departing from the scope of the application. The scope of the application is limited only by the appended claims.

Claims

1. A barcode recognition method, characterized in that, The method includes: The first frame and the second frame are acquired from a video containing a barcode, and a difference operation is performed between the first frame and the second frame to obtain a first difference image. The first difference image is used to characterize the degree of difference between the first frame and the second frame. Obtain all connected components of the first difference image. If the pixel size of the largest connected component in all connected components is greater than a first preset value, select an image from the remaining frames of the captured video as the third frame image, and perform a difference operation between the third frame image and the second frame image to obtain the binarized region containing the barcode in the third frame image. The length and width of the binarized region are obtained, and the barcode region is determined based on the length and width of the binarized region. The barcode in the barcode region is then decoded to obtain the information corresponding to the barcode. The step of performing a difference operation on the first frame image and the second frame image to obtain a first difference image includes: The first frame image is converted into a first grayscale image, and the second frame image is converted into a second grayscale image; Edge extraction is performed on the first grayscale image to obtain a first edge image, and edge extraction is performed on the second grayscale image to obtain a second edge image; Calculate the first pixel difference between the pixels in the first edge image and the corresponding pixels in the second edge image, and construct a first difference image based on the absolute value of the first pixel difference.

2. The method according to claim 1, characterized in that, The step of performing edge extraction on the first grayscale image to obtain a first edge image, and performing edge extraction on the second grayscale image to obtain a second edge image, includes: Obtain the first convolution kernel in the horizontal direction and the second convolution kernel in the vertical direction; The first grayscale image is convolved using the first convolution kernel and the second convolution kernel respectively to obtain the first gradient matrix of the first grayscale image; The second grayscale image is convolved using the first convolution kernel and the second convolution kernel respectively to obtain the second gradient matrix of the second grayscale image; The first gradient matrix and the second gradient matrix are binarized respectively to obtain the first edge image and the second edge image.

3. The method according to claim 2, characterized in that, The step of binarizing the first gradient matrix and the second gradient matrix respectively to obtain the first edge image and the second edge image includes: Calculate the first average value of the gradient values ​​in the first gradient matrix and the second average value of the gradient values ​​in the second gradient matrix; If the gradient value in the first gradient matrix is ​​greater than the first average value multiplied by the second preset value, then the gradient value is modified to a first pixel value representing white; if the gradient value in the first gradient matrix is ​​less than or equal to the first average value multiplied by the second preset value, then the gradient value is modified to a second pixel value representing black. If the gradient value in the second gradient matrix is ​​greater than the second average value multiplied by the second preset value, then the gradient value is modified to the first pixel value representing white; if the gradient value in the second gradient matrix is ​​less than or equal to the second average value multiplied by the second preset value, then the gradient value is modified to the second pixel value representing black. The first edge image and the second edge image are generated based on the first pixel value and the second pixel value.

4. The method according to claim 1, characterized in that, The step of performing a difference operation between the third frame image and the second frame image to obtain the binarized region containing the barcode in the third frame image includes: Edge extraction is performed on the third grayscale image corresponding to the third frame image to obtain a third edge image, and edge extraction is performed on the second grayscale image corresponding to the second frame image to obtain a second edge image; Calculate the second pixel difference between the corresponding pixel in the third edge image and the second edge image, and construct a second difference image based on the absolute value of the second pixel difference; Obtain the coordinates of the pixels in the connected components of the second difference image, generate the minimum bounding rectangle of the connected components based on the coordinates of the pixels in the connected components, and use the minimum bounding rectangle as the binarized region containing the barcode.

5. The method according to claim 1, characterized in that, Determining the barcode region based on the length and width of the binarized region includes: Divide the length by the width to obtain the aspect ratio; The area of ​​the binarized region is calculated. When the aspect ratio is within a first range and the area of ​​the binarized region is within a second range, the length is multiplied by the width, and the area of ​​the binarized region is divided by the product of the length and the width to obtain the rectangularity. The rectangularity is used to characterize the similarity between the binarized region and the rectangular region. When the rectangle size is greater than a third preset value, the binarized region is cropped to obtain the barcode region.

6. The method according to claim 1, characterized in that, After decoding the barcode in the barcode area to obtain the information corresponding to the barcode, the method further includes: When a barcode image is incorrectly identified, the orientation of the barcode image is obtained. If the orientation of the barcode image is vertical, the barcode image is adjusted to a horizontal barcode image. The orientation of the barcode image refers to the arrangement direction of the barcodes in the barcode image. The horizontal barcode image is subjected to mean filtering to obtain a mean-filtered image, and an enhanced image is obtained based on the comparison between the pixel values ​​of the pixels in the mean-filtered image and the pixel values ​​of the corresponding pixels in the horizontal barcode image. The enhanced image is decoded to obtain the information corresponding to the enhanced image.

7. The method according to claim 6, characterized in that, The step of obtaining the enhanced image based on the comparison result between the pixel values ​​of the pixels in the mean-filtered image and the pixel values ​​of the corresponding pixels in the horizontal barcode image includes: If the difference between the pixel value of the horizontal barcode image pixel and the pixel value of the corresponding pixel in the mean-filtered image is less than a fourth preset value, then the pixel value of the corresponding pixel in the enhanced image is modified to the second pixel value representing black. If the difference between the pixel value of the horizontal barcode image pixel and the pixel value of the corresponding pixel in the mean-filtered image is greater than a fifth preset value, then the pixel value of the corresponding pixel in the enhanced image is modified to the first pixel value representing white. If the difference between the pixel value of the horizontal barcode image and the pixel value of the corresponding pixel in the mean-filtered image is greater than a fourth preset value and less than a fifth preset value, then the difference is divided by the fifth preset value, and the result of the division is added to the sixth preset value to obtain the addition result. The pixel value of the corresponding pixel in the enhanced image is then modified to the addition result.

8. The method according to claim 1, characterized in that, After decoding the barcode in the barcode area to obtain the information corresponding to the barcode, the method further includes: When the barcode image is incorrectly identified, the barcode image is scaled using a preset scaling factor to obtain a scaled barcode image; The scaled barcode image is decoded to obtain the information corresponding to the scaled barcode image.

9. The method according to claim 1, characterized in that, The method further includes: If the number of pixels occupied by the largest connected component among all connected components is less than the first preset value, then proceed to the step of acquiring the first and second adjacent frames of the captured video including the barcode.

10. The method according to claim 1, characterized in that, Selecting an image from the remaining frames of the captured video as the third frame includes: The image adjacent to the second frame image is used as the third frame image, or an image is randomly selected from the remaining frames of the captured video as the third frame image.

11. A barcode recognition device, characterized in that, The device includes: The first calculation module is used to acquire adjacent first frame images and second frame images in the captured video including the barcode, and to perform a difference operation on the first frame image and the second frame image to obtain a first difference image; the first difference image is used to characterize the degree of difference between the first frame image and the second frame image. The second calculation module is used to obtain all connected components of the first difference image. If the pixel size of the largest connected component in all connected components is greater than a first preset value, then an image is selected from the remaining frames of the captured video as the third frame image, and the third frame image is subjected to a difference operation with the second frame image to obtain the binarized region containing the barcode in the third frame image. The first decoding module is used to obtain the length and width of the binarized region, determine the barcode region based on the length and width of the binarized region, and decode the barcode in the barcode region to obtain the information corresponding to the barcode. The first arithmetic module is specifically used for: The first frame image is converted into a first grayscale image, and the second frame image is converted into a second grayscale image; Edge extraction is performed on the first grayscale image to obtain a first edge image, and edge extraction is performed on the second grayscale image to obtain a second edge image; Calculate the first pixel difference between the pixels in the first edge image and the corresponding pixels in the second edge image, and construct a first difference image based on the absolute value of the first pixel difference.

12. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the barcode recognition method as described in any one of claims 1 to 10.

13. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the barcode recognition method as described in any one of claims 1 to 10.

Citation Information

Patent Citations

  • Panorama video frame image processing method and device

    CN105844256A

  • Bar code decoding method, terminal equipment and storage medium

    CN112241641A