A method, system, device and storage medium for recognizing a distorted two-dimensional barcode

By employing a closed-loop iterative feedback mechanism of dynamic adaptive binarization and perspective transformation correction, the robustness and real-time performance issues of 2D barcode recognition in complex industrial scenarios are resolved, achieving efficient barcode decoding.

CN122222883APending Publication Date: 2026-06-16FUJIAN NETPOWER TECH DEV CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
FUJIAN NETPOWER TECH DEV CO LTD
Filing Date
2026-03-24
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

Existing technologies for 2D barcode recognition in complex industrial scenarios suffer from poor robustness to lighting and complex backgrounds, rigid geometric distortion correction mechanisms, and low deployment and real-time detection efficiency.

Method used

The system employs image feature-driven dynamic adaptive binarization, joint background screening based on multi-dimensional geometric features such as solidity, corner extraction constrained by physical interior angle legality, and a closed-loop iterative feedback mechanism that inversely adjusts front-end image parameters based on the underlying decoding error type. Through Sauvola algorithm parameter adaptive adjustment and perspective transformation correction, the decoding success rate is improved.

Benefits of technology

It significantly reduces the false detection rate and computational complexity, achieves efficient recognition under extreme lighting and complex backgrounds, meets the high-speed requirements of industrial production lines, and improves decoding success rate and robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122222883A_ABST
    Figure CN122222883A_ABST
Patent Text Reader

Abstract

The application discloses a kind of distortion two-dimensional bar code recognition method, system, equipment and storage medium, the method includes the following steps: taking image feature dynamic calculation Sauvola algorithm parameter and carrying out binarization;Estimate bar code basic size and generate structure element to carry out self-adapting morphological enhancement;Utilize the solid degree of multidimensional geometric feature filter background interference and retain candidate area;Combining internal angle legality constraint is accurately extracted four corner points of distorted quadrilateral by polygon approximation;Perspective transformation is carried out to candidate area and decoding, if decoding fails, then according to the type of failure self-adapting recall front-end parameter and iteration feedback.The application can be in severe distortion, uneven illumination and complex background interference etc. extreme industrial scene, greatly improve the positioning accuracy of two-dimensional bar code and decoding success rate, and algorithm is light, real-time is strong.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of intelligent detection and image processing technology, and specifically relates to a method, system, device and storage medium for identifying distorted two-dimensional barcodes. Background Technology

[0002] With the development of Industry 4.0 and IoT technologies, two-dimensional barcodes (such as QR codes and Data Matrix codes) are widely used in industrial settings as information carriers for asset tracking, equipment status reading, parts traceability, and automated production line control. Currently, industrial sites commonly use camera-based vision systems to automatically collect two-dimensional barcodes on equipment, and then use OpenCV combined with standard decoding libraries (such as ZBar and ZXing), or deep learning-based object detection models (such as the YOLO series) for positioning and decoding.

[0003] The real industrial environment is extremely complex. Due to differences in component materials, variations in ambient light, wear and tear on working surfaces, and oil contamination, coupled with the limited installation space of industrial equipment which often forces cameras to take large-angle side-tilt shots, the captured 2D barcode images typically suffer from severe uneven lighting, complex background interference, and extreme planar perspective distortion. These combined factors cause a sharp decline in the decoding success rate of traditional recognition algorithms.

[0004] To address the problem of identifying distorted barcodes, those skilled in the art have explored various approaches. For example, Chinese invention patent application CN105046184A discloses a QR code decoding method and system based on distortion image correction. This method first acquires an image containing the QR code and determines its type by identifying feature points, then performs initial correction using perspective transformation. If decoding fails, a more complex surface correction algorithm is initiated for secondary correction to handle large distortion patterns, thereby improving the decoding success rate. However, this method has significant limitations in practical industrial applications: it heavily relies on the initial accurate positioning of feature points within the QR code. In industrial settings, strong glare or severe contamination can cause internal feature points to stick together or be lost, rendering the algorithm ineffective. Furthermore, the surface correction algorithm has extremely high computational complexity, making it difficult to meet the high-speed, real-time requirements of industrial production lines and edge devices.

[0005] For example, Chinese invention patent application CN117974419A discloses a method, apparatus, device, and storage medium for acquiring distorted QR codes. This scheme obtains at least one combination of corner coordinates corresponding to a real QR code, and generates multiple candidate QR codes by performing an affine transformation on a standard QR code based on these combinations, thereby obtaining the matching distorted QR code. While this scheme improves the efficiency of acquiring and simulating distorted QR codes, its technical premise is that the system can already successfully acquire the corner coordinate combinations of real QR codes. When facing real complex industrial backgrounds, traditional edge detection or connected component analysis is prone to mistaking background noise for barcode corners. This scheme lacks pre-emptive anti-interference measures to accurately isolate the real barcode area under complex lighting and strong interference, which easily leads to corner extraction errors, causing a complete deviation in subsequent transformation processing at the source.

[0006] In summary, existing technologies still generally suffer from the following shortcomings when dealing with the recognition of distorted 2D barcodes in complex industrial scenarios: poor robustness to lighting and complex backgrounds, rigid geometric distortion correction mechanisms, and low deployment and real-time detection efficiency. Summary of the Invention

[0007] This invention provides a method, system, device, and storage medium for recognizing distorted two-dimensional barcodes. By introducing image feature-driven dynamic adaptive binarization, background joint screening based on multi-dimensional geometric features such as solidity, corner point extraction constrained by physical interior angle legality, and a closed-loop iterative feedback mechanism that inversely adjusts front-end image parameters based on the type of underlying decoding error, it aims to solve the problems of difficult localization, low decoding success rate, poor robustness, and lack of automatic error correction capability of traditional unidirectional open-loop visual algorithms caused by extreme lighting, strong background interference, and severe planar perspective distortion of two-dimensional barcodes in complex industrial environments.

[0008] To address the aforementioned technical problems, this invention proposes a method for recognizing distorted two-dimensional barcodes, comprising the following steps: The image to be identified is acquired, image features are extracted and Sauvola algorithm parameters are dynamically calculated, and the image is binarized. Based on the estimated results of the basic size of the barcode module, the size of the structuring element is generated by morphological closing operation, and morphological processing is performed on the binarized image to enhance connectivity. The connected components of the processed image are extracted, and the background interference is filtered out by using a multidimensional geometric feature threshold that includes the solidity, while retaining the candidate barcode region. Calculate the convex hull of the candidate barcode region and extract the four corner points of the distorted quadrilateral by polygon approximation; The candidate barcode region is then corrected by perspective transformation using the corner points and input into the decoder.

[0009] Preferably, after inputting the perspective-transformed corrected image into the decoder, the method further includes the following steps: If decoding fails, the Sauvola algorithm parameters are updated or the coordinates of the four corner points are fine-tuned according to the decoding failure type, and subsequent steps are re-executed until decoding is successful or the maximum number of iterations is reached.

[0010] Preferably, the step of adaptively updating the Sauvola algorithm parameters or fine-tuning the coordinates of the four corner points based on the decoding failure type specifically involves: If the decoding failure type is positioning failure, it is determined to be distortion correction deviation. The coordinates of the four corner points are adjusted outward according to the preset step size and the perspective transformation is performed again. If the decoding failure type is error correction failure, it is determined that the barcode module is stuck or lost. The Sauvola algorithm parameters are updated according to the preset step size and binarization is performed again.

[0011] Preferably, the Sauvola algorithm parameters are calculated as follows: Extract the global contrast and local grayscale variance of the image; calculate the penalty coefficient of the Sauvola algorithm based on the global contrast, and determine the local window size by combining the local grayscale variance.

[0012] Preferably, the method for estimating the basic size of the barcode module is as follows: The average connected component width of the high-frequency texture region in the binarized image is extracted and used as the base size of the barcode module. The size of the structuring element is then generated by a correlation multiple of the base size.

[0013] Preferably, the multidimensional geometric features include: The connected component area, solidity, and aspect ratio are considered; wherein, the solidity is the ratio of the area of ​​the connected component to the area of ​​its corresponding convex hull, and connected components with a solidity lower than a preset threshold are filtered out.

[0014] Preferably, the method for extracting the four corner points is as follows: In the polygon approximation process, interior angle legality constraints are introduced to calculate the interior angles of the fitted quadrilateral. When an interior angle exceeds the preset physical deformation limit angle range, the accuracy parameters of the polygon approximation are adjusted and the fitting is performed again until the four corner points that meet the interior angle legality constraints are output.

[0015] A second aspect of the present invention also provides a distorted two-dimensional barcode recognition system, said system for implementing the recognition method as described in the first aspect of the present invention, comprising: The binarization module is used to acquire the image to be recognized, extract image features, dynamically calculate Sauvola algorithm parameters, and perform binarization processing on the image. The morphological processing module is used to generate the structuring element size of morphological closing operation based on the estimated result of the basic size of the barcode module, and to perform morphological processing on the binarized image to enhance connectivity. The region filtering module is used to extract connected components of the processed image, filter out background interference using multidimensional geometric feature thresholds that include solidity, and retain candidate barcode regions. The corner extraction module is used to calculate the convex hull of the candidate barcode region and extract the four corner points of the distorted quadrilateral by polygon approximation. The correction and decoding module is used to perform perspective transformation correction on the candidate barcode area using the corner points and then input it into the decoder.

[0016] A third aspect of the present invention also provides an electronic device comprising: One or more processors; Memory, used to store one or more computer programs; One or more computer programs stored in the memory are executed by the one or more processors, causing the one or more processors to implement the identification method as described in the first aspect of the invention.

[0017] A fourth aspect of the invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the identification method as described in the first aspect of the invention.

[0018] Compared with the prior art, the present invention has the following technical effects: 1. The distorted 2D barcode recognition method proposed in this invention introduces a core identification feature based on solidity. Combined with adaptive morphological stitching at the barcode module scale, it can accurately separate the true 2D barcode from various industrial backgrounds, significantly reducing the false detection rate and the unnecessary computational consumption of subsequent distortion correction.

[0019] 2. The distorted two-dimensional barcode recognition method proposed in this invention proposes a dual adaptive mechanism that uses global contrast to dynamically calculate the penalty coefficient and local grayscale variance to adaptively determine the size of the local window, so as to effectively preserve the details of the black and white data modules inside the barcode under various extreme lighting conditions.

[0020] 3. The distortion-based 2D barcode recognition method proposed in this invention employs a highly optimized classical computer vision algorithm throughout the entire recognition process. It boasts low computational complexity and can achieve high-speed real-time detection at the tens of millisecond level on edge devices with limited computing power, such as ARM-based industrial smart cameras and embedded barcode scanners, perfectly meeting the high-speed requirements of industrial production lines.

[0021] 4. The distortion 2D barcode recognition method proposed in this invention introduces the physical deformation limit angle range as a legality constraint verification. When edge damage causes the fitted extreme acute or obtuse angles, the algorithm can automatically adjust the approximation accuracy parameters and refit, ensuring that the four corner points obtained conform to the real physical spatial perspective law, avoiding severe image tearing and distortion caused by perspective correction.

[0022] 5. The distortion 2D barcode recognition method proposed in this invention captures the failure type at the bottom layer of the decoder as a feedback signal, and reversely fine-tunes the corner coordinates of the perspective transformation or updates the penalty coefficient of Sauvola binarization, effectively improving the overall decoding success rate of severely oil-stained and reflective distortion components. Attached Figure Description

[0023] Figure 1 This is a flowchart illustrating the identification method described in this invention. Detailed Implementation

[0024] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with specific embodiments of the present application and with reference to the accompanying drawings.

[0025] Before providing a detailed description of the embodiments of this application, some of the nouns and terms involved in the embodiments of this application will be explained first. The nouns and terms involved in the embodiments of this application are subject to the following interpretations.

[0026] The Sauvola algorithm, a classic local adaptive thresholding method, is particularly suitable for binarizing images with uneven illumination. It calculates the mean and standard deviation of grayscale values ​​within a neighborhood window centered on each pixel, and dynamically generates a threshold according to a formula, thereby effectively preserving details and suppressing background noise.

[0027] The Otsu algorithm, proposed by Japanese scholar Nobuyuki Otsu in 1979, is a method for automatic image thresholding segmentation. This method is used to binarize clustered images, converting a grayscale image into a binary image. The algorithm assumes that the image contains two classes of pixels based on its bimodal histogram (foreground and background pixels) and calculates the optimal threshold that separates these two classes, minimizing intra-class variance, or equivalently, maximizing inter-class variance.

[0028] The Sobel operator is a widely used edge detection operator in image processing. It detects edges by calculating the grayscale approximation of the image's brightness function. Especially with coarse precision, the Sobel operator is the most commonly used edge detection tool.

[0029] The Laplacian operator is a commonly used edge detection technique in image processing. It identifies edges and texture features in an image by calculating the second derivative of the image. Its basic idea is to enhance the edges and details of the image by performing second-order differentiation operations.

[0030] Suzuki85 is an extended version of the Border Following Algorithm, used for topological analysis of digitized binary images, primarily to obtain the enclosing relationships of the boundaries of binary images.

[0031] Graham's scan algorithm is a flexible convex hull algorithm. The principle is to first find the bottom leftmost point in the point set. It can be proven that this point must be on the convex hull. Then, taking this point as the pole, all points are sorted according to the polar angle with this point, and at the same time, a stack structure is used to maintain the points on the convex hull.

[0032] The Douglas-Peucker algorithm, also known as the Lamer-Douglas-Peucker algorithm, is an algorithm used to reduce the number of points representing a curve in order to simplify the data while maintaining the overall shape of the curve. This algorithm is particularly suitable for graphics processing, used to simplify polylines or polygonal outlines.

[0033] Example 1 This embodiment describes a method for recognizing distorted two-dimensional barcodes, such as... Figure 1 As shown, it includes the following steps one through five: Step 1: Obtain the image to be identified, extract image features and dynamically calculate Sauvola algorithm parameters, and perform binarization processing on the image.

[0034] The calculation method for the Sauvola algorithm parameters is as follows: Extract the global contrast and local grayscale variance of the image; calculate the penalty coefficient of the Sauvola algorithm based on the global contrast, and determine the local window size by combining the local grayscale variance.

[0035] In complex industrial environments, traditional global binarization algorithms (such as the Otsu algorithm) and local binarization algorithms with fixed parameters often fail to effectively preserve the complete structure of 2D barcodes due to surface reflections, local shadows, or oil smudges. Therefore, this embodiment employs the Sauvola local dynamic thresholding algorithm with adaptive parameters for binarization.

[0036] The specific implementation details for this step are as follows: First, the acquired image to be identified is converted into a grayscale image. Then, the global standard deviation of the entire grayscale image is calculated. This serves as a representation of global contrast. Subsequently, the penalty coefficient of the Sauvola algorithm is dynamically calculated according to the following formula. :

[0037] In the formula, It is the penalty coefficient for dynamically generating the current image; This is the preset upper limit of the penalty coefficient, and in this embodiment, it is preferably set to 0.5; This is an adjustment coefficient, preferably with a value range of [0.2, 0.4], for example, 0.3; The global standard deviation of the image reflects the degree of dispersion in the distribution of brightness and darkness across the entire image. The grayscale level is the number of gray levels in the image. For an 8-bit grayscale image, .

[0038] When industrial parts are covered with large areas of oil or are in extremely dark environments, global contrast is crucial. When the value is relatively small, a larger penalty coefficient is applied. (Approaching 0.5) to effectively suppress background noise; when there is strong metallic reflection on the surface of the component, the global contrast ratio is [high / low]. When the value is large, a smaller penalty coefficient is applied. (e.g., close to 0.2) to prevent the 2D barcode module in the highlighted area from being excessively eroded and lost.

[0039] After determining the penalty coefficient, a uniform window size is not used across the entire image. Instead, the window size is determined based on the coordinates in the image. Using the pixel as the center, calculate the initial base window (e.g. Local standard deviation within) (That is, the square root of the local grayscale variance). The size of the local window for binarization of the pixel is dynamically determined based on this local standard deviation. The calculation formula is as follows:

[0040] In the formula, It is a pixel. The side length of dynamically generated local windows must be an odd number. This is the preset minimum window size, which is usually set according to the image resolution, such as 11 or 15. This is the dynamic adjustment range of the window size, such as 10; This represents the local standard deviation within the initial base window at that point. The dynamic range of the standard deviation; for an 8-bit grayscale image, the maximum theoretical standard deviation is usually taken as... ; This indicates rounding down to the nearest integer.

[0041] In the 2D barcode area (a region with dense high-frequency features), the interlacing of black and white modules leads to local standard deviation. The calculated window is very large. Approaching the smaller This helps preserve the sharpness of barcode edges and prevents modules from sticking together; while in smooth industrial background areas, the local standard deviation is small, and the calculated window... It automatically enlarges to include more background pixels, avoiding misinterpreting subtle textures or noise as black blocks in a barcode.

[0042] After obtaining the above dynamic parameters, the standard Sauvola thresholding formula is used to calculate the threshold for each pixel. Binarization threshold :

[0043] In the formula, For pixels Local binarization threshold at; To be in dynamic size The average grayscale value of all pixels within a local window; To be in dynamic size The standard deviation of grayscale values ​​for all pixels within a local window; The penalty coefficient is dynamically calculated based on the global contrast ratio in the aforementioned steps.

[0044] Finally, the grayscale value of each pixel in the original grayscale image is... Its corresponding dynamic threshold Comparison: If If the value is 255, it is identified as the background (usually assigned a value of 255, i.e., white); otherwise, it is identified as the foreground barcode module (usually assigned a value of 0, i.e., black), thus outputting a binarized image that overcomes uneven lighting and has complete details, providing a high-quality data foundation for subsequent connected component enhancement and morphological processing.

[0045] Step 2: Based on the estimated basic size of the barcode module, generate the structuring element size for morphological closing operations, and perform morphological processing on the binarized image to enhance connectivity. The method for estimating the basic size of the barcode module is as follows: The average connected component width of the high-frequency texture region in the binarized image is extracted and used as the base size of the barcode module. The size of the structuring element is then generated by a correlation multiple of the base size.

[0046] In industrial settings, 2D barcodes (such as laser-engraved Data Matrix codes or dot matrix metal markings) often exhibit broken, hole-like, or isolated pixel clusters in the binarized image from step one due to uneven marking pressure or surface wear. Using a fixed-size morphological kernel for processing can easily lead to adjacent modules of small barcodes being incorrectly stuck together, or broken sections of large barcodes failing to close effectively. This step addresses this problem through adaptive scale extraction and dynamic kernel generation mechanisms. Specific implementation details are as follows: Two-dimensional barcode regions, due to their dense interlacing of black and white modules, exhibit typical high-frequency texture features in images. First, the Sobel or Laplacian operator is used to calculate the edge gradient of the binarized image (or the original grayscale image) output from step one, obtaining a gradient magnitude map. Then, the gradient magnitude map is subjected to mean filtering and simple fixed threshold segmentation to extract the densely textured regions as a high-frequency texture mask. This mask roughly locates the regions of interest (ROIs) in the image where two-dimensional barcodes may exist.

[0047] Within the acquired high-frequency texture mask region, for the foreground pixels (i.e., the black barcode module) in the binarized image, the width of connected components is statistically analyzed using run-length encoding or the scan-line method: multiple scan lines are evenly spaced along the horizontal and vertical directions, and the length of consecutive foreground pixels (i.e., run length) on each scan line is calculated. A statistical histogram is constructed from all collected run lengths, and the pixel length corresponding to the first significant peak in the histogram is identified, denoted as . This peak It accurately represents the average pixel width (basic size) of a single smallest data module in a 2D barcode at the current shooting distance. This statistically based scaling method is highly robust to localized contamination.

[0048] Get the basic dimensions of the barcode module Then, the side length dimensions of the structuring element for morphological closing operations are dynamically generated according to the following formula. :

[0049] In the formula, The dimensions of dynamically generated morphological structural elements must be odd numbers, such as... , wait; The preset correlation multiple is preferably taken in the range of [1.2, 1.8], for example, 1.5 is often used for dot matrix marking codes.

[0050] Subsequently, construct a size of The rectangular or cross-shaped structuring elements are used to perform dilation and erosion operations (morphological closing operations) on the binarized image obtained in step one:

[0051] In the formula, This represents the enhanced image output. The binarized image output from step one; The dynamically generated size is Structural elements; This indicates a morphological dilation operation, which bridges broken barcode modules and fills in small white reflective holes inside the modules. This refers to the morphological erosion operation, which restores the overall outline of the barcode to its original size after bridging internal breakpoints, preventing the barcode area from expanding outwards and sticking to background noise.

[0052] Through the adaptive morphological enhancement in this step, the originally discrete and broken dot matrix marked barcodes or worn barcodes are stitched into one or a few high-density continuous wholes (connected regions) in the image, thus laying the topological foundation for extracting the complete barcode outer contour and performing geometric screening in the subsequent step three.

[0053] Step 3: Extract the connected components of the processed image, and use multidimensional geometric feature thresholding with solidity to filter out background interference and retain candidate barcode regions.

[0054] The multidimensional geometric features include: The connected component area, solidity, and aspect ratio are considered; wherein, the solidity is the ratio of the area of ​​the connected component to the area of ​​its corresponding convex hull, and connected components with a solidity lower than a preset threshold are filtered out.

[0055] After the morphological closing operation in step two, the modules inside the 2D barcode are connected into a dense whole. However, in complex industrial environments, non-barcode interfering connected components such as product batch numbers, circular screw mounting holes, and blocky reflective spots may still remain. To achieve highly robust target extraction, this step establishes a multi-dimensional geometric feature joint screening mechanism, the specific implementation details of which are as follows: Perform topological analysis on the enhanced image output from step two, such as using the Suzuki85 boundary tracking algorithm, to extract all outer closed contours in the image. Each closed contour encloses a set of foreground pixels, denoted as the i-th connected component. .

[0056] For each extracted connected component Calculate its geometric features in the following three dimensions in sequence, and then perform concatenated filtering: Feature 1: Area of ​​connected regions Calculate connected components The total number of pixels contained, i.e., the area Alternatively, it can be obtained by integrating the contour using Green's formula. Based on the prior mapping relationship between the industrial camera's field of view and the barcode's physical size, an area threshold range is set. .like If it is, it is determined to be isolated noise, ink splatter, or minor scratch; if If the object is identified as a huge workpiece outline or a large area of ​​shadow background, it will be directly rejected.

[0057] Feature 2: Aspect Ratio Calculate the connected components Find the minimum bounding rectangle and obtain its length. Hekuan The formula for calculating the aspect ratio is:

[0058] Most 2D barcodes are square, with very few being rectangles of known proportions. Even when shooting from the side with an industrial camera and experiencing perspective distortion, their aspect ratio rarely exceeds a certain physical deformation limit (e.g., 3.0). Therefore, a maximum aspect ratio threshold should be set. The preferred value is between 2.5 and 3.0. If the connected component is determined to be a long, thin string of text, a pipeline edge, or a long, narrow scratch, it will be removed.

[0059] Feature 3: Solidity For connected components that have passed the area and aspect ratio screening, the polygon approximation algorithm in computational geometry is further used to obtain the connected components. The convex hull. Let the region enclosed by the convex hull be denoted as . Calculate the area of ​​the convex hull region. Then, the formula for calculating solidity is:

[0060] In the formula, Indicates the first The solidity of a connected component; Indicates the first The actual pixel area of ​​each connected component; It means that the first The area of ​​the smallest convex polygon (convex hull) completely enclosed by connected components. Regardless of the degree of tilt, rotation, or perspective distortion of a 2D barcode, its outermost positioning bounding box, after morphological closure, will geometrically approximate a convex quadrilateral. Therefore, the actual area of ​​the barcode's connected components is... Extremely close to its convex hull area Actually, heart Extremely high, typically approaching 0.90 or higher. Conversely, interference in industrial settings often exhibits numerous morphological depressions, resulting in connected domain areas much smaller than their convex hull areas, leading to extremely low solidity, typically less than 0.60. By setting a solidity threshold... For example, 0.80, when If it is valid, it will be retained; otherwise, it will be considered interference and removed.

[0061] After the above , and After rigorous intersection filtering of 3D geometric features, the vast majority of background interference is completely eliminated. The remaining connected components are the high-confidence candidate barcode regions. This area-morphology joint filtering mechanism based on geometric priors greatly improves the accuracy of barcode positioning while significantly reducing the computational load of complex distortion corner point extraction in subsequent steps, meeting the real-time detection requirements of high-speed industrial production lines.

[0062] Step 4: Calculate the convex hull of the candidate barcode region and extract the four corner points of the distorted quadrilateral by polygon approximation.

[0063] The method for extracting the four corner points is as follows: In the polygon approximation process, interior angle legality constraints are introduced to calculate the interior angles of the fitted quadrilateral. When an interior angle exceeds the preset physical deformation limit angle range, the accuracy parameters of the polygon approximation are adjusted and the fitting is performed again until the four corner points that meet the interior angle legality constraints are output.

[0064] The candidate barcode areas selected and retained through the aforementioned steps often appear as irregular perspective quadrilaterals (trapezoidal, parallelogram, or arbitrary quadrilaterals) in the image due to the influence of camera shooting angles (such as tilted installation or non-planar scanning). Traditional bounding box extraction cannot obtain their true physical boundary corners, and conventional polygon approximation algorithms are prone to fitting distorted vertices when there is dirt or smudges on the barcode edges. This step extracts four true corner points through dynamic approximation and interior angle verification loop closure. The specific implementation details are as follows: First, the Graham scan method is applied to the connected component contours of the candidate barcode regions output in step three to obtain the convex hull, eliminating minor indentations at the contour edges. Then, the Douglas-Peucker algorithm (DP algorithm) is used to approximate the convex hull as a polygon. The fitting accuracy of the DP algorithm is determined by the accuracy parameter. Decision made. Initially, the basic accuracy parameters are set as follows:

[0065] in, Let be the perimeter of the convex hull of the current candidate barcode region; The initial approximation coefficient is preferably between 0.02 and 0.05.

[0066] After performing DP polygon approximation, the fitted vertex set is statistically analyzed. If the number of vertices Then directly adjust the approximation coefficient. , such as when Time increases ,when Time decrease Then refit the data. When four vertices are successfully fitted, the three adjacent vertices are traversed in turn. Construct two edge vectors and Calculate the vertex using the vector dot product formula. interior angle at :

[0067] In the formula, This represents the dot product of two adjacent edge vectors; It represents the magnitude of two adjacent edge vectors.

[0068] In real-world industrial visual inspection, the deformation of a physical plane has objective limits. If the calculated interior angles contain extremely acute angles (such as...), then... ) or obtuse angle (such as This indicates that the fitted corner points are not the actual physical corner points of the barcode, and may have incorporated surrounding linear stains. The preset physical deformation limit angle range is... ,like If any interior angle of a quadrilateral... If the fit is invalid, the system will determine that the fit is invalid. The system will then proceed according to the preset step size. (e.g., 0.005) Dynamically fine-tuning the approximation coefficient Return and re-execute the DP polygon approximation until the coordinates of the four compliant corner points that satisfy all interior angle constraints are found. to .

[0069] Step 5: After performing perspective transformation correction on the candidate barcode area using the corner points, input it into the decoder.

[0070] After obtaining the four corner points of the real and compliant distorted quadrilateral, in order to eliminate the impact of perspective distortion on the decoder sampling, it is necessary to establish a mathematical mapping relationship between the original image space and the orthogonal projection space. The specific implementation details are as follows: Perform a geometric sort on the four unordered corner points extracted in step four, ensuring they strictly correspond to the four directions: top left (TL), top right (TR), bottom right (BR), and bottom left (BL). The sorting logic can be achieved using the coordinate sum and difference method: calculate the coordinate sum and difference for each corner point. and value, The smallest is in the top left, and the largest is in the bottom right; The smallest is in the top right corner, and the largest is in the bottom left corner. After sorting, calculate the maximum width of the top and bottom sides of the distorted quadrilateral. and the maximum height on the left and right sides To avoid losing image resolution during correction, the side length of the transformed standard square image is set. for: .

[0071] Construct a set of corner points from the source image and the set of corner points of the distortion-free target image. Based on these four pairs of corresponding control points, the solution is obtained using the least squares method or direct linear transformation algorithm. perspective transformation matrix The perspective mapping relationship satisfies the following formula:

[0072] These are the homogeneous coordinates after perspective transformation; Perspective transformation matrix The 9 parameters; the actual target pixel coordinates after transformation are Using the obtained matrix The candidate barcode region in the original image to be recognized is subjected to inverse interpolation mapping, and the output side length is... A regular square corrected image.

[0073] The corrected image, which has been completely flattened by perspective transformation and is free from lighting and distortion interference, is input into a standard QR code decoding library (such as ZBar, ZXing, or a dedicated industrial Data Matrix decoding algorithm) for pixel grid sampling and error correction decoding. Since the image has undergone pixel-level geometric normalization and binarization enhancement, the decoder will no longer be affected by grid drift caused by distortion when searching for and aligning with the detection pattern, thus achieving high-speed and accurate recognition output of 2D barcodes in extremely complex industrial scenarios.

[0074] In this embodiment, after the perspective-corrected image is input into the decoder, the method further includes step six: If decoding fails, the Sauvola algorithm parameters are updated or the coordinates of the four corner points are fine-tuned according to the decoding failure type, and subsequent steps are re-executed until decoding is successful or the maximum number of iterations is reached.

[0075] The adaptive callback based on the decoding failure type to update the Sauvola algorithm parameters or fine-tune the coordinates of the four corner points specifically involves: If the decoding failure type is positioning failure, it is determined to be distortion correction deviation. The coordinates of the four corner points are adjusted outward according to the preset step size and the perspective transformation is performed again. If the decoding failure type is error correction failure, it is determined that the barcode module is stuck or lost. The Sauvola algorithm parameters are updated according to the preset step size and binarization is performed again.

[0076] When a traditional decoder fails to output a decoded image, the underlying layer throws a specific exception code. This step captures these underlying exceptions, accurately traces the error in the front-end image processing, and performs targeted parameter self-correction. The specific implementation details are as follows: To meet the real-time requirements of high-speed industrial production lines and prevent the algorithm from getting stuck in an infinite loop, the maximum number of feedback iterations of the system is preset. In this embodiment, the preferred value is 3 to 5, and the current iteration number is initialized. Each time the feedback mechanism is triggered, ;when When the loop is interrupted, an unreadable alarm signal is output.

[0077] When the decoder returns an error type of "detector pattern not found" or "barcode boundary cannot be determined," it is collectively referred to as a positioning failure. This usually means that the four corner points extracted by polygon approximation in step four are too inwardly contracted, causing the image after perspective transformation to lose the essential still area or L-shaped positioning solid line of the edge of the 2D barcode. At this time, the coordinates of the four corner points extracted in step four... ( Perform a radial outward expansion based on the centroid. First, calculate the geometric centroids of the four corner points. :

[0078]

[0079] Subsequently, according to the preset expansion ratio coefficient (That is, the preset step size, such as 0.05, which represents an outward expansion of 5%), recalculate the fine-tuned corner coordinates. :

[0080]

[0081] After the parameters are adjusted, the system directly carries the new set of corner points. Return to step five, re-perspective transformation correction, and attempt decoding again; this is short path feedback.

[0082] When the decoder successfully locates the barcode, but throws a checksum error during Reed-Solomon error correction decoding, this is collectively referred to as error correction failure. This indicates that the barcode's geometry has been fully recovered, but due to lighting, shadows, or overexposure, large areas of black blocks have merged or white dots have swallowed black blocks during the binarization stage in step one, exceeding the error tolerance limit. At this point, long-path feedback is required, returning to the step one callback to update the Sauvola algorithm parameters. Depending on the degree of error correction failure or brightness characteristics, the algorithm is adjusted according to a preset step size. Dynamically adjust penalty coefficient The updated formula is as follows:

[0083] in, The updated Sauvola penalty coefficient; This refers to the penalty coefficient initially calculated in step one; This represents the current feedback iteration number; Adjust the step size for the preset parameters, with a preferred value of 0.05. After the parameters are updated, the system will use the new values. Repeat the binarization process from step one, along with subsequent morphological enhancement and decoding actions.

[0084] Example 2 This embodiment is a distorted two-dimensional barcode recognition system. The system is used to implement the recognition method as described in Embodiment 1, including: The binarization module is used to acquire the image to be recognized, extract image features, dynamically calculate Sauvola algorithm parameters, and perform binarization processing on the image. The morphological processing module is used to generate the structuring element size of morphological closing operation based on the estimated result of the basic size of the barcode module, and to perform morphological processing on the binarized image to enhance connectivity. The region filtering module is used to extract connected components of the processed image, filter out background interference using multidimensional geometric feature thresholds that include solidity, and retain candidate barcode regions. The corner extraction module is used to calculate the convex hull of the candidate barcode region and extract the four corner points of the distorted quadrilateral by polygon approximation. The correction and decoding module is used to perform perspective transformation correction on the candidate barcode area using the corner points and then input it into the decoder.

[0085] Example 3 This embodiment is an electronic device, including: One or more processors; Memory, used to store one or more computer programs; One or more computer programs stored in the memory are executed by the one or more processors, causing the one or more processors to implement the identification method as described in Embodiment 1.

[0086] Example 4 This embodiment is a computer-readable storage medium storing a computer program that, when executed by a processor, implements the identification method as described in Embodiment 1.

[0087] The above description is only a preferred embodiment of the present invention. It should be noted that those skilled in the art can make several modifications and improvements without departing from the inventive concept of the present invention, and these all fall within the protection scope of the present invention.

Claims

1. A method for recognizing distorted two-dimensional barcodes, characterized in that, Includes the following steps: The image to be identified is acquired, image features are extracted and Sauvola algorithm parameters are dynamically calculated, and the image is binarized. Based on the estimated results of the basic size of the barcode module, the size of the structuring element is generated by morphological closing operation, and morphological processing is performed on the binarized image to enhance connectivity. The connected components of the processed image are extracted, and the background interference is filtered out by using a multidimensional geometric feature threshold that includes the solidity, while retaining the candidate barcode region. Calculate the convex hull of the candidate barcode region and extract the four corner points of the distorted quadrilateral by polygon approximation; The candidate barcode region is then corrected by perspective transformation using the corner points and input into the decoder.

2. The method according to claim 1, characterized in that, After the perspective-transformed corrected image is input into the decoder, the method further includes the following steps: If decoding fails, the Sauvola algorithm parameters are updated or the coordinates of the four corner points are fine-tuned according to the decoding failure type, and subsequent steps are re-executed until decoding is successful or the maximum number of iterations is reached.

3. The method according to claim 2, characterized in that, The adaptive callback based on the decoding failure type to update the Sauvola algorithm parameters or fine-tune the coordinates of the four corner points specifically involves: If the decoding failure type is positioning failure, it is determined to be distortion correction deviation. The coordinates of the four corner points are adjusted outward according to the preset step size and the perspective transformation is performed again. If the decoding failure type is error correction failure, it is determined that the barcode module is stuck or lost. The Sauvola algorithm parameters are updated according to the preset step size and binarization is performed again.

4. The method according to claim 1, characterized in that, The calculation method for the Sauvola algorithm parameters is as follows: Extract the global contrast and local grayscale variance of the image; calculate the penalty coefficient of the Sauvola algorithm based on the global contrast, and determine the local window size by combining the local grayscale variance.

5. The method according to claim 1, characterized in that, The method for estimating the basic dimensions of the barcode module is as follows: The average connected component width of the high-frequency texture region in the binarized image is extracted and used as the base size of the barcode module. The size of the structuring element is then generated by a correlation multiple of the base size.

6. The method according to claim 1, characterized in that, The multidimensional geometric features include: The connected component area, solidity, and aspect ratio are considered; wherein, the solidity is the ratio of the area of ​​the connected component to the area of ​​its corresponding convex hull, and connected components with a solidity lower than a preset threshold are filtered out.

7. The method according to claim 1, characterized in that, The method for extracting the four corner points is as follows: In the polygon approximation process, interior angle legality constraints are introduced to calculate the interior angles of the fitted quadrilateral. When an interior angle exceeds the preset physical deformation limit angle range, the accuracy parameters of the polygon approximation are adjusted and the fitting is performed again until the four corner points that meet the interior angle legality constraints are output.

8. A distorted two-dimensional barcode recognition system, characterized in that, The system is used to implement the identification method as described in any one of claims 1-7, including: The binarization module is used to acquire the image to be recognized, extract image features, dynamically calculate Sauvola algorithm parameters, and perform binarization processing on the image. The morphological processing module is used to generate the structuring element size of morphological closing operation based on the estimated result of the basic size of the barcode module, and to perform morphological processing on the binarized image to enhance connectivity. The region filtering module is used to extract connected components of the processed image, filter out background interference using multidimensional geometric feature thresholds that include solidity, and retain candidate barcode regions. The corner extraction module is used to calculate the convex hull of the candidate barcode region and extract the four corner points of the distorted quadrilateral by polygon approximation. The correction and decoding module is used to perform perspective transformation correction on the candidate barcode area using the corner points and then input it into the decoder.

9. An electronic device, comprising: One or more processors; Memory, used to store one or more computer programs; The feature is that one or more computer programs stored in the memory are executed by the one or more processors, causing the one or more processors to implement the identification method as described in any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the identification method as described in any one of claims 1-7.