Bar code identification method and system based on segmented wave crest and adaptive threshold adjustment, and medium
Through the method of segmented peaks and adaptive threshold adjustment, the recognition reliability problems caused by damage, occlusion, missing and blur in industrial-grade applications are solved, and a higher recognition accuracy is achieved.
Patent Information
- Application Number
- CN202510820153.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-19
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2045-06-19
AI Technical Summary
In industrial-grade application scenarios, due to poor recognition reliability in non-ideal states such as damage, occlusion, missing and blur, it is difficult for the existing technology to break through these defects from the level of encoding principle.
By acquiring the original image, barcode positioning information is obtained based on the positioning algorithm analysis and affine transformation is performed, segmented vertical projection is carried out and smooth and differential processing is performed. The peak and trough data are analyzed using adaptive threshold adjustment, and the stroke encoding is extracted and decoded. If it fails, the threshold is adjusted for secondary analysis.
It improves the accuracy of barcode recognition in industrial scenarios, can effectively deal with damaged, missing, blurred and obscured barcode images, and improves the robustness of recognition.
Smart Images

Figure CN120339040A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of bar code recognition technology. Specifically, it relates to a bar code recognition method, system and medium based on segmented wave peaks and adaptive threshold adjustment. Background Technique
[0002] As a linear information coding carrier, the physical structure characteristics of one-dimensional barcodes determine that there are inherent technical defects in non-ideal states such as breakage, occlusion, missing, and blurring, which seriously restrict their reliability in industrial application scenarios.
[0003] 1. Cascade failure problem caused by bar code breakage One-dimensional barcodes use equal-width or modular bar and space structures to encode data. When a local area of the bar code is torn, worn, or chemically corroded, the ratio of bar and space widths changes irreversibly. Taking the Code 39 standard as an example, each character consists of 5 bar and space modules. If the bar width error of a certain module exceeds 15% of the standard value, the character is determined to be invalid. What is more dangerous is the cascade effect caused by breakage: when the start or stop character area is damaged, the scanner cannot locate the valid data area, resulting in the entire bar code being invalid. Experiments show that in the scenario of metal-etched barcodes, 3% breakage of the bar and space area can cause a reading failure rate of more than 82%.
[0004] 2. Information fault crisis caused by occlusion The linear scanning mechanism of one-dimensional barcodes requires complete acquisition of a continuous bar and space sequence. When there is liquid coverage (such as condensate), label pasting, or foreign object occlusion on the bar code surface, continuous signal loss will occur when the scanning line passes through the occluded area. Taking the EAN-13 standard as an example, each of its left / right data areas contains 6 characters. If the middle 4 characters are occluded, not only the data in the occluded area is lost, but also the positioning reference of the left and right data areas is misaligned, and the subsequent decoding algorithm cannot establish effective bit synchronization. A logistics warehousing case shows that when 5% of the bar code area is covered with dust, the first reading rate drops by 47%, and it needs to be reswept more than three times to succeed.
[0005] 3. Decoding collapse caused by missing bars and spaces One-dimensional barcodes lack a redundancy check mechanism, and the absence of any bar or space unit directly leads to the breakage of the coding sequence. Taking the ITF-14 standard as an example, it uses an interleaved 25-code structure. If a single bar or space is missing, the coding boundary of adjacent characters will be misaligned, causing a domino-style decoding error. In a high-speed printing scenario, the intermittent missing of bars and spaces caused by inkjet head blockage can increase the batch coding error rate by 3 orders of magnitude. This kind of missing not only destroys the current data, but also contaminates the subsequent character parsing through the bit synchronization mechanism.
[0006] 4. Recognition dilemma caused by optical blurring The reading of one-dimensional barcodes relies on precise judgment of the light intensity contrast threshold. When the barcode printing quality is poor (such as uneven carbon ribbon printing density), the scanning distance is too far, or there is motion blur, the optical features at the edges of the bars and spaces are smoothed. For scanners using edge detection algorithms, when the signal-to-noise ratio is lower than 15 dB, the error rate increases exponentially. Tests on a medical device traceability system show that for every 10% increase in barcode blur, the first-pass reading rate drops by 38%, ultimately forcing the manual intervention ratio to rise to 65%.
[0007] Existing technical solutions address the above problems by improving printing accuracy, increasing the number of scans, or manual assisted verification, etc., but all significantly increase the system complexity. The physical structure characteristics of one-dimensional barcodes determine that it is impossible to break through the above defects from the encoding principle level, becoming a technical bottleneck restricting the development of automated identification systems towards high robustness. Summary of the Invention
[0008] The purpose of the embodiments of the present application is to provide a barcode recognition method, system and medium based on segmented wave peaks and adaptive threshold adjustment. By analyzing the segmented wave 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.
[0009] The embodiments of the present application also provide a barcode recognition method based on segmented wave peaks and adaptive threshold adjustment, including: Obtain 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; Perform segmented vertical projection on the aligned barcode image to obtain waveform data for each segment, perform smoothing processing and difference processing on the waveform data for each segment to obtain difference waveform data; Analyze the difference waveform data based on the set threshold to obtain peak and valley data, and analyze the peak and valley data for each segment to obtain run-length encoding; Transmit the run-length encoding to the multi-format barcode image processing library for decoding, and analyze whether the decoding is successful; If the decoding is successful, obtain the barcode recognition result. If the decoding fails, adjust the threshold to perform secondary analysis on the difference waveform data.
[0010] Optionally, in the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment described in the embodiments of the present application, obtaining the original image, analyzing the original image based on the positioning algorithm to obtain barcode positioning information, and performing affine transformation based on the barcode positioning information to obtain the aligned barcode image specifically includes: Pre-set representative feature points on the barcode template; Obtain the original image, extract the image features, match the image features with the set representative feature points, and obtain the positional relationship of the barcode in the original image; Analyze the position and pose of the barcode in the original image based on the positional relationship of the barcode in the original image; Obtain the barcode positioning information based on the position and pose of the barcode; Perform an affine transformation on the barcode based on the barcode positioning information. The affine transformation includes rotation, translation, scaling, or shearing processing, and transform the barcode image to a standard aligned state to obtain an aligned barcode image.
[0011] Optionally, in the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment described in the embodiments of the present application, perform a segmented vertical projection on the aligned barcode image to obtain waveform data for each segment, specifically including: Obtain the aligned barcode image, convert the aligned barcode image into a grayscale image, and perform binarization processing on the grayscale image; Evenly divide the binarized barcode image into several segments in the horizontal direction, and the width of each segment is the same; Extract the image region of each segment in turn to obtain several corresponding independent sub-images; Perform a vertical projection process on each segment of the barcode image from left to right for the several independent sub-images 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.
[0012] Optionally, in the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment described in the embodiments of the present application, perform a smoothing process and a difference process on the waveform data of each segment to obtain difference waveform data, specifically including: Obtain the waveform data of each segment, perform a smoothing process on the waveform data based on median filtering to remove the noise features in the waveform data; Perform a first-order difference process on the smoothed waveform data of each segment to analyze the change rate of the waveform data; Analyze the boundary positions of the barcode bars and spaces based on the change rate of the waveform data to obtain the difference waveform data.
[0013] Optionally, in the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment described in the embodiments of the present application, analyze the difference waveform data based on a set threshold to obtain peak and valley data, specifically including: Set a threshold, traverse the difference waveform data of each segment based on the set threshold, and analyze the value of the difference waveform data; When the value of the difference waveform data changes from positive to negative, it is determined as a change point. If the data value of the change point is greater than the set threshold, it is determined that the change point is a peak point; When the value of the differential waveform data changes from negative to positive, and the data value at the change point is less than the opposite of the set threshold, it is determined that the change point is a trough point, and the positions of all peak points and trough points and the corresponding waveform data values are recorded.
[0014] Optionally, in the barcode recognition method based on segmented peak and adaptive threshold adjustment described in the embodiments of the present application, analyzing the peak and trough data of each segment to obtain run-length encoding specifically includes: Define the distance between one peak point and the next peak point or between one trough point and the next trough point as a run. Analyze the peak and trough data of each segment, and calculate the run length between adjacent peaks or troughs in sequence according to the defined run-length encoding rule. Arrange the calculated run lengths of each segment in order to obtain the run-length encoding sequence corresponding to each segment. Integrate the run-length encoding sequences of each segment in the order of image segmentation to obtain a complete run-length encoding sequence.
[0015] In a second aspect, an embodiment of the present application provides a barcode recognition system based on segmented peak and adaptive threshold adjustment. The system includes: a memory and a processor. The memory includes a program of the barcode recognition method based on segmented peak and adaptive threshold adjustment. When the program of the barcode recognition method based on segmented peak and adaptive threshold adjustment is executed by the processor, the following steps are implemented: Obtain the original image, analyze the original image based on the positioning algorithm to obtain barcode positioning information, and perform an affine transformation based on the barcode positioning information to obtain an aligned barcode image. Perform segmented vertical projection on the aligned barcode image to obtain the waveform data of each segment, perform smoothing processing and differential processing on the waveform data of each segment to obtain differential waveform data. Analyze the differential waveform data based on the set threshold to obtain peak and trough data, and analyze the peak and trough data of each segment to obtain run-length encoding. Transmit the run-length encoding to a multi-format barcode image processing library for decoding, and analyze whether the decoding is successful. If the decoding is successful, obtain the barcode recognition result. If the decoding fails, adjust the threshold to perform secondary analysis on the differential waveform data.
[0016] Optionally, in the barcode recognition system based on segmented peak and adaptive threshold adjustment described in the embodiments of the present application, obtaining the original image, analyzing the original image based on the 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 includes: Pre-set representative feature points on the barcode template. Obtain the original image, extract the image features, match the image features with the set representative feature points, and obtain the positional relationship of the barcode in the original image; Analyze the position and pose of the barcode in the original image based on the positional relationship of the barcode in the original image; Obtain the barcode positioning information based on the position and pose of the barcode; Perform an affine transformation process on the barcode based on the barcode positioning information. The affine transformation process includes rotation, translation, scaling, or shearing processing, and transform the barcode image to a standard aligned state to obtain an aligned barcode image.
[0017] Optionally, in the barcode recognition system based on segmented wave peaks and adaptive threshold adjustment described in the embodiments of the present application, perform segmented vertical projection on the aligned barcode image to obtain waveform data for each segment, specifically including: Obtain the aligned barcode image, convert the aligned barcode image into a grayscale image, and perform binarization processing on the grayscale image; Divide the binarized barcode image evenly into several segments in the horizontal direction, and the width of each segment is the same; Extract the image region of each segment in turn to obtain several independent sub-images corresponding to several segments; Perform vertical projection processing on each segment of the barcode image from left to right for several independent sub-images 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.
[0018] In a third aspect, the embodiments of the present application also provide a computer-readable storage medium, which includes a barcode recognition method program based on segmented wave peaks and adaptive threshold adjustment. When the barcode recognition method program based on segmented wave peaks and adaptive threshold adjustment is executed by a processor, the steps of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment described in any one of the above are implemented.
[0019] As described above, a barcode recognition method, system and medium based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application obtain an original image, analyze the original image based on a positioning algorithm to obtain barcode positioning information, and perform an affine transformation based on the barcode positioning information to obtain an aligned barcode image; perform a segmented vertical projection on the aligned barcode image to obtain waveform data for each segment, perform smoothing processing and difference processing on the waveform data for each segment to obtain difference waveform data; analyze the difference waveform data based on a set threshold to obtain wave peak and wave valley data, analyze the wave peak and wave valley data for each segment to obtain run-length encoding; transmit the run-length encoding to a multi-format barcode image processing library for decoding, and analyze whether the decoding is successful; if the decoding is successful, obtain a barcode recognition result, if the decoding fails, adjust the threshold to perform secondary analysis on the difference waveform data; by analyzing the segmented wave peaks, extract the most likely position as the boundary position of the barcode, which can process the recognition of damaged, missing, blurred and occluded barcode images and improve the accuracy of barcode recognition in industrial scenarios. Description of the Drawings
[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other related drawings can also be obtained based on these drawings.
[0021] Figure 1 It is a flowchart of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application; Figure 2 It is a schematic diagram of the specific steps of barcode recognition of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application; Figure 3 It is a schematic diagram of the original image of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application; Figure 4 It is a schematic diagram of the four corner points of the positioned barcode of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application; Figure 5 It is a schematic diagram of the alignment of the barcode image of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application; Figure 6 It is a schematic diagram of the waveform data of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application; Figure 7Schematic diagram of waveform data and differential data for the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application; Figure 8 Schematic diagram of the light and dark positions for the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application; Figure 9 Schematic diagram showing the cursor moving from the current position to the next position according to the minimum distance for the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment provided by the embodiments of the present application. Detailed implementation manners
[0022] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application usually described and illustrated in the accompanying drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application claimed, but only represents the selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative efforts belong to the scope of protection of the present application.
[0023] It should be noted that similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of the present application, the terms "first", "second", etc. are only used for distinguishing descriptions and cannot be understood as indicating or implying relative importance.
[0024] Please refer to Figures 1-9 As shown, the present application discloses a barcode recognition method based on segmented wave peaks and adaptive threshold adjustment. This barcode recognition method based on segmented wave peaks and adaptive threshold adjustment is used in a terminal device. The barcode recognition method based on segmented wave peaks and adaptive threshold adjustment includes the following steps: S101, obtain an original image, analyze the original image based on a positioning algorithm to obtain barcode positioning information, and perform an affine transformation based on the barcode positioning information to obtain an aligned barcode image; S102, perform segmented vertical projection on the aligned barcode image to obtain waveform data for each segment, perform smoothing processing and differential processing on the waveform data for each segment to obtain differential waveform data; S103, analyze the differential waveform data based on a set threshold to obtain wave peak and wave valley data, and analyze the wave peak and wave valley data for each segment to obtain a run-length encoding; S104. Transmit the run-length encoding to the multi-format barcode image processing library (ZXing library) for decoding, and analyze whether the decoding is successful; S105. If the decoding is successful, obtain the barcode recognition result. If the decoding fails, adjust the threshold to perform a secondary analysis on the differential waveform data.
[0025] It should be noted that for the cases of damage, occlusion, and missing, by analyzing the segmented wave peaks and extracting the most likely position as the boundary position of the barcode, it is possible to avoid the problem that the barcode information is lost and cannot be parsed due to partial damage, occlusion, and missing.
[0026] For blurred barcodes, adopt the segmented vertical projection method and the adaptive threshold adjustment method to extract the boundary of the barcode to the greatest extent, so as to accurately identify the barcode.
[0027] As Figure 2 shown, according to a preferred embodiment of the present invention, the barcode recognition steps specifically include: S1: First, roughly locate a barcode through a positioning algorithm (traditional or AI algorithm). First, it is necessary to locate the approximate position of the barcode through an algorithm, such as a traditional or deep learning algorithm. The following steps are based on the barcode that is roughly aligned. The position only needs to be roughly aligned because the subsequent algorithm has a certain degree of fault tolerance. Therefore, the present invention does not have very high requirements for barcode positioning. S2: Extract the segmented waveform of the aligned barcode image, specifically including: after obtaining the roughly aligned barcode image, perform segmented vertical projection on the image to obtain the waveform data of each segment. S3: Smooth the waveform. To avoid the influence of noise, perform smoothing processing on the waveform data extracted above here. Median filtering is used here. Median filtering can filter small salt-and-pepper noise. S4: Perform differential processing on the waveform data to obtain differential waveform data. To extract the light and dark boundaries of the barcode, perform first-order differential processing on the waveform. The peaks and valleys of the first-order differential of the curve represent the places where the gray level changes fastest, which are the light and dark positions in the barcode. S5: Calculate the peaks and valleys according to the differential waveform data. S6: Perform segmented peak statistics detection. Through S1 - S5, the peak and valley vectors of each segment can be obtained, and the best light and dark positions of the barcode can be obtained according to the data of all segments. S7: Repeat S6 until the scanning of the peak and valley vectors ends, obtain a run-length encoding, transmit the run-length encoding to the multi-format barcode image processing library (ZXing library) for decoding. If the decoding is successful, end. Otherwise, perform step S8. S8: Loop through the threshold ratio in S3 and repeat S5 - S7.
[0028] 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 affine transformation is performed based on the barcode positioning information to obtain an aligned barcode image, specifically including: Set representative feature points on the barcode template in advance; Obtain the original image, extract image features, match the image features with set representative feature points, and obtain the position relationship of the barcode in the original image; Analyze the position and posture of the barcode in the original image based on the position relationship of the barcode in the original image; Obtain barcode positioning information based on the position and posture of the barcode; The barcode is subjected to affine transformation processing based on the barcode positioning information. The affine transformation processing includes rotation, translation, scaling or shearing processing. The barcode image is transformed into a standard alignment state to obtain an aligned barcode image.
[0029] It should be noted that segmented waveforms can avoid defects, occlusions, and missing problems, because the lost information can most likely be obtained from other segments.
[0030] Segmented waveforms can accommodate roughly aligned barcodes better than full-image extracted waveforms because each segment is closer to vertical, making it easier to extract boundaries.
[0031] Specifically, affine transformation is a linear transformation from two-dimensional coordinates to two-dimensional coordinates, which can maintain the flatness and parallelism of the image. Affine transformation includes operations such as translation, rotation, scaling and shearing. By calculating the affine transformation matrix, the barcode image can be transformed to a standard alignment state. The calculation is relatively simple and can handle common transformations such as translation, rotation and scaling of the barcode.
[0032] In barcode recognition, if the barcode undergoes simple translation, rotation, or scaling, affine transformation can quickly and effectively align the barcode.
[0033] According to an embodiment of the present invention, the aligned barcode image is vertically projected in segments to obtain waveform data of each segment, specifically including: Obtaining the aligned barcode image, converting the aligned barcode image into a grayscale image, and performing binarization processing on the grayscale image; The binary barcode image is evenly divided into several segments in the horizontal direction, and the width of each segment is the same; Extract the image area of each segment in turn to obtain several independent sub-images corresponding to several segments; Perform vertical projection processing on each segment of the barcode image using several independent sub-images from left to right to obtain the projection value of each segment; Arrange the projection values of each segment in sequence to obtain the waveform data of each segment.
[0034] It should be noted that the grayscale value information is more convenient for analyzing the bar and space distribution of the barcode. Converting to a grayscale image can simplify the calculation and remove the interference brought by color information. The binarization process specifically includes: by setting an appropriate threshold, the pixel points in the image are divided into two categories. One category represents the bars of the barcode (usually set to black, with a grayscale value of 0), and the other category represents the spaces of the barcode (usually set to white, with a grayscale value of 255), which can make the structure of the barcode clearer and facilitate subsequent projection operations.
[0035] According to the embodiments of the present invention, smooth processing and difference processing are performed on the waveform data of each segment to obtain difference waveform data, which specifically includes: Obtain the waveform data of each segment, and perform smooth processing on the waveform data based on median filtering to remove the noise characteristics in the waveform data; Perform first-order difference processing on the waveform data after smooth processing of each segment to analyze the change rate of the waveform data; Based on the change rate analysis of the waveform data, analyze the boundary positions of the barcode bars and spaces to obtain difference waveform data.
[0036] It should be noted that in order to avoid the influence of noise, median filtering is used to perform smooth processing on the waveform data. Median filtering can filter small salt-and-pepper noises. The peaks and valleys of the first-order difference of the curve represent the places where the grayscale changes fastest, that is, the light and dark alternating positions.
[0037] Specifically, the median filtering method is as follows: select a window size n. For each point in the waveform data, take n points within its window, sort the values of these points from small to large, and take the middle value as the new value of the current point. Median filtering has a significant effect on removing pulse noises (such as sudden large fluctuations) in the data and can achieve smooth processing while retaining the basic shape of the waveform.
[0038] According to the embodiments of the present invention, based on a set threshold, analyze the difference waveform data to obtain peak and valley data, which specifically includes: Set a threshold, and traverse each segment of the difference waveform data based on the set threshold to analyze the values of the difference waveform data; When the value of the difference waveform data changes from positive to negative, it is determined as a change point. If the data value of the change point is greater than the set threshold, the change point is determined as a peak point; When the value of the difference waveform data changes from negative to positive, and the data value at the change point is less than the opposite of the set threshold, then the change point is determined as a valley point, and record the positions of all peak points and valley points and the corresponding waveform data values.
[0039] It should be noted that for the obtained differential data, the peaks and valleys are found. The peak value is the place where the change from dark to bright is the fastest, and the valley value is the place where the change from bright to dark is the fastest.
[0040] To extract the peaks and valleys, a threshold needs to be set. When the data is greater than the threshold and is a local maximum or minimum, it can be recognized as a peak or a valley.
[0041] Due to the problem that the barcode may be uneven or blurred in light and dark, resulting in improper threshold setting, an adaptive threshold method is used for processing.
[0042] First, obtain the maximum value of the differential data: , Take a specified proportion of the maximum value as the threshold: , where wave is the waveform data extracted by projection, maxValue is the maximum value of the waveform data, and ratio is the threshold ratio, which is used for barcodes under different contrasts.
[0043] To adapt to the problem of difficult extraction of peaks and valleys in the case of low contrast, ratio is set to {0.5, 0.3, 0.2, 0.1} respectively.
[0044] According to the embodiments of the present invention, run-length encoding is obtained by analyzing the peak and valley data of each segment, specifically including: Define the distance between one peak point and the next peak point or between one valley point and the next valley point as a run; Analyze the peak and valley data of each segment, and calculate the run length between adjacent peaks or valleys in turn according to the defined run-length encoding rules; Arrange the calculated run lengths of each segment in order to obtain the corresponding run-length encoding sequence of each segment; Integrate the run-length encoding sequences of each segment in the order of image segmentation to obtain the complete run-length encoding sequence.
[0045] It should be noted that when traversing the peak and valley vector from left to right, a cursor is set for each segment to point to the current index position accessed by each segment. Taking a white background and black barcode as an example, the first time is from bright to dark, that is, the valley. Then the next time, a peak should be found, and so on.
[0046] Obtain the next optimal position. Move the cursor to the next position, and the next position must satisfy the opposite light and dark. For example, if the current is from bright to dark, then the next time must be from dark to bright. After obtaining the next positions of all segments in this way, calculate the moving distances of each segment, and find the minimum value of the distances, which is the distance that each segment needs to move this time.
[0047] Move the cursor of each segment from the current position to the next position according to the above minimum distance, and record the distance of this movement in a vector as the run-length encoding for barcode parsing.
[0048] In a second aspect, an embodiment of the present application provides 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 the 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, the following steps are implemented: Obtain the original image, analyze the original image based on the positioning algorithm to obtain barcode positioning information, and perform an affine transformation based on the barcode positioning information to obtain an aligned barcode image; Perform a segmented vertical projection on the aligned barcode image to obtain waveform data for each segment, and perform smoothing processing and differential processing on the waveform data for each segment to obtain differential waveform data; Analyze the differential waveform data based on a set threshold to obtain peak and valley data, and analyze the peak and valley data for each segment to obtain run-length encoding; Transmit the run-length encoding to the multi-format barcode image processing library (ZXing library) for decoding, and analyze whether the decoding is successful; If the decoding is successful, obtain the barcode recognition result. If the decoding fails, adjust the threshold and perform a secondary analysis on the differential waveform data.
[0049] According to an embodiment of the present invention, obtaining the original image, analyzing the original image based on the 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 includes: Pre-set representative feature points on the barcode template in advance; Obtain the original image, extract image features, match the image features with the pre-set representative feature points to obtain the positional relationship of the barcode in the original image; Analyze the position and pose of the barcode in the original image based on the positional relationship of the barcode in the original image; Obtain barcode positioning information based on the position and pose of the barcode; Perform an affine transformation on the barcode based on the barcode positioning information. The affine transformation includes rotation, translation, scaling, or shearing processing, and transform the barcode image to a standard aligned state to obtain an aligned barcode image.
[0050] According to an embodiment of the present invention, performing a segmented vertical projection on the aligned barcode image to obtain waveform data for each segment specifically includes: Obtain the aligned barcode image, convert the aligned barcode image to a grayscale image, and perform binarization processing on the grayscale image; The binarized barcode image is evenly divided into several segments in the horizontal direction, and each segment has the same width; The image regions of each segment are sequentially extracted to obtain several independent sub-images corresponding to the several segments; The several independent sub-images are used to perform vertical projection processing on each segment of the barcode image from left to right to obtain the projection values of each segment; The projection values of each segment are arranged in order to obtain the waveform data of each segment.
[0051] It should be noted that the grayscale value information is more convenient for analyzing the distribution of bars and spaces of the barcode. Converting to a grayscale image can simplify the calculation and remove the interference brought by color information. The binarization process specifically includes: by setting an appropriate threshold, the pixel points in the image are divided into two categories. One category represents the bars of the barcode (usually set to black, with a grayscale value of 0), and the other category represents the spaces of the barcode (usually set to white, with a grayscale value of 255), which can make the structure of the barcode clearer and facilitate subsequent projection operations.
[0052] According to the embodiments of the present invention, the waveform data of each segment is smoothed and differentiated to obtain differential waveform data, which specifically includes: Obtain the waveform data of each segment, and smooth the waveform data based on median filtering to remove the noise characteristics in the waveform data; Perform first-order differentiation on the smoothed waveform data of each segment to analyze the change rate of the waveform data; Based on the change rate of the waveform data, analyze the boundary positions of the bars and spaces of the barcode to obtain differential waveform data.
[0053] 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 small salt-and-pepper noises. The peaks and valleys of the first-order difference of the curve represent the places where the grayscale changes fastest, that is, the positions where light and dark alternate.
[0054] Specifically, the median filtering method is as follows: select a window size n. For each point in the waveform data, take n points within its window, sort the values of these points from small to large, and take the middle value as the new value of the current point. Median filtering has a significant effect on removing pulse noises (such as sudden large fluctuations) in the data and can achieve smoothing while retaining the basic shape of the waveform.
[0055] According to the embodiments of the present invention, based on a set threshold, the differential waveform data is analyzed to obtain peak and valley data, which specifically includes: Set a threshold, and based on the set threshold, traverse the differential waveform data of each segment to analyze the values of the differential waveform data; When the value of the differential waveform data changes from positive to negative, it is determined as a change point. If the data value of the change point is greater than the set threshold, the change point is determined as a peak point; When the value of the differential waveform data changes from negative to positive and the data value at the change point is less than the opposite of the set threshold, the change point is determined as a trough point, and the positions of all peak points and trough points and the corresponding waveform data values are recorded.
[0056] It should be noted that for the obtained differential data, the peak and trough are found. The peak value is the place where the change from dark to bright is the fastest, and the trough is the place where the change from bright to dark is the fastest.
[0057] To extract the peak and trough, a threshold needs to be set. When the data is greater than the threshold and is a local maximum or minimum, it can be recognized as a peak or trough.
[0058] Due to the problem that the barcode may be uneven in brightness or blurred, resulting in improper threshold setting, an adaptive threshold method is used for processing.
[0059] First, obtain the maximum value of the differential data: , Take a specified proportion of the maximum value as the threshold: .
[0060] To adapt to the problem of difficult peak and trough extraction in low-contrast situations, ratio is set to {0.5, 0.3, 0.2, 0.1} respectively.
[0061] According to the embodiments of the present invention, analyzing the peak and trough data of each segment to obtain run-length encoding specifically includes: Define the distance between one peak point and the next peak point or between one trough point and the next trough point as a run; Analyze the peak and trough data of each segment, and calculate the run length between adjacent peaks or troughs in turn according to the defined run-length encoding rules; Arrange the calculated run lengths of each one in order to obtain the corresponding run-length encoding sequence of each segment; Integrate the run-length encoding sequences of each segment in the order of image segmentation to obtain a complete run-length encoding sequence.
[0062] It should be noted that when traversing the peak and trough vector from left to right, a cursor is set for each segment to point to the current index position accessed by each segment. Taking a white background and black code as an example, the first time is from bright to dark, that is, the trough. Then the next time, a peak should be found, and so on.
[0063] Obtain the next optimal position. Move the cursor to the next position, and the next position must have the opposite light and dark states. For example, if it is currently from light to dark, then the next time it must be from dark to light. After obtaining the next positions of all segments in this way, calculate the moving distances of each segment, and find the minimum value of the distances as the distance that each segment needs to move this time.
[0064] Move the cursor of each segment from the current position to the next position according to the above minimum distance, and at the same time record the distance of this movement in a vector as the run-length encoding of barcode parsing.
[0065] The third aspect of the present invention provides a computer-readable storage medium, which includes a program for a barcode recognition method based on segmented wave peaks and adaptive threshold adjustment. When the program for the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment is executed by a processor, the steps of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment as described in any one of the above are implemented.
[0066] A barcode recognition method, system and medium based on segmented wave peaks and adaptive threshold adjustment disclosed by the present invention. By obtaining 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; performing a segmented vertical projection on the aligned barcode image to obtain waveform data for each segment, performing smoothing processing and difference processing on the waveform data for each segment to obtain difference waveform data; analyzing the difference waveform data based on a set threshold to obtain wave peak and wave valley data, analyzing the wave peak and wave valley data of each segment to obtain run-length encoding; transmitting the run-length encoding to the ZXing library for decoding, and analyzing whether the decoding is successful; if the decoding is successful, the barcode recognition result is obtained, if the decoding fails, the threshold is adjusted to perform secondary analysis on the difference waveform data; by analyzing the segmented wave 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.
[0067] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed with each other can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0068] The units described above as separate components may or may not be physically separated, and 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 can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0069] In addition, each functional unit in the embodiments of the present invention may be all integrated in a processing unit, or each unit may be separately regarded as a unit, or two or more units may be integrated in one unit; the above-mentioned integrated units may be implemented in the form of hardware, or in the form of a combination of hardware and software functional units.
[0070] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a readable storage medium. When the program is executed, it performs the steps including the above method embodiments; and the foregoing storage medium includes: removable storage devices, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks or optical discs and other various media that can store program codes.
[0071] If the above-mentioned integrated units of the present invention are implemented in the form of software functional modules and sold or used as independent products, they can also be stored in a readable storage medium. Based on such an understanding, the technical solution of the embodiments of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. The software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the embodiments of the present invention. And the foregoing storage medium includes: removable storage devices, ROM, RAM, magnetic disks or optical discs and other various media that can store program codes.
Claims
1. A bar code recognition method based on segmented wave peaks and adaptive threshold adjustment, characterized in that, Including: Obtain the original image, analyze the original image based on the positioning algorithm to obtain barcode positioning information, and perform an affine transformation based on the barcode positioning information to obtain an aligned barcode image; Perform a segmented vertical projection on the aligned barcode image to obtain waveform data for each segment, perform smoothing processing and differential processing on the waveform data for each segment to obtain differential waveform data; Analyze the differential waveform data based on a set threshold to obtain peak and valley data, and analyze the peak and valley data for each segment to obtain run-length encoding; Transmit the run-length encoding to a multi-format barcode image processing library for decoding, and analyze whether the decoding is successful; If the decoding is successful, obtain the barcode recognition result. If the decoding fails, adjust the threshold to perform a secondary analysis on the differential waveform data.
2. The barcode recognition method based on segmented wave peaks and adaptive threshold adjustment according to claim 1, wherein Obtain the original image, analyze the original image based on the positioning algorithm to obtain barcode positioning information, and perform an affine transformation based on the barcode positioning information to obtain an aligned barcode image. Specifically, it includes: Pre-set representative feature points on the barcode template in advance; Obtain the original image, extract image features, match the image features with the pre-set representative feature points to obtain the positional relationship of the barcode in the original image; Analyze the position and posture of the barcode in the original image based on the positional relationship of the barcode in the original image; Obtain barcode positioning information based on the position and posture of the barcode; Perform an affine transformation on the barcode based on the barcode positioning information. The affine transformation includes rotation, translation, scaling, or shearing processing, and transform the barcode image to a standard aligned state to obtain an aligned barcode image.
3. The barcode recognition method based on segmented wave peaks and adaptive threshold adjustment according to claim 2, wherein, Perform a segmented vertical projection on the aligned barcode image to obtain waveform data for each segment. Specifically, it includes: Obtain the aligned barcode image, convert the aligned barcode image to a grayscale image, and perform binarization processing on the grayscale image; Divide the binarized barcode image evenly into several segments in the horizontal direction, and the width of each segment is the same; Extract the image area of each segment in turn to obtain several corresponding independent sub-images; Perform a vertical projection process on each segment of the barcode image from left to right for several independent sub-images to obtain the projection value for each segment; Arrange the projection values for each segment in order to obtain the waveform data for each segment.
4. The barcode recognition method based on segmented wave peaks and adaptive threshold adjustment according to claim 3, wherein Perform smoothing processing and differential processing on the waveform data for each segment to obtain differential waveform data. Specifically, it includes: Obtain the waveform data for each segment, perform smoothing processing on the waveform data based on median filtering to remove the noise features in the waveform data; Perform first-order differential processing on the waveform data after smoothing for each segment to analyze the change rate of the waveform data; Analyze the boundary positions of barcode bars and spaces based on the change rate of the waveform data to obtain differential waveform data.
5. The barcode recognition method based on segmented wave peaks and adaptive threshold adjustment according to claim 4, wherein Analyze the differential waveform data based on a set threshold to obtain peak and valley data. Specifically, it includes: Set a threshold, traverse the differential waveform data for each segment based on the set threshold, 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 as a change point. If the data value of the change point is greater than the set threshold, the change point is determined as a peak point; When the value of the differential waveform data changes from negative to positive and the data value at the change point is less than the opposite of the set threshold, it is determined that the change point is a trough point, and the positions of all peak points and trough points and the corresponding waveform data values are recorded.
6. The barcode recognition method based on segmented wave peaks and adaptive threshold adjustment according to claim 5, characterized in that, Analyze the peak and trough data of each segment to obtain run-length encoding, specifically including: Define the distance between one peak point and the next peak point or between one trough point and the next trough point as a run; Analyze the peak and trough data of each segment, and calculate the run length between adjacent peaks or troughs in turn according to the defined run-length encoding rules; Arrange the calculated run lengths of each segment in sequence to obtain the corresponding run-length encoding sequence of each segment; Integrate the run-length encoding sequences of each segment in the order of image segmentation to obtain the complete run-length encoding sequence.
7. A bar code recognition system based on segmented wave peaks and adaptive threshold adjustment, characterized in that, The system includes: a memory and a processor. The memory includes a program of a barcode recognition method based on segmented peaks and adaptive threshold adjustment. When the program of the barcode recognition method based on segmented peaks and adaptive threshold adjustment is executed by the processor, the following steps are implemented: Obtain the original image, analyze the original image based on the positioning algorithm to obtain barcode positioning information, and perform an affine transformation based on the barcode positioning information to obtain an aligned barcode image; Perform a segmented vertical projection on the aligned barcode image to obtain the waveform data of each segment, and perform smoothing processing and differential processing on the waveform data of each segment to obtain differential waveform data; Analyze the differential waveform data based on the set threshold to obtain peak and trough data, and analyze the peak and trough data of each segment to obtain run-length encoding; Transmit the run-length encoding to the multi-format barcode image processing library for decoding, and analyze whether the decoding is successful; If the decoding is successful, obtain the barcode recognition result. If the decoding fails, adjust the threshold to perform a secondary analysis on the differential waveform data.
8. The barcode recognition system based on segmented peak and adaptive threshold adjustment according to claim 7, characterized in that, Obtain the original image, analyze the original image based on the positioning algorithm to obtain barcode positioning information, and perform an affine transformation based on the barcode positioning information to obtain an aligned barcode image, specifically including: Pre-set representative feature points on the barcode template in advance; Obtain the original image, extract image features, and match the image features with the pre-set representative feature points to obtain the position relationship of the barcode in the original image; Analyze the position and posture of the barcode in the original image based on the position relationship of the barcode in the original image; Obtain barcode positioning information based on the position and posture of the barcode; Perform an affine transformation process on the barcode based on the barcode positioning information. The affine transformation process includes rotation, translation, scaling, or shearing processing, and transform the barcode image to a standard aligned state to obtain an aligned barcode image.
9. The barcode recognition system based on segmented peak and adaptive threshold adjustment according to claim 8, characterized in that Perform a segmented vertical projection on the aligned barcode image to obtain the waveform data of each segment, specifically including: Obtain the aligned barcode image, convert the aligned barcode image into a grayscale image, and perform binarization processing on the grayscale image; Divide the binarized barcode image evenly into several segments in the horizontal direction, and the width of each segment is the same; Extract the image area of each segment in turn to obtain several independent sub-images corresponding to several segments; Perform vertical projection processing on each barcode image segment by arranging several independent sub-images from left to right to obtain the projection values of each segment; Arrange the projection values of each segment in sequence to obtain the waveform data of each segment.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a barcode recognition method program based on segmented wave peaks and adaptive threshold adjustment. When the barcode recognition method program based on segmented wave peaks and adaptive threshold adjustment is executed by a processor, the steps of the barcode recognition method based on segmented wave peaks and adaptive threshold adjustment as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
One-dimensional barcode identification method based on image sampling line grey scale information analysis
CN104732183A
Method for decoding barcode
CN105868667A
Bar code detection method and equipment
CN108171098A
A one-dimensional bar code identification method and system based on waveform matching
CN109902529A
Barcode recognition method and device, electronic equipment and readable storage medium
CN117077710A
Cited By
One-dimensional barcode quality multi-dimensional characterization parameter system and defect visualization method
CN122311264A