Barcode detection method, device and storage medium based on improved YOLOv8 model
Patent Information
- Application Number
- CN202610901248.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-22
- Publication Date
- 2026-10-20
AI Technical Summary
[0004]鉴于上述问题,本申请实施例提供了一种基于改进的YOLOv8模型的条形码检测方法、设备和存储介质,用于解决现有技术中存在的现有的YOLOv8模型无法准确检测条形码的问题
[0015]本申请实施例中,通过在改进的YOLOv8模型的颈部网络设置条码增强型混合特征融合模块,将第一中间特征切分为低维特征和高维特征,并对低维特征进行加权处理,能够针对性地增强对条码细节敏感的特征表达,随后对加权后的低维特征与高维特征进行空间注意力增强处理和通道注意力校准处理,能够从空间维度抑制背景干扰并突出条码的高对比度边缘与纹理结构,同时从通道维度校准特征响应,从而有效解决了条码检测中边缘细节丢失及背景干扰抑制不足的问题,提升了模型对不同尺度及复杂场景下条形码的检测精度。且通过利用条码增强型混合特征融合模块替换原YOLOv8颈部的相应位置的C2F模块,不改变上采样模块和拼接模块等模块间的连接结构,改动小、落地成本低,为后续检测头提供高质量、高鲁棒性的条码特征输入。
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] This application relates to the field of barcode recognition technology, specifically to a barcode detection method, device, and storage medium based on an improved YOLOv8 model. Background Technology
[0002] With the rapid development of intelligent manufacturing and logistics automation, barcodes such as 1D barcodes, QR codes, and DM codes (collectively referred to as barcodes) have become the core carriers of information storage and traceability, and are widely used in key scenarios such as product manufacturing, warehousing management, and logistics distribution. To obtain the information carried by a barcode, a camera is used to capture the barcode. When decoding the barcode in the captured image, it is usually necessary to first detect the position of the barcode in the image before decoding the detected barcode area. If the background area outside the barcode area in the captured image is complex, or if the barcode is damaged, reflective, or tilted at a large angle, the difficulty of barcode detection will increase. However, if the position of the barcode in the image cannot be accurately detected, decoding of the barcode is impossible.
[0003] The YOLOv8 series of models is widely used in embedded barcode readers due to its advantages such as fast detection speed, lightweight structure, and deployment on terminal devices. The YOLOv8 model extracts multi-scale features through a backbone network and relies on a neck feature fusion structure to achieve complementarity between shallow fine-grained features and deep semantic features, providing a more comprehensive feature representation for the final detection head. However, due to the strong edges, strong periodicity, and strong texture of barcodes, existing YOLOv8 models cannot accurately detect barcodes. Summary of the Invention
[0004] In view of the above problems, this application provides a barcode detection method, device and storage medium based on an improved YOLOv8 model to solve the problem that the existing YOLOv8 model cannot accurately detect barcodes in the prior art.
[0005] According to one aspect of the embodiments of this application, a barcode detection method based on an improved YOLOv8 model is provided. The method includes: inputting an image to be detected into the backbone network of an improved YOLOv8 model for feature extraction to obtain multiple first features of different scales output by the backbone network; inputting the multiple first features into the neck network of the improved YOLOv8 model, and performing feature fusion on the multiple first features through the neck network to obtain multiple second features of different scales, wherein the neck network includes a first unit and a barcode-enhanced hybrid feature fusion module, and the first unit is used to perform feature fusion on the multiple first features. The barcode-enhanced hybrid feature fusion module is used to: divide the first intermediate feature into low-dimensional features and high-dimensional features; perform weighted processing on the low-dimensional features to obtain weighted low-dimensional features; and perform spatial attention enhancement processing, channel attention calibration processing, and feature fusion processing on the weighted low-dimensional features and the high-dimensional features to obtain one of the plurality of second features; input the plurality of second features into the detection head of the improved YOLOv8 model for detection to obtain detection results, wherein the detection results include the position information of the barcode in the image to be detected.
[0006] In one optional embodiment, the barcode-enhanced hybrid feature fusion module includes a second unit, a third unit, and a channel attention calibration unit. The second unit includes a cascaded edge-sensitive spatial attention module, a first module, a second module, and a first activation function layer. The third unit includes a cascaded edge-sensitive spatial attention module, a first module, a second module, and a second activation function layer. The edge-sensitive spatial attention module is used to perform edge enhancement and spatial attention processing on the input features. The first and second modules are both used to perform convolution operations and normalized activation processing on the input features. Specifically, the barcode-enhanced hybrid feature fusion module performs the following steps: [The text abruptly ends here, so the translation stops.] The weighted low-dimensional features are input into the edge-sensitive spatial attention module in the second unit, and the low-dimensional features and the features output by the first activation function layer are multiplied element-wise to obtain the third feature; the high-dimensional features are input into the edge-sensitive spatial attention module in the third unit, and the high-dimensional features and the features output by the second activation function layer are multiplied element-wise to obtain the fourth feature; the third feature and the fourth feature are fused to obtain the fifth feature; the fifth feature is convolved to obtain the sixth feature, and the sixth feature is calibrated by the channel attention calibration unit to obtain the seventh feature.
[0007] In one optional embodiment, the barcode-enhanced hybrid feature fusion module further includes a third module, a fourth module, a fifth module, and a third activation function layer. The third, fourth, and fifth modules are all used to perform convolution operations and normalized activation processing on the input features. Specifically, the barcode-enhanced hybrid feature fusion module is further used to perform the following steps: processing the seventh feature through the third activation function layer to obtain the eighth feature; performing element-wise addition of the low-dimensional feature and the feature output by the first module in the second unit to obtain the ninth feature; and processing the ninth feature through the third module to obtain... The process proceeds as follows: The tenth feature is obtained by performing element-wise multiplication on the eighth and tenth features; the eleventh feature is obtained by performing element-wise addition on the high-dimensional feature and the feature output by the first module in the third unit; the twelfth feature is obtained by processing the twelfth feature through the fourth module; the thirteenth feature is obtained by performing element-wise multiplication on the thirteenth feature and the eighth feature; the fourteenth feature and the eleventh feature are fused together to obtain the fifteenth feature; and the fifteenth feature is obtained by processing the fifth module to obtain one of the plurality of second features.
[0008] In one alternative approach, the channel attention calibration unit comprises a cascaded global average pooling layer, a one-dimensional convolutional layer, and a fourth activation function layer.
[0009] In one alternative approach, the channel attention calibration unit is specifically used to input the sixth feature into the global average pooling layer, and to multiply the sixth feature and the feature output by the fourth activation function layer element-wise to obtain the seventh feature.
[0010] In one alternative embodiment, the first module includes a cascaded 3×3 convolution module, a batch normalization module, and a corrected linear unit; the second module includes a cascaded 1×1 convolution module, a batch normalization module, and a corrected linear unit.
[0011] In one optional embodiment, the edge-sensitive spatial attention module includes a 1×1 convolutional module, a fifth activation function layer, a sixth activation function layer, a global average pooling layer, a global max pooling layer, and a channel concatenation layer. Specifically, the edge-sensitive spatial attention module performs the following steps: processing the features input to the edge-sensitive spatial attention module through the cascaded 1×1 convolutional module and the fifth activation function layer to obtain a first attention feature; processing the first attention feature through the global average pooling layer to obtain a second attention feature; processing the first attention feature through the global max pooling layer to obtain a third attention feature; concatenating the second and third attention features through the channel concatenation layer to obtain a fourth attention feature; processing the fourth attention feature through the cascaded 1×1 convolutional module and the sixth activation function layer to obtain a nonlinear feature; and performing element-wise multiplication of the nonlinear feature and the features input to the edge-sensitive spatial attention module to obtain and output the output feature of the edge-sensitive spatial attention module.
[0012] In one alternative approach, the low-dimensional feature is F. low The weighted low-dimensional features Through the following formula It is confirmed that, among them, .
[0013] According to another aspect of the embodiments of this application, a barcode detection device based on an improved YOLOv8 model is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the barcode detection method based on the improved YOLOv8 model as described above.
[0014] According to another aspect of the embodiments of this application, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the barcode detection method based on the improved YOLOv8 model as described above.
[0015] In this embodiment, a barcode-enhanced hybrid feature fusion module is set in the neck network of the improved YOLOv8 model. The first intermediate feature is segmented into low-dimensional and high-dimensional features, and the low-dimensional features are weighted to specifically enhance the expression of features sensitive to barcode details. Subsequently, spatial attention enhancement and channel attention calibration are applied to the weighted low-dimensional and high-dimensional features. This suppresses background interference in the spatial dimension and highlights the high-contrast edges and texture structure of the barcode, while simultaneously calibrating the feature response in the channel dimension. This effectively solves the problems of edge detail loss and insufficient background interference suppression in barcode detection, improving the model's detection accuracy for barcodes at different scales and in complex scenes. Furthermore, by replacing the corresponding C2F module in the neck of the original YOLOv8 model with the barcode-enhanced hybrid feature fusion module, the connection structure between modules such as the upsampling and stitching modules remains unchanged. This requires minimal modification and has low implementation costs, providing high-quality and robust barcode feature input for subsequent detection heads.
[0016] The improved YOLOv8 model provided in this application embodiment retains the original architecture compatibility of the original YOLOv8 model while strictly controlling the amount of computation and parameters to ensure the real-time inference requirements on the embedded code reader side.
[0017] The above description is merely an overview of the technical solutions of the embodiments of this application. In order to better understand the technical means of the embodiments of this application and to implement them in accordance with the contents of the specification, and to make the above and other objects, features and advantages of the embodiments of this application more obvious and understandable, specific implementation methods of this application are described below. Attached Figure Description
[0018] The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 A flowchart illustrating the barcode detection method based on the improved YOLOv8 model provided in this application embodiment is shown. Figure 2 A schematic diagram of the structure of the improved YOLOv8 model provided in the embodiments of this application is shown; Figure 3 This paper shows a schematic diagram of the structure of the barcode enhanced hybrid feature fusion module provided in an embodiment of this application; Figure 4 This paper shows a schematic diagram of the structure of the edge-sensitive spatial attention module provided in an embodiment of this application; Figure 5 A schematic diagram of the structure of the first module provided in an embodiment of this application is shown; Figure 6A schematic diagram of the structure of the second module provided in an embodiment of this application is shown; Figure 7 A schematic diagram of the channel attention calibration unit provided in an embodiment of this application is shown; Figure 8 A schematic diagram of the structure of a barcode detection device based on an improved YOLOv8 model provided in an embodiment of this application is shown. Detailed Implementation
[0019] Exemplary embodiments of the present application will now be described in more detail with reference to the accompanying drawings. Although exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application may be implemented in various forms and should not be limited to the embodiments set forth herein.
[0020] Due to the strong edges, strong periodicity, and strong texture of barcodes, existing YOLOv8 models cannot accurately detect them. On one hand, the traditional feature fusion modules in existing YOLOv8 models lack specific enhancement mechanisms for barcode edges and stripe structures, resulting in weak preservation of high-frequency details. In complex backgrounds, they are easily affected by barcode-like textures, leading to blurred edges, location misalignment, and false detections. On the other hand, the channel attention and spatial attention mechanisms in existing YOLOv8 models are mostly general structures, not specifically optimized for the periodic stripes of barcodes, failing to effectively highlight the unique structure of barcodes and suppress irrelevant background channels. Furthermore, during cross-scale feature fusion, low-dimensional fine-grained features are often suppressed by high-level semantic features, and detailed information of small-sized and weakly textured barcodes is easily lost, leading to an increased false detection rate.
[0021] Therefore, how to design a feature fusion method that can enhance edge response, focus on periodic structure, and adaptively enhance low-dimensional fine-grained features while maintaining the model's lightweight nature has become a key technical bottleneck for improving the accuracy, robustness, and practicality of barcode detection, and is also a problem that urgently needs to be solved in this field.
[0022] Based on this, this application proposes a barcode detection method based on an improved YOLOv8 model. The improved YOLOv8 model provided in the embodiments of this application is used to detect the position of the barcode in the image, so as to improve the accuracy of the detection results. Figure 1This diagram illustrates a flowchart of a barcode detection method based on an improved YOLOv8 model provided in an embodiment of this application. The method is executed by a barcode detection device based on the improved YOLOv8 model. This device can be a device including one or more processors, such as a server, computer, barcode reader, touchscreen phone, smartphone, tablet computer, or other electronic device. The processor may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application; no limitation is made herein. The one or more processors included in the barcode detection device based on the improved YOLOv8 model can be processors of the same type, such as one or more CPUs; or they can be processors of different types, such as one or more CPUs and one or more ASICs; no limitation is made herein.
[0023] The barcode detection equipment is equipped with the improved YOLOv8 model according to embodiments of this application. Figure 2 A schematic diagram of the structure of the improved YOLOv8 model provided in the embodiments of this application is shown. The following will be combined with... Figure 1 and Figure 2 The barcode detection method of this application embodiment will be introduced together.
[0024] like Figure 1 As shown, the method includes the following steps 110 to 130.
[0025] Step 110: Input the image to be detected into the backbone network of the improved YOLOv8 model for feature extraction, and obtain multiple first features of different scales output by the backbone network.
[0026] The image to be detected is an image captured by a camera device of the barcode. If the barcode detection device based on the improved YOLOv8 model implementing this embodiment includes a camera device, the image to be detected can be an image captured by the camera device of that device; if the barcode detection device based on the improved YOLOv8 model implementing this embodiment does not include a camera device, the barcode image can be captured by an electronic device including a camera device and then transmitted to the barcode detection device based on the improved YOLOv8 model implementing this embodiment via wired network, WIFI, or Bluetooth.
[0027] like Figure 2As shown, the improved YOLOv8 model includes a backbone network, a neck network, and a detector head. The backbone network and detector head have the same structure as the original YOLOv8 model, and will not be described further here. The neck network is an improvement on the original YOLOv8 model, which will be detailed below.
[0028] It is worth noting that before implementing the barcode detection method based on the improved YOLOv8 model provided in this application embodiment, the improved YOLOv8 model is first trained using a training dataset, and then tested using a test dataset. If the test passes, the trained model is deployed to the barcode detection device.
[0029] In a barcode detection device with a deployed model, the image to be detected is input into the backbone network of a trained improved YOLOv8 model for feature extraction. The first feature F101 at the first scale is output by a Faster Implementation of Cross Stage Partial Bottleneck with 2convolutions (C2F) module in the backbone network, the first feature F102 at the second scale is output by another C2F module, and the first feature F103 at the third scale is output by a Spatial Pyramid Pooling - Fast (SPPF) module.
[0030] Step 120: Input multiple first features into the neck network of the improved YOLOv8 model, and perform feature fusion on the multiple first features through the neck network to obtain multiple second features at different scales (including second feature F201 at the first scale, second feature F202 at the second scale, and second feature F203 at the third scale).
[0031] like Figure 2 As shown in the embodiments of this application, the neck network of the improved YOLOv8 model includes a first unit and a barcode-enhanced hybrid feature fusion module, wherein the barcode-enhanced hybrid feature fusion module replaces the C2F module at the corresponding position in the original YOLOv8 model. The first unit includes a cascaded upsampling module, a concat module, a C2F module, an upsampling module, and a concat module.
[0032] The barcode-enhanced hybrid feature fusion module divides the first intermediate feature Fm1 output by the first unit into low-dimensional features F. low (i.e., the first feature F101 at the first scale) and the high-dimensional feature F high (i.e., feature F1), for low-dimensional feature Flow We perform weighted processing to obtain the weighted low-dimensional features. And for the weighted low-dimensional features and high-dimensional features F high Spatial attention enhancement processing, channel attention calibration processing, and feature fusion processing are performed to obtain the second feature F201 at the first scale (i.e., the second feature at one of the three scales). The barcode-enhanced hybrid feature fusion module uses the formula... Determine the weighted low-dimensional features ,and .in, This is a scalar learnable parameter, initially set to 1.1, used to enhance low-dimensional features. During training, it is automatically updated through backpropagation, and the network adaptively adjusts based on the loss of the barcode detection task. Size: If low-dimensional details contribute significantly to barcode detection, It will increase (e.g., 1.2~1.4), enhancing edges and stripes; if background noise interference is strong, It will be appropriately reduced to avoid overfitting. It automatically adjusts during training, accurately adapting to barcode sizes and background complexity in different scenarios.
[0033] To address the characteristics of barcodes—small target size and strong marginal dependence—this application embodiment, before cross-level feature fusion, processes the low-dimensional feature F... low Introducing a learnable scaling factor By adaptively enhancing the weight of low-dimensional features, the proportion of barcode edges, stripes and other details in the fusion process is strengthened, avoiding the weakening or submergence of small-sized barcode features when fusing high-level semantic features. Moreover, this method does not require additional network structures and has extremely low computational overhead.
[0034] Step 130: Input multiple second features into the detection head of the improved YOLOv8 model for detection and obtain the detection results.
[0035] Specifically, by inputting the second feature F201 of the first scale, the second feature F202 of the second scale, and the second feature F203 of the third scale into the detection head, the detection result output by the detection head can be obtained, and the detection result includes the position information of the barcode in the image to be detected.
[0036] In this embodiment, by setting a barcode-enhanced hybrid feature fusion module in the neck network of the improved YOLOv8 model, the first intermediate feature is divided into low-dimensional and high-dimensional features. The low-dimensional features are then weighted to specifically enhance the feature representation sensitive to barcode details. Subsequently, spatial attention enhancement and channel attention calibration are applied to the weighted low-dimensional and high-dimensional features. This suppresses background interference in the spatial dimension and highlights the high-contrast edges and texture structure of the barcode, while simultaneously calibrating the feature response in the channel dimension. This effectively solves the problems of edge detail loss and insufficient background interference suppression in barcode detection, improving the model's detection accuracy for barcodes at different scales and in complex scenes. In other words, the improved YOLOv8 model performs edge-sensitive and periodic-aware attention enhancement on the image to be detected, enabling it to accurately focus on key barcode features and effectively suppress background noise. Therefore, the model is less susceptible to barcode-like interference regions in complex backgrounds, improving the model's barcode detection accuracy. Furthermore, the improved YOLOv8 model adaptively enhances the low-dimensional feature F through a learnable scaling factor. low The weighting of barcode details in the fusion process ensures they remain significant in the final features, thereby improving the detection rate and accuracy of small-sized barcodes. Furthermore, by replacing the corresponding C2F module in the neck region of the original YOLOv8 with a barcode-enhanced hybrid feature fusion module, the connection structure between modules such as the upsampling and stitching modules remains unchanged. This approach requires minimal modification and has low implementation costs, providing high-quality, robust barcode feature input for subsequent detection heads.
[0037] The following will provide a detailed description in conjunction with the accompanying drawings. Figure 2 The barcode-enhanced hybrid feature fusion module. Figure 3 A schematic diagram of the structure of the barcode-enhanced hybrid feature fusion module provided in an embodiment of this application is shown. Figure 3 As shown, the barcode enhanced hybrid feature fusion module includes a second unit, a third unit, a channel attention calibration unit, a third module, a fourth module, a fifth module, and a third activation function layer. The second unit includes a cascaded Edge-Sensitive Spatial Attention Module (ESAM), a first module, a second module, and a first activation function layer. The third unit includes a cascaded Edge-Sensitive Spatial Attention Module, a first module, a second module, and a second activation function layer.
[0038] like Figure 3 As shown, the barcode-enhanced hybrid feature fusion module divides the first intermediate feature Fm1 into low-dimensional features F low and high-dimensional features F high Then, for the low-dimensional feature F low We perform weighted processing to obtain the weighted low-dimensional features. (Right now ), weighted low-dimensional features Input the edge-sensitive spatial attention module in the second unit and apply it to the low-dimensional feature F. low The feature Fm2 output from the first activation function layer in the second unit is multiplied element-wise to obtain the third feature F3. The barcode-enhanced hybrid feature fusion module then integrates the high-dimensional feature Fm2. high Input the edge-sensitive spatial attention module in the third unit and process the high-dimensional feature F. high The feature Fm3 output from the second activation function layer in the third unit is multiplied element-wise to obtain the fourth feature F4. Next, the barcode-enhanced hybrid feature fusion module fuses the third feature F3 and the fourth feature F4 to obtain the fifth feature F5. Then, a 1×1 convolution module (1×1 Conv) is used to convolve the fifth feature F5 to obtain the sixth feature F6. The sixth feature F6 is then calibrated using a channel attention calibration unit to obtain the seventh feature F7. Finally, the seventh feature is processed by the third activation function layer to obtain the eighth feature F8. Furthermore, the barcode-enhanced hybrid feature fusion module processes the low-dimensional feature Fm3. low The feature Fm4 output by the first module in the second unit is added element-wise to obtain the ninth feature F9. The ninth feature F9 is then processed by convolution and normalization activation by the third module to obtain the tenth feature. Finally, the eighth feature F8 and the tenth feature F10 are multiplied element-wise to obtain the eleventh feature F11.
[0039] The barcode-enhanced hybrid feature fusion module also applies high-dimensional feature F high The feature Fm5 output by the first module in the third unit is added element-wise to obtain the twelfth feature F12. The twelfth feature F12 is then convolved and normalized for activation by the fourth module to obtain the thirteenth feature F13. The thirteenth feature F13 and the eighth feature F8 are multiplied element-wise to obtain the fourteenth feature F14. The fourteenth feature F14 and the eleventh feature F11 are then fused to obtain the fifteenth feature F15. Finally, the fifteenth feature F15 is convolved and normalized for activation by the fifth module to obtain the second feature F201 of the first scale.
[0040] The barcode-enhanced hybrid feature fusion module provided in this application addresses the shortcomings of existing YOLov8 feature fusion structures in barcode detection by employing learnable low-dimensional weighting, edge-sensitive spatial attention, and periodic-aware channel attention.
[0041] Specifically, by introducing learnable scalars Low-dimensional features with fine granularity Global pre-weighting is performed to fundamentally enhance the prominence of fine-grained information such as edges and stripes in cross-scale fusion, preventing them from being suppressed by high-level semantic features; this is combined with an edge-sensitive spatial attention module to address low-dimensional features. The edge-specific enhancement of the branches further strengthens the high-contrast boundary features that are unique to small-sized barcodes. Compared to the C2F module at the corresponding position in the original YOLov8 model, the barcode-enhanced hybrid feature fusion module ensures that the detailed information of small barcodes remains significant throughout the feature stream, improving the detection rate and positioning accuracy of small-sized barcodes and solving the core pain point of low-dimensional details being buried.
[0042] The edge-sensitive spatial attention module first filters out background noise in non-edge areas in the spatial dimension, retaining only the high-contrast boundaries of the barcode. The channel attention calibration unit then filters out feature channels that do not have a periodic alternation of black and white, retaining only the effective channels corresponding to the barcode stripes. This dual filtering effectively distinguishes the barcode from barcode-like interference in the background, such as striped fabric, grid flooring, and metallic textures, thereby enhancing the anti-interference capability against complex backgrounds and reducing the false detection rate of barcode-like patterns.
[0043] Furthermore, the channel attention calibration unit incorporates the prior knowledge that the barcode has alternating black and white periodic stripes into the initialization of the one-dimensional convolutional kernel. This allows the model to possess prior knowledge of the barcode's periodic structure before training begins, thereby accelerating model convergence and improving generalization ability in scenarios with few samples. Furthermore, all core components in the barcode-enhanced hybrid feature fusion module adopt a lightweight design; the edge-sensitive spatial attention module uses 1×1 convolution and global pooling; and the channel attention calibration unit only adds directional initialization of the 1D convolution kernel. It uses scalar parameters with no computational overhead, and by replacing the corresponding C2F module in the neck of YOLOv8 with a barcode-enhanced hybrid feature fusion module, no other network structure needs to be modified, resulting in lower costs.
[0044] The improved YOLOv8 model provided in this application embodiment retains the original architecture compatibility of the original YOLOv8 model while strictly controlling the amount of computation and parameters through lightweight operations (1×1 convolution dimensionality reduction, learnable scalar weights, etc.) to ensure the real-time inference requirements on the embedded code reader side.
[0045] The following will provide a detailed description in conjunction with the accompanying drawings. Figure 3 Edge-sensitive spatial attention module in [the context of the project]. Figure 4 A schematic diagram of the edge-sensitive spatial attention module provided in an embodiment of this application is shown. Figure 4As shown, the edge-sensitive spatial attention module includes a 1×1 convolutional module (1×1Conv), an activation function layer (Sigmoid), a global average pooling layer, a global max pooling layer, and a channel splicing layer.
[0046] Specifically, the edge-sensitive spatial attention module processes the input feature Fin of the edge-sensitive spatial attention module through a cascaded 1×1 convolutional module and a fifth activation function layer to obtain the first attention feature Fa1. The first attention feature Fa1 is then processed through a global average pooling layer to obtain the second attention feature Fa2. The first attention feature Fa1 is then processed through a global max pooling layer to obtain the third attention feature Fa3. The second attention feature Fa2 and the third attention feature Fa3 are concatenated through a channel concatenation layer to obtain the fourth attention feature Fa4. The fourth attention feature Fa4 is then processed through a cascaded 1×1 convolutional module and a sixth activation function layer to obtain the nonlinear feature F2. The nonlinear feature F2 and the input feature Fin of the edge-sensitive spatial attention module are multiplied element-wise to obtain and output the output feature Fout of the edge-sensitive spatial attention module.
[0047] The barcode-enhanced hybrid feature fusion module provided in this application, based on general spatial attention, solves the problems of ordinary spatial attention being insensitive to high-contrast edges and easily interfered with by background textures.
[0048] Specifically, firstly, the input features are processed through a cascaded 1×1 convolutional module and an edge enhancement branch of the Sigmoid activation function (i.e., the fifth activation function layer). This step is specifically designed for the high-contrast black-and-white edges of barcodes. The 1×1 convolutional module performs a linear transformation on the channel information of each pixel of the input features, enhancing the gray-level differences between different channels. The Sigmoid activation function compresses the feature values to the 0~1 range, characterized by large gradients in extreme regions close to 0 and 1, and small gradients in intermediate gray-level regions. For barcodes, the pixel gray-level differences at the black-and-white boundaries are extremely large. After processing by the Sigmoid activation function, the feature responses at the boundaries of the barcode in the image to be detected are significantly amplified, while the feature responses of uniform textures and gradient regions in the background of the image to be detected are greatly compressed.
[0049] Secondly, the edge-enhanced features (i.e., the first attention feature Fa1) serve as input to two branches. One branch performs global average pooling (GAP) on the first attention feature Fa1, and the other branch performs global max pooling (GMP) on the first attention feature Fa1. These two branches work together to achieve accurate localization of the barcode region. Specifically, global average pooling calculates the average value of all pixels in each channel, capturing the overall brightness distribution and approximate location of the barcode. Since the average grayscale value of the barcode region in the image to be detected differs significantly from the background, average pooling effectively distinguishes the barcode region from the background region. Global max pooling extracts the maximum value of all pixels in each channel, capturing the most significant edge points and high-contrast features of the barcode. Because the black-and-white boundaries of the barcode are where the grayscale value changes most dramatically in the image to be detected, max pooling accurately locates these edge points.
[0050] Subsequently, the pooling results from the two branches are concatenated along the channel dimension, so that the resulting fourth attention feature Fa4 simultaneously contains feature vectors of both the overall barcode position and the precise edge positions, solving the problem of either inaccurate positioning or loss of detail inherent in single pooling methods. The concatenated feature (fourth attention feature Fa4) is processed by a 1×1 convolution module to compress the number of channels back to the original number, and then processed by the Sigmoid activation function (i.e., the sixth activation function layer) to generate a spatial weight map between 0 and 1, which is finally multiplied element-wise with the original input feature Fin. Positions with weight values close to 1 correspond to the edges and main body regions of the barcode; through the above processing, the features of the barcode's edges and main body regions are enhanced. Positions with weight values close to 0 correspond to the background region; through the above processing, the features of the background region are suppressed.
[0051] Finally, the weight map (i.e., the non-linear feature F2) is multiplied by the original input feature Fin, rather than by the edge-enhanced feature. This preserves the complete information of the original features and avoids the bias introduced by the edge enhancement branch affecting the final feature quality. General spatial attention (such as the spatial attention of CBAM) directly pools the original features without pre-enhancing the barcode edges. Therefore, it treats background textures and barcode edges equally, easily misidentifying stripes and grids in the background as barcodes. In contrast, the edge-sensitive spatial attention module in this embodiment allows the network to focus on the core high-contrast edge features of the barcode from the beginning, fundamentally reducing the false detection rate of the background and improving the localization accuracy of the barcode edges, thus improving the accuracy of the obtained barcode position information in the image to be detected.
[0052] The following will provide a detailed description in conjunction with the accompanying drawings. Figure 3 The first, second, third, fourth and fifth modules. Figure 5A schematic diagram of the structure of the first module provided in an embodiment of this application is shown. Figure 5 As shown, the first module includes a cascaded 3×3 convolution module (3×3Conv), a batch normalization module (BN), and a rectified linear unit (ReLU).
[0053] Figure 6 A schematic diagram of the structure of the second module provided in an embodiment of this application is shown. Figure 6 As shown, the second module includes a cascaded 1×1 convolution module (1×1Conv), a batch normalization module (BN), and a corrected linear unit (ReLU).
[0054] The structures of modules three, four, and five are identical to those of module two; therefore, their specific structures can be found by referring to [reference needed]. Figure 6 This will not be elaborated upon here.
[0055] The following will provide a detailed description in conjunction with the accompanying drawings. Figure 3 The channel attention calibration unit in the middle, Figure 7 A schematic diagram of the channel attention calibration unit provided in an embodiment of this application is shown. Figure 7 As shown, the channel attention calibration unit includes a cascaded global average pooling layer, a one-dimensional convolutional layer, and a fourth activation function layer (Sigmoid). Specifically, the channel attention calibration unit inputs the sixth feature F6 into the global average pooling layer, and performs element-wise multiplication of the sixth feature F6 and the feature F61 output by the fourth activation function layer to obtain and output the seventh feature F7.
[0056] In this embodiment, the channel attention calibration unit performs barcode periodic orientation initialization on a one-dimensional (1D) convolutional kernel based on the standard attention mechanism (EfficientChannel Attention, ECA). This solves the problem that general channel attention cannot specifically capture the alternation period of black and white barcodes and requires a large amount of data for training to converge.
[0057] The standard ECA process is as follows: First, global average pooling is used to compress the spatial information of each channel into a scalar; then, 1D convolution is used to capture the correlation between adjacent channels; finally, sigmoid is used to generate channel weights. Its core is to learn the dependencies between adjacent channels through 1D convolution. However, the 1D convolution kernels in standard ECA are randomly initialized. For targets with strong periodic structures like barcodes, the network requires a large amount of training data to learn which channels correspond to periodic stripes, resulting in slow convergence and poor performance in small sample scenarios.
[0058] In this embodiment, the channel attention calibration unit sets the initial value of the 1D convolutional kernel to [0.25, 0.5, 0.25], forming a Gaussian bandpass filter distribution with a high center and low sides. This distribution better matches the periodic structural characteristics of the barcode. The alternating black and white stripes of the barcode manifest as a periodic change in the strength of responses from adjacent channels in the channel dimension: when a channel responds strongly to black stripes, its adjacent channels respond strongly to white stripes, and so on. In this embodiment, the 1D convolutional kernel initialized to [0.25, 0.5, 0.25] precisely captures this periodic pattern of alternating responses from adjacent channels: it assigns the highest weight to the central channel and the second highest weight to the left and right adjacent channels, thereby strengthening the responses of all channels containing periodic stripe information. Therefore, the network possesses prior knowledge of the barcode's periodic structure before training begins, eliminating the need for relearning from scratch, thus improving convergence speed. Furthermore, it can more accurately distinguish between barcodes and non-periodic background textures in complex environments.
[0059] The channel statistical vector obtained by global average pooling in the channel attention calibration unit is processed by directional initialization 1D convolution, and then activated by Sigmoid to generate a channel weight map between 0 and 1. This map is then multiplied with the input features channel by channel. Channels with high weight values, corresponding to periodic features such as barcode stripes and modules, are significantly enhanced. Channels with low weight values, corresponding to invalid channels such as background noise and ambiguous semantics, are effectively suppressed. However, general channel attention (such as SE and ECA) treats all types of targets equally and does not utilize the prior knowledge of the periodic structure unique to barcodes. The channel attention calibration unit in this embodiment incorporates the prior knowledge that barcodes have alternating black and white periodic stripes into the initialization of the convolution kernel, allowing the network's attention mechanism to adapt to barcode recognition. This enables accurate capture of the periodic features of barcodes with less computation and less training data, thereby improving the detection accuracy of barcodes.
[0060] In summary, addressing the lack of attention enhancement mechanisms for barcode edges and periodic structures, this application's embodiments utilize an edge-sensitive spatial attention module and a channel attention calibration unit to achieve precise focusing of key barcode features and effective suppression of background interference. The edge-sensitive spatial attention module enhances leading edges and generates a spatial weight map, precisely enhancing barcode edge details; the channel attention calibration unit uses 1D convolutional kernel orientation initialization to adapt to the barcode's periodic structure and calibrates channel weights to highlight barcode features. Together, they distinguish barcodes from the background from both spatial and channel dimensions, overcoming the limitation of general attention mechanisms in specifically capturing barcode features and reducing the false detection rate of background interference.
[0061] To address the issue of low-dimensional fine-grained features being easily weakened in cross-scale fusion, this application employs a weighted fusion strategy based on low-dimensional fine-grained features to effectively preserve barcode details and improve the detection rate of small-sized barcodes. (Learnable scalar) It is applied to the main branch of low-dimensional features, and the weights are adaptively adjusted during training to enhance the proportion of fine-grained information such as barcode edges and stripes in the fusion, so as to avoid the details of small-sized barcodes being submerged by high-level semantic features. At the same time, it works in conjunction with the edge-sensitive spatial attention module and the channel attention calibration unit to improve feature expression and reduce the false detection rate of small-sized barcodes.
[0062] To address the challenge of balancing lightweight design with high detection accuracy, this application's embodiments achieve both lightweight deployment and high-precision detection. The edge-sensitive spatial attention module and channel attention calibration unit both employ lightweight designs, utilizing simple operators such as 1×1 convolution and global pooling. The parameters incur no additional computational overhead; and it only replaces the corresponding C2F module in the original YOLOv8n neck, without changing the original network structure, thus preserving the lightweight characteristics to the maximum extent. Furthermore, the implementation of this embodiment does not require sacrificing feature extraction capabilities to compress the model, improving detection accuracy and robustness while keeping the number of parameters and computational load essentially unchanged. It is also suitable for deployment on embedded barcode readers, making it highly practical.
[0063] Figure 8 The diagram shows a structural schematic of a barcode detection device based on an improved YOLOv8 model provided in an embodiment of this application. The barcode detection device can be a barcode reader or an electronic device with an embedded barcode reader. The specific embodiments of this application do not limit the specific implementation of the barcode detection device based on the improved YOLOv8 model.
[0064] like Figure 8 As shown, the barcode detection device 200 based on the improved YOLOv8 model may include a processor 202 and a memory 204.
[0065] The memory 204 is used to store the computer program 206. The memory 204 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk drive. The computer program 206 may include computer-executable instructions.
[0066] The processor 202 is used to execute the computer program 206 to implement the above-described embodiment of the barcode detection method based on the improved YOLOv8 model.
[0067] The processor 202 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application. The barcode detection device 200 based on the improved YOLOv8 model includes one or more processors, which may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0068] This application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described barcode detection method embodiment based on the improved YOLOv8 model.
[0069] This application provides a computer program that can be executed by a processor to implement the above-described barcode detection method based on the improved YOLOv8 model.
[0070] This application provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described barcode detection method embodiment based on the improved YOLOv8 model.
[0071] In the several embodiments provided in this application, any function, if implemented as a software functional module / unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on this understanding, all or part of the technical solution of this application can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or other electronic device) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing computer program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0072] The algorithms or displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used in conjunction with the teachings herein. The required structure for constructing such systems is apparent from the above description. Furthermore, the embodiments of this application are not directed to any particular programming language. It should be understood that the content of this application described herein can be implemented using various programming languages, and the above description of specific languages is for the purpose of disclosing the best mode of implementation of this application.
[0073] It should be noted that the above embodiments are illustrative of this application and not restrictive, and those skilled in the art can devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. This application can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In claims enumerating several means, several units or modules of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words can be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be construed as limiting the order of execution.
[0074] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A barcode detection method based on an improved YOLOv8 model, characterized in that, The method includes: The image to be detected is input into the backbone network of the improved YOLOv8 model for feature extraction, and multiple first features of different scales are obtained from the output of the backbone network. The multiple first features are input into the neck network of the improved YOLOv8 model. The neck network performs feature fusion on the multiple first features to obtain multiple second features at different scales. The neck network includes a first unit and a barcode-enhanced hybrid feature fusion module. The first unit is used to perform feature fusion on the multiple first features and output a first intermediate feature. The barcode-enhanced hybrid feature fusion module is used to: divide the first intermediate feature into low-dimensional features and high-dimensional features; perform weighted processing on the low-dimensional features to obtain weighted low-dimensional features; and perform spatial attention enhancement processing, channel attention calibration processing, and feature fusion processing on the weighted low-dimensional features and the high-dimensional features to obtain one of the multiple second features. Multiple second features are input into the detection head of the improved YOLOv8 model for detection to obtain detection results, wherein the detection results include the location information of the barcode in the image to be detected.
2. The method according to claim 1, characterized in that, The barcode-enhanced hybrid feature fusion module includes a second unit, a third unit, and a channel attention calibration unit. The second unit includes a cascaded edge-sensitive spatial attention module, a first module, a second module, and a first activation function layer. The third unit includes a cascaded edge-sensitive spatial attention module, a first module, a second module, and a second activation function layer. The edge-sensitive spatial attention module is used to perform edge enhancement and spatial attention processing on the input features. The first module and the second module are both used to perform convolution operations and normalized activation processing on the input features. The barcode enhanced hybrid feature fusion module is specifically used to perform the following steps: The weighted low-dimensional features are input into the edge-sensitive spatial attention module in the second unit, and the low-dimensional features and the features output by the first activation function layer are multiplied element-wise to obtain the third feature. The high-dimensional feature is input into the edge-sensitive spatial attention module in the third unit, and the high-dimensional feature and the feature output by the second activation function layer are multiplied element-wise to obtain the fourth feature; The third feature and the fourth feature are fused together to obtain the fifth feature; The fifth feature is convolved to obtain the sixth feature, and the sixth feature is then subjected to channel attention calibration by the channel attention calibration unit to obtain the seventh feature.
3. The method according to claim 2, characterized in that, The barcode-enhanced hybrid feature fusion module further includes a third module, a fourth module, a fifth module, and a third activation function layer, wherein the third module, the fourth module, and the fifth module are all used to perform convolution operations and normalized activation processing on the input features; The barcode enhanced hybrid feature fusion module is further used to perform the following steps: The seventh feature is processed by the third activation function layer to obtain the eighth feature; The low-dimensional feature and the feature output by the first module in the second unit are added element by element to obtain the ninth feature; The tenth feature is obtained by processing the ninth feature through the third module; The eleventh feature is obtained by performing element-wise multiplication on the eighth and tenth features; The high-dimensional feature and the feature output by the first module in the third unit are added element by element to obtain the twelfth feature; The thirteenth feature is obtained by processing the twelfth feature through the fourth module; The thirteenth feature and the eighth feature are multiplied element-wise to obtain the fourteenth feature; The fourteenth feature and the eleventh feature are fused together to obtain the fifteenth feature; The fifth module processes the fifteenth feature to obtain one of the plurality of second features.
4. The method according to claim 3, characterized in that, The channel attention calibration unit includes a cascaded global average pooling layer, a one-dimensional convolutional layer, and a fourth activation function layer.
5. The method according to claim 4, characterized in that, The channel attention calibration unit is specifically used to input the sixth feature into the global average pooling layer, and to multiply the sixth feature and the feature output by the fourth activation function layer element by element to obtain the seventh feature.
6. The method according to claim 2 or 3, characterized in that, The first module includes a cascaded 3×3 convolution module, a batch normalization module, and a corrected linear unit; the second module includes a cascaded 1×1 convolution module, a batch normalization module, and a corrected linear unit.
7. The method according to claim 2, characterized in that, The edge-sensitive spatial attention module includes a 1×1 convolutional module, a fifth activation function layer, a sixth activation function layer, a global average pooling layer, a global max pooling layer, and a channel concatenation layer; the edge-sensitive spatial attention module is specifically used to perform the following steps: The features input to the edge-sensitive spatial attention module are processed by the cascaded 1×1 convolutional module and the fifth activation function layer to obtain the first attention feature; The first attention feature is processed by the global average pooling layer to obtain the second attention feature; The first attention feature is processed by the global max pooling layer to obtain the third attention feature; The second attention feature and the third attention feature are processed by channel splicing through the channel splicing layer to obtain the fourth attention feature; The fourth attention feature is processed by the cascaded 1×1 convolutional module and the sixth activation function layer to obtain nonlinear features; The nonlinear features and the features input to the edge-sensitive spatial attention module are multiplied element-wise to obtain and output the output features of the edge-sensitive spatial attention module.
8. The method according to claim 1, characterized in that, The low-dimensional feature is F low The weighted low-dimensional features Through the following formula It is confirmed that, among them, .
9. A barcode detection device based on an improved YOLOv8 model, comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the barcode detection method based on the improved YOLOv8 model as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the barcode detection method based on the improved YOLOv8 model as described in any one of claims 1 to 8.