Equipment bar code identification method and system, equipment and storage medium
By locating the stripe area and correcting the barcode angle, the efficiency and accuracy issues of barcode recognition technology in complex environments have been solved, achieving efficient and accurate barcode recognition.
Patent Information
- Application Number
- CN202511242770.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-02
- Publication Date
- 2026-01-23
AI Technical Summary
Existing barcode recognition technologies cannot balance recognition accuracy and efficiency in complex imaging environments. In particular, under conditions such as image distortion, uneven lighting, and shadow coverage, blurred bar and space boundaries, projection distortion, and physical deformation lead to recognition failures, increasing decoding complexity and computational load.
By locating the stripe area, extracting the features of parallel stripe segments, obtaining the barcode correction angle, performing image correction and decoding, and combining text recognition, outputting structured data.
It improves recognition efficiency and accuracy, reduces computational burden and recognition latency, and solves the problem of low recognition efficiency and accuracy in complex imaging environments.
Smart Images

Figure CN121390101A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of equipment barcode recognition, specifically to a method, system, device, and storage medium for equipment barcode recognition. Background Technology
[0002] Barcode recognition technology is widely used in many fields, but it has significant drawbacks when dealing with complex images: Under complex imaging conditions such as image distortion and pixelation, uneven ambient lighting, and shadow coverage, the bar and space boundaries of the barcode symbol will produce a blurring effect, thereby compromising the accuracy of the bar and space width ratio. When the barcode carrier and the scanning module form a non-perpendicular scanning condition, the projection distortion of the bar and space structure will cause incomplete information sampling, making it impossible to accurately locate the barcode area. Additional bar and space boundary compensation is required, increasing decoding complexity and thus reducing recognition efficiency. In addition, physical deformation of the barcode carrier or local information loss will directly destroy the geometric structure of the code standard, triggering multiple error correction mechanisms of the decoder, causing recognition deviations and increasing computational load and processing time. This not only leads to recognition failure but also reduces recognition efficiency.
[0003] The patent "Receipt Information Comparison and Verification System Based on OCR Technology", publication number: CN120088808 A, discloses: a ticket information recognition module, a ticket information comparison module, and a ticket information verification module. The ticket information recognition module is used to acquire images of tickets in real time, determine the text content detection area and image content detection area of the ticket, and use the CTPN text detection algorithm to recognize the ticket information in the text content detection area through OCR technology to obtain the recognition result of the ticket information. The ticket information comparison module is used to format the recognition result and compare the recognized and formatted information with the information in the barcode. The ticket information verification module is used to verify ticket information that is inconsistent with the recognition result and the barcode information. It corrects and segments the image through binarization processing, inter-class variance calculation, and Hough transform method, and uses a semantic analysis model to verify the recognition result. This solution only performs text content detection and image content detection on the image once before recognizing the text. Only when the recognition result is inconsistent with the barcode information is the image corrected. Obviously, this increases the complexity of the recognition process, reduces efficiency, and cannot simultaneously improve recognition efficiency and accuracy. Summary of the Invention
[0004] The purpose of this application is to address the problem that conventional barcode recognition technology cannot balance recognition accuracy and efficiency in complex imaging environments. It proposes a device barcode recognition method, system, device, and storage medium. By locating the stripe region of the scanned image and further correcting the image to obtain the target barcode image, the method ensures that the image contains the fine area of the real barcode stripes, avoids interference and resource waste from invalid areas, and improves recognition efficiency while maintaining recognition accuracy.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows: In a first aspect, embodiments of this application provide a method for identifying device barcodes, the method comprising the following steps: The stripe region is located based on the scanned image of the barcode to be identified, and a stripe region map is obtained. Line segment features of parallel stripes are extracted from the stripe region map, and the barcode correction angle is obtained based on the angular distribution of the line segment features. The stripe region image is corrected based on the barcode correction angle to obtain the target barcode image. The target barcode image is decoded and text is recognized. The recognized text information is associated and mapped with the decoded information to output structured barcode recognition data.
[0006] In this solution, by locating the stripe region of the barcode from the scanned image, irrelevant background interference is eliminated, and the image processing range is narrowed. This reduces the computational burden of subsequent steps and avoids the background misleading feature extraction, effectively addressing the complex imaging environment of barcodes on devices. By extracting line segment features, accurate barcode correction angles can be obtained based on effective stripe line segment features, avoiding angle misjudgment and ensuring correct image correction. This improves decoding efficiency based on the corrected image. Furthermore, text recognition is performed based on the corrected target barcode image, avoiding the calculation process of angle compensation for the recognition results, reducing recognition delay caused by character deformation, and significantly improving recognition accuracy and efficiency. This solves the problem that conventional barcode recognition technology cannot balance recognition efficiency and low recognition accuracy in complex imaging environments.
[0007] Preferably, the step of locating the stripe region based on the scanned image of the barcode to be identified and obtaining a stripe region map includes: performing image preprocessing on the scanned image of the barcode to be identified, including image grayscale conversion, image filtering, and barcode region detection, and marking the barcode region in the scanned image with candidate boxes to obtain an initial barcode region map; filtering the target region of the initial barcode region map based on the attribute features of the barcode, expanding the filtered target region according to a preset pixel range to obtain a reference barcode region map; performing stripe density detection based on the reference barcode region map and calculating the horizontal pixel transition frequency; and obtaining a stripe region map based on the stripe density and pixel transition frequency.
[0008] Preferably, the step of detecting stripe density based on the barcode reference area map and calculating the jump frequency of pixels in the horizontal direction includes: extracting several horizontal scan lines from the barcode reference area map; traversing pixels from left to right based on each scan line to compare adjacent pixel values; wherein, if adjacent pixel values are not equal, a jump occurs; obtaining the jump count of all scan lines based on adjacent pixel values, and then calculating the average jump count; filtering out jump counts that exceed the fluctuation range of the average jump count; calculating the jump frequency based on the remaining jump count after filtering and the scan line length; and obtaining the average stripe count based on the remaining jump count after filtering, and then calculating the stripe density through the average stripe count.
[0009] Preferably, obtaining the stripe region map based on stripe density and pixel transition frequency includes: comprehensively judging whether the barcode reference region map needs to be updated based on stripe density and pixel transition frequency; if the pixel transition frequency does not exceed a frequency threshold and the stripe density conforms to the standard barcode density characteristic value, then the barcode reference region map does not need to be updated, and the barcode reference region map is used as the stripe region map; if the pixel transition frequency exceeds the frequency threshold and / or the stripe density exceeds the standard barcode density characteristic value, then the pixel range and expansion direction are dynamically adjusted, and the barcode reference region map is expanded according to the adjusted pixel range and expansion direction; barcode region detection is performed based on the expanded barcode reference region map to obtain the final stripe region map.
[0010] Preferably, the step of extracting the line segment features of parallel stripes from the stripe area map and obtaining the barcode correction angle based on the angle distribution of the line segment features includes: performing a Hough line transform on the stripe area map to extract the coordinate data of the line segments corresponding to all parallel stripes in the stripe area map; statistically analyzing the angle value distribution of the line segments based on the coordinate data of the line segments of the parallel stripes, taking the angle value with the highest frequency as the barcode tilt angle, and then taking the barcode tilt angle as the barcode correction angle; wherein, if the angle value distribution is discrete, all line segments are fitted with the principal direction, and the angle between the fitted line and the horizontal line is calculated, and the barcode correction angle is determined based on the angle.
[0011] Preferably, before performing Hough line transform on the striped region map, the method includes: performing binarization processing on the striped region map to convert it into a black and white binary image; and extracting edge features from the black and white binary image to obtain features containing striped contour lines.
[0012] Preferably, the step of decoding and recognizing text in the target barcode image, and associating the recognized text information with the decoded information to output structured barcode recognition data, includes: decoding the target barcode image based on a stripe segmentation decoding mechanism to obtain barcode decoding information; locating text regions using a text detection algorithm based on the target barcode image, performing text recognition based on the text regions to obtain text information within the barcode regions; preprocessing the text information, calculating the text similarity of the text information based on a keyword dictionary containing key fields of the barcode, and determining whether the text information is valid barcode association information based on the text similarity; associating the valid barcode association information with the barcode decoding information obtained by decoding the stripe region image, and outputting structured barcode recognition results.
[0013] Secondly, embodiments of this application provide a device barcode recognition system, comprising: a positioning module, used to locate the stripe region based on a scanned image of the barcode to be recognized, and obtain a stripe region map; a correction module, used to extract line segment features of parallel stripes based on the stripe region map, and obtain a barcode correction angle based on the angular distribution of the line segment features; correcting the stripe region image based on the barcode correction angle to obtain a target barcode image; and a recognition module, used to decode the target barcode image and perform text recognition, associate and map the recognized text information with the decoded information, and output structured barcode recognition data.
[0014] Thirdly, embodiments of this application provide a computer device, including: a processor, a memory, and a communication bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the communication bus, and the processor executes the machine-readable instructions to perform the steps of the device barcode recognition method as described in the first aspect above.
[0015] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the device barcode recognition method described in the first aspect above.
[0016] The beneficial effects of this application are as follows: By locating the stripe area of the barcode from the scanned image, irrelevant background interference is eliminated, and the image processing range is narrowed. This reduces the computational burden of subsequent steps and avoids the background misleading the feature extraction, effectively addressing the complex imaging environment of barcodes on devices. By extracting line segment features, accurate barcode correction angles can be obtained based on effective stripe line segment features, avoiding angle misjudgment and ensuring correct image correction. This improves decoding efficiency based on the corrected image. Furthermore, text recognition based on the corrected target barcode image avoids the calculation process of angle compensation for the recognition results, reduces recognition delay caused by character deformation, and significantly improves recognition accuracy and efficiency. This solves the problem that conventional barcode recognition technology cannot balance recognition efficiency and low recognition accuracy in complex imaging environments. Attached Figure Description
[0017] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings. The drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings.
[0018] Figure 1 A flowchart of the device barcode recognition method provided in this application embodiment.
[0019] Figure 2 This is a schematic diagram of a device barcode recognition system module provided in an embodiment of this application.
[0020] Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description of this application is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely one preferred embodiment of this application and are only used to explain this application. They do not limit the scope of protection of this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0022] Example 1: As Figure 1 As shown, a method for identifying device barcodes includes the following steps: S1. Locate the stripe region based on the scanned image of the barcode to be identified and obtain a stripe region map.
[0023] As an optional implementation, step S1 specifically includes: S11. Perform image preprocessing on the scanned image of the barcode to be recognized, including image grayscale conversion, image filtering, and barcode region detection, and use candidate boxes to mark the barcode regions in the scanned image to obtain the initial barcode region map. S12. Based on the attribute features of the barcode, the initial area map of the barcode is filtered for target areas, and the filtered target areas are expanded according to a preset pixel range to obtain the barcode reference area map. S13. Based on the barcode reference area map, perform stripe density detection and calculate the jump frequency of pixels in the horizontal direction; S14. Obtain the stripe region map based on stripe density and pixel jump frequency.
[0024] In this embodiment, image grayscale conversion includes converting the image into a grayscale image and then converting the grayscale image into a binary image, so that the image pixel values are only 0 or 255, representing the black and white bars of the barcode stripes, respectively, thereby enhancing image contrast, highlighting the boundaries of black and white stripes, and eliminating interference from grayscale gradients; image filtering includes using Gaussian filtering or median filtering to remove image noise; barcode region detection includes identifying barcode boundaries based on edge detection algorithms, and candidate box markers are used to mark areas where barcodes may exist, thereby obtaining an initial barcode region map, which facilitates accurate screening and positioning of subsequent stripe region maps.
[0025] Furthermore, after obtaining the initial area map of the barcode, the target area is selected in the candidate box according to the target width-to-height ratio based on the color attributes and distribution characteristics of the barcode stripes. The target area is used as the reference area to expand outward by a preset pixel range to serve as a coarse local map, which is then used as the reference area map of the barcode.
[0026] In some examples, a barcode edge detection model is trained using the YOLO model based on historical barcode samples. The scanned image of the barcode to be identified is processed into grayscale and filtered before being detected by the barcode edge detection model, outputting candidate bounding boxes for the barcode region in the image. Based on the barcode's characteristic of "alternating black and white, continuous distribution," regions with an aspect ratio between 3:1 and 5:1 are selected from the candidate bounding boxes. Using the selected candidate bounding boxes as a baseline, a 5% pixel range is expanded outwards to create a coarse local localization map, completing the first localization of the barcode stripe region.
[0027] Specifically, step S13 above includes: Several horizontal scan lines are extracted from the barcode reference area map. Pixels are traversed from left to right based on each scan line to compare adjacent pixel values. If adjacent pixel values are not equal, a jump occurs. The number of jumps for all scan lines is obtained based on the values of adjacent pixels, and then the average number of jumps is calculated. Jumps that exceed the fluctuation range of the average number of jumps are filtered out. The transition frequency is calculated based on the number of transitions remaining after filtering and the scan line length, and the average stripe is obtained based on the number of transitions remaining after filtering. Then, the stripe density is calculated from the average stripe.
[0028] In this embodiment, a transition refers to a sudden change in adjacent pixels from black to white or white to black, which is a direct manifestation of the stripe edge. Multiple horizontal scan lines, such as 10-20 (the number of scan lines depends on the barcode height), are evenly selected from top to bottom in the barcode reference area image. Multi-line scanning can reduce random errors in a single line, such as local blurring.
[0029] Furthermore, for each scan line, pixels are traversed from left to right, and adjacent pixel values are compared to obtain the number of transitions for a single scan line. If adjacent pixel values are not equal, a transition occurs. For example, if adjacent pixel values are p[i] and p[i+1] respectively, and p[i] ≠ p[i+1], it is recorded as 1 transition, i.e., black → white or white → black both belong to one transition. The transition "black-white-black" in the stripe sequence is represented as "black → white" and "white → black", which are 2 transitions. The number of transitions for all scan lines is calculated, and outliers that deviate too much from the average number of transitions (such as exceeding twice the standard deviation of the average number of transitions) are removed to overcome the interference of noise or edge defects.
[0030] In this embodiment, the average number of transitions = the sum of the remaining transitions after filtering / the number of valid scan lines (the number of scan lines remaining after filtering out abnormal transitions). Jump frequency = average number of jumps / scan line pixel length (scan line length is the number of pixels in the candidate box width); Stripe density = average number of stripes / scan line pixel length; Average number of stripes = (average number of jumps / 2) + 1.
[0031] Specifically, step S14 above includes: The barcode reference area map is determined based on the stripe density and pixel transition frequency. If the pixel transition frequency does not exceed the frequency threshold and the stripe density meets the standard barcode density characteristic value, the barcode reference area map does not need to be updated, and the barcode reference area map is used as the stripe area map. If the pixel transition frequency exceeds the frequency threshold or / and the stripe density exceeds the standard barcode density feature value, the pixel range and expansion direction are dynamically adjusted, and the barcode reference area map is expanded according to the adjusted pixel range and expansion direction. Barcode region detection is performed based on the extended barcode reference region map to obtain the final stripe region map.
[0032] In this embodiment, the stripe arrangement of the standard barcode is highly regular. The stripe density and transition frequency within the region can be used to reasonably determine whether the barcode reference area is a valid area. The stripes (black and white) of the standard barcode are arranged in a regular alternation along the horizontal direction. Therefore, within an accurately positioned barcode area, the transition frequencies calculated from different horizontal scan lines should be highly consistent. This is because the width and spacing of the stripes are uniform or vary according to a fixed rule throughout the barcode area, and the corresponding stripe density should also remain stable, without sudden large increases or decreases. If the standard deviation of the transition frequency / stripe density within the positioning area is too large (e.g., exceeding 20% of the mean), it indicates the presence of a large number of "non-barcode features" (such as solid-color background areas or messy textured interference areas), causing abnormal transition frequencies (too high or too low) for some scan lines, resulting in inaccurate positioning.
[0033] Furthermore, different types of barcodes have clearly defined stripe density ranges. Therefore, in this embodiment, the rationality of the jump frequency and stripe density values is determined by using a frequency threshold and standard barcode density feature values. Both must meet the corresponding conditions to avoid the one-sidedness and error of judging by a single value. If the value is within the standard range, but the consistency within the region is poor, it may still be that the background was partially included during positioning, causing the "effective stripes" to be diluted. Therefore, only when both the jump frequency and stripe density meet the conditions can the barcode reference area be considered as an effective area.
[0034] In some examples, the horizontal pixel transition frequency (number of alternations between black and white pixels) is calculated. If the number of transitions per centimeter is between 20 and 50 (meeting the standard barcode density characteristics) and the stripe density exceeds the standard barcode density characteristic value, the positioning is considered accurate, and the barcode reference area map is directly used as the stripe area map. If the deviation exceeds 10% of the pixel range, the range is expanded by 20% in all directions (up, down, left, and right) with the barcode reference area as the center. The barcode edge detection model is called again to detect the barcode area, identify the area with the "continuous parallel stripes" feature, and output the stripe area map to complete the secondary positioning of the barcode stripe area.
[0035] In this embodiment, by performing secondary localization on the barcode area (first coarse localization to obtain the barcode baseline area map, and second fine localization to obtain the stripe area map), non-barcode areas can be eliminated, redundant backgrounds can be cropped, and valid stripes can be completed, ultimately locking in a fine area containing only the true barcode stripes. Since the horizontal / vertical pixel transition frequency of the barcode area is stable and the barcode density of a standard barcode is fixed, while the stripe density of non-barcode areas is irregular or exceeds the standard range, more than 90% of non-barcode interference can be eliminated from the "suspected areas" of the barcode baseline area map by using both pixel transition frequency and stripe density dimensions. This avoids wasting subsequent processing resources, helps improve barcode recognition efficiency and accuracy, and solves the problems that barcode localization is easily affected by complex background interference, relying on simple contour screening is difficult to accurately lock the barcode area, and is prone to localization deviations, leading to unreliable foundations for subsequent recognition.
[0036] S2. Extract the line segment features of parallel stripes based on the stripe area map, and obtain the barcode correction angle based on the angular distribution of the line segment features.
[0037] As an optional implementation, step S2 specifically includes: S21. Perform Hough line transform on the striped area map to extract the coordinate data of the line segments corresponding to all parallel stripes in the striped area map. S22. Based on the coordinate data of the straight line segments of parallel stripes, statistically analyze the distribution of the angle values of the straight line segments, take the angle value with the highest frequency as the barcode tilt angle, and then take the barcode tilt angle as the barcode correction angle. If the angle values are discrete, then all straight line segments are fitted with the main direction, and the angle between the fitted line and the horizontal line is calculated. The barcode correction angle is determined based on the angle.
[0038] As an optional implementation, step S21 above, before performing the Hough line transform on the striped region map, includes: The striped area image is binarized to convert it into a black and white binary image. Edge features are extracted from the black-and-white binary image to obtain features including striped contour lines.
[0039] In some embodiments, the stripe contour features in the stripe region map are processed based on the probabilistic Hough transform to filter out short noise line segments or isolated edge features, and the endpoint coordinates of the line segments corresponding to the parallel stripes are output; the obtained line segments are filtered based on the line segment length attribute of the parallel stripes in the barcode, filtering out line segments whose length is lower than the stripe region width threshold in the stripe region map, and line segments whose line segment direction and the angle difference with the parallel stripes exceed the deflection angle range, and valid line segments and their coordinate data are obtained.
[0040] In some examples, the adaptive thresholding OTSU algorithm is used to binarize the striped area map above, generating a binary map containing only 0 and 1 pixel values.
[0041] In this embodiment, image preprocessing is required before performing the Hough line transform on the stripe region map. The purpose is to strengthen the stripe edges, ensuring clear edges with low noise and reducing interference from non-edge pixels. In this embodiment, the Hough transform maps lines in the image space to the parameter space. By statistically analyzing the coordinate data of the lines in the parameter space, significant lines are finally extracted. The probabilistic Hough transform outputs the endpoint coordinates of the line segments, which need further filtering to extract valid line segments. For example, line segments with a length less than 1 / 5 of the stripe region width in the stripe region map are filtered out, as these segments may be noise or incomplete stripe sections. Line segments with consistent direction (angle difference within ±2°) are retained, initially focusing on the parallel stripes of the barcode.
[0042] It is understandable that the core feature of a barcode consists of a set of parallel black and white stripes, all of which theoretically have the same tilt angle. The straight line segments extracted by the Hough transform mainly correspond to the edges of the stripes (the left and right edges of each black or white stripe are straight lines). Since the stripes are parallel, the angles of these edge lines should be highly concentrated. Therefore, the angle value with the highest frequency in the angle value distribution of the straight line segments of the parallel stripes represents the angle supported by the most stripe edges in the parameter space, i.e., the common tilt direction of most stripes. This angle reflects the overall tilt trend of the barcode and has statistical significance. Therefore, in this embodiment, it is used as the barcode tilt angle to obtain the angle to be corrected, which is consistent with the essential characteristics of parallel stripes in a barcode. Moreover, determining the correction angle through angle distribution statistics is a "statistical rapid decision-making" method that does not require complex global optimization algorithms (such as pixel-by-pixel fitting) and can quickly determine the angle correction requirements of the image.
[0043] In some embodiments, when the angle distribution is discrete, such as large differences in the angles of different stripe edges and no clearly dominant frequency peak, it is usually due to: local stripe deformation (such as printing blurring or wrinkles causing discontinuous edges), noise interference (such as stains covering part of the stripes, leading to edge extraction errors), excessively thin stripes, or the ROI region containing part of the background, resulting in few effective edge pixels and high randomness in the angles of the straight line segments extracted by the Hough transform. In this case, the "highest frequency angle" may be affected by a few abnormal line segments (such as the angle of noise line segments) and cannot represent the true main direction of the barcode.
[0044] Furthermore, the main direction line can be fitted using the least squares method. Specifically, this involves minimizing the sum of squared deviations of all line segments from the fitted line to find a single line that can represent the overall trend of all stripe edges. Therefore, even if local line segment angles are dispersed, a potential main direction still exists globally, thus eliminating local line segment angle deviations and ultimately achieving accurate acquisition of the barcode's tilt angle. The angle between the fitted main direction line and the horizontal line is controlled within the range of (-45°, 45°), avoiding multiple solutions caused by angle dispersion. This provides a unique and reliable reference angle for subsequent tilt correction (rotating the barcode to horizontal), thereby overcoming the problem of insufficient correction accuracy.
[0045] S3. Correct the striped area image based on the barcode correction angle to obtain the target barcode image.
[0046] In this embodiment, the coordinate mapping relationship between the original striped area image and the pixels of the corrected image (i.e., the target barcode image) is calculated based on the correction angle. The transformed pixel values are filled by bilinear interpolation algorithm, and the invalid areas (such as black borders) generated by rotation are processed to obtain the corrected target barcode image.
[0047] In this embodiment, subsequent barcode decoding relies on precise stripe width. Bilinear interpolation can eliminate jagged edges during pixel filling while maintaining computational efficiency, meeting the recognition requirements of most barcodes. Rotation will produce blank areas or black borders in the image. These areas contain no barcode information, increasing the computational load for subsequent decoding and text recognition. Therefore, cropping can be used to retain the effective area, reducing computational load and ultimately outputting a target barcode image with "regular stripe direction, clear details, and no redundant information." This lays the foundation for efficient subsequent decoding and accurate text recognition and association with decoded information.
[0048] S4. Decode the target barcode image and perform text recognition, associate and map the recognized text information with the decoded information, and output structured barcode recognition data.
[0049] As an optional implementation, step S4 specifically includes: The target barcode image is decoded based on a stripe segmentation decoding mechanism to obtain barcode decoding information; Based on the target barcode image, a text detection algorithm is used to locate the text region, and text recognition is performed based on the text region to obtain the text information within the barcode region; The text information is preprocessed, and the text similarity of the text information is calculated based on a keyword dictionary containing the key fields of the barcode. The text similarity is used to determine whether the text information is a valid barcode-related information. The effective association information of the barcode is associated with the barcode decoding information obtained by decoding the stripe area map, and the structured barcode recognition result is output.
[0050] In some embodiments, the Zxing open-source library is used to decode the target barcode image, and a stripe segmentation decoding mechanism is introduced: the barcode is divided into three equal segments according to its width, and the results are compared after decoding each segment. If the results match, the barcode is output directly; otherwise, the middle segment is decoded with emphasis. This optimizes the decoding time complexity from O(n²) to O(n), enabling rapid acquisition of barcode decoding information. Relationship mapping is then performed on subsequent barcode recognition results to obtain structured barcode recognition results, thereby improving barcode recognition efficiency.
[0051] Since the target barcode image is already a corrected image, the black and white transitions of its stripes are distributed horizontally or vertically. Therefore, during decoding, it is only necessary to traverse the pixels in a fixed direction (such as a horizontal scan line) to quickly identify the stripe width and complete the encoding and parsing. There is no need to constantly adjust the scan line angle during the decoding process, which significantly reduces the time complexity of decoding and improves decoding efficiency.
[0052] In some embodiments, the CTPN text detection algorithm is used to locate the text region around the barcode, and the text region is recognized based on the GOT-OCR large model to output the text content (i.e., text information). For blurred text, image enhancement (such as contrast stretching) is used.
[0053] Furthermore, the text information is preprocessed, including at least: invalid text removal, non-target character filtering, and scattered text filtering. For example, text shorter than 2 characters, such as single characters and garbled text, is removed; special symbols that are not numbers, letters, or Chinese characters are filtered out; and scattered text that appears less than 3 times is deleted to eliminate accidental erroneous recognition content, improve the accuracy of recognition results, and thus achieve both efficiency and accuracy in barcode recognition.
[0054] Specifically, barcode keywords are collected based on barcode demand scenarios and business types to establish a keyword dictionary. The similarity between text information and key barcode fields in the keyword dictionary is calculated. If the similarity exceeds a threshold, the text information is deemed valid barcode-related information. This text is then associated with and stored in the barcode decoding information obtained from the decoded stripe area map to output structured data. Text similarity calculation accurately determines whether text information is a key barcode field, serving as the final verification of the recognition results. Associating the text information with the barcode decoding information to output structured data provides a clear and intuitive display of the recognition results.
[0055] In some examples, the keyword dictionary (such as "specification", "batch number", "production date" etc.) covers common barcode association information; the TF-IDF algorithm is used to calculate the similarity between the identified text and the keywords, and text with a matching degree of ≥80% is judged as valid association information; for fuzzy matching results (60%-80%), the contextual semantics (such as "production date" followed by date format text) are further confirmed, and the successfully matched text information is associated with the barcode decoding content and stored to output structured data, for example: {"barcode content": "6923456789012", "production date": "2025-07-18"}.
[0056] Example 2, as Figure 2 As shown, based on the same inventive concept, this application also provides a device barcode recognition system corresponding to the device barcode recognition method. The system includes: The positioning module 201 is used to locate the stripe region based on the scanned image of the barcode to be identified and to obtain a stripe region map; The correction module 202 is used to extract the line segment features of parallel stripes based on the stripe area map, obtain the barcode correction angle based on the angle distribution of the line segment features, and correct the stripe area image based on the barcode correction angle to obtain the target barcode image. The recognition module 203 is used to decode the target barcode image and recognize text, associate and map the recognized text information with the decoded information, and output structured barcode recognition data.
[0057] This application also provides a computer device, such as... Figure 3 The diagram shown is a schematic representation of the structure of a computer device provided in an embodiment of this application, including: a processor 31, a memory 32, and a communication bus 33. The memory 32 stores machine-readable instructions executable by the processor 31 (e.g., ...). Figure 2 In the system, the execution instructions corresponding to the positioning module 201, correction module 202 and identification module 203 are executed. When the computer device is running, the processor 31 and the memory 32 communicate through the communication bus 33. When the machine-readable instructions are executed by the processor 31, the steps of the device barcode identification method in the above embodiment are executed.
[0058] This application also provides a computer-readable storage medium storing a computer program. When the computer program is run by a processor, it executes the steps of the device barcode recognition method described in the above embodiments.
[0059] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the specific device can be divided into different functional modules to complete all or part of the functions described above.
[0060] In the embodiments provided in this application, it should be understood that the disclosed structures and methods can be implemented in other ways. For example, the structural embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another structure, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, or indirect coupling or communication connection between structures or units, and may be electrical, mechanical, or other forms.
[0061] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0062] Furthermore, in the embodiments of this application, the functional units can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0063] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, 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 device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0064] The above-described embodiments are preferred embodiments of this application and are not intended to limit the specific scope of this application. The scope of this application includes but is not limited to the specific embodiments described above. All equivalent changes made in accordance with the shape, structure, and method of this application are within the protection scope of this application.
Claims
1. A method for identifying equipment barcodes, characterized in that: Includes the following steps: Based on the scanned image of the barcode to be identified, the stripe region is located to obtain a stripe region map; Extract the line segment features of parallel stripes from the stripe area map, and obtain the barcode correction angle based on the angular distribution of the line segment features; The striped area image is corrected based on the barcode correction angle to obtain the target barcode image; The target barcode image is decoded and text is recognized. The recognized text information is associated and mapped with the decoded information to output structured barcode recognition data.
2. The equipment barcode recognition method according to claim 1, characterized in that: The step of locating the stripe region based on the scanned image of the barcode to be identified and obtaining a stripe region map includes: Image preprocessing is performed on the scanned image of the barcode to be recognized, including image grayscale conversion, image filtering, and barcode region detection. Candidate boxes are used to mark the barcode regions in the scanned image to obtain the initial barcode region map. Based on the attribute features of the barcode, the initial area map of the barcode is filtered for target areas, and the filtered target areas are expanded according to a preset pixel range to obtain the barcode reference area map. Stripe density detection is performed based on the barcode reference area map, and the jump frequency of pixels in the horizontal direction is calculated; Stripe region map is obtained based on stripe density and pixel jump frequency.
3. The equipment barcode recognition method according to claim 2, characterized in that: The step of detecting stripe density based on the barcode reference area map and calculating the transition frequency of pixels in the horizontal direction includes: Several horizontal scan lines are extracted from the barcode reference area map. Pixels are traversed from left to right based on each scan line to compare adjacent pixel values. If adjacent pixel values are not equal, a jump occurs. The number of jumps for all scan lines is obtained based on the values of adjacent pixels, and then the average number of jumps is calculated. Jumps that exceed the fluctuation range of the average number of jumps are filtered out. The transition frequency is calculated based on the number of transitions remaining after filtering and the scan line length, and the average stripe is obtained based on the number of transitions remaining after filtering. Then, the stripe density is calculated from the average stripe.
4. The device barcode recognition method according to claim 3, characterized in that: The process of obtaining the stripe region map based on stripe density and pixel jump frequency includes: The barcode reference area map is determined based on the stripe density and pixel transition frequency. If the pixel transition frequency does not exceed the frequency threshold and the stripe density meets the standard barcode density characteristic value, the barcode reference area map does not need to be updated, and the barcode reference area map is used as the stripe area map. If the pixel transition frequency exceeds the frequency threshold or / and the stripe density exceeds the standard barcode density feature value, the pixel range and expansion direction are dynamically adjusted, and the barcode reference area map is expanded according to the adjusted pixel range and expansion direction. Barcode region detection is performed based on the extended barcode reference region map to obtain the final stripe region map.
5. The method for identifying equipment barcodes according to claim 2, characterized in that: The step of extracting the line segment features of parallel stripes based on the stripe area map, and obtaining the barcode correction angle based on the angular distribution of the line segment features, includes: Perform a Hough line transform on the striped area map to extract the coordinate data of the line segments corresponding to all parallel stripes in the striped area map; Based on the coordinate data of parallel stripe line segments, the distribution of angle values of the line segments is statistically analyzed. The angle value with the highest frequency is taken as the barcode tilt angle, and then the barcode tilt angle is taken as the barcode correction angle. If the angle values are discrete, then all straight line segments are fitted with the main direction, and the angle between the fitted line and the horizontal line is calculated. The barcode correction angle is determined based on the angle.
6. The method for identifying equipment barcodes according to claim 5, characterized in that: Before performing the Hough linear transform on the striped region map, the following steps are included: The striped area image is binarized to convert it into a black and white binary image; Edge features are extracted from the black-and-white binary image to obtain features including stripe contour lines.
7. The method for identifying equipment barcodes according to claim 1, characterized in that: The process of decoding and recognizing text in the target barcode image, as well as associating and mapping the recognized text information with the decoded information to output structured barcode recognition data, includes: The target barcode image is decoded based on a stripe segmentation decoding mechanism to obtain barcode decoding information; Based on the target barcode image, a text detection algorithm is used to locate the text region, and text recognition is performed based on the text region to obtain the text information within the barcode region; The text information is preprocessed, and the text similarity of the text information is calculated based on a keyword dictionary containing the key fields of the barcode. The text similarity is used to determine whether the text information is a valid barcode-related information. The effective association information of the barcode is associated with the barcode decoding information obtained by decoding the stripe area map, and the structured barcode recognition result is output.
8. A device barcode recognition system, characterized in that: A device barcode identification method applicable to any one of claims 1-7, comprising: The positioning module is used to locate the stripe region based on the scanned image of the barcode to be recognized and obtain a stripe region map; The correction module is used to extract the line segment features of parallel stripes based on the stripe area map, obtain the barcode correction angle based on the angle distribution of the line segment features, and correct the stripe area image based on the barcode correction angle to obtain the target barcode image. The recognition module is used to decode the target barcode image and recognize text, associate and map the recognized text information with the decoded information, and output structured barcode recognition data.
9. A computer device, comprising: The computer device includes a processor, a memory, and a communication bus. The memory stores machine-readable instructions executable by the processor. When the computer device is running, the processor communicates with the memory via the communication bus, and the processor executes the machine-readable instructions to perform the steps of a device barcode recognition method as described in any one of claims 1-7.
10. A computer-readable storage medium storing a computer program, the computer program being executed by a processor to perform the steps of a device barcode recognition method as described in any one of claims 1-7.
Citation Information
Patent Citations
Receipt information comparison and verification system based on OCR technology
CN120088808A