Bar code identification method and device, electronic equipment and readable storage medium

By performing differential operations and stability judgment on the frame images in the captured video, and selecting appropriate frame images for binarization and decoding of the barcode area, the problem of low barcode recognition accuracy in complex backgrounds is solved, and higher recognition accuracy and calculation efficiency are achieved.

CN120493967AActive Publication Date: 2025-08-15BEIJING MYSHER TECH
View PDF 6 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In the case where the shooting background is relatively complex, the accuracy of barcode recognition in the prior art is low.

Method used

By acquiring the adjacent first frame image and the second frame image in the captured video for differential operations, the differential image is obtained, and the video stability is judged based on the connection domain of the differential image, the third frame image is selected from the stable video frame for differential operations, the binarized area is obtained, and the barcode area is determined using the length and width of the binarized area, and decoded.

Benefits of technology

In a complex context, the accuracy of barcode recognition is improved, the occupancy rate of computing resources is reduced, and it does not depend on the shooting angle and item placement direction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120493967A_ABST
    Figure CN120493967A_ABST
Patent Text Reader

Abstract

The invention provides a bar code identification method and device, electronic equipment and a readable storage medium, and the method comprises the steps: obtaining a first frame image and a second frame image which are adjacent in a shot video comprising a bar code, carrying out the differential operation of the first frame image and the second frame image, obtaining a first difference image, obtaining all connected domains of the first difference image, and obtaining a second difference image; if the pixel occupied by the maximum connected domain in all the connected domains is greater than a first preset value, selecting one image from the rest frames of images of the shot video as a third frame of image, and carrying out differential operation on the third frame of image and the second frame of image to obtain a binary region containing a bar code in the third frame of image, according to the method and the device, the length and the width of the binarization region are obtained, the bar code region is determined according to the length and the width of the binarization region, and the bar code in the bar code region is decoded to obtain the information corresponding to the bar code, so that the accuracy of bar code identification can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image recognition technology, and in particular to a barcode recognition method, device, electronic device, and computer-readable storage medium. Background Art

[0002] Barcode recognition technology uses a scanner to read the information contained in a barcode and then identify the content represented by the barcode. One-dimensional barcodes are a common barcode type in the current market, often used on various industrial and daily necessities to record product information for easy identification and traceability.

[0003] Related technologies use devices such as cameras or scanners to obtain barcode images, then denoise and segment the barcode images, determine the position and size of the barcode in the image, and finally convert the barcode image into corresponding digital or letter information according to the barcode encoding rules.

[0004] When the shooting background is relatively complex, the accuracy of barcode recognition by the method proposed in the related art is low. Summary of the Invention

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

[0006] In a first aspect, an embodiment of the present application provides a barcode recognition method, the method comprising: Obtaining a first frame image and a second frame image adjacent to each other in a captured video including a barcode, and performing 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 represent a degree of difference between the first frame image and the second frame image; Obtaining all connected domains of the first difference image, and if the number of pixels occupied by the largest connected domain among all the connected domains is greater than a first preset value, selecting an image from the remaining frame images of the captured video as a third frame image, and performing a 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; The length and width of the binary area are obtained, and a barcode area is determined according to the length and width of the binary area. The barcode in the barcode area is decoded to obtain information corresponding to the barcode.

[0007] In a second aspect, an embodiment of the present application provides a barcode recognition device, the device comprising: a first operation module, configured to obtain a first frame image and a second frame image adjacent to each other in a video shot including a barcode, and 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 represent a degree of difference between the first frame image and the second frame image; a second operation module, configured to obtain all connected domains of the first difference image, and if the number of pixels occupied by the largest connected domain among all the connected domains is greater than a first preset value, select an image from the remaining frame images of the captured video as a third frame image, and perform a 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; The first decoding module is used to obtain the length and width of the binary area, determine the barcode area according to the length and width of the binary area, and decode the barcode in the barcode area to obtain information corresponding to the barcode.

[0008] In a third aspect, an embodiment of the present application further provides an electronic device comprising a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the method of the first aspect.

[0009] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to execute the method of the first aspect.

[0010] In an embodiment of the present application, a first and second adjacent frames of a video containing a barcode are obtained, and a difference operation is performed on the first and second frames to obtain a first difference image. If the pixel count of the largest connected region among all connected regions in the first difference image is greater than a first preset value, indicating that the video is relatively stable, an image is selected from the remaining frames of the video as a third frame, and a difference operation is performed on the third frame and the second frame to obtain a binary region containing the barcode in the third frame. By using the second frame of the previous stable video as the background frame, repeated calculations can be avoided, reducing computing resource usage. The barcode region is determined based on the length and width of the binary region, and the barcode in the barcode region is decoded to obtain information corresponding to the barcode. The present application calculates the barcode region by performing calculations on three frames of the video. In the case of complex backgrounds, it can obtain a relatively complete barcode region independent of the shooting angle and the orientation of the object, thereby improving the decoding accuracy of the barcode.

[0011] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0013] Figure 1 This is a flowchart of a barcode recognition method provided in an embodiment of the present application; Figure 2 is a schematic diagram of a frame image provided by an embodiment of the present application; Figure 3 This is a flowchart of the specific steps of a barcode recognition method provided in an embodiment of the present application; Figure 4 This is a flowchart of another barcode recognition method provided in an embodiment of the present application; Figure 5 This is a flowchart of another barcode recognition method provided in an embodiment of the present application; Figure 6 This is a block diagram of a bar code recognition device provided in an embodiment of the present application; Figure 7 is a block diagram of an electronic device provided in an embodiment of the present application; Figure 8 This is a block diagram of another electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0014] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0015] The terms "first", "second", etc. in the specification and claims of this 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 interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. 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 association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. In the embodiments of this application, the term "multiple" refers to two or more, and other quantifiers are similar.

[0016] Figure 1 This is a flowchart of a barcode recognition method provided by an embodiment of the present application. Figure 1 As shown, the method may include: Step 101: Acquire a first frame image and a second frame image that are adjacent to each other in a video shot including a barcode, and perform a differential 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 degree of difference between the first frame image and the second frame image.

[0017] For example, the video captured in this application does not depend on the angle and direction of the shooting, nor on the direction of the barcode. Figure 2 , Figure 2 Image 20 in the image includes items 21, 22, and 23. Each item has XXX, oriented differently. XXX represents a barcode. Item 21 has a vertical barcode 211, while item 22 has a horizontal barcode 221. Item 23 has a diagonal barcode 231. These items can be medicine boxes or other barcoded products.

[0018] For example, a differential operation detects moving targets by comparing pixel differences between adjacent frames in a captured video. This method is simple and efficient, and is suitable for scenarios with high real-time requirements. Specifically, the first and second frames are converted into a first grayscale image and a second grayscale image. The pixel values of the pixels in the first grayscale image are then subtracted from the pixel values of the corresponding pixels in the second grayscale image. The absolute value of the subtraction result is used as the pixel value of the corresponding pixel in the first difference image to construct a first difference image.

[0019] For example, the first difference image is used to characterize the degree of difference between the first frame image and the second frame image, and the degree of difference is used to reflect the stability of the captured 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 fewer and evenly distributed. If the video is unstable (such as shaking or fast motion), the edge pixels in the first difference image will be more and concentrated. Specifically, the statistics of the first difference image are calculated. When the statistics of the first difference image exceeds a threshold, the captured video is considered unstable, otherwise the captured video is considered stable. For example, the statistic can be the pixel size of the complete edge of the first difference image, and the threshold is 100. If the pixel size of the complete edge of the first difference image is greater than 100, the captured video is considered unstable, otherwise the captured video is considered stable.

[0020] Step 102: Obtain all connected domains of the first difference image. If the number of pixels occupied by the largest connected domain among all the connected domains is greater than a first preset value, select an image from the remaining frame images of the captured video as a third frame image, and perform a 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.

[0021] For example, a connected domain in an image is a region of adjacent pixels with the same pixel value. OpenCV's findContours function is called to obtain all connected domains in the first difference image. The pixel size of the largest connected domain among all connected domains is then obtained, i.e., the number of pixels occupied by the connected domain. For example, using the first preset value of 100 as an example, if the pixel size of the largest connected domain among all connected domains is greater than 100, the captured video is considered stable.

[0022] For example, if the video is stable, an image is selected from the remaining frames of the video as the third frame. Specifically, the frame after the second frame can be used as the third frame, and the second frame can be determined as the background frame to determine whether the stabilized video is the same as the previous one, thus avoiding repeated calculations. By modeling the background and then comparing the current frame with the background frame, moving objects can be separated.

[0023] For example, after determining the third frame image, a difference operation is performed on the third frame image and the second frame image to obtain a binary region containing the barcode in the third frame image. Specifically, a difference operation is performed on the third frame image and the second frame image to obtain a second difference image. It is then determined whether there is a difference between the third frame image and the second frame image. If there is a difference, it indicates that there is a moving area in the video and it is necessary to crop the moving area to obtain a binary region containing the barcode. If there is no difference, it indicates that there is no moving object in the video and the barcode image can be cropped.

[0024] Step 103 : Obtain the length and width of the binary area, determine the barcode area according to the length and width of the binary area, and decode the barcode in the barcode area to obtain information corresponding to the barcode.

[0025] For example, barcodes are typically rectangular or nearly rectangular. Their aspect ratio is typically within a certain range, such as 2:1 to 5:1. The area of a barcode depends on the image resolution and the actual size of the barcode. Barcode edges are typically sharp and well-defined. Because barcodes have these characteristics, OpenCV's findContours function can be used to detect binary regions. Based on the shape and size of the binary regions, the region most likely to represent a barcode is selected. Specifically, the barcode region is determined based on the geometric characteristics of the binary regions, such as area, aspect ratio, and rectangularity.

[0026] For example, after obtaining the barcode area, zbar and zxing are used to decode the barcode in the barcode area to obtain the information corresponding to the barcode. This application uses zbar and zxing to decode the barcode in the barcode area, which can improve the accuracy of barcode recognition and achieve more comprehensive barcode detection.

[0027] In summary, in an embodiment of the present application, adjacent first and second frames of a video containing a barcode are obtained, and a difference operation is performed on the first and second frames to obtain a first difference image. If the number of pixels occupied by the largest connected domain among all connected domains in the first difference image is greater than a first preset value, indicating that the video is relatively stable, an image is selected from the remaining frames of the video as a third frame, and the third frame is differenced with the second frame to obtain a binary region containing the barcode in the third frame. By using the second frame of the previous stable video as the background frame, repeated calculations can be avoided, reducing the utilization of computing resources. The barcode region is determined based on the length and width of the binary region, and the barcode in the barcode region is decoded to obtain the information corresponding to the barcode. The present application obtains the barcode region by performing calculations on three frames of the video. In the case of a complex shooting background, it can obtain a relatively complete barcode region independently of the shooting angle and the placement of the object, thereby improving the decoding accuracy of the barcode.

[0028] Figure 3 This is a flowchart of the specific steps of a barcode recognition method provided by an embodiment of the present application, such as Figure 3 As shown, the method may include: Step 201 : Acquire a first frame image and a second frame image that are adjacent to each other in a captured video including a barcode, convert the first frame image into a first grayscale image, and convert the second frame image into a second grayscale image.

[0029] For example, after using OpenCV to read the video frame image, the first frame image and the second frame image are obtained, and the first frame image is converted into a first grayscale image and the second frame image is converted into a second grayscale image, which can reduce the amount of calculation.

[0030] Step 202: 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.

[0031] For example, edge extraction is used to identify areas in an image where brightness changes significantly. These areas typically correspond to the edges of objects. Edges are areas where brightness changes significantly in an image, typically corresponding to object boundaries or texture changes. The core of edge extraction is to calculate the gradient of the image, that is, the rate of change of pixel values. Areas with large gradients typically correspond to edges.

[0032] Optionally, step 202 may specifically include: Sub-step 2021, obtaining a first convolution kernel in the horizontal direction and a second convolution kernel in the vertical direction; Sub-step 2022: convolve the first grayscale image using the first convolution kernel and the second convolution kernel respectively to obtain a first gradient matrix of the first grayscale image; Sub-step 2023: convolve the second grayscale image using the first convolution kernel and the second convolution kernel respectively to obtain a second gradient matrix of the second grayscale image; Sub-step 2024 : performing binarization processing on the first gradient matrix and the second gradient matrix respectively to obtain the first edge image and the second edge image.

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

[0034] For example, a first grayscale image is convolved with a first convolution kernel and a second convolution kernel to obtain a first gradient matrix of the first grayscale image. A second grayscale image is convolved with the first convolution kernel and the second convolution kernel to obtain a second gradient matrix of the second grayscale image. This application calculates the horizontal and vertical gradients of an image through convolution, which is computationally simple and fast.

[0035] Optionally, sub-step 2024 may specifically include: Sub-step 20241, calculating 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; Sub-step 20242: If the gradient value in the first gradient matrix is greater than the first average value multiplied by the second preset value, modify the gradient value 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, modify the gradient value to a second pixel value representing black; Sub-step 20243: If the gradient value in the second gradient matrix is greater than the second average value multiplied by the second preset value, modify the gradient value to a 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, modify the gradient value to a second pixel value representing black; Sub-step 20244: Generate the first edge image and the second edge image according to the first pixel value and the second pixel value.

[0036] For sub-steps 20241-20244, both the first edge image and the second edge image are binarized images, where pixels are assigned two extreme grayscale values: 0 (black) or 255 (white). This processing method creates a distinct black and white image effect, facilitating subsequent image analysis and processing. The first pixel value can be 255, and the second pixel value can be 0.

[0037] For example, the gradient values in the first gradient matrix are summed and averaged to obtain a first average value, and the gradient values in the second gradient matrix are summed and averaged to obtain a second average value.

[0038] Taking the second preset value of 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. 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. 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, a first edge image composed of the modified gradient values is obtained. After the gradient values in the second gradient matrix are modified, a second edge image composed of the modified gradient values is obtained.

[0039] Step 203 : Calculate first pixel differences between pixels in the first edge image and corresponding pixels in the second edge image, and construct a first difference image based on absolute values of the first pixel differences.

[0040] For example, after obtaining the first edge image and the second edge image, the first pixel difference between the pixel point in the first edge image and the corresponding pixel point in the second edge image is calculated, and the absolute value of the first pixel difference is used as the pixel value of the corresponding pixel point in the first difference image to construct the first difference image.

[0041] Step 204: Obtain all connected domains of the first difference image. If the number of pixels occupied by the largest connected domain among all the connected domains is greater than a first preset value, select an image from the remaining frame images of the captured video as a third frame image, and perform a 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.

[0042] This step may be specifically referred to the above step 102 and will not be described in detail here.

[0043] Optionally, step 204 may specifically include: Sub-step 2041: select an image adjacent to the second frame image as the third frame image, or randomly select an image from the remaining frame images of the captured video as the third frame image.

[0044] For example, an image adjacent to the second frame image may be used as the third frame image. Compared with subsequent frame images in the second frame image, the inter-frame time difference between the third frame image and the second frame image is the shortest.

[0045] For example, an image can be randomly selected from the remaining frames of the captured video as the third frame. After the video stabilizes, the barcode is detected only once. If the detected barcode is not decoded successfully, each subsequent frame is decoded. This can significantly reduce the impact of barcode reflections on barcode recognition.

[0046] Optionally, step 204 may further include: Sub-step 2042: performing edge extraction on the third grayscale image corresponding to the third frame image to obtain a third edge image, and performing edge extraction on the second grayscale image corresponding to the second frame image to obtain a second edge image; Sub-step 2043, calculating a second pixel difference between a pixel in the third edge image and a corresponding pixel in the second edge image, and constructing a second difference image based on the absolute value of the second pixel difference; Sub-step 2044: obtaining the coordinates of the pixels of the connected domain of the second difference image, generating a minimum bounding rectangle of the connected domain based on the coordinates of the pixels of the connected domain, and using the minimum bounding rectangle as the binary region containing the barcode.

[0047] For sub-steps 2042-2044, the third frame 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 frame 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 obtaining the third edge image and the second edge image, a second pixel difference is calculated between a pixel in the third edge image and a corresponding pixel in the second edge image. The absolute value of the second pixel difference is used as the pixel value of the corresponding pixel in the second difference image to construct a second difference image.

[0048] For example, after obtaining the second difference image, the second difference image is used to determine whether there is a difference between the third frame image and the second frame image. If there is a difference, the moving area is cropped. Specifically, for the second difference image obtained by difference, the minimum bounding rectangle of all moving areas is calculated, and the minimum bounding rectangle is used as the binary area containing the barcode. For example, the OpenCV findContours function is called to obtain the pixel coordinate values of all connected domains in the second difference image, the coordinates of all connected domain pixels are merged, and the OpenCV boundingRect function is called to calculate the coordinate values (min_x, min_y, width, height) of the moving area, and the [min_x, min_y, width, height] area of the image is cropped. The cropped image is then binarized using a barcode segmentation model trained using a reduced parameter size u2netp network to obtain a binary area containing the barcode. OpenCV is then used to process the binary image to accurately locate the barcode.

[0049] Optionally, the method further includes: In step A, if the number of pixels occupied by the largest connected domain among all connected domains is less than the first preset value, the process proceeds to the step of acquiring the adjacent first frame image and second frame image in the captured video including the barcode.

[0050] For example, taking the first preset value as 100, if the pixels occupied by the largest connected domain among all connected domains are less than 100, it is considered that the captured video is unstable. At this time, it is necessary to re-search the frame image, determine the first frame image and the second frame image, until a frame image that makes the captured video stable is found.

[0051] Step 205 : Obtain the length and width of the binary area, determine the barcode area according to the length and width of the binary area, and decode the barcode in the barcode area to obtain information corresponding to the barcode.

[0052] This step may be specifically referred to the above step 103 and will not be described in detail here.

[0053] Optionally, step 205 may specifically include: Sub-step 2051 , dividing the length by the width to obtain an aspect ratio; Sub-step 2052: Calculate the area of the binary region. When the aspect ratio is within the first range and the area of the binary region is within the second range, multiply the length by the width, and divide the area of the binary region by the product of the length and the width to obtain a rectangularity. The rectangularity is used to indicate the degree of similarity between the binary region and the rectangular region. Sub-step 2053 : When the rectangular degree is greater than a third preset value, the binarized area is cropped to obtain the barcode area.

[0054] For sub-steps 2051-2053, after obtaining the length and width of the binary area, divide the length by the width to obtain the aspect ratio, and calculate the area of the binary area. 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 binary area is greater than 1000 and less than 50000, multiply the length by the width, and divide the area of the binary area by the product of the length and the width to obtain the rectangularity. When the rectangularity is greater than 0.7, the binary area is cropped to obtain the barcode area. For example, the warpAffine function of OpenCV can be called to crop the barcode area in the binary area.

[0055] Optionally, after step 205, the method further includes: Step 206: When the barcode image is incorrectly recognized, the direction of the barcode image is obtained. 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. Step 207: performing mean filtering on the horizontal barcode image to obtain a mean filtered image, and obtaining the enhanced image based on a result of comparing pixel values of pixels in the mean filtered image with pixel values of corresponding pixels in the horizontal barcode image. Step 208: Decode the enhanced image to obtain information corresponding to the enhanced image.

[0056] For steps 206-208, misidentification refers to failure to identify or the decoded information not meeting drug traceability barcode specifications. When a barcode image is misidentified, you can enhance the barcode image using an adaptive barcode enhancement algorithm and then decode the enhanced barcode image using zbar and zxing. This can reduce the impact of environmental factors on barcode recognition and improve barcode image recognition accuracy.

[0057] For example, because the orientation of a one-dimensional barcode may not be horizontal, the cropped barcode image may be vertical. Therefore, the orientation of the barcode image needs to be adjusted to the horizontal direction to unify the orientation of the barcode image. After adjusting the orientation of the barcode image to the horizontal direction, the horizontal barcode image is mean filtered to obtain a mean filtered image. Mean filtering replaces the value of each pixel in the image by calculating the average value of the pixels in its neighborhood. Specifically, for each pixel in the image, an area around it (such as a 3x3 or 5x5 area) is taken, the average of these pixel values is calculated, and then this average value is assigned to the center pixel. This processing method smoothes high-frequency information (such as edges and details), thereby achieving the effect of noise reduction and blurring.

[0058] For example, after obtaining the mean filtered image, an enhanced image is obtained based on the comparison results of the pixel values of the pixels in the mean filtered image with 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, which can improve the accuracy of barcode image recognition.

[0059] Optionally, step 207 may specifically include: Sub-step 2071 , 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, modifying the pixel value of the corresponding pixel in the enhanced image to a second pixel value representing black; Sub-step 2072: 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, modifying the pixel value of the corresponding pixel in the enhanced image to a first pixel value representing white; In sub-step 2073, if the difference between the pixel value of the horizontal barcode image pixel point and the pixel value of the corresponding pixel point in the mean filtered image is greater than the fourth preset value and less than the fifth preset value, the difference is divided by the fifth preset value, and the division result is added to the sixth preset value to obtain an addition result, and the pixel value of the corresponding pixel point in the enhanced image is modified to the addition result.

[0060] For sub-steps 2071 to 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 a horizontal barcode image pixel and the pixel value s(x, y) of the corresponding pixel in the mean filtered image is less than -50, the pixel value g(x, y) of the corresponding pixel in the enhanced image is modified to 0. If the difference between the pixel value f(x, y) of a horizontal barcode image pixel and the pixel value s(x, y) of the corresponding pixel in the mean filtered image is greater than 50, the pixel value g(x, y) of the corresponding pixel in the enhanced image is modified to 255. If the difference between the pixel value f(x, y) of a horizontal barcode image pixel and the pixel value s(x, y) of the corresponding pixel in the mean filtered image is greater than -50 and less than 50, the difference is divided by 50, and the division result is added to 128 to obtain the addition result. The pixel value g(x, y) of the corresponding pixel in the enhanced image is modified to the addition result. The formula for obtaining the enhanced image based on the horizontal barcode image and the mean filtered image is as follows:

[0061] Where 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 filtered image, and g(x, y) represents the pixel value corresponding to the pixel point with coordinates (x, y) in the enhanced image.

[0062] Optionally, after step 205, the method further includes: Step 209: When the barcode image is incorrectly recognized, the barcode image is scaled using a preset scaling factor to obtain a scaled barcode image; Step 210: Decode the scaled barcode image to obtain information corresponding to the scaled barcode image.

[0063] Regarding steps 209 and 210, incorrect recognition refers to failure to recognize or the decoded information not meeting the drug traceability barcode specification. When a barcode image is incorrectly recognized, the barcode image can be scaled using a preset scaling factor (e.g., [0.5:0.25:2]) to obtain a scaled barcode image. Using zbar and zxing to decode the scaled barcode image can achieve more comprehensive barcode detection and improve barcode image recognition accuracy.

[0064] In summary, in an embodiment of the present application, adjacent first and second frames of a video containing a barcode are obtained, and a difference operation is performed on the first and second frames to obtain a first difference image. If the number of pixels occupied by the largest connected domain among all connected domains in the first difference image is greater than a first preset value, indicating that the video is relatively stable, an image is selected from the remaining frames of the video as a third frame, and the third frame is differenced with the second frame to obtain a binary region containing the barcode in the third frame. By using the second frame of the previous stable video as the background frame, repeated calculations can be avoided, reducing the utilization of computing resources. The barcode region is determined based on the length and width of the binary region, and the barcode in the barcode region is decoded to obtain the information corresponding to the barcode. The present application obtains the barcode region by performing calculations on three frames of the video. In the case of a complex shooting background, it can obtain a relatively complete barcode region independently of the shooting angle and the placement of the object, thereby improving the decoding accuracy of the barcode.

[0065] Figure 4 This is a flowchart of another barcode recognition method provided by the embodiment of the present application, referring to Figure 4 , this step may specifically include: Step S1, obtaining the first and second adjacent frames of the video, and performing moving target detection using an adjacent frame difference method; Step S2, determine whether there is a moving target, if there is a moving target, jump to step S1, otherwise jump to step S3; Step S3, using the second frame image as a background frame image and the third frame image to perform moving target detection using a background elimination method; Step S4, determine whether there is a moving target, if there is a moving target, jump to step S5, otherwise jump to step S12; Step S5, binarizing the image using the barcode segmentation model, and then accurately positioning the barcode image; Step S6, judging whether the barcode image is recognized correctly, if the barcode image is recognized correctly, jumping to step S12, otherwise jumping to step S7; Step S7, using an adaptive barcode enhancement algorithm to enhance the barcode image to obtain an enhanced image; Step S8, using zbar and zxing to decode the enhanced image to obtain decoded information; 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; Step S10, scaling the barcode image using the scaling factor to obtain a scaled barcode image; Step S11, using zbar and zxing to decode the scaled barcode image to obtain decoded information; Step S12: Use zbar and zxing to decode the barcode image to obtain decoded information.

[0066] Figure 5 This is a flowchart of another barcode recognition method provided in the embodiment of the present application, referring to Figure 5 , this step may specifically include: Step M1, obtaining the captured video; Step M2, performing moving target detection on the frame images in the captured video to obtain a moving area; Step M3, detecting the motion area to obtain a barcode area; Step M4, cropping the barcode area to obtain a barcode image; Step M5: adaptively enhance the barcode image to obtain an enhanced image, or scale the barcode image to obtain a scaled barcode image; Step M6: decode the enhanced image or the scaled barcode image to obtain information corresponding to the image.

[0067] Figure 6 is a block diagram of a barcode recognition device 30 provided in an embodiment of the present application, the device comprising: A first operation module 301 is configured to obtain a first frame image and a second frame image that are adjacent to each other in a video shot including a barcode, and 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 represent the degree of difference between the first frame image and the second frame image; A second operation module 302 is configured to obtain all connected domains of the first difference image. If the number of pixels occupied by the largest connected domain among all the connected domains is greater than a first preset value, an image is selected from the remaining frames of the captured 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 binary region containing the barcode in the third frame image. The first decoding module 303 is configured to obtain the length and width of the binary area, determine the barcode area according to the length and width of the binary area, and decode the barcode in the barcode area to obtain information corresponding to the barcode.

[0068] Optionally, the first operation module includes: A first conversion submodule, configured to convert the first frame image into a first grayscale image, and convert the second frame image into a second grayscale image; a first edge extraction submodule, configured to perform edge extraction on the first grayscale image to obtain a first edge image, and to perform edge extraction on the second grayscale image to obtain a second edge image; The first calculation submodule is configured to calculate a first pixel difference between a pixel in the first edge image and a corresponding pixel in the second edge image, and construct a first difference image according to an absolute value of the first pixel difference.

[0069] Optionally, the first edge extraction submodule includes: A first acquisition unit is used to acquire a first convolution kernel in the horizontal direction and a second convolution kernel in the vertical direction; a first convolution unit, configured to convolve the first grayscale image using the first convolution kernel and the second convolution kernel respectively, to obtain a first gradient matrix of the first grayscale image; a second convolution unit, configured to convolve the second grayscale image using the first convolution kernel and the second convolution kernel respectively, to obtain a second gradient matrix of the second grayscale image; A processing unit is configured to perform binarization processing on the first gradient matrix and the second gradient matrix respectively to obtain the first edge image and the second edge image.

[0070] Optionally, the processing unit includes: a calculation subunit, configured to calculate 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; a first modifying subunit, 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 to modify the gradient value to a second pixel value representing black 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; a second modifying subunit, configured to modify the gradient value in the second gradient matrix to a first pixel value representing white if the gradient value is greater than the second average value multiplied by a second preset value, and to modify the gradient value to a second pixel value representing black 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; A generating subunit is configured to generate the first edge image and the second edge image according to the first pixel value and the second pixel value.

[0071] Optionally, the second operation module includes: a second edge extraction submodule, configured to perform edge extraction on a third grayscale image corresponding to the third frame image to obtain a third edge image, and to perform edge extraction on a second grayscale image corresponding to the second frame image to obtain a second edge image; a second calculation submodule, configured to calculate a second pixel difference between a pixel in the third edge image and a corresponding pixel in the second edge image, and construct a second difference image according to an absolute value of the second pixel difference; The generation submodule is configured to obtain the coordinates of the pixel points of the connected domain of the second difference image, generate a minimum bounding rectangle of the connected domain based on the coordinates of the pixel points of the connected domain, and use the minimum bounding rectangle as the binary area containing the barcode.

[0072] Optionally, the first decoding module includes: a third calculation submodule, configured to divide the length by the width to obtain an aspect ratio; a fourth calculation submodule, configured to calculate the area of the binary region, and when the aspect ratio is within a first range and the area of the binary region is within a second range, multiply the length by the width, and divide the area of the binary region by the product of the length and the width to obtain a rectangularity; the rectangularity is used to indicate the degree of similarity between the binary region and the rectangular region; The cropping submodule is configured to crop the binarized area to obtain the barcode area when the rectangularity is greater than a third preset value.

[0073] Optionally, the device further includes: an adjustment module, configured to obtain the direction of the barcode image when the barcode image is incorrectly recognized, and adjust the barcode image to a horizontal barcode image if the direction of the barcode image is vertical; the direction of the barcode image is the arrangement direction of the barcodes in the barcode image; a mean filtering module configured to perform mean filtering on the horizontal barcode image to obtain a mean filtered image, and obtain the enhanced image based on a comparison result between pixel values of pixels in the mean filtered image and pixel values of corresponding pixels in the horizontal barcode image; The second decoding module is used to decode the enhanced image to obtain information corresponding to the enhanced image.

[0074] Optionally, the mean filtering module includes: a first modifying submodule, configured to modify the pixel value of the corresponding pixel point in the enhanced image to a second pixel value representing black if the difference between the pixel value of the horizontal barcode image pixel point and the pixel value of the corresponding pixel point in the mean filtered image is less than a fourth preset value; a second modifying submodule, configured to modify the pixel value of the corresponding pixel point in the enhanced image to a first pixel value representing white if the difference between the pixel value of the horizontal barcode image pixel point and the pixel value of the corresponding pixel point in the mean filtered image is greater than a fifth preset value; The third modification submodule is used to divide the difference between the pixel value of the horizontal barcode image pixel point and the pixel value of the corresponding pixel point in the mean filtered image by the fifth preset value, and add the division result to the sixth preset value to obtain an addition result, and modify the pixel value of the corresponding pixel point in the enhanced image to the addition result if the difference between the pixel value of the horizontal barcode image pixel point and the pixel value of the corresponding pixel point in the mean filtered image is greater than the fourth preset value and less than the fifth preset value.

[0075] Optionally, the device further includes: A scaling module, configured to scale the barcode image using a preset scaling factor to obtain a scaled barcode image when the barcode image is incorrectly recognized; The third decoding module is configured to decode the scaled barcode image to obtain information corresponding to the scaled barcode image.

[0076] Optionally, the device further includes: The judgment module is configured to enter the step of obtaining a first frame image and a second frame image adjacent to each other in the captured video including the barcode if the number of pixels occupied by the largest connected domain among all connected domains is less than the first preset value.

[0077] Optionally, the second operation module includes: The determination submodule is configured to select an image adjacent to the second frame image as the third frame image, or randomly select an image from the remaining frame images of the captured video as the third frame image.

[0078] In summary, in an embodiment of the present application, adjacent first and second frames of a video containing a barcode are obtained, and a difference operation is performed on the first and second frames to obtain a first difference image. If the number of pixels occupied by the largest connected domain among all connected domains in the first difference image is greater than a first preset value, indicating that the video is relatively stable, an image is selected from the remaining frames of the video as a third frame, and the third frame is differenced with the second frame to obtain a binary region containing the barcode in the third frame. By using the second frame of the previous stable video as the background frame, repeated calculations can be avoided, reducing the utilization of computing resources. The barcode region is determined based on the length and width of the binary region, and the barcode in the barcode region is decoded to obtain the information corresponding to the barcode. The present application obtains the barcode region by performing calculations on three frames of the video. In the case of a complex shooting background, it can obtain a relatively complete barcode region independently of the shooting angle and the placement of the object, thereby improving the decoding accuracy of the barcode.

[0079] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0080] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0081] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0082] An embodiment of the present application provides a barcode recognition device, comprising a memory and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by one or more processors to perform the methods described in one or more of the above embodiments.

[0083] Figure 7 4 is a block diagram of an electronic device 400 provided in an embodiment of the present application. For example, the electronic device 400 may 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.

[0084] Reference Figure 7The electronic device 400 may include one or more of the following components: a processing component 402 , a memory 404 , a power 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 .

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

[0086] The memory 404 is used to store various types of data to support operations on the electronic device 400. Examples of such data include instructions for any application or method operating on the electronic device 400, contact data, phone book data, messages, pictures, multimedia, etc. The memory 404 can be implemented by any type of volatile or non-volatile storage 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.

[0087] The power supply assembly 406 provides power to the various components of the electronic device 400. The power supply assembly 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 400.

[0088] The multimedia component 408 includes a screen that provides an output interface between the electronic device 400 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, it may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensors can not only sense the demarcation of a touch or slide action, but also detect the duration and pressure associated with the touch or slide action. In some embodiments, the multimedia component 408 includes a front-facing camera and / or a rear-facing camera. When the electronic device 400 is in an operating mode, such as a capture mode or a multimedia mode, the front-facing camera and / or the rear-facing camera can receive external multimedia data. Each front-facing camera and the rear-facing camera can have a fixed optical lens system or have focal length and optical zoom capabilities.

[0089] The audio component 410 is used to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC) that is used to receive external audio signals when the electronic device 400 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may 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.

[0090] The input / output interface 412 provides an interface between the processing component 402 and peripheral interface modules, such as a keyboard, a click wheel, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.

[0091] The sensor assembly 414 includes one or more sensors for providing various aspects of status assessment for the electronic device 400. For example, the sensor assembly 414 can detect the open / closed state of the electronic device 400, the relative positioning of components, such as the display and keypad of the electronic device 400. The sensor assembly 414 can also detect changes in the 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 of the electronic device 400, and temperature changes of the electronic device 400. The sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 414 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 414 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0092] The communication component 416 is used 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 carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 416 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 416 also includes 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) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.

[0093] In an exemplary embodiment, the electronic device 400 may be implemented by 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, microcontrollers, microprocessors, or other electronic components to implement the methods provided in the embodiments of the present application.

[0094] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, which can be executed by a processor 420 of an electronic device 400 to perform the above method. For example, the non-transitory storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0095] Figure 8 is a block diagram of another electronic device 500 provided in an embodiment of the present application. For example, the electronic device 500 can be provided as a server. 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. The application stored in the memory 532 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 522 is configured to execute the instructions to perform the method provided in the embodiments of the present application.

[0096] The electronic device 500 may further 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 may operate based on an operating system stored in the memory 532, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or the like.

[0097] An embodiment of the present application further provides a computer program product, including a computer program, which implements the method described in the above embodiment when executed by a processor.

[0098] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of the present application and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0099] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A barcode recognition method, characterized in that: The method comprises: Obtaining a first frame image and a second frame image adjacent to each other in a captured video including a barcode, and performing 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 represent a degree of difference between the first frame image and the second frame image; Obtaining all connected domains of the first difference image, and if the number of pixels occupied by the largest connected domain among all the connected domains is greater than a first preset value, selecting an image from the remaining frame images of the captured video as a third frame image, and performing a 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; The length and width of the binary area are obtained, and a barcode area is determined according to the length and width of the binary area. The barcode in the barcode area is decoded to obtain information corresponding to the barcode.

2. The method according to claim 1, characterized in that The performing a difference operation on the first frame image and the second frame image to obtain a first difference image includes: Converting the first frame image into a first grayscale image, and converting the second frame image into a second grayscale image; 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; A first pixel difference between a pixel in the first edge image and a corresponding pixel in the second edge image is calculated, and a first difference image is constructed based on an absolute value of the first pixel difference.

3. The method according to claim 2, characterized in that The performing edge extraction on the first grayscale image to obtain a first edge image, and the performing edge extraction on the second grayscale image to obtain a second edge image, comprises: Obtain a first convolution kernel in the horizontal direction and a second convolution kernel in the vertical direction; Convolving the first grayscale image using the first convolution kernel and the second convolution kernel respectively to obtain a first gradient matrix of the first grayscale image; Convolving the second grayscale image using the first convolution kernel and the second convolution kernel respectively to obtain a second gradient matrix of the second grayscale image; Binarization is performed on the first gradient matrix and the second gradient matrix respectively to obtain the first edge image and the second edge image.

4. The method according to claim 3, characterized in that The binarizing the first gradient matrix and the second gradient matrix to obtain the first edge image and the second edge image includes: Calculating 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; If the gradient value in the first gradient matrix is greater than the first average value multiplied by a second preset value, modify the gradient value 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, modify the gradient value 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 a second preset value, modify the gradient value to a 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 a second preset value, modify the gradient value to a second pixel value representing black; The first edge image and the second edge image are generated according to the first pixel value and the second pixel value.

5. The method according to claim 1, wherein The step of performing a differential operation on the third frame image and the second frame image to obtain a binary region containing a barcode in the third frame image includes: Performing edge extraction on a third grayscale image corresponding to the third frame image to obtain a third edge image, and performing edge extraction on a second grayscale image corresponding to the second frame image to obtain a second edge image; Calculating a second pixel difference between a pixel in the third edge image and a corresponding pixel in the second edge image, and constructing a second difference image based on an absolute value of the second pixel difference; The coordinates of the pixels of the connected domain of the second difference image are obtained, a minimum bounding rectangle of the connected domain is generated according to the coordinates of the pixels of the connected domain, and the minimum bounding rectangle is used as the binarized region containing the barcode.

6. The method according to claim 1, characterized in that Determining the barcode region according to the length and width of the binary region includes: Dividing the length by the width to obtain an aspect ratio; Calculating the area of the binary region, and when the aspect ratio is within a first range and the area of the binary region is within a second range, multiplying the length by the width, and dividing the area of the binary region by the product of the length and the width to obtain a rectangularity; the rectangularity is used to indicate the degree of similarity between the binary region and the rectangular region; When the rectangular degree is greater than a third preset value, the binarized area is cropped to obtain the barcode area.

7. The method according to claim 1, characterized in that After decoding the barcode in the barcode area to obtain information corresponding to the barcode, the method further includes: When the barcode image is incorrectly recognized, 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; performing mean filtering on the horizontal barcode image to obtain a mean filtered image, and obtaining an enhanced image based on a result of comparing pixel values of pixels in the mean filtered image with pixel values of corresponding pixels in the horizontal barcode image; The enhanced image is decoded to obtain information corresponding to the enhanced image.

8. The method according to claim 7, characterized in that Obtaining the enhanced image according to a comparison result between the pixel value of a pixel point in the mean filtered image and the pixel value of a corresponding pixel point 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, modifying the pixel value of the corresponding pixel in the enhanced image to a 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, modifying the pixel value of the corresponding pixel in the enhanced image to a first pixel value representing white; If the difference between the pixel value of the horizontal barcode image pixel point and the pixel value of the corresponding pixel point in the mean filtered image is greater than the fourth preset value and less than the fifth preset value, the difference is divided by the fifth preset value, and the division result is added to the sixth preset value to obtain an addition result, and the pixel value of the corresponding pixel point in the enhanced image is modified to the addition result.

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

10. The method according to claim 1, characterized in that The method further comprises: If the number of pixels occupied by the largest connected domain among all connected domains is smaller than the first preset value, the process proceeds to the step of acquiring the adjacent first frame image and second frame image in the captured video including the barcode.

11. The method according to claim 1, wherein The step of selecting an image from the remaining frame images of the captured video as the third frame image includes: An image adjacent to the second frame image is used as the third frame image, or an image is randomly selected from the remaining frame images of the captured video as the third frame image.

12. A barcode recognition device, characterized in that: The device comprises: a first operation module, configured to obtain a first frame image and a second frame image adjacent to each other in a video shot including a barcode, and 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 represent a degree of difference between the first frame image and the second frame image; a second operation module, configured to obtain all connected domains of the first difference image, and if the number of pixels occupied by the largest connected domain among all the connected domains is greater than a first preset value, select an image from the remaining frame images of the captured video as a third frame image, and perform a 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; The first decoding module is used to obtain the length and width of the binary area, determine the barcode area according to the length and width of the binary area, and decode the barcode in the barcode area to obtain information corresponding to the barcode.

13. An electronic device, characterized in that: The invention comprises a processor, a memory and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the barcode recognition method according to any one of claims 1 to 11.

14. A readable storage medium, characterized in that The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the barcode recognition method according to any one of claims 1 to 11 are implemented.

Citation Information

Patent Citations

  • Panorama video frame image processing method and device

    CN105844256A

  • Bar code decoding method, terminal equipment and storage medium

    CN112241641A

  • Bar code detection method and device, equipment and storage apparatus

    CN112699704A

  • Electric energy meter image information acquisition method based on background difference method

    CN116485844A

  • Two-dimensional code decoding method and related device, electronic equipment and storage medium

    CN117574929A