Two-dimensional code recovery method based on edge constraint

By detecting and repairing the QR code image through the edge constraint method, the problems of unstable edge detection and large structure recognition errors in the existing technology are solved, and the feasibility and accuracy of QR code decoding in complex environments are realized.

CN120805955AInactive Publication Date: 2025-10-17深圳牛图科技有限公司
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510900810.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-01
Publication Date
2025-10-17
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing technology in QR code image processing has problems such as unstable edge detection, path direction jumps, large structure recognition errors and unstable repair effects, making it difficult to ensure decoding feasibility in complex environments.

Method used

Through an edge constraint-based method, the QR code image is scanned pixel by pixel, edge pixels are detected and lines are connected, the path angle is calculated, the continuous path is screened, a rectangular structure diagram is constructed, the jump area is identified, the edge offset is repaired, and the repaired QR code image is generated.

Benefits of technology

Ensure the consistency of path direction, improve vertex recognition accuracy, guarantee the accuracy of rectangular structure, eliminate the influence of distortion, and ensure the edge continuity and decoding accuracy of QR codes under complex backgrounds and interference conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120805955A_ABST
    Figure CN120805955A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image recognition, in particular to a two-dimensional code recovery method based on edge constraint, which comprises the following steps: acquiring a two-dimensional code grey-scale map, extracting an edge to generate a feature map, screening a path to generate a frame, calculating extended path coordinate points to construct a rectangle, detecting jump and repairing offset, and generating a repaired two-dimensional code image. According to the method, the path directions are ensured to be consistent through direction included angle calculation, jump interference is avoided, the vertex recognition precision is improved through path extension and intersection calculation, the accuracy of a rectangular structure is guaranteed, the path continuity is detected point by point, the jump position is recorded, the fracture area is accurately recognized, and recognition errors caused by interruption are avoided. The edge offset repair of the symmetrical area ensures that the image structure is symmetrical, the distortion influence is eliminated, and the edge coherence, the structural integrity and the decoding precision of the two-dimensional code under the complex background and interference conditions are ensured through refined edge extraction, path repair and structure correction.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image recognition, and particularly relates to a two-dimensional code recovery method based on edge constraint. BACKGROUND

[0002] The technical field of image recognition includes related technologies for automatically detecting and classifying targets, features, or patterns in images. The core of this technical field is to convert visual information in image signals into a processable digital form, through image acquisition, preprocessing, feature extraction, and pattern matching processes, to identify the specific content expressed in the image. Image recognition technology is widely used in identity recognition, industrial detection, traffic monitoring, medical diagnosis, and two-dimensional code recognition, among other application scenarios. Currently, the development in this field focuses on image quality improvement, structural information extraction, and decoding accuracy optimization, with particular attention on how to improve the usability and interpretation efficiency of image data in complex environments.

[0003] Among them, the two-dimensional code recovery method based on edge constraint refers to a processing method that improves the quality of two-dimensional code images and completes image restoration through edge detection and structural constraint. This patent subject mainly covers key steps such as obtaining the edge contour of the two-dimensional code image, analyzing the continuity of the structural boundary, and reconstructing the pixel value of the local region. Specifically, it uses an edge positioning method based on gradient direction to identify the contour of the two-dimensional code image, combines edge consistency analysis to infer the structure of damaged areas, and completes the image restoration process through a pixel filling strategy under edge constraint conditions. This method focuses on the reconstruction and integrity correction of spatial structural information of the image, aiming to improve the decoding feasibility of two-dimensional codes under damaged or disturbed conditions.

[0004] The existing technology has many shortcomings in two-dimensional code image processing. Edge detection often uses global threshold or fixed gradient direction, which is difficult to adapt to complex lighting or background changes, leading to unstable edge feature extraction and often resulting in edge loss or false edges. Direction continuity analysis lacks fine control and is only based on basic direction changes, which can easily cause path direction jumps and affect edge continuity. In structural recognition, there is a lack of accurate geometric constraints, resulting in large positioning errors of rectangular structures, often causing vertex offset or structural deformation. Path repair mainly relies on simple filling methods, ignoring the structural features of broken areas, resulting in unstable repair effects and difficulty in ensuring the natural transition of edges. Overall, the existing technology lacks the ability to handle two-dimensional code edge and structural information in complex environments, making it difficult to ensure the decoding feasibility of two-dimensional codes under damaged or disturbed conditions. SUMMARY

[0005] The purpose of the present application is to solve the shortcomings in the prior art, and a two-dimensional code recovery method based on edge constraint is proposed.

[0006] In order to achieve the above object, the present application adopts the following technical scheme: the two-dimensional code recovery method based on edge constraint includes the following steps:

[0007] S1: obtaining a two-dimensional code image, converting it into a gray image, scanning the region pixel by pixel, detecting the brightness change, extracting and connecting the edge pixels, and integrating all the edge lines to generate a two-dimensional code edge feature map;

[0008] S2: based on the two-dimensional code edge feature map, scanning the edge lines pixel by pixel, recording the starting point and the ending point of the path, calculating the direction angle, screening the continuous path, excluding the jump path, and integrating into a border path set;

[0009] S3: calling the border path set, extending the path to calculate the path coordinate point after extension, recording the intersection point as the vertex, screening the vertex combination conforming to the parallel and vertical structure, constructing a closed rectangle according to the vertex connecting line, and generating a two-dimensional code rectangular structure map;

[0010] S4: based on the two-dimensional code rectangular structure map, detecting the pixel continuity along the rectangular border path point by point, identifying the jump region, recording the jump position and coordinates, screening the broken region according to the jump position continuity, and generating a border path continuity information table;

[0011] S5: according to the border path continuity information table, extracting the symmetrical region in the horizontal and vertical directions along the center of the two-dimensional code rectangular structure, comparing the edge position, calculating the offset of the symmetrical region, repairing the offset region and integrating the repair information, and generating a repaired two-dimensional code image.

[0012] As a further scheme of the present application, the two-dimensional code edge feature map includes edge pixel coordinates, edge line direction, and edge line connection information, the border path set includes path starting point coordinates, path ending point coordinates, and path direction information, the two-dimensional code rectangular structure map includes rectangular vertex coordinates, rectangular side length, and rectangular angle, the border path continuity information table includes jump position coordinates, jump type, and jump direction, and the repaired two-dimensional code image includes repair region coordinates, repaired edge position, and repaired border line.

[0013] As a further scheme of the present application, the specific steps of S1 are,

[0014] S101: obtaining a two-dimensional code image, converting it into a gray image, and performing a weighted operation on the red, green, and blue channel values of each pixel to generate a gray value, sequentially traversing the image region according to the two-dimensional coordinates of the pixels and recording the gray value distribution to generate a gray pixel distribution matrix;

[0015] S102: Based on the gray scale pixel distribution matrix, the gray scale values of the four adjacent areas above, below, left and right of the pixel are extracted, the difference value is calculated and the absolute value is taken, the difference value set is compared with the edge brightness difference threshold value to establish a mark matrix, and an edge direction mark distribution map is generated.

[0016] S103: The edge direction mark distribution map is called, the direction consistency and position continuity between edge pixels are judged, the pixels meeting the conditions are connected and a path set is established, and a two-dimensional code edge feature map is generated.

[0017] As a further scheme of the present application, the specific steps of S2 are,

[0018] S201: The two-dimensional code edge feature map is called, and point-by-point scanning operation is performed along each edge line according to the pixel order, the positions of the starting pixel and the ending pixel on the path in the image coordinate matrix are detected, the two-dimensional coordinates of the starting point and the ending point are recorded respectively according to the edge line section, and an edge path coordinate set is generated.

[0019] S202: Based on the edge path coordinate set, the direction vector is constructed by the coordinate difference between adjacent pixels, the included angle value between adjacent vectors is calculated, whether the difference between the included angle and the set direction continuity threshold value is out of range is judged, the exclusion operation is performed on the path section that is out of range, and a direction continuous path sequence is generated.

[0020] S203: The direction continuous path sequence is called, the remaining path sections are combined according to the pixel connection order, the continuous path set is established, and the path sequence is integrated, and a border path set is generated.

[0021] As a further scheme of the present application, the included angle value calculation formula between adjacent vectors is specifically:

[0022]

[0023] Where, θ i represents the included angle of adjacent direction, v i represents the direction quantity composed of pixel points (x i , y i ) to (x i+1 , y i+1 ), v i+1 represents the direction quantity composed of pixel points (x i+1 , y i+1 ) to (x i+2 , y i+2 ), and ∈ represents a minimum constant.

[0024] As a further scheme of the present application, the specific steps of S3 are,

[0025] S301: Call the border path set, for the starting point and end point coordinates of each path, respectively extend the line segment outward based on the path direction vector, detect the intersection relationship between paths point by point in the image two-dimensional coordinate system, calculate the extended path coordinate point according to the coordinate overlapping position, and generate the intersection point coordinate set;

[0026] S302: According to the intersection point coordinate set, construct a vector group in the direction of the line between any two points, calculate the included angle value between the vector group, and compare the difference with the set structure included angle reference value, select the point pair combination whose included angle is approximately perpendicular and parallel, and obtain the structure angle matching vertex set;

[0027] S303: Call the structure angle matching vertex set, group the vertex combinations that meet the structure angle requirements according to adjacency, establish a closed coordinate loop according to the sequence of the line between the inner vertices, merge and arrange all closed loop data, and generate a two-dimensional code rectangular structure diagram.

[0028] As a further scheme of the application, the extended path coordinate point calculation formula is specifically:

[0029]

[0030] Wherein, P ext represents the extended coordinate point, P represents the path end point original coordinate, L1 represents the horizontal component of the direction, L2 represents the preset extension height, and ∈ represents a small constant.

[0031] As a further scheme of the application, the specific steps of S4 are,

[0032] S401: Call the two-dimensional code rectangular structure diagram, detect the position change of adjacent pixels in sequence along each border path according to the pixel sequence, construct a direction vector sequence according to the arrangement order of the pixels in the two-dimensional coordinate, perform step-by-step traversal on all pixel pairs in the path, record all direction information, and generate a pixel direction distribution sequence;

[0033] S402: Based on the pixel direction distribution sequence, determine whether the included angle change amplitude exceeds the direction jump threshold, perform a marking operation on the position coordinates that exceed the range, and according to the recording order, all marked position points and two-dimensional coordinates are obtained. Get the direction jump coordinate set;

[0034] S403: Call the direction jump coordinate set, perform continuity judgment according to the interval value of the jump position on the coordinate axis, classify the jump points that meet the set continuous segment length into the same segment, integrate the boundary coordinate information of all segments, and generate a border path continuity information table.

[0035] As a further scheme of the application, the specific steps of S5 are,

[0036] S501: Calling the border path continuity information table, constructing horizontal and vertical coordinate axes based on the coordinate center positions in the QR code rectangular structure diagram, extracting symmetrical region image blocks from the image based on the coordinate axes, classifying and marking the pixel positions at the edges of the symmetrical blocks, and obtaining a symmetrical region edge coordinate set;

[0037] S502: Based on the symmetric region edge coordinate set, pixel position difference vectors are established for symmetric point pairs, the vector lengths of the symmetric region edge coordinate pairs are calculated, and difference judgment is performed with a set edge offset reference value. Pixel pairs with differences outside the range are recorded, and a mapping correction matrix for all corresponding coordinates is established to obtain an edge offset correction path set.

[0038] S503: Call the edge offset correction path set, perform pixel value replacement operation based on the corresponding coordinates in the original image, write the correction area information into the original image data matrix according to the coordinate mapping relationship, merge all replaced areas according to image integrity, and generate a repaired QR code image.

[0039] As a further solution of the present invention, the calculation formula of the vector length of the symmetric region edge coordinate pair is specifically:

[0040]

[0041] Among them, L represents the vector length deviation value of the symmetric edge coordinate, W 1u ,W 2u Represents the horizontal coordinate of the symmetric point, W 1v , W 2v Represents the vertical coordinate of the stacked point, and Q represents the set edge offset reference value.

[0042] Compared with the prior art, the advantages and positive effects of the present invention are:

[0043] In the present invention, the direction angle is calculated to ensure the consistency of the path direction and avoid jump interference. The path extension and intersection point calculation are used to improve the vertex recognition accuracy and ensure the accuracy of the rectangular structure. The path continuity is detected point by point and the jump position is recorded. The broken area is accurately identified to avoid recognition errors caused by interruption. The edge offset repair of the symmetrical area ensures the symmetry of the image structure and eliminates the influence of distortion. Through refined edge extraction, path repair and structural correction, the edge continuity, structural integrity and decoding accuracy of the QR code under complex background and interference conditions are ensured. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 Schematic diagram of the steps of the present invention;

[0045] Figure 2 is a flow chart of the steps of S1 of the present invention;

[0046] Figure 3 The step flow chart for S2 of the present application;

[0047] Figure 4 The step flow chart for S3 of the present application;

[0048] Figure 5 The step flow chart for S4 of the present application;

[0049] Figure 6 The step flow chart for S5 of the present application. DETAILED DESCRIPTION

[0050] In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and not intended to limit the present application.

[0051] In the description of the present application, it should be understood that the terms "length", "width", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, and therefore cannot be understood as indicating or implying that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the present application. In addition, in the description of the present application, the meaning of "a plurality of" is two or more, unless otherwise explicitly and specifically limited.

[0052] Please refer to Figure 1 , the edge-constrained-based two-dimensional code recovery method comprises the following steps:

[0053] S1: acquiring a two-dimensional code image, converting it into a gray-scale image, scanning the image area pixel by pixel, detecting the brightness change of each pixel, extracting edge pixels according to the brightness change amplitude and direction, connecting adjacent edge pixels to form lines, and integrating all edge lines to generate a two-dimensional code edge feature map;

[0054] S2: calling the two-dimensional code edge feature map, scanning along the edge lines pixel by pixel, recording the starting point and ending point of each edge path, calculating the included angle between adjacent pixels, judging the included angle change and selecting the paths with continuous direction, excluding the paths with direction jump, integrating all paths to generate a border path set;

[0055] S3: calling the border path set, extending straight lines at the starting point and ending point of each path, calculating the intersection points of adjacent paths, recording all intersection points as vertices, selecting vertex combinations that meet the parallel and vertical structure, constructing a closed rectangle according to the connecting lines between vertices, and generating a two-dimensional code rectangular structure map;

[0056] S4: calling the two-dimensional code rectangular structure diagram, detecting the pixel continuity along each rectangular frame path point by point, calculating the adjacent pixel direction change, identifying the direction jump area, recording all the jump positions and coordinates, screening the broken area according to the continuity of the jump position, and generating the frame path continuity information table;

[0057] S5: calling the frame path continuity information table, extracting the symmetric area in the horizontal and vertical directions according to the center of the two-dimensional code rectangular structure diagram, comparing the edge positions of the symmetric areas, calculating the edge offset between each pair of symmetric areas, repairing the offset area and integrating all the repair information, and generating the repaired two-dimensional code image.

[0058] The two-dimensional code edge feature map includes edge pixel coordinates, edge line direction, and edge line connection information, the frame path set includes path starting point coordinates, path end point coordinates, and path direction information, the two-dimensional code rectangular structure diagram includes rectangular vertex coordinates, rectangular side length, and rectangular angle, the frame path continuity information table includes jump position coordinates, jump type, and jump direction, and the repaired two-dimensional code image includes repair area coordinates, repaired edge position, and repaired frame line.

[0059] Please refer to Figure 2 , the specific steps of S1 are as follows:

[0060] S101: acquiring the two-dimensional code image, converting it into a gray-scale image, performing weighted operation on the red, green, and blue channel values of each pixel to generate a gray-scale value, traversing the image area according to the two-dimensional coordinates of the pixels and recording the gray-scale value distribution, and generating a gray-scale pixel distribution matrix;

[0061] When acquiring the two-dimensional code image, the two-dimensional code printed on the paper can be captured by a common mobile phone camera, and the image is saved in color format. Each pixel point contains three color component values, usually between 0 and 255. During the gray scale conversion process, these color pixel values need to be processed into a single gray scale value. For example, the RGB value of a certain pixel point is (100, 150, 200). By setting the weighting coefficient as 0.3 for the red channel, 0.6 for the green channel, and 0.1 for the blue channel, the weighted average is obtained, and the gray scale value is 100*0.3+150*0.6+200*0.1=30+90+20=140. The same weighted processing is performed on each pixel of the entire image. For example, if the image size is 640*480 pixels, a total of 307,200 pixels need to be processed. Each pixel is processed by the above weight combination to obtain a gray scale value. All pixel gray scale values are arranged and recorded in a two-dimensional manner to form a gray scale pixel distribution matrix. The first row of the matrix represents the gray scale value sequence of the topmost pixel of the image, and the first column represents the gray scale value sequence of the leftmost pixel of the image. Each matrix element corresponds to the gray scale intensity value of a pixel point, which is convenient for subsequent analysis and feature extraction of the local structure of the image.

[0062] S102: Based on the gray scale pixel distribution matrix, the gray scale values of the four adjacent areas above, below, left and right of the pixel are extracted, the difference value is calculated with the gray scale value of the center pixel and the absolute value is taken, the difference value set is compared with the edge brightness difference threshold value to establish a mark matrix, and an edge direction mark distribution map is generated;

[0063] After obtaining the gray pixel distribution matrix, for any non-edge pixel point in the image, such as the pixel at position (50, 100), the adjacent pixels in its four directions are (49, 100), (51, 100), (50, 99), and (50, 101). The gray level differences between these adjacent points and the center point are calculated, for example, the center gray level is 120, and the adjacent gray levels are 80, 130, 115, and 140, respectively. The difference values are 40, 10, 5, and 20, respectively. The edge brightness difference threshold is set to 20. According to experience, this threshold is suitable for standard printing quality and normal indoor lighting conditions for shooting two-dimensional code images. For low light or reflective conditions, the threshold is recommended to be 30. If the captured image is clear and contrast is strong, the threshold is recommended to be reduced to 15. According to the above example, the directions with a difference value greater than or equal to 20 are up (40) and right (20). Therefore, in the edge direction marking matrix, the position (50, 100) is marked as 1 in the up and right directions, and 0 in the other directions. In this way, each pixel in the entire image is traversed, and the difference value in each adjacent direction is judged. Each pixel will generate a four-direction marking result containing 0 or 1, and the complete edge direction marking distribution map is formed by collecting these results. Each pixel in the map records the possible edge directions, which helps to extract and analyze the boundary structure later.

[0064] S103: Call the edge direction marking distribution map, judge the consistency of the edge pixels in the direction and the continuity of the position, execute the connection for the pixel points meeting the conditions and establish the path set to generate the two-dimensional code edge feature map;

[0065] Using the edge direction marking distribution map, all pixel positions in the image are traversed row by row. For example, the pixel at position (200, 300) is scanned, and its edge marking is 1 in the right direction. Then, it is checked whether the left direction of the adjacent pixel (200, 301) on the right side is also marked as 1. If so, it means that the edge directions of the two pixels are consistent, and a preliminary connection trend is formed. When judging continuity, it is continued to check whether the pixels (200, 302), (200, 303), etc. have the same direction marking. If there are three or more pixels meeting the consistency condition in a certain direction, it is determined that a stable edge path is formed, and the connection operation is performed. These consecutive pixel points are numbered and recorded in the path set, for example, the path record is [(200, 300), (200, 301), (200, 302), (200, 303)]. In actual operation, if there are multiple two-dimensional code module areas in the image, their edge directions will also be different. Therefore, complete consistency judgment needs to be performed for each pixel marked as 1, and the path is marked in time after being formed to avoid repeated judgment. Finally, the path set meeting the consistency and continuity constitutes the edge feature map of the two-dimensional code, which is convenient for extracting the frame, the reference pattern, and other feature areas, thereby providing a structural basis for subsequent decoding.

[0066] Referring to Figure 3 , the specific steps of S2 are:

[0067] S201: Call the two-dimensional code edge feature map, perform point-by-point scanning operation along each edge line according to the pixel order, detect the positions of the starting pixel and the ending pixel on the path in the image coordinate matrix, record the two-dimensional coordinates of the starting point and the ending point for each edge line segment respectively, and generate an edge path coordinate set;

[0068] Calling the two-dimensional code edge feature map refers to extracting structured path data from the edge pixel path map obtained in the previous processing step. Each edge path is composed of multiple consecutive pixels. The path is scanned point by point in order. The first pixel is extracted from the path array as the starting pixel, and its position value in the image coordinate matrix is recorded, such as (150, 320) for a starting pixel. The next pixel is read in order until the path terminates, and the last pixel coordinate is recorded as the ending pixel, such as (150, 370) for a path that extends continuously by 50 pixels in the horizontal direction. The starting and ending pixels of all paths in the image are read and their coordinate values are recorded. The data is saved in the form of two-dimensional coordinate structure, and the data structure of each path is: starting point coordinates (x1, y1), ending point coordinates (x2, y2), such as a group of edge path coordinates (80, 400) and (130, 400), which correspond to a horizontal path with a length of 50 pixels. The path information is written into the edge path coordinate set. The set data structure can use list, array or key-value mapping. Each item records the two-dimensional coordinate values of the starting point and the ending point of a path. In multi-path processing, to avoid repeated recording, unique numbering of the edge path is required. The numbering method can be based on the ascending order of the starting point coordinates, such as the starting point closest to the upper left corner being recorded first, with numbers P1, P2, etc. The numbering and path coordinates are bound to form a set table structure. After all the paths in the edge feature map are completely traversed, the edge path coordinate set is finally generated.

[0069] S202: Based on the edge path coordinate set, construct direction vectors based on the coordinate difference between adjacent pixels, calculate the angle value between adjacent vectors, judge whether the difference between the angle and the set direction continuity threshold value is out of range, and perform exclusion operation on the path segment that is out of range, to generate a direction continuous path sequence;

[0070] The formula for calculating the angle value between adjacent vectors is:

[0071]

[0072] Where, θ iThe angle between the adjacent direction vectors, v i The direction vector from pixel point (x i , y i ) to (x i+1 , y i+1 ), v i+1 The direction vector from pixel point (x i+1 , y i+1 ) to (x i+2 , y i+2 ), ∈ represents a minimum constant;

[0073] Given the coordinates of three consecutive points: point A (80, 400), point B (85, 403), and point C (90, 405)

[0074] Calculation process: vector calculation: v i = (85-80, 403-400) = (5, 3) v i+1 = (90-85, 405-403) = (5, 2);

[0075] Dot product calculation: v i · v i+1 = 5x5 + 3x2 = 31;

[0076] Module length calculation:

[0077] Substitute the formula:

[0078]

[0079] S203: Call the direction continuous path sequence, perform merging processing on the remaining path segments according to the pixel connection order, establish a continuous path set, and uniformly integrate the path sequence to generate a border path set;

[0080] The above direction continuous path sequence is called, and each path segment is integrated according to the natural order of pixel point connection. First, the coordinates of all pixel points in each path segment are read in the connection order, and are sequentially combined into a complete path. For example, the first segment is [(80, 100), (81, 101), (82, 102)], and the second segment is [(83, 103), (84, 104)]. If the coordinate difference between the first point of the second segment and the last point of the first segment is within 1 pixel, it is determined that the paths can be connected, and the two segments are directly combined into [(80, 100), (81, 101), (82, 102), (83, 103), (84, 104)]. During the combination process, it is necessary to determine whether the distance between the start and end points of the path segment meets the connection condition. The connection distance threshold is empirically set to be within 2 pixels. That is, when the distance between two path segments is not more than 2 pixels, it is determined that the path segments are continuous and the combination operation is performed. If the distance is more than 3 pixels, the path segments remain independent. The connection between the path segments is based on the Euclidean distance calculation result between the end point and the start point. After combination, all paths are renumbered, and all combined path sets are integrated to generate a complete border path set. The set structure is a two-dimensional path point sequence array, and all connected point coordinate information is arranged in pixel order within each path.

[0081] Please refer to Figure 4 The specific steps of S3 are as follows:

[0082] S301: Call the border path set, and based on the start and end point coordinates of each path, respectively extend the line segment outward based on the path direction vector, and detect the intersection relationship between the paths point by point in the two-dimensional coordinate system of the image. According to the coordinate coincidence position, the extended path coordinate point is calculated to generate a set of intersection point coordinates.

[0083] The formula for calculating the extended path coordinate point is as follows:

[0084]

[0085] Wherein, P ext represents the extended coordinate point, P represents the original coordinate of the path end point, L1 represents the horizontal component of the direction vector, L2 represents the preset extension height, and ∈ represents a small constant;

[0086] Embodiment: Given path segment: start point (150, 320), end point (150, 370), extension length D = 30 pixels

[0087] Calculation process: Direction vector calculation: L1 = 150-150 = 0 L2 = 370-320 = 50;

[0088] Unit vector calculation:

[0089]

[0090] Extended coordinate calculation: P ext = (150, 370) + 30 x (0, 1) = (150, 400).

[0091] S302: According to the intersection point coordinate set, a vector group is constructed in the direction of the line between any two points, the included angle value between the vector group is calculated, and the difference is compared with the set structure angle reference value, the point pair combination with approximate perpendicularity and parallelism is screened, and the structure angle matching vertex set is obtained;

[0092] According to the above intersection point coordinate set, a group of two points is selected, for example, point pair A (190, 300) and B (200, 300), the direction vector of its line is (10, 0), indicating the horizontal direction, and the direction included angle calculation is continued with the vector (0, 10) formed by another point pair C (200, 300) and D (200, 310). The calculation method is to call the components of the two vectors and calculate the direction included angle value, and then compare the difference with the structure angle reference value. The structure angle reference value is set according to the standard two-dimensional code pattern characteristics, in which the horizontal and vertical included angle is 90°, the parallel included angle is 0° or 180°, and the allowable range of the included angle error is ±10°. That is, if the included angle between two vectors is between 80° and 100°, it is determined to be approximately perpendicular, and if the included angle is between 0° and 10° or 170° and 180°, it is determined to be approximately parallel. For all vector combination pairs formed by intersection points, the included angle is calculated one by one and compared with the above range to determine whether it meets the approximate included angle condition. For example, the included angle between vectors (10, 0) and (0, 10) is 90°, which meets the perpendicular condition, and the point pair A and B are retained. If the included angle between vectors (8, 1) and (0, 9) is 83.6°, it also falls within 80° to 100°, which meets the retention condition. Otherwise, the combination is rejected. After screening, all point pairs that meet the structure angle matching requirements are stored in the structure angle matching vertex set. The vertex set records all coordinate point combinations that meet the structure angle rules.

[0093] S303: Call the structure angle matching vertex set, group the vertex combinations that meet the structure angle requirements according to adjacency, establish a closed coordinate loop according to the sequence of the line between the inner vertices, and merge and arrange all closed loop data to generate a two-dimensional code rectangular structure diagram.

[0094] The vertex set is matched in terms of the structure angle, and for each pair of coordinate points, it is determined whether there is adjacency according to the coordinate position relationship. The adjacency determination condition is that the distance between two points is less than a set maximum interval threshold. The threshold is set with reference to the size of the two-dimensional code module and the image resolution. If the two-dimensional code single module occupies 10x10 pixels, the adjacency threshold is set to within 20 pixels. The coordinate difference between the points is calculated. If the difference in the x direction and the y direction is not more than 20, the two points are considered adjacent points, which meet the grouping condition. The adjacent points are sequentially grouped into the same group. The points in the group are sorted in the order of the coordinates to form a closed loop structure. The closure is determined according to whether the starting point and the ending point coordinates are consistent or whether the ending point can return to the starting point coordinates. For example, a group of points are (100, 100), (100, 200), (200, 200), and (200, 100) in turn. If a line is added to return to the starting point (100, 100), a closed path is formed. For each group of points, a closed path is constructed in this way. All closed path structures are stored in a new closed path data set. Finally, multiple closed paths are sequentially numbered and arranged, and are uniformly stored in a two-dimensional code rectangular structure diagram. The structure diagram stores the point coordinate sequence of all closed paths in a list structure, which is convenient for subsequent structure analysis and position positioning.

[0095] Referring to Figure 5 The specific steps of S4 are as follows:

[0096] S401: Call the two-dimensional code rectangular structure diagram, and detect the position change of adjacent pixels along each edge path in the order of pixel sequence. A direction vector sequence is constructed according to the arrangement order of the pixels in the two-dimensional coordinates. All pixels are traversed in sections, and all direction information is recorded to generate a pixel direction distribution sequence.

[0097] The calling two-dimensional code rectangular structure diagram refers to all closed path graphics constituting the two-dimensional code frame obtained from the previous processing step, each path is composed of a group of continuous pixel points, these pixel points are recorded in the form of two-dimensional coordinates, in the traversal process, the adjacent pixel pairs are taken out in order from the first pixel according to the arrangement order of the pixels in the path, the coordinate difference value of each adjacent pixel pair is calculated to construct a direction vector, for example, the first pixel is (100, 150), the next one is (101, 150), and the direction vector is (1, 0), indicating the horizontal direction to the right, the second pair of pixels (101, 150) and (102, 150) are processed, and the direction vector (1, 0) is obtained, and so on. All pixel pairs in the path are traversed in pairs, and the coordinate difference value between each pair of pixels is recorded, and the direction vector data is saved in sequence, for example, the pixel point sequence of a certain frame path is [(100, 150), (101, 150), (102, 150), (102, 151)], and the corresponding direction vector is [(1, 0), (1, 0), (0, 1)], indicating that the path is first horizontally extended by two pixels and then vertically upward by one pixel. Each pair of direction vectors records the coordinate difference value Δx and Δy, for example, Δx is the horizontal displacement difference value, and Δy is the vertical displacement difference value, this process is performed on all pixel sequences in the closed path, to ensure that each path generates complete direction information data. The direction vector data of all paths is archived according to the path number, and finally a pixel direction distribution sequence containing all path direction change conditions is generated.

[0098] S402: Based on the pixel direction distribution sequence, it is judged whether the change amplitude of the included angle exceeds the direction jump threshold value, and the marked position coordinates are executed, all marked position points and two-dimensional coordinates are collected in the recording order, and the direction jump coordinate set is obtained;

[0099] Based on the pixel direction distribution sequence generated above, the angle change of each pair of continuous direction vectors is judged one by one. For example, the continuous direction vectors of a certain path are [(1, 0), (1, 0), (0, 1)], the first and second directions are completely consistent, the included angle is 0°, the second and third directions are from horizontal right to vertical up, the included angle is 90°, and the included angle change value is recorded as 90°. The included angle change value is compared with the set direction jump threshold value, the direction jump threshold value is set according to the image scanning resolution and the two-dimensional code fault tolerance feature, and the recommended setting value is 45°. If the included angle change between the two continuous direction vectors is greater than or equal to 45°, it is considered that the direction jump occurs. In this example, the included angle is 90°, which exceeds the threshold value, so the next pixel of the jump position is marked, and its two-dimensional coordinate value is recorded. The judgment and marking operation is repeatedly executed in the entire direction sequence, and all the marked pixel point coordinates constitute a jump position set. For example, the coordinates of the jump points in a path are (102, 150), (110, 160), and (130, 180). The coordinate information of these points is arranged in order and uniformly summarized to form a direction jump coordinate set. Each element in the set consists of a path number and a corresponding jump pixel two-dimensional coordinate, which ensures that the jump point can be located in the image space.

[0100] S403: Call the direction jump coordinate set, perform continuity judgment according to the interval value of the jump position on the coordinate axis, classify the jump points that meet the set continuous segment length into the same segment, integrate the boundary coordinate information of all segments, and generate a border path continuity information table;

[0101] The direction jump coordinate set is called, and each item is compared according to the position of the coordinate point on the image coordinate axis. The coordinate difference between adjacent jump points is calculated to determine whether they belong to the same continuous jump paragraph. For example, the jump point coordinates in the set are (100, 150), (102, 152), (104, 154), and (120, 170). The difference in x and y axes of the first three points is 2, which is judged as a continuous segment. The difference between the fourth point and the previous jump point is 16, which is much larger than the continuous segment judgment threshold value, so it is not included in this segment. The continuous segment judgment threshold value is set to the maximum pixel interval of 5 pixels. If the difference between the two adjacent jump points on the x or y axis does not exceed 5, they are included in the same segment. The starting coordinate and ending coordinate of each segment are recorded, and the paragraph number is assigned. After integration, multiple direction jump continuous segments are obtained. Each segment records the boundary coordinates of the starting and ending jump points. For example, the boundary points of segment 1 are (100, 150) to (104, 154), and the boundary points of segment 2 are (120, 170) to (122, 172). The numbering and boundary information of all jump segments are bound, and finally a border path continuity information table is generated. The information table records the number, starting coordinate, ending coordinate, and path number of each jump paragraph.

[0102] Please refer to Figure 6 , the specific steps of S5 are:

[0103] S501: Call the border path continuity information table, construct the horizontal and vertical coordinate axes according to the coordinate center position in the two-dimensional code rectangular structure diagram, extract the symmetrical region image block from the image based on the coordinate axes, classify and mark the pixel positions of the symmetrical block edges, and obtain the symmetrical region edge coordinate set;

[0104] Calling the border path continuity information table refers to obtaining the boundary coordinate information of each segment after completing the direction jump continuous segment analysis, extracting the continuous path coordinate data of the four-side boundary in the overall image according to the spatial distribution of these path segments in the overall rectangular structure diagram of the two-dimensional code, then taking the pixel point coordinates of all the closed border paths in the two-dimensional code rectangular structure diagram as the reference, statistically analyzing the overall position, and calculating the average value of the x coordinates and y coordinates of all the border pixel points as the two-dimensional code center coordinate point. For example, the total number of border path pixel points in a two-dimensional code image is 4000, the sum of all x coordinates is 480,000, and the sum of all y coordinates is 360,000. Then the two-dimensional code coordinate center is (480,000÷4000, 360,000÷4000) = (120, 90). The horizontal coordinate axis is established to the left and right of this center point, and the vertical coordinate axis is established to the top and bottom of this center point. Four symmetrical region image blocks are extracted in the original image based on the coordinate axes, for example, 80x80 pixel image regions are extracted from the center to the upper left, upper right, lower left, and lower right directions, forming four symmetrical region image blocks. The edge pixels of each image block are classified and marked, that is, the pixels on the edge of each image block are classified according to their boundary positions in the image coordinate system, for example, the right edge column and the upper edge row of the upper left block, and the left edge column and the lower edge row of the lower right block. The coordinate information of the pixels is recorded. The classified pixel edge points establish a numbering table and perform coordinate comparison and confirmation. All edge coordinates that meet the symmetry relationship are uniformly summarized to form the symmetrical region edge coordinate set.

[0105] S502: Based on the symmetrical region edge coordinate set, establish a pixel position difference vector according to the symmetrical point pairs, calculate the vector length of the symmetrical region edge coordinate pairs, and perform difference judgment with the set edge offset reference value. Record the pixels whose difference value exceeds the range, establish a mapping correction matrix of all corresponding coordinates, and obtain the edge offset correction path set;

[0106] The vector length calculation formula of the symmetrical region edge coordinate pair is specifically:

[0107]

[0108] Wherein, L represents the vector length deviation value of the symmetrical edge coordinates, W 1u ,W 2uHorizontal coordinate representing the symmetry point, W 1v , W 2v Vertical coordinate representing the stacking point, Q represents the set edge offset reference value

[0109] Example: Known symmetry point pair: upper left region point (100, 80), lower right region point (220, 200), reference value Q = 120 pixels

[0110] Calculation process: Euclidean distance calculation

[0111]

[0112] Deviation calculation

[0113] L = 169.7 - 120 = 49.7 pixels

[0114] The results show that the actual distance is 49.7 pixels larger than the ideal value, and compression correction is needed.

[0115] S503: Call the edge offset correction path set, perform pixel value replacement operation based on the corresponding coordinates in the original image as the reference, write the correction region information into the original image data matrix according to the coordinate mapping relationship, and merge all replaced regions according to the image integrity to generate the repaired two-dimensional code image

[0116] Call the above edge offset correction path set, that is, according to the point pair coordinate difference recorded in the mapping correction matrix, replace the pixel value in the original image according to the mapping relationship. During the execution process, for each pair of pixel points that need to be corrected, read the pixel value at the original coordinate position, and perform overwrite writing according to the mapping target coordinate. For example, the pixel value of point (90, 70) in the original image is 255, which needs to be replaced to the target point (150, 110) according to the correction path. After reading the pixel value of (90, 70), write it into the image data matrix of (150, 110). During the writing operation, ensure that the target point coordinate is not overwritten repeatedly. If the target point is pointed to by multiple source points, the one closest to the center point is retained first, and the others are discarded. After the replacement process is performed according to all mapping relationships, record all coordinates that have performed replacement operation, and perform region merging processing according to their coordinates in the image matrix. The merging is performed according to the adjacent point clustering rule, that is, if multiple replacement points are continuous or adjacent in the same region, they are recorded as a correction block. Finally, multiple correction block regions are formed, and they are written into the corrected image data matrix according to the pixel continuous structure. After all the processing is completed, the complete repaired two-dimensional code image is output.

[0117] The above merely describes the preferred embodiments of the present application, and is not intended to limit the present application in other forms. Any skilled person in the art can modify or change the disclosed technical content into equivalent embodiments with equivalent changes, and apply them to other fields. However, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present application, without departing from the technical solution content of the present application, still falls within the protection scope of the present application.

Claims

1. A QR code recovery method based on edge constraints, characterized in that: The following steps are involved: S1: Obtain a QR code image, convert it into a grayscale image, scan the area pixel by pixel, detect brightness changes, extract and connect edge pixels, and integrate all edge lines to generate a QR code edge feature map; S2: Based on the QR code edge feature map, scan the edge lines pixel by pixel, record the starting and ending points of the paths, calculate the direction angle, filter the continuous paths, exclude the jump paths, and integrate them into a border path set; S3: Call the border path set, extend the path to calculate the extended path coordinate points, record the intersection points as vertices, select vertex combinations that meet the parallel and vertical structures, construct a closed rectangle based on the vertex connection lines, and generate a QR code rectangle structure diagram; S4: Based on the rectangular structure diagram of the QR code, pixel continuity is detected point by point along the rectangular border path, transition areas are identified, transition positions and coordinates are recorded, and broken areas are screened based on the continuity of the transition positions to generate a border path continuity information table; S5: According to the border path continuity information table, extract the symmetrical areas in the horizontal and vertical directions along the center of the QR code rectangular structure, compare the edge positions, calculate the offset of the symmetrical area, repair the offset area and integrate the repair information to generate a repaired QR code image.

2. The edge-constrained two-dimensional code recovery method according to claim 1, characterized in that: The QR code edge feature map includes edge pixel coordinates, edge line direction, and edge line connection information; the border path set includes path starting point coordinates, path ending point coordinates, and path direction information; the QR code rectangular structure map includes rectangle vertex coordinates, rectangle side length, and rectangle angle; the border path continuity information table includes jump position coordinates, jump type, and jump direction; the repaired QR code image includes repair area coordinates, repaired edge position, and repaired border lines.

3. The edge-constrained two-dimensional code recovery method according to claim 1, characterized in that: The specific steps of S1 are: S101: Obtain a QR code image, convert it into a grayscale image, perform a weighted operation on the red, green, and blue channel values ​​of each pixel to generate a grayscale value, traverse the image area in sequence according to the two-dimensional coordinates of the pixels and record the grayscale value distribution to generate a grayscale pixel distribution matrix; S102: Based on the grayscale pixel distribution matrix, extract the grayscale values ​​of the four upper, lower, left, and right neighborhoods of the pixel, calculate the difference between the grayscale value of the central pixel and take the absolute value, compare the difference set with the edge brightness difference threshold to establish a label matrix, and generate an edge direction label distribution map; S103: calling the edge direction marker distribution map, judging the direction consistency and position continuity between edge pixels, connecting pixels that meet the conditions and establishing a path set, and generating a QR code edge feature map.

4. The edge-constrained two-dimensional code recovery method according to claim 1, characterized in that: The specific steps of S2 are: S201: Calling the QR code edge feature map, performing a point-by-point scanning operation along each edge line in pixel order, detecting the positions of the starting pixel and the ending pixel on the path in the image coordinate matrix, recording the two-dimensional coordinates of the starting point and the ending point respectively according to the edge line segment, and generating an edge path coordinate set; S202: Based on the edge path coordinate set, construct a direction vector using the coordinate difference between adjacent pixels, calculate the angle between adjacent vectors, determine whether the difference between the angle and a set direction continuity threshold exceeds a range, perform an exclusion operation on the path segments that exceed the range, and generate a direction-continuous path sequence; S203: calling the direction continuous path sequence, performing merging processing on the remaining path segments according to the pixel connection order, establishing a continuous path set, and unifying and integrating the path sequence to generate a border path set.

5. The edge-constrained two-dimensional code recovery method according to claim 4, characterized in that: The numerical calculation formula for the angle between adjacent vectors is specifically: Among them, θ i Represents the angle between adjacent direction quantities, v i Represents the pixel (x i ,y i ) to (x i+1 ,y i+1 ) direction quantity, v i+1 Represents the pixel (x i+1 ,y i+1 ) to (x i+2 ,y i+2 ) is a direction quantity, and ∈ represents a minimum constant.

6. The edge-constrained two-dimensional code recovery method according to claim 1, characterized in that: The specific steps of S3 are: S301: Calling the bounding box path set, extending line segments outward based on the path direction vector for the start and end coordinates of each path, detecting the intersection relationship between the paths point by point in the image two-dimensional coordinate system, calculating the extended path coordinate points based on the coordinate coincidence positions, and generating a set of intersection point coordinates; S302: Based on the intersection point coordinate set, construct a vector group with the direction of the line between any two points, calculate the angle between the vector groups, and compare the difference with the set structural angle reference value, select point pairs whose angles are close to perpendicularity and parallelism, and obtain a structural angle matching vertex set; S303: calling the structure angle matching vertex set, grouping the vertex combinations that meet the structure angle requirements according to adjacency, establishing a closed coordinate loop based on the sequence of connections between internal vertices, merging and arranging all closed loop data, and generating a QR code rectangular structure diagram.

7. The edge-constrained two-dimensional code recovery method according to claim 6, characterized in that: The calculation formula of the extended path coordinate point is specifically: Among them, P ext Represents the coordinate point after extension, P represents the original coordinate of the end point of the path, L1 represents the horizontal component of the direction quantity, L2 represents the preset extension height, and ∈ represents a minimum constant.

8. The edge-constrained two-dimensional code recovery method according to claim 1, characterized in that: The specific steps of S4 are: S401: calling the QR code rectangular structure diagram, detecting position changes of adjacent pixels in sequence along each border path, constructing a direction vector sequence based on the arrangement order of the pixels in the two-dimensional coordinates, performing a segment-by-segment traversal of all pixel pairs in the path, recording all direction information, and generating a pixel direction distribution sequence; S402: Based on the pixel direction distribution sequence, determine whether the angle change amplitude exceeds the direction jump threshold, perform a marking operation on the position coordinates that exceed the range, and summarize all marked position points and two-dimensional coordinates in the recording order to obtain a direction jump coordinate set; S403: Call the direction jump coordinate set, perform continuity judgment according to the interval value of the jump position on the coordinate axis, classify the jump points that meet the set continuous segment length into the same segment, integrate the boundary coordinate information of all segments, and generate a border path continuity information table.

9. The edge-constrained two-dimensional code recovery method according to claim 1, characterized in that: The specific steps of S5 are: S501: Calling the border path continuity information table, constructing horizontal and vertical coordinate axes based on the coordinate center positions in the QR code rectangular structure diagram, extracting symmetrical region image blocks from the image based on the coordinate axes, classifying and marking the pixel positions at the edges of the symmetrical blocks, and obtaining a symmetrical region edge coordinate set; S502: Based on the symmetric region edge coordinate set, pixel position difference vectors are established for symmetric point pairs, the vector lengths of the symmetric region edge coordinate pairs are calculated, and difference judgment is performed with a set edge offset reference value. Pixel pairs with differences outside the range are recorded, and a mapping correction matrix for all corresponding coordinates is established to obtain an edge offset correction path set. S503: Call the edge offset correction path set, perform pixel value replacement operation based on the corresponding coordinates in the original image, write the correction area information into the original image data matrix according to the coordinate mapping relationship, merge all replaced areas according to image integrity, and generate a repaired QR code image.

10. The edge-constrained two-dimensional code recovery method according to claim 1, characterized in that: The specific calculation formula for the vector length of the symmetric region edge coordinate pair is: Among them, L represents the vector length deviation value of the symmetric edge coordinate, W 1u ,W 2u Represents the horizontal coordinate of the symmetric point, W 1v , W 2v Represents the vertical coordinate of the stacked point, and Q represents the set edge offset reference value.

Citation Information

Cited By

  • Label two-dimensional code printing detection system and detection method thereof

    CN121937409A