Barcode recognition method, system, and medium based on segmented peaks and adaptive threshold adjustment

By using segmented peaks and adaptive threshold adjustment, the reliability of one-dimensional barcode recognition under damaged, occluded, missing, and blurred conditions is solved, improving the accuracy of barcode recognition and making it suitable for industrial applications.

CN120339040BActive Publication Date: 2025-10-31HANGZHOU HUICUI INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510820153.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-19
Publication Date
2025-10-31
Estimated Expiration
2045-06-19

AI Technical Summary

Technical Problem

One-dimensional barcodes have poor recognition reliability under non-ideal conditions such as damage, obstruction, missing parts, and blurring, resulting in a high recognition failure rate in industrial application scenarios. Existing technologies increase system complexity and cannot break through from the level of encoding principles.

Method used

By using a segmented peak and adaptive threshold adjustment method, barcode positioning information is obtained, affine transformation and segmented vertical projection are performed, waveform data is extracted and smoothed and differentially processed, peaks and troughs are analyzed, thresholds are adjusted for decoding, and damaged, missing, blurred and occluded barcode images are processed.

Benefits of technology

It improves the accuracy of barcode recognition and can effectively handle damaged, missing, blurry, and obscured barcode images, thereby enhancing the reliability of recognition in industrial scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120339040B_ABST
    Figure CN120339040B_ABST
Patent Text Reader

Abstract

This application provides a barcode recognition method, system, and medium based on segmented peaks and adaptive threshold adjustment. The method includes: acquiring an original image; analyzing the original image based on a positioning algorithm to obtain barcode positioning information; performing an affine transformation based on the barcode positioning information to obtain an aligned barcode image; segmenting the aligned barcode image into vertical projections to obtain waveform data for each segment; performing smoothing and differential processing on the waveform data for each segment to obtain differential waveform data; analyzing the differential waveform data based on a set threshold to obtain peak and trough data; analyzing the peak and trough data for each segment to obtain a run-length encoding; decoding the run-length encoding and analyzing whether the decoding is successful; if the decoding is successful, obtaining the barcode recognition result; if the decoding fails, adjusting the threshold; by analyzing the segmented peaks, extracting the most probable position as the boundary position of the barcode, thereby improving the accuracy of barcode recognition in industrial scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of barcode recognition technology, and more specifically, to a barcode recognition method, system, and medium based on segmented peaks and adaptive threshold adjustment. Background Technology

[0002] As a linear information encoding carrier, one-dimensional barcodes have inherent technical defects due to their physical structure characteristics, such as damage, occlusion, missing parts, and blurring. These defects severely restrict their reliability in industrial applications.

[0003] 1. Cascading failure caused by damaged barcodes

[0004] One-dimensional barcodes use a bar-space structure with equal width or modularity to encode data. When a barcode is torn, worn, or chemically corroded, the bar-space width ratio changes irreversibly. Taking the Code 39 standard as an example, each character consists of 5 bar-space modules. If the bar width error of a module exceeds 15% of the standard value, the character is considered invalid. Even more dangerous is the cascading effect caused by damage: when the start or stop character area is damaged, the scanner cannot locate the valid data area, causing the entire barcode to fail. Experiments show that in metal-etched barcode scenarios, 3% damage to the bar-space area can cause a reading failure rate of over 82%.

[0005] 2. The information gap crisis caused by obstruction

[0006] The linear scanning mechanism of one-dimensional barcodes requires the complete acquisition of a continuous sequence of bars and spaces. When the barcode surface is covered by liquid (such as condensation), has a label, or is obstructed by foreign objects, the scan lines will experience continuous signal loss when passing through the obstructed area. Taking the EAN-13 standard as an example, its left and right data areas each contain 6 characters. If the middle 4 characters are obstructed, not only is the data in the obstructed area lost, but the positioning reference of the left and right data areas is also misaligned, and subsequent decoding algorithms cannot establish effective bit synchronization. A logistics warehousing case shows that when 5% of the barcode area is covered by dust, the first-read rate drops by 47%, requiring more than three rescans to succeed.

[0007] 3. Decoding crashes caused by missing bars / spaces

[0008] One-dimensional barcodes lack redundancy check mechanisms; the absence of any bar or space unit directly leads to a break in the encoded sequence. Taking the ITF-14 standard as an example, which uses an interleaved 25-code structure, if a single bar or space is missing, the encoding boundaries of adjacent characters will misalign, triggering a domino effect of decoding errors. In high-speed printing scenarios, intermittent missing bars and spaces caused by inkjet head clogging can increase the batch encoding error rate by three orders of magnitude. This loss not only corrupts the current data but also contaminates subsequent character parsing through bit synchronization mechanisms.

[0009] 4. Recognition difficulties caused by optical blurring

[0010] One-dimensional barcode reading relies on precise light intensity contrast threshold judgment. When barcode printing quality is poor (e.g., uneven ribbon printing density), the scanning distance is too far, or motion blur exists, the optical features of the bar and space edges are smoothed. Scanners using edge detection algorithms experience an exponential increase in error rate when the signal-to-noise ratio is below 15dB. Tests conducted by a medical device traceability system showed that for every 10% increase in barcode ambiguity, the first-read rate decreased by 38%, ultimately forcing manual intervention up to 65%.

[0011] Existing technical solutions address these issues by improving printing accuracy, increasing the number of scans, or employing manual verification, but all of these significantly increase system complexity. The physical structure of one-dimensional barcodes means that these deficiencies cannot be overcome at the encoding principle level, becoming a technical bottleneck restricting the development of highly robust automated identification systems. Summary of the Invention

[0012] The purpose of this application is to provide a barcode recognition method, system, and medium based on segmented peaks and adaptive threshold adjustment. By analyzing segmented peaks, the most likely position is extracted as the boundary position of the barcode, which can handle the recognition of damaged, missing, blurred, and occluded barcode images, and improve the accuracy of barcode recognition in industrial scenarios.

[0013] This application also provides a barcode recognition method based on segmented peaks and adaptive threshold adjustment, including:

[0014] The original image is acquired, and the original image is analyzed based on the positioning algorithm to obtain the barcode positioning information. Based on the barcode positioning information, an affine transformation is performed to obtain the aligned barcode image.

[0015] The aligned barcode image is segmented and vertically projected to obtain waveform data for each segment. The waveform data for each segment is then smoothed and differentially processed to obtain differential waveform data.

[0016] Based on a set threshold, differential waveform data is analyzed to obtain peak and trough data. The stroke code is obtained by analyzing the peak and trough data of each segment.

[0017] The travel code is transmitted to a multi-format barcode image processing library for decoding, and the decoding success is analyzed.

[0018] If decoding is successful, the barcode recognition result is obtained; if decoding fails, the threshold is adjusted to perform a secondary analysis of the differential waveform data.

[0019] Optionally, in the barcode recognition method based on segmented peaks and adaptive threshold adjustment described in this application embodiment, the process includes: acquiring an original image; analyzing the original image based on a positioning algorithm to obtain barcode positioning information; and performing an affine transformation based on the barcode positioning information to obtain an aligned barcode image. Specifically, this includes:

[0020] Pre-define representative feature points on the barcode template;

[0021] The original image is acquired, image features are extracted, and the image features are matched with designated representative feature points to obtain the positional relationship of the barcode in the original image.

[0022] Analysis of the position and orientation of the barcode in the original image based on the positional relationship of the barcode in the original image;

[0023] Barcode positioning information is obtained based on the barcode's position and orientation;

[0024] Based on the barcode positioning information, an affine transformation is performed on the barcode. The affine transformation includes rotation, translation, scaling, or cropping to transform the barcode image to a standard aligned state, resulting in an aligned barcode image.

[0025] Optionally, in the barcode recognition method based on segmented peaks and adaptive threshold adjustment described in the embodiments of this application, the aligned barcode image is segmented and vertically projected to obtain waveform data for each segment, specifically including:

[0026] Obtain the aligned barcode image, convert the aligned barcode image to a grayscale image, and perform binarization on the grayscale image;

[0027] The binarized barcode image is divided into several segments in the horizontal direction, with each segment having the same width.

[0028] Extract the image region of each segment in sequence to obtain several independent sub-images corresponding to several segments;

[0029] Several independent sub-images are vertically projected onto each segment of the barcode image from left to right to obtain the projection value of each segment.

[0030] Arrange the projection values ​​of each segment in order to obtain the waveform data of each segment.

[0031] Optionally, in the barcode recognition method based on segmented peaks and adaptive threshold adjustment described in the embodiments of this application, the waveform data of each segment is smoothed and differentially processed to obtain differential waveform data, specifically including:

[0032] The waveform data of each segment is acquired, and the waveform data is smoothed by median filtering to remove noise features from the waveform data.

[0033] Each smoothed waveform data segment is subjected to first-order difference processing to analyze the rate of change of the waveform data.

[0034] Differential waveform data is obtained by analyzing the boundary positions of barcode bars and spaces based on the rate of change of waveform data.

[0035] Optionally, in the barcode recognition method based on segmented peaks and adaptive threshold adjustment described in the embodiments of this application, the differential waveform data is analyzed based on a set threshold to obtain peak and trough data, specifically including:

[0036] Set a threshold, and based on the set threshold, traverse the differential waveform data of each segment and analyze the value of the differential waveform data;

[0037] When the value of the differential waveform data changes from positive to negative, it is determined to be a change point. If the data value of the change point is greater than a set threshold, the change point is determined to be a peak point.

[0038] When the value of the differential waveform data changes from negative to positive, and the data value at the point of change is less than the opposite of the set threshold, the point of change is determined to be a trough point, and the positions of all peak points and trough points and their corresponding waveform data values ​​are recorded.

[0039] Optionally, in the barcode recognition method based on segmented peaks and adaptive threshold adjustment described in the embodiments of this application, the run-length encoding is obtained by analyzing the peak and trough data of each segment, specifically including:

[0040] Define the distance between one wave crest point and the next wave crest point or between one wave trough point and the next wave trough point as a journey;

[0041] Analyze the peak and trough data of each segment, and calculate the travel length between adjacent peaks or troughs in sequence according to the defined travel coding rules;

[0042] Arrange the calculated trip lengths in order to obtain the trip code sequence corresponding to each segment;

[0043] The run-length encoded sequences of each segment are integrated according to the order of image segmentation to obtain the complete run-length encoded sequence.

[0044] Secondly, embodiments of this application provide a barcode recognition system based on segmented peaks and adaptive threshold adjustment. The system includes a memory and a processor. The memory includes a program for a barcode recognition method based on segmented peaks and adaptive threshold adjustment. When the program for the barcode recognition method based on segmented peaks and adaptive threshold adjustment is executed by the processor, it implements the following steps:

[0045] The original image is acquired, and the original image is analyzed based on the positioning algorithm to obtain the barcode positioning information. Based on the barcode positioning information, an affine transformation is performed to obtain the aligned barcode image.

[0046] The aligned barcode image is segmented and vertically projected to obtain waveform data for each segment. The waveform data for each segment is then smoothed and differentially processed to obtain differential waveform data.

[0047] Based on a set threshold, differential waveform data is analyzed to obtain peak and trough data. The stroke code is obtained by analyzing the peak and trough data of each segment.

[0048] The travel code is transmitted to a multi-format barcode image processing library for decoding, and the decoding success is analyzed.

[0049] If decoding is successful, the barcode recognition result is obtained; if decoding fails, the threshold is adjusted to perform a secondary analysis of the differential waveform data.

[0050] Optionally, in the barcode recognition system based on segmented peaks and adaptive threshold adjustment described in this application embodiment, the process includes: acquiring an original image; analyzing the original image based on a positioning algorithm to obtain barcode positioning information; and performing an affine transformation based on the barcode positioning information to obtain an aligned barcode image. Specifically, this includes:

[0051] Pre-define representative feature points on the barcode template;

[0052] The original image is acquired, image features are extracted, and the image features are matched with designated representative feature points to obtain the positional relationship of the barcode in the original image.

[0053] Analysis of the position and orientation of the barcode in the original image based on the positional relationship of the barcode in the original image;

[0054] Barcode positioning information is obtained based on the barcode's position and orientation;

[0055] Based on the barcode positioning information, an affine transformation is performed on the barcode. The affine transformation includes rotation, translation, scaling, or cropping to transform the barcode image to a standard aligned state, resulting in an aligned barcode image.

[0056] Optionally, in the barcode recognition system based on segmented peaks and adaptive threshold adjustment described in this application embodiment, the aligned barcode image is segmented and vertically projected to obtain waveform data for each segment, specifically including:

[0057] Obtain the aligned barcode image, convert the aligned barcode image to a grayscale image, and perform binarization on the grayscale image;

[0058] The binarized barcode image is divided into several segments in the horizontal direction, with each segment having the same width.

[0059] Extract the image region of each segment in sequence to obtain several independent sub-images corresponding to several segments;

[0060] Several independent sub-images are vertically projected onto each segment of the barcode image from left to right to obtain the projection value of each segment.

[0061] Arrange the projection values ​​of each segment in order to obtain the waveform data of each segment.

[0062] Thirdly, embodiments of this application also provide a computer-readable storage medium, which includes a barcode recognition method program based on segmented peaks and adaptive threshold adjustment. When the barcode recognition method program based on segmented peaks and adaptive threshold adjustment is executed by a processor, it implements the steps of the barcode recognition method based on segmented peaks and adaptive threshold adjustment as described in any of the preceding claims.

[0063] As can be seen from the above, the barcode recognition method, system, and medium based on segmented peaks and adaptive threshold adjustment provided in this application acquires an original image, analyzes the original image based on a positioning algorithm to obtain barcode positioning information, and performs an affine transformation based on the barcode positioning information to obtain an aligned barcode image. The aligned barcode image is then segmented and vertically projected to obtain waveform data for each segment. The waveform data for each segment is then smoothed and differentially processed to obtain differential waveform data. The differential waveform data is analyzed based on a set threshold to obtain peak and trough data. The peak and trough data for each segment are analyzed to obtain a run-length encoding. The run-length encoding is transmitted to a multi-format barcode image processing library for decoding, and the decoding success is analyzed. If decoding is successful, a barcode recognition result is obtained; if decoding fails, the threshold is adjusted to perform a secondary analysis of the differential waveform data. By analyzing the segmented peaks, the most probable position is extracted as the boundary position of the barcode, which can handle the recognition of damaged, missing, blurred, and occluded barcode images, improving the accuracy of barcode recognition in industrial scenarios. Attached Figure Description

[0064] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0065] Figure 1 A flowchart illustrating the barcode recognition method based on segmented peaks and adaptive threshold adjustment provided in this application embodiment;

[0066] Figure 2A schematic diagram illustrating the specific steps of the barcode recognition method based on segmented peaks and adaptive threshold adjustment provided in this application embodiment;

[0067] Figure 3 A schematic diagram of the original image for the barcode recognition method based on segmented peaks and adaptive threshold adjustment provided in the embodiments of this application;

[0068] Figure 4 A schematic diagram illustrating the location of the four corner points of a barcode using a barcode recognition method based on segmented peaks and adaptive threshold adjustment, provided in an embodiment of this application.

[0069] Figure 5 A schematic diagram of barcode image alignment for a barcode recognition method based on segmented peaks and adaptive threshold adjustment provided in an embodiment of this application;

[0070] Figure 6 A schematic diagram of waveform data for a barcode recognition method based on segmented peaks and adaptive threshold adjustment provided in an embodiment of this application;

[0071] Figure 7 A schematic diagram of waveform data and differential data for the barcode recognition method based on segmented peaks and adaptive threshold adjustment provided in the embodiments of this application;

[0072] Figure 8 A schematic diagram of the alternating bright and dark positions of the barcode recognition method based on segmented peaks and adaptive threshold adjustment provided in the embodiments of this application;

[0073] Figure 9 This is a schematic diagram showing the cursor of the barcode recognition method based on segmented peaks and adaptive threshold adjustment provided in the embodiments of this application moving from the current position to the next position according to the minimum distance. Detailed Implementation

[0074] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.

[0075] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, the terms "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0076] Please refer to Figures 1-9 As shown, this application discloses a barcode recognition method based on segmented peaks and adaptive threshold adjustment. This barcode recognition method based on segmented peaks and adaptive threshold adjustment is used in terminal devices and includes the following steps:

[0077] S101, acquire the original image, analyze the original image based on the positioning algorithm to obtain barcode positioning information, and perform affine transformation based on the barcode positioning information to obtain the aligned barcode image;

[0078] S102, the aligned barcode image is segmented and vertically projected to obtain waveform data for each segment. The waveform data for each segment is then smoothed and differentially processed to obtain differential waveform data.

[0079] S103, Analyze the differential waveform data based on the set threshold to obtain peak and trough data, and obtain the run-length code by analyzing the peak and trough data of each segment;

[0080] S104, transmit the travel code to the multi-format barcode image processing library (ZXing library) for decoding, and analyze whether the decoding was successful;

[0081] S105: If decoding is successful, the barcode recognition result is obtained; if decoding fails, the threshold is adjusted to perform secondary analysis on the differential waveform data.

[0082] It should be noted that, for cases of damage, obstruction, and missing information, by analyzing segmented peaks, the most likely location is extracted as the boundary position of the barcode. This can avoid the problem of barcode information loss and inability to be parsed due to partial damage, obstruction, or missing information.

[0083] For blurry barcodes, a segmented vertical projection method and an adaptive threshold adjustment method are used to extract the barcode boundary to the greatest extent, thereby accurately recognizing the barcode.

[0084] like Figure 2 As shown, according to a preferred embodiment of the present invention, the barcode recognition step specifically includes:

[0085] S1: First, a barcode is roughly located using a positioning algorithm (traditional or AI algorithm).

[0086] First, the approximate location of the barcode needs to be determined using algorithms, such as traditional or deep learning algorithms. The following steps are based on the analysis of the roughly aligned barcode. The location only needs to be roughly aligned, as the subsequent algorithms have a certain degree of error tolerance; therefore, this invention does not have very high requirements for barcode positioning.

[0087] S2: Extract the waveform of the aligned barcode image by segmentation, specifically including: after obtaining the roughly aligned barcode image, segment the image and project it vertically to obtain the waveform data of each segment;

[0088] S3: Smooth the waveform. To avoid noise interference, the extracted waveform data is smoothed using median filtering. Median filtering can filter out small amounts of salt-and-pepper noise.

[0089] S4: Differential waveform data is obtained by performing differential processing on the waveform data. In order to extract the boundary between light and dark areas in the barcode, first-order differential processing is performed on the waveform. The peaks and troughs of the first-order difference curve represent the places where the grayscale changes the fastest, and the positions of the light and dark areas in the barcode;

[0090] S5: Determine the peaks and troughs based on the differential waveform data;

[0091] S6: Segmented peak statistical detection. The peak and trough vectors of each segment can be obtained through S1-S5. The optimal position of the barcode light and dark alternation can be obtained based on the data of all segments.

[0092] S7: Repeat S6 until the peak and trough vector scanning is completed, and a run-length code is obtained. The run-length code is transmitted to the multi-format barcode image processing library (ZXing library) for decoding. If the decoding is successful, the process ends; otherwise, proceed to step S8.

[0093] S8: Iterate through the threshold ratios in S3, repeating S5-S7.

[0094] According to an embodiment of the present invention, an original image is acquired, the original image is analyzed based on a positioning algorithm to obtain barcode positioning information, and an aligned barcode image is obtained by performing an affine transformation based on the barcode positioning information. Specifically, this includes:

[0095] Pre-define representative feature points on the barcode template;

[0096] The original image is acquired, image features are extracted, and the image features are matched with designated representative feature points to obtain the positional relationship of the barcode in the original image.

[0097] Analysis of the position and orientation of the barcode in the original image based on the positional relationship of the barcode in the original image;

[0098] Barcode positioning information is obtained based on the barcode's position and orientation;

[0099] Based on the barcode positioning information, an affine transformation is performed on the barcode. The affine transformation process includes rotation, translation, scaling, or cropping to transform the barcode image to a standard aligned state, resulting in an aligned barcode image.

[0100] It should be noted that segmented waveforms can avoid problems such as loss, occlusion, and missing information, because the lost information can most likely be obtained from other segments.

[0101] Segmented waveforms are better suited to roughly aligned barcodes than waveforms extracted from the whole image because each segment is closer to vertical, making it easier to extract the boundaries.

[0102] Specifically, an affine transformation is a linear transformation between two-dimensional coordinates that preserves the flatness and parallelism of an image. Affine transformations include operations such as translation, rotation, scaling, and shearing. By calculating the affine transformation matrix, a barcode image can be transformed to a standard aligned state. The calculation is relatively simple and can handle common transformations of barcodes such as translation, rotation, and scaling.

[0103] In barcode recognition, if the barcode undergoes simple translation, rotation, or scaling, affine transformations can quickly and effectively align the barcode.

[0104] According to an embodiment of the present invention, the aligned barcode image is segmented and vertically projected to obtain waveform data for each segment, specifically including:

[0105] Obtain the aligned barcode image, convert the aligned barcode image to a grayscale image, and perform binarization on the grayscale image;

[0106] The binarized barcode image is divided into several segments in the horizontal direction, with each segment having the same width.

[0107] Extract the image region of each segment in sequence to obtain several independent sub-images corresponding to several segments;

[0108] Several independent sub-images are vertically projected onto each segment of the barcode image from left to right to obtain the projection value of each segment.

[0109] Arrange the projection values ​​of each segment in order to obtain the waveform data of each segment.

[0110] It should be noted that grayscale information is more convenient for analyzing the distribution of bars and spaces in a barcode. Converting to a grayscale image simplifies calculations and removes interference from color information. Binarization specifically involves setting an appropriate threshold to divide the pixels in the image into two categories: one representing the bars of the barcode (usually black with a grayscale value of 0), and the other representing the spaces (usually white with a grayscale value of 255). This makes the barcode structure clearer and facilitates subsequent projection operations.

[0111] According to an embodiment of the present invention, smoothing and differential processing are performed on each segment of waveform data to obtain differential waveform data, specifically including:

[0112] The waveform data of each segment is acquired, and the waveform data is smoothed by median filtering to remove noise features from the waveform data.

[0113] Each smoothed waveform data segment is subjected to first-order difference processing to analyze the rate of change of the waveform data.

[0114] Differential waveform data is obtained by analyzing the boundary positions of barcode bars and spaces based on the rate of change of waveform data.

[0115] It should be noted that, in order to avoid the influence of noise, median filtering is used to smooth the waveform data. Median filtering can filter out small salt and pepper noise. The peaks and troughs of the first difference of the curve represent the places where the gray level changes the fastest, that is, the positions where light and dark alternate.

[0116] Specifically, the median filtering method is as follows: Select a window size n. For each point in the waveform data, take n points within the window, sort the values ​​of these points from smallest to largest, and take the median value as the new value of the current point. Median filtering is effective in removing impulse noise (such as sudden large fluctuations) from the data and can achieve smoothing while preserving the basic shape of the waveform.

[0117] According to an embodiment of the present invention, differential waveform data is analyzed based on a set threshold to obtain peak and trough data, specifically including:

[0118] Set a threshold, and based on the set threshold, traverse the differential waveform data of each segment and analyze the value of the differential waveform data;

[0119] When the value of the differential waveform data changes from positive to negative, it is determined to be a change point. If the data value of the change point is greater than a set threshold, the change point is determined to be a peak point.

[0120] When the value of the differential waveform data changes from negative to positive, and the data value at the point of change is less than the opposite of the set threshold, the point of change is determined to be a trough point, and the positions of all peak points and trough points and their corresponding waveform data values ​​are recorded.

[0121] It should be noted that the peaks and troughs of the obtained difference data are calculated. The peak is the place where the change from dark to light is the fastest, and the trough is the place where the change from light to dark is the fastest.

[0122] To extract peaks and troughs, a threshold needs to be set. Only when the data is greater than the threshold and is a local maximum or minimum value can it be identified as a peak or trough.

[0123] Because barcodes may have uneven brightness or be blurry, causing problems with inappropriate threshold settings, an adaptive threshold method is used to address this issue.

[0124] First, obtain the maximum value of the difference data:

[0125] ,

[0126] Use a specified percentage of the maximum value as the threshold:

[0127] ,

[0128] The waveform data extracted by wave projection, maxValue is the maximum value of the waveform data, and ratio is the threshold ratio, which is used for barcodes with different contrast levels.

[0129] To address the difficulty of extracting peaks and valleys in low-contrast conditions, the ratios were set to {0.5, 0.3, 0.2, 0.1}.

[0130] According to an embodiment of the present invention, the run-length encoding is obtained by analyzing the peak and trough data of each segment, specifically including:

[0131] Define the distance between one wave crest point and the next wave crest point or between one wave trough point and the next wave trough point as a journey;

[0132] Analyze the peak and trough data of each segment, and calculate the travel length between adjacent peaks or troughs in sequence according to the defined travel coding rules;

[0133] Arrange the calculated trip lengths in order to obtain the trip code sequence corresponding to each segment;

[0134] The run-length encoded sequences of each segment are integrated according to the order of image segmentation to obtain the complete run-length encoded sequence.

[0135] It's important to note that the peak and trough vectors are traversed from left to right, with a cursor assigned to each segment to indicate the current index position. Taking a white background with black text as an example, the first step is from light to dark, i.e., a trough. The next step should then be to find a peak, and so on.

[0136] Find the next optimal position. Move the cursor to the next position, which must satisfy the condition that the light and dark areas are reversed. For example, if the current position is from light to dark, the next position must be from dark to light. After finding the next position for all segments, calculate the distance each segment moves and find the minimum distance, which is the distance each segment needs to move for this iteration.

[0137] The cursor of each segment is moved from the current position to the next position according to the minimum distance above, and the distance of this movement is recorded and put into a vector as the run-length encoding for barcode parsing.

[0138] Secondly, embodiments of this application provide a barcode recognition system based on segmented peaks and adaptive threshold adjustment. The system includes a memory and a processor. The memory includes a program for a barcode recognition method based on segmented peaks and adaptive threshold adjustment. When the program is executed by the processor, it implements the following steps:

[0139] The original image is acquired, and the original image is analyzed based on the positioning algorithm to obtain the barcode positioning information. Based on the barcode positioning information, an affine transformation is performed to obtain the aligned barcode image.

[0140] The aligned barcode image is segmented and vertically projected to obtain waveform data for each segment. The waveform data for each segment is then smoothed and differentially processed to obtain differential waveform data.

[0141] Based on a set threshold, differential waveform data is analyzed to obtain peak and trough data. The stroke code is obtained by analyzing the peak and trough data of each segment.

[0142] The travel code is transmitted to the multi-format barcode image processing library (ZXing library) for decoding, and the decoding success is analyzed.

[0143] If decoding is successful, the barcode recognition result is obtained; if decoding fails, the threshold is adjusted to perform a secondary analysis of the differential waveform data.

[0144] According to an embodiment of the present invention, an original image is acquired, the original image is analyzed based on a positioning algorithm to obtain barcode positioning information, and an aligned barcode image is obtained by performing an affine transformation based on the barcode positioning information. Specifically, this includes:

[0145] Pre-define representative feature points on the barcode template;

[0146] The original image is acquired, image features are extracted, and the image features are matched with designated representative feature points to obtain the positional relationship of the barcode in the original image.

[0147] Analysis of the position and orientation of the barcode in the original image based on the positional relationship of the barcode in the original image;

[0148] Barcode positioning information is obtained based on the barcode's position and orientation;

[0149] Based on the barcode positioning information, an affine transformation is performed on the barcode. The affine transformation process includes rotation, translation, scaling, or cropping to transform the barcode image to a standard aligned state, resulting in an aligned barcode image.

[0150] According to an embodiment of the present invention, the aligned barcode image is segmented and vertically projected to obtain waveform data for each segment, specifically including:

[0151] Obtain the aligned barcode image, convert the aligned barcode image to a grayscale image, and perform binarization on the grayscale image;

[0152] The binarized barcode image is divided into several segments in the horizontal direction, with each segment having the same width.

[0153] Extract the image region of each segment in sequence to obtain several independent sub-images corresponding to several segments;

[0154] Several independent sub-images are vertically projected onto each segment of the barcode image from left to right to obtain the projection value of each segment.

[0155] Arrange the projection values ​​of each segment in order to obtain the waveform data of each segment.

[0156] It should be noted that grayscale information is more convenient for analyzing the distribution of bars and spaces in a barcode. Converting to a grayscale image simplifies calculations and removes interference from color information. Binarization specifically involves setting an appropriate threshold to divide the pixels in the image into two categories: one representing the bars of the barcode (usually black with a grayscale value of 0), and the other representing the spaces (usually white with a grayscale value of 255). This makes the barcode structure clearer and facilitates subsequent projection operations.

[0157] According to an embodiment of the present invention, smoothing and differential processing are performed on each segment of waveform data to obtain differential waveform data, specifically including:

[0158] The waveform data of each segment is acquired, and the waveform data is smoothed by median filtering to remove noise features from the waveform data.

[0159] Each smoothed waveform data segment is subjected to first-order difference processing to analyze the rate of change of the waveform data.

[0160] Differential waveform data is obtained by analyzing the boundary positions of barcode bars and spaces based on the rate of change of waveform data.

[0161] It should be noted that, in order to avoid the influence of noise, median filtering is used to smooth the waveform data. Median filtering can filter out small salt and pepper noise. The peaks and troughs of the first difference of the curve represent the places where the gray level changes the fastest, that is, the positions where light and dark alternate.

[0162] Specifically, the median filtering method is as follows: Select a window size n. For each point in the waveform data, take n points within the window, sort the values ​​of these points from smallest to largest, and take the median value as the new value of the current point. Median filtering is effective in removing impulse noise (such as sudden large fluctuations) from the data and can achieve smoothing while preserving the basic shape of the waveform.

[0163] According to an embodiment of the present invention, differential waveform data is analyzed based on a set threshold to obtain peak and trough data, specifically including:

[0164] Set a threshold, and based on the set threshold, traverse the differential waveform data of each segment and analyze the value of the differential waveform data;

[0165] When the value of the differential waveform data changes from positive to negative, it is determined to be a change point. If the data value of the change point is greater than a set threshold, the change point is determined to be a peak point.

[0166] When the value of the differential waveform data changes from negative to positive, and the data value at the point of change is less than the opposite of the set threshold, the point of change is determined to be a trough point, and the positions of all peak points and trough points and their corresponding waveform data values ​​are recorded.

[0167] It should be noted that the peaks and troughs of the obtained difference data are calculated. The peak is the place where the change from dark to light is the fastest, and the trough is the place where the change from light to dark is the fastest.

[0168] To extract peaks and troughs, a threshold needs to be set. Only when the data is greater than the threshold and is a local maximum or minimum value can it be identified as a peak or trough.

[0169] Because barcodes may have uneven brightness or be blurry, causing problems with inappropriate threshold settings, an adaptive threshold method is used to address this issue.

[0170] First, obtain the maximum value of the difference data:

[0171] ,

[0172] Use a specified percentage of the maximum value as the threshold:

[0173] .

[0174] To address the difficulty of extracting peaks and valleys in low-contrast conditions, the ratios were set to {0.5, 0.3, 0.2, 0.1}.

[0175] According to an embodiment of the present invention, the run-length encoding is obtained by analyzing the peak and trough data of each segment, specifically including:

[0176] Define the distance between one wave crest point and the next wave crest point or between one wave trough point and the next wave trough point as a journey;

[0177] Analyze the peak and trough data of each segment, and calculate the travel length between adjacent peaks or troughs in sequence according to the defined travel coding rules;

[0178] Arrange the calculated trip lengths in order to obtain the trip code sequence corresponding to each segment;

[0179] The run-length encoded sequences of each segment are integrated according to the order of image segmentation to obtain the complete run-length encoded sequence.

[0180] It's important to note that the peak and trough vectors are traversed from left to right, with a cursor assigned to each segment to indicate the current index position. Taking a white background with black text as an example, the first step is from light to dark, i.e., a trough. The next step should then be to find a peak, and so on.

[0181] Find the next optimal position. Move the cursor to the next position, which must satisfy the condition that the light and dark areas are reversed. For example, if the current position is from light to dark, the next position must be from dark to light. After finding the next position for all segments, calculate the distance each segment moves and find the minimum distance, which is the distance each segment needs to move for this iteration.

[0182] The cursor of each segment is moved from the current position to the next position according to the minimum distance above, and the distance of this movement is recorded and put into a vector as the run-length encoding for barcode parsing.

[0183] A third aspect of the present invention provides a computer-readable storage medium including a barcode recognition method program based on segmented peaks and adaptive threshold adjustment. When the barcode recognition method program based on segmented peaks and adaptive threshold adjustment is executed by a processor, it implements the steps of the barcode recognition method based on segmented peaks and adaptive threshold adjustment as described in any of the above claims.

[0184] This invention discloses a barcode recognition method, system, and medium based on segmented peaks and adaptive threshold adjustment. The method involves acquiring an original image, analyzing the image using a positioning algorithm to obtain barcode positioning information, and performing an affine transformation based on this information to obtain an aligned barcode image. The aligned barcode image is then segmented and vertically projected to obtain waveform data for each segment. This waveform data is then smoothed and differentially processed to obtain differential waveform data. The differential waveform data is analyzed based on a set threshold to obtain peak and trough data, and the analysis of these peaks and troughs yields a run-length encoding. This run-length encoding is transmitted to the ZXing library for decoding, and the decoding success is analyzed. If decoding is successful, a barcode recognition result is obtained; if decoding fails, the threshold is adjusted for a second analysis of the differential waveform data. By analyzing the segmented peaks, the most probable position is extracted as the barcode's boundary position, enabling the recognition of damaged, missing, blurred, and occluded barcode images, thus improving the accuracy of barcode recognition in industrial scenarios.

[0185] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.

[0186] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.

[0187] In addition, in the various embodiments of the present invention, each functional unit can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0188] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0189] If the integrated units of this invention are implemented as software functional modules and sold or used as independent products, they can also be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This 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 network device, etc.) to execute all or part of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.

Claims

1. A barcode recognition method based on segmented peaks and adaptive threshold adjustment, characterized in that, include: The original image is acquired, and the original image is analyzed based on the positioning algorithm to obtain the barcode positioning information. Based on the barcode positioning information, an affine transformation is performed to obtain the aligned barcode image. The aligned barcode image is segmented and vertically projected to obtain waveform data for each segment. The waveform data for each segment is then smoothed and differentially processed to obtain differential waveform data. Based on a set threshold, differential waveform data is analyzed to obtain peak and trough data. The stroke code is obtained by analyzing the peak and trough data of each segment. The travel code is transmitted to a multi-format barcode image processing library for decoding, and the decoding success is analyzed. If decoding is successful, the barcode recognition result is obtained; if decoding fails, the threshold is adjusted to perform a secondary analysis on the differential waveform data. The process involves segmenting the aligned barcode image and projecting it vertically to obtain waveform data for each segment, specifically including: Obtain the aligned barcode image, convert the aligned barcode image to a grayscale image, and perform binarization on the grayscale image; The binarized barcode image is divided into several segments in the horizontal direction, with each segment having the same width. Extract the image region of each segment in sequence to obtain several independent sub-images corresponding to several segments; Several independent sub-images are vertically projected onto each segment of the barcode image from left to right to obtain the projection value of each segment. Arrange the projection values ​​of each segment in order to obtain the waveform data of each segment; Due to uneven or blurry barcode brightness causing issues with inappropriate threshold settings, an adaptive threshold approach is adopted for processing. Specifically: Get the maximum value of the difference data: ; Use a specified percentage of the maximum value as the threshold: ; in The waveform data extracted from the projection. The maximum value of the waveform data. This is the threshold ratio, used for barcode scenarios with different contrast levels; Set them to {0.5, 0.3, 0.2, 0.1} respectively.

2. The barcode recognition method based on segmented peaks and adaptive threshold adjustment according to claim 1, characterized in that, The process involves acquiring the original image, analyzing it using a localization algorithm to obtain barcode localization information, and then performing an affine transformation based on this information to obtain an aligned barcode image. Specifically, this includes: Pre-define representative feature points on the barcode template; The original image is acquired, image features are extracted, and the image features are matched with designated representative feature points to obtain the positional relationship of the barcode in the original image. Analysis of the position and orientation of the barcode in the original image based on the positional relationship of the barcode in the original image; Barcode positioning information is obtained based on the barcode's position and orientation; Based on the barcode positioning information, an affine transformation is performed on the barcode. The affine transformation includes rotation, translation, scaling, or cropping to transform the barcode image to a standard aligned state, resulting in an aligned barcode image.

3. The barcode recognition method based on segmented peaks and adaptive threshold adjustment according to claim 2, characterized in that, Each waveform segment is smoothed and differentially processed to obtain differential waveform data, specifically including: The waveform data of each segment is acquired, and the waveform data is smoothed by median filtering to remove noise features from the waveform data. Each smoothed waveform data segment is subjected to first-order difference processing to analyze the rate of change of the waveform data. Differential waveform data is obtained by analyzing the boundary positions of barcode bars and spaces based on the rate of change of waveform data.

4. The barcode recognition method based on segmented peaks and adaptive threshold adjustment according to claim 3, characterized in that, Based on a set threshold, differential waveform data is analyzed to obtain peak and trough data, specifically including: Set a threshold, and based on the set threshold, traverse the differential waveform data of each segment and analyze the value of the differential waveform data; When the value of the differential waveform data changes from positive to negative, it is determined to be a change point. If the data value of the change point is greater than a set threshold, the change point is determined to be a peak point. When the value of the differential waveform data changes from negative to positive, and the data value at the point of change is less than the opposite of the set threshold, the point of change is determined to be a trough point, and the positions of all peak points and trough points and their corresponding waveform data values ​​are recorded.

5. The barcode recognition method based on segmented peaks and adaptive threshold adjustment according to claim 4, characterized in that, The run-length encoding is obtained by analyzing the peak and trough data of each segment, specifically including: Define the distance between one wave crest point and the next wave crest point or between one wave trough point and the next wave trough point as a journey; Analyze the peak and trough data of each segment, and calculate the travel length between adjacent peaks or troughs in sequence according to the defined travel coding rules; Arrange the calculated trip lengths in order to obtain the trip code sequence corresponding to each segment; The run-length encoded sequences of each segment are integrated according to the order of image segmentation to obtain the complete run-length encoded sequence.

6. A barcode recognition system based on segmented peaks and adaptive threshold adjustment, characterized in that, The system includes a memory and a processor. The memory contains a program for a barcode recognition method based on segmented peaks and adaptive threshold adjustment. When the program for the barcode recognition method based on segmented peaks and adaptive threshold adjustment is executed by the processor, it performs the following steps: The original image is acquired, and the original image is analyzed based on the positioning algorithm to obtain the barcode positioning information. Based on the barcode positioning information, an affine transformation is performed to obtain the aligned barcode image. The aligned barcode image is segmented and vertically projected to obtain waveform data for each segment. The waveform data for each segment is then smoothed and differentially processed to obtain differential waveform data. Based on a set threshold, differential waveform data is analyzed to obtain peak and trough data. The stroke code is obtained by analyzing the peak and trough data of each segment. The travel code is transmitted to a multi-format barcode image processing library for decoding, and the decoding success is analyzed. If decoding is successful, the barcode recognition result is obtained; if decoding fails, the threshold is adjusted to perform a secondary analysis on the differential waveform data. The process involves segmenting the aligned barcode image and projecting it vertically to obtain waveform data for each segment, specifically including: Obtain the aligned barcode image, convert the aligned barcode image to a grayscale image, and perform binarization on the grayscale image; The binarized barcode image is divided into several segments in the horizontal direction, with each segment having the same width. Extract the image region of each segment in sequence to obtain several independent sub-images corresponding to several segments; Several independent sub-images are vertically projected onto each segment of the barcode image from left to right to obtain the projection value of each segment. Arrange the projection values ​​of each segment in order to obtain the waveform data of each segment; Due to uneven or blurry barcode brightness causing issues with inappropriate threshold settings, an adaptive threshold approach is adopted for processing. Specifically: Get the maximum value of the difference data: ; Use a specified percentage of the maximum value as the threshold: ; in The waveform data extracted from the projection. The maximum value of the waveform data. This is the threshold ratio, used for barcode scenarios with different contrast levels; Set them to {0.5, 0.3, 0.2, 0.1} respectively.

7. The barcode recognition system based on segmented peaks and adaptive threshold adjustment according to claim 6, characterized in that, The process involves acquiring the original image, analyzing it using a localization algorithm to obtain barcode localization information, and then performing an affine transformation based on this information to obtain an aligned barcode image. Specifically, this includes: Pre-define representative feature points on the barcode template; The original image is acquired, image features are extracted, and the image features are matched with designated representative feature points to obtain the positional relationship of the barcode in the original image. Analysis of the position and orientation of the barcode in the original image based on the positional relationship of the barcode in the original image; Barcode positioning information is obtained based on the barcode's position and orientation; Based on the barcode positioning information, an affine transformation is performed on the barcode. The affine transformation includes rotation, translation, scaling, or cropping to transform the barcode image to a standard aligned state, resulting in an aligned barcode image.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a barcode recognition method program based on segmented peaks and adaptive threshold adjustment. When the barcode recognition method program based on segmented peaks and adaptive threshold adjustment is executed by a processor, it implements the steps of the barcode recognition method based on segmented peaks and adaptive threshold adjustment as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Bar code decoding method and device and computer readable medium

    CN117521695A