QR code sampling grid division method and device, equipment, storage medium and product
By preprocessing the QR code image and calculating the gradient projection value, determining and repairing the mesh division line, the problem of inaccurate mesh division of deformation QR codes in the prior art is solved, and higher accuracy and adaptability are achieved.
Patent Information
- Application Number
- CN202410879462.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-11-08
AI Technical Summary
In the prior art, the sampling grid is not accurately divided under deformation, resulting in decoding failure.
By obtaining the QR code image for preprocessing, the gradient projection value is calculated to determine the gradient projection peak position, and the meshing lines are patched to improve the accuracy of meshing.
It improves the accuracy of meshing, can better adapt to deformation QR codes, and ensures efficient and automated meshing.
Smart Images

Figure CN118918301A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a QR code sampling grid division method, device, equipment, storage medium and product. Background Art
[0002] The current method of meshing QR codes is to calculate the edge point coordinates based on the geometric relationship after locating the three center points of the QR code mark, and then use these four point coordinates to perform affine transformation to correct the QR code. After the correction is completed, uniform sampling mesh division is performed, and the width and height of each grid are consistent. If the QR code has a certain deformation, the QR code after affine transformation using four points will still be distorted, so uniform mesh division will lead to some mesh division errors, resulting in sampling failure. Summary of the invention
[0003] The main purpose of the present application is to provide a QR code sampling grid division method, device, equipment, storage medium and product, aiming to solve the technical problem in the prior art that when the QR code is distorted, the sampling grid division of the QR code is inaccurate, resulting in decoding failure.
[0004] To achieve the above object, the present application provides a QR code sampling grid division method, the QR code sampling grid division method comprising the following steps:
[0005] Acquire a QR code image, and preprocess the QR code image to obtain a target QR code image;
[0006] Determine the gradient projection peak position according to the gradient projection value of the target QR code image in the gradient projection map in different directions;
[0007] Determine the vertical grid division lines and the horizontal grid division lines according to the gradient projection peak position;
[0008] Repairing the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain repaired grid division lines;
[0009] The target QR code image is divided according to the repaired grid division lines to obtain a grid division result of the target QR code image.
[0010] Optionally, the direction includes a horizontal direction and a vertical direction, and the step of determining the gradient projection peak position according to the gradient projection value in the gradient projection map of the target QR code image in different directions includes:
[0011] Call the opencv library function to calculate the horizontal and vertical gradients of the target QR code to obtain the horizontal and vertical gradient values;
[0012] Normalizing the horizontal gradient value and the vertical gradient value to obtain a first gradient and a second gradient;
[0013] Project the first gradient and the second gradient to obtain a vertical gradient projection value and a horizontal gradient projection value;
[0014] Determine the vertical gradient projection peak position according to the vertical gradient projection value;
[0015] The horizontal gradient projection peak position is determined according to the horizontal gradient projection value.
[0016] Optionally, after the step of determining vertical grid division lines and horizontal grid division lines according to the gradient projection peak positions, the method further includes:
[0017] Determine whether the number of vertical grid division lines and the number of horizontal grid division lines are less than a preset division order;
[0018] If so, it is determined that the vertical grid division lines and the horizontal grid division lines need to be repaired;
[0019] If not, it is determined that the vertical grid division lines and the horizontal grid division lines do not need to be repaired.
[0020] Optionally, the step of determining vertical grid division lines and horizontal grid division lines according to the gradient projection peak position includes:
[0021] Divide the gradient projection image into grids according to a preset division order based on the vertical direction and the horizontal direction, and compare the distances between the peak positions corresponding to the maximum peak values in adjacent grids in the vertical direction and the horizontal direction respectively, to determine whether the distances between the peak positions corresponding to the maximum peak values in adjacent grids are greater than a preset threshold;
[0022] If so, the vertical gradient projection peak position and the horizontal gradient projection peak position corresponding to the maximum peak value in the adjacent grids are used as the vertical grid division line and the horizontal grid division line; and continue to traverse the next grid until the peak position comparison corresponding to the maximum peak value in all grids is completed to obtain the vertical grid division line and the horizontal grid division line.
[0023] Optionally, the step of repairing the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain the repaired grid division lines includes:
[0024] Determine the grid to be repaired according to the grid line intervals corresponding to the adjacent vertical grid division lines and horizontal grid division lines in the vertical grid division lines and the horizontal grid division lines;
[0025] The vertical gradient projection wave peak position and the horizontal gradient projection wave peak position in the grid to be repaired are selected from the gradient projection wave peak position as the repair grid line;
[0026] The vertical grid division lines and the horizontal grid division lines are repaired based on the repairing grid lines to obtain repaired grid division lines.
[0027] Optionally, the step of dividing the target QR code image according to the repaired grid division lines to obtain a grid division result of the target QR code image includes:
[0028] Divide the target QR code image according to the repaired grid division lines to obtain the division results of the target QR code image in the vertical direction and the horizontal direction;
[0029] The division results in the vertical direction and the horizontal direction are combined to obtain the grid division result of the target QR code image.
[0030] In addition, to achieve the above-mentioned purpose, the present application also provides a QR code sampling grid division device, the QR code sampling grid division device comprising:
[0031] An image acquisition module, used to acquire a QR code image;
[0032] A preprocessing module, used for preprocessing the QR code image to obtain a target QR code image;
[0033] A gradient projection module is used to determine the gradient projection peak position according to the gradient projection values in the gradient projection map of the target QR code image in different directions;
[0034] A grid division module, used to determine vertical grid division lines and horizontal grid division lines according to the positions of the gradient projection peaks;
[0035] A grid repair module, used to repair the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines, to obtain repaired grid division lines;
[0036] The grid division module is also used to divide the target QR code image according to the repaired grid division lines to obtain the grid division result of the target QR code image.
[0037] In addition, to achieve the above-mentioned purpose, the present application also proposes a QR code sampling grid division device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the QR code sampling grid division method as described above.
[0038] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the QR code sampling grid division method as described above are implemented.
[0039] In addition, to achieve the above-mentioned purpose, the present application also proposes a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the QR code sampling grid division method as described above are implemented.
[0040] One or more technical solutions proposed in this application have at least the following technical effects:
[0041] The present application obtains a QR code image, pre-processes the QR code image to obtain a target QR code image; determines the gradient projection peak position according to the gradient projection value in the gradient projection map of the target QR code image in different directions; determines the vertical grid division lines and the horizontal grid division lines according to the gradient projection peak position; repairs the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain the repaired grid division lines; divides the target QR code image according to the repaired grid division lines to obtain the grid division result of the target QR code image. Compared with the prior art that directly divides the QR code image into uniform sampling grids, so that the grid lines after division cannot accurately locate the edge positions of the black and white squares in the QR code, the present application improves the accuracy of grid division and has stronger adaptability to deformed QR codes. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0043] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0044] Figure 1 A schematic diagram of a flow chart provided for the first embodiment of the QR code sampling grid division method of the present application;
[0045] Figure 2 A schematic diagram of QR code correction provided for the first embodiment of the QR code sampling grid division method of the present application;
[0046] Figure 3 A gradient schematic diagram provided for the first embodiment of the QR code sampling grid division method of the present application;
[0047] Figure 4 A schematic diagram of gradient projection provided for the first embodiment of the QR code sampling grid division method of the present application;
[0048] Figure 5 A schematic diagram of a gradient projection peak provided in the first embodiment of the QR code sampling grid division method of the present application;
[0049] Figure 6 A schematic diagram of initial grid division lines provided for the second embodiment of the QR code sampling grid division method of the present application;
[0050] Figure 7 A schematic diagram of the target QR code sampling grid division result of the repaired grid division lines provided in the second embodiment of the QR code sampling grid division method of the present application;
[0051] Figure 8 A schematic diagram of the system execution flow provided for the second embodiment of the QR code sampling grid division method of the present application;
[0052] Fig. 9 A comparison diagram of target QR code sampling grid division provided in the second embodiment of the QR code sampling grid division method of the present application;
[0053] Fig.10 This is a schematic diagram of the module structure of the QR code sampling grid division device according to an embodiment of the present application;
[0054] Fig.11 Schematic diagram of the device structure of the hardware operating environment involved in the QR code sampling grid division method in the embodiment of the present application.
[0055] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0056] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0057] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0058] The main solution of the embodiment of the present application is: obtain a QR code image, pre-process the QR code image to obtain a target QR code image; determine the gradient projection peak position according to the gradient projection value in the gradient projection map of the target QR code image in different directions; determine the vertical grid division lines and the horizontal grid division lines according to the gradient projection peak position; repair the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain repaired grid division lines; divide the target QR code image according to the repaired grid division lines to obtain the grid division result of the target QR code image.
[0059] In this embodiment, for ease of description, the following description is made with the computing service device as the execution entity.
[0060] Since the prior art directly performs grid division, the position of the QR code cannot be accurately located in the divided grid.
[0061] The present application provides a solution to improve the accuracy of grid division, which can efficiently and automatically complete the QR code sampling grid division and has stronger adaptability to deformed QR codes.
[0062] As can be seen from the above embodiments, the present application obtains a QR code image, pre-processes the QR code image to obtain a target QR code image; determines the gradient projection peak position according to the gradient projection value in the gradient projection map of the target QR code image in different directions; determines the vertical grid division lines and the horizontal grid division lines according to the gradient projection peak position; repairs the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain the repaired grid division lines; divides the target QR code image according to the repaired grid division lines to obtain the grid division result of the target QR code image. The present application improves the accuracy of grid division, can efficiently and automatically complete the QR code sampling grid division, and has stronger adaptability to deformed QR codes.
[0063] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, including a device of a QR code sampling grid division system, etc. The following takes a computer as an example to illustrate this embodiment and the following embodiments.
[0064] Based on this, the present application embodiment provides a QR code sampling grid division method, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the QR code sampling grid division method of the present application.
[0065] In this embodiment, the QR code sampling grid division method includes steps S10 to S50:
[0066] Step S10, obtaining a QR code image, and preprocessing the QR code image to obtain a target QR code image.
[0067] It should be noted that QR code may refer to a calibrated QR code, wherein QR code (Quick Response Code) is a two-dimensional code, which is a two-dimensional barcode that encodes data in a matrix form. Compared with traditional barcodes, it can store more information and scan faster. The QR code image is composed of black and white squares, and can be nested to contain a large amount of text, website addresses, phone numbers, emails, images and other data. Preprocessing may refer to performing calibration preprocessing on the acquired QR code image to obtain the target QR code image.
[0068] It is understandable that, in order to further illustrate the QR code image correction process, reference can be made to Figure 2 The QR code correction schematic diagram shown in FIG. 1 shows a QR code correction schematic diagram, wherein the present application corrects the image (A) to the image (B), and the lined parts in the image (A) are the four corner points for positioning. Subsequent operations are completed based on the correction image.
[0069] Step S20, determining the gradient projection peak position according to the gradient projection values in the gradient projection map of the target QR code image in different directions.
[0070] It should be understood that determining the gradient projection peak position by the gradient projection values in the gradient projection map of the corrected QR code image in different directions can be that the gradient values of the corrected image are calculated in different directions, and the gradient values are projected to obtain gradient projection maps in different directions, and the peak position is determined according to the gradient projection values in the gradient projection map in different directions to obtain the gradient projection peak position.
[0071] Furthermore, the direction includes a horizontal direction and a vertical direction, and step S20 also includes: calling an opencv library function to perform horizontal and vertical gradient calculations on the target QR code to obtain a horizontal gradient value and a vertical gradient value; normalizing the horizontal gradient value and the vertical gradient value to obtain a first gradient and a second gradient; projecting the first gradient and the second gradient to obtain a vertical gradient projection value and a horizontal gradient projection value; determining a vertical gradient projection peak position according to the vertical gradient projection value; and determining a horizontal gradient projection peak position according to the horizontal gradient projection value.
[0072] It should be noted that, in order to further illustrate the gradient calculation results of this application, reference can be made to Figure 3The gradient schematic diagram shown includes a horizontal gradient schematic diagram in Figure (A) and a vertical gradient schematic diagram in Figure (B), wherein in this application, the horizontal and vertical gradients of the target QR code are calculated by calling the opencv library function, and the gradient values are unified to 0-255 pixel values to obtain a horizontal gradient map and a vertical gradient map.
[0073] It should be understood that, to further illustrate the gradient projection in this application, reference can be made to Figure 4 The gradient projection schematic diagram shown includes: Figure (A) horizontal gradient projection schematic diagram, Figure (B) vertical gradient projection schematic diagram, wherein, after calculating the gradient value of the image, the present application obtains a gradient map, and the size of the pixel value of the gradient map at this time is unknown, so it needs to be normalized, and the pixel value is unified to 0-255, and the middle value of 0-255 is used as the threshold, so the gradient pixel points greater than 125 are counted. That is, the present application obtains the first gradient by counting the number of pixel values greater than 125 in each row of the horizontal gradient map, and obtains the second gradient by counting the number of pixel values greater than 125 in each row of the vertical gradient map, and the first gradient and the second gradient are characterized in the form of a peak map by projection.
[0074] It can be understood that by projecting the first gradient and the second gradient, the vertical gradient projection value and the horizontal gradient projection value are obtained, and the peak position of the gradient projection graph is found, and the vertical gradient projection peak position is determined according to the vertical gradient projection value; the horizontal gradient projection peak position is determined according to the horizontal gradient projection value, wherein the larger the gradient projection value, the greater the probability that the position is the edge area of the QR code, so the position of the gradient projection peak should be the edge position of each module in the QR code. To further illustrate the calculation results of the gradient projection peak of the present application, refer to Figure 5 The schematic diagram of the gradient projection peak is shown, where Figure (A) is a horizontal gradient projection peak diagram, and Figure (B) is a vertical gradient projection peak diagram. For example, taking a horizontal line as an example, when the grayscale difference between the top and bottom of a horizontal line is larger, for example, the top is white and the bottom is black, the greater the probability of being an edge, the greater the change in its gradient value. The sum SUM1 of the gradient values of this straight line is the above-mentioned gradient projection operation. The larger SUM1 is, the greater the probability that this straight line is an edge. When the application preliminarily counts the peaks, the maximum peak value * 0.3 can be used as the threshold a, and the peak values less than a are deleted, so as to obtain the final gradient projection peak position information, including the vertical gradient projection peak position and the horizontal gradient projection peak position.
[0075] Step S30, determining vertical grid division lines and horizontal grid division lines according to the gradient projection peak positions.
[0076] It should be noted that, first, the first initial grid division line (including the first initial vertical grid division line and the first initial horizontal grid division line) is determined according to the gradient projection peak position, and then the peaks are screened (i.e., screened from the first initial grid division line) to obtain vertical grid division lines and horizontal grid division lines. The present application screens peaks from the vertical gradient projection peak position as vertical grid division lines, and screens peaks from the horizontal gradient projection peak position as horizontal grid division lines.
[0077] In a specific implementation, horizontal grid division lines and vertical grid division lines are respectively screened out from the horizontal gradient projection peak image and the vertical gradient projection peak image.
[0078] Step S40: repairing the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain repaired grid division lines.
[0079] It should be noted that the grid line spacing between adjacent grid lines in the vertical grid lines and the horizontal grid lines is used to determine whether the grid lines need to be repaired, so that the area with the largest grid line spacing is used as the grid line area to be repaired, and the grid lines are repaired to obtain the repaired grid lines.
[0080] In a specific implementation, the grid line intervals between adjacent division lines in the initial horizontal grid division lines and the initial vertical grid division lines are respectively used to determine whether the grid division lines need to be repaired, so that the area with the largest grid line interval is used as the grid line area to be repaired, and the grid line area to be repaired includes the horizontal grid line area to be repaired and the vertical grid line area to be repaired. By performing grid division line repair on the horizontal grid line area to be repaired and the vertical grid line area to be repaired, the repaired grid division lines are obtained, and the repaired grid division lines include the horizontal grid division result and the vertical division result.
[0081] Furthermore, after step S30, it also includes: determining whether the number of vertical grid division lines and the number of horizontal grid division lines are less than a preset division order; if so, determining that the vertical grid division lines and the horizontal grid division lines need to be repaired; if not, determining that the vertical grid division lines and the horizontal grid division lines do not need to be repaired.
[0082] It should be noted that the number of vertical grid division lines and horizontal grid division lines can be determined according to a preset image division order, for example: the image is divided into uniform grids, the number of grids is the order, and the order is 21 at this time. That is, the number of vertical grid division lines and horizontal grid division lines is the order + 1. When the order is 21, the QR code is divided into grids of 21 rows and 21 columns, and each grid is sampled to obtain a 21*21 grid, which requires a total of 22*22 lines. Therefore, the number of grid lines = order + 1, that is, the grid lines need to be determined according to the order + 1, and the order + 1 grid lines are screened out by the gradient projection peak position. Before performing grid line repair, it is necessary to determine whether the number of vertical grid division lines and the number of horizontal grid division lines are less than the preset division order, where the preset division order can be an order determined according to the grid division order + 1. If the number of vertical grid division lines is less than the preset division order or the number of horizontal grid division lines is less than the preset division order, it is determined that the number of vertical grid division lines and the horizontal grid division lines need to be repaired; if the number of vertical grid division lines is not less than the preset division order or the number of horizontal grid division lines is not less than the preset division order, it is determined that the number of vertical grid division lines and the horizontal grid division lines do not need to be repaired.
[0083] It is understandable that, since the present application has two directions, vertical and horizontal, when repairing the grid division lines, it is necessary to judge the vertical and horizontal directions.
[0084] Step S50: Divide the target QR code image according to the repaired grid division lines to obtain a grid division result of the target QR code image.
[0085] It should be noted that the target QR code image is divided according to the horizontal grid division result and the vertical grid division result, and the horizontal and vertical grids are merged to obtain the grid division result of the target QR code image.
[0086] This embodiment obtains a QR code image, pre-processes the QR code image to obtain a target QR code image; determines the gradient projection peak position according to the gradient projection value in the gradient projection map of the target QR code image in different directions; determines the vertical grid division lines and the horizontal grid division lines according to the gradient projection peak position; repairs the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain the repaired grid division lines; divides the target QR code image according to the repaired grid division lines to obtain the grid division result of the target QR code image. Compared with the prior art that directly divides the QR code image into uniform sampling grids, so that the grid lines after division cannot accurately locate the edge positions of the black and white squares in the QR code, this application improves the accuracy of grid division and has stronger adaptability to deformed QR codes.
[0087] Based on the above Figure 1 The first embodiment shown in the present application proposes a second embodiment of the QR code sampling grid division method; based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as the above-mentioned first embodiment can be referred to the above introduction and will not be repeated later.
[0088] In this embodiment, step S30 also includes: dividing the gradient projection image into grids based on the vertical direction and the horizontal direction according to a preset division order, comparing the distances between the peak positions corresponding to the maximum peak values in adjacent grids in the vertical direction and the horizontal direction respectively, and judging whether the distances between the peak positions corresponding to the maximum peak values in adjacent grids are greater than a preset threshold; if so, taking the vertical gradient projection peak position and the horizontal gradient projection peak position corresponding to the maximum peak value in the adjacent grids as the vertical grid division line and the horizontal grid division line; and continuing to traverse the next grid until the peak position comparison corresponding to the maximum peak value in all grids is completed, and the vertical grid division line and the horizontal grid division line are obtained.
[0089] It should be noted that the present application divides the gradient projection image into grids based on the vertical and horizontal directions according to a preset division order. The preset division order means that when the image is divided into uniform grids, the number of grids is the order, for example: the order is 21, and the height of each grid is the image height / order. After the grids are divided, it is necessary to traverse the peaks in the grids, and compare the distances between the peak positions corresponding to the maximum peak values in adjacent grids in the vertical and horizontal directions respectively, to determine whether the distances between the peak positions corresponding to the maximum peak values in adjacent grids are greater than a preset threshold; if so, the vertical gradient projection peak position and the horizontal gradient projection peak position corresponding to the maximum peak value in the adjacent grids are used as the vertical grid division line and the horizontal grid division line; and continue to traverse the next grid until the peak position comparison corresponding to the maximum peak value in all grids is completed, and the vertical grid division line and the horizontal grid division line are obtained.
[0090] In the specific implementation, to further illustrate the initial grid division diagram of this application, please refer to Figure 6The schematic diagram of the initial grid division lines is shown, where Figure (A) is the preliminary division diagram of the horizontal grid lines, and Figure (B) is the preliminary division diagram of the vertical grid lines. In actual processing, after the grids are divided, starting from the first grid, find the peak with the largest peak value in the grid and record it as A, and the peak with the largest peak value in the next grid is B. If the distance between AB is greater than 0.5*the height of the grid, the gradient projection peak positions corresponding to the A and B peaks are used as the grid division lines, and peak B is used as the reference to continue traversing the next grid according to the preset division order. Otherwise, the grid division line corresponding to peak B is removed, and the largest peak C is found in the third grid. The distance between peak C and peak A is greater than 0.5*the height of the grid, and peak C is retained. Then peak C is used as the reference to continue traversing the next grid according to the preset division order, and this step is repeated until all grids are traversed.
[0091] In this embodiment, step S40 also includes: determining the grid to be repaired according to the grid line intervals corresponding to adjacent vertical grid division lines and horizontal grid division lines in the vertical grid division lines and the horizontal grid division lines; screening out the vertical gradient projection peak positions and the horizontal gradient projection peak positions in the grid to be repaired from the gradient projection peak positions as the repair grid lines; and repairing the vertical grid division lines and the horizontal grid division lines based on the repair grid lines to obtain the repaired grid division lines.
[0092] It should be noted that the grid to be repaired is determined according to the grid line intervals corresponding to adjacent vertical grid division lines and horizontal grid division lines in the vertical grid division lines and the horizontal grid division lines; the vertical gradient projection peak positions and the horizontal gradient projection peak positions in the grid to be repaired are screened out from the gradient projection peak positions as the repairing grid lines; the grid division lines are repaired based on the repairing grid lines to obtain the repaired grid division lines.
[0093] It is understandable that if the number of grid lines is less than the order + 1, it is determined that grid line repair is required, wherein the repair method is: find the two lines with the largest interval among the grid lines, for example: Figure 6 The second and third grid lines in the "Preliminary Horizontal Grid Line Division Diagram" shown in Figure (A) are marked as grid lines C and D, respectively. The distance between them is the largest distance between all adjacent grid lines. Figure 5It can be seen from the figure (A) "Horizontal Gradient Projection Peak Graph" that there are three peaks between CD. Find the value with the largest peak value from the three peaks as the grid line for repair. The value with the largest peak value in this application is found by storing all the peak values into an array in the previous operation, where the peak has two parameters, namely the position and the peak value. At this time, there are three peaks between CD. Assuming that the position of C is 10 and the position of D is 50, the positions of the three peaks between CD are between 10-50, which can be directly obtained from the array. Among these three peaks, find the peak with the largest peak value as the repair line. The grid division is completed by looping the above steps until the number of grid lines is equal to the order + 1. The grid repair method in the vertical direction is the same as it, so it will not be repeated. For further explanation, refer to Figure 7 The schematic diagram of the grid division results of the target QR code sampling by the repaired grid division lines is shown, wherein Figure (A) is the horizontal grid division result and Figure (B) is the vertical grid division result.
[0094] In the specific implementation, to further illustrate the execution process of this application, please refer to Figure 8 The system execution flow diagram shown in the figure, wherein the corrected QR code is subjected to vertical and horizontal gradient projection, the vertical grid division lines and the horizontal grid division lines are determined by the positions of the projection peaks, and it is determined whether the number of vertical grid division lines and horizontal grid division lines is equal to the order + 1, so as to determine whether the grid division lines need to be repaired. If so, the position with the largest peak is determined as a new grid line for repair according to the two grid lines with the largest distance interval between the vertical grid division lines, and the position with the largest peak is determined as a new grid line for repair according to the two grid lines with the largest distance interval between the horizontal grid division lines, so as to complete the grid division, so as to achieve obvious distinction between black and white blocks in the divided grid.
[0095] In this embodiment, a QR code image is acquired and preprocessed to obtain a target QR code image; a gradient projection peak position is determined according to the gradient projection value in the gradient projection map of the target QR code image in different directions; the gradient projection map is divided into grids according to a preset division order based on the vertical direction and the horizontal direction, and the distances between the peak positions corresponding to the maximum peak values in adjacent grids are compared in the vertical direction and the horizontal direction respectively, to determine whether the distances between the peak positions corresponding to the maximum peak values in adjacent grids are greater than a preset threshold; if so, the vertical gradient projection peak position and the horizontal gradient projection peak position corresponding to the maximum peak value in the adjacent grids are used as the vertical grid division line and the horizontal grid division line; And continue to traverse the next grid until the peak position comparison corresponding to the maximum peak value in all grids is completed, and the vertical grid division line and the horizontal grid division line are obtained; the grid to be repaired is determined according to the grid line interval corresponding to the adjacent vertical grid division lines and the horizontal grid division lines in the vertical grid division line and the horizontal grid division line; the vertical gradient projection peak position and the horizontal gradient projection peak position in the grid to be repaired are selected from the gradient projection peak position as the repair grid line; the vertical grid division line and the horizontal grid division line are repaired based on the repair grid line to obtain the repaired grid division line; the target QR code image is divided according to the repaired grid division line to obtain the grid division result of the target QR code image. Compared with the prior art that directly divides the QR code image into uniform sampling grids, so that the grid lines after division cannot accurately locate the edge position of the black and white squares in the QR code, the present application improves the grid division accuracy and has stronger adaptability to deformed QR codes.
[0096] Based on the first embodiment of the present application, a third embodiment of the present application is proposed. In the third embodiment of the present application, the same or similar contents as those of the above-mentioned first embodiment can be referred to the above introduction and will not be repeated later.
[0097] In this embodiment, step S50 also includes: dividing the target QR code image according to the repaired grid division lines to obtain the division results of the target QR code image in the vertical direction and the horizontal direction; merging the division results in the vertical direction and the horizontal direction to obtain the grid division result of the target QR code image.
[0098] It should be noted that the target QR code image is divided according to the repaired grid division lines to obtain the division results of the target QR code image in the vertical direction and the horizontal direction. The grid division results in the vertical direction and the grid division results in the horizontal direction are merged to obtain the grid division result of the target QR code image, that is, after obtaining the repaired vertical grid division result and the horizontal grid division result, the vertical grid and the horizontal grid are merged to obtain the merged grid division diagram of the target QR code image.
[0099] In the specific implementation, to further explain the difference between the QR code image grid division diagram in this application and the uniform grid division diagram, please refer to Fig. 9 The target QR code sampling grid division comparison schematic diagram is shown, where Figure (A) is the gradient projection grid division result, and Figure (B) is the uniform grid division result. It can be seen from the figure that the gradient projection grid division diagram is more accurate than the uniform grid division result.
[0100] This embodiment obtains a QR code image, pre-processes the QR code image to obtain a target QR code image; determines the gradient projection peak position according to the gradient projection value in the gradient projection map of the target QR code image in different directions; determines the vertical grid division line and the horizontal grid division line according to the gradient projection peak position; repairs the vertical grid division line and the horizontal grid division line according to the grid line interval corresponding to the vertical grid division line and the horizontal grid division line to obtain the repaired grid division line; divides the target QR code image according to the repaired grid division line to obtain the division results of the target QR code image in the vertical direction and the horizontal direction; merges the division results in the vertical direction and the horizontal direction to obtain the grid division result of the target QR code image. Compared with the prior art that directly divides the QR code image into uniform sampling grids, so that the grid lines after division cannot accurately locate the edge position of the black and white squares in the QR code, this application improves the grid division accuracy and has stronger adaptability to deformed QR codes.
[0101] This application also provides a QR code sampling grid division device, please refer to Fig.10 , the QR code sampling grid division device comprises:
[0102] An image acquisition module 10, used to acquire a QR code image;
[0103] A preprocessing module 20, used for preprocessing the QR code image to obtain a target QR code image;
[0104] A gradient projection module 30, used to determine the gradient projection peak position according to the gradient projection values in the gradient projection map of the target QR code image in different directions;
[0105] A grid division module 40, used to determine vertical grid division lines and horizontal grid division lines according to the gradient projection peak position;
[0106] A grid repair module 50, used to repair the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines, to obtain repaired grid division lines;
[0107] The grid division module 40 is further used to divide the target QR code image according to the repaired grid division lines to obtain a grid division result of the target QR code image.
[0108] Furthermore, the direction includes a horizontal direction and a vertical direction. The gradient projection module 30 is used to call the library function of opencv to calculate the horizontal and vertical gradients of the target QR code to obtain a horizontal gradient value and a vertical gradient value; normalize the horizontal gradient value and the vertical gradient value to obtain a first gradient and a second gradient; project the first gradient and the second gradient to obtain a vertical gradient projection value and a horizontal gradient projection value; determine the vertical gradient projection peak position according to the vertical gradient projection value; determine the horizontal gradient projection peak position according to the horizontal gradient projection value.
[0109] Furthermore, the grid repair module 50 is also used to determine whether the number of vertical grid division lines and the number of horizontal grid division lines are less than a preset division order; if so, it is determined that the vertical grid division lines and the horizontal grid division lines need to be repaired; if not, it is determined that the vertical grid division lines and the horizontal grid division lines do not need to be repaired.
[0110] Furthermore, the grid division module 40 is also used to divide the gradient projection image into grids based on the vertical direction and the horizontal direction according to a preset division order, and compare the distances between the peak positions corresponding to the maximum peak values in adjacent grids in the vertical direction and the horizontal direction respectively, to determine whether the distances between the peak positions corresponding to the maximum peak values in adjacent grids are greater than a preset threshold; if so, the vertical gradient projection peak position and the horizontal gradient projection peak position corresponding to the maximum peak value in the adjacent grids are used as the vertical grid division line and the horizontal grid division line; and continue to traverse the next grid until the peak position comparison corresponding to the maximum peak value in all grids is completed, and the vertical grid division line and the horizontal grid division line are obtained.
[0111] Furthermore, the grid repair module 50 is also used to determine the grid to be repaired based on the grid line intervals corresponding to adjacent vertical grid division lines and horizontal grid division lines in the vertical grid division lines and the horizontal grid division lines; select the vertical gradient projection peak position and the horizontal gradient projection peak position in the grid to be repaired from the gradient projection peak position as the repair grid lines; and repair the vertical grid division lines and the horizontal grid division lines based on the repair grid lines to obtain the repaired grid division lines.
[0112] Furthermore, the grid division module 40 is also used to divide the target QR code image according to the repaired grid division lines to obtain the division results of the target QR code image in the vertical and horizontal directions; and merge the division results in the vertical and horizontal directions to obtain the grid division results of the target QR code image.
[0113] The QR code sampling grid division device provided by the present application adopts the QR code sampling grid division method in the above embodiment, which can solve the technical problem of QR code sampling grid division. Compared with the prior art, the beneficial effects of the QR code sampling grid division device provided by the present application are the same as the beneficial effects of the QR code sampling grid division method provided by the above embodiment, and other technical features in the QR code sampling grid division device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0114] The present application provides a QR code sampling grid division device, the QR code sampling grid division device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the QR code sampling grid division method in the first embodiment described above.
[0115] Reference below Fig.11 , which shows a schematic diagram of the structure of a QR code sampling grid division device suitable for implementing the embodiment of the present application. The QR code sampling grid division device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The QR code sampling grid division device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0116] like Fig.11As shown, the QR code sampling grid division device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the QR code sampling grid division device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems may be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 may allow the QR code sampling grid division device to communicate wirelessly or wired with other devices to exchange data. Although the QR code sampling grid division device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.
[0117] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0118] The QR code sampling grid division device provided by the present application adopts the QR code sampling grid division method in the above embodiment, which can solve the technical problem of QR code sampling grid division. Compared with the prior art, the beneficial effects of the QR code sampling grid division device provided by the present application are the same as the beneficial effects of the QR code sampling grid division method provided by the above embodiment, and the other technical features in the QR code sampling grid division device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0119] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0120] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0121] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the QR code sampling grid division method in the above-mentioned embodiment.
[0122] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0123] The computer-readable storage medium may be included in the QR code sampling grid division device; or may exist independently without being assembled into the QR code sampling grid division device.
[0124] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the QR code sampling grid division device, the QR code sampling grid division device: When the QR code sampling grid division device is executed, the QR code sampling grid division device: obtains a QR code image, pre-processes the QR code image to obtain a target QR code image; determines a gradient projection peak position according to a gradient projection value in a gradient projection map of the target QR code image in different directions; determines vertical grid division lines and horizontal grid division lines according to the gradient projection peak position; repairs the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain repaired grid division lines; divides the target QR code image according to the repaired grid division lines to obtain a grid division result of the target QR code image.
[0125] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0126] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0127] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0128] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned QR code sampling grid division method, and can solve the technical problem of QR code sampling grid division. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the QR code sampling grid division method provided in the above-mentioned embodiment, and will not be repeated here.
[0129] The above are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A QR code sampling grid division method, characterized in that: The QR code sampling grid division method comprises: Acquire a QR code image, and preprocess the QR code image to obtain a target QR code image; Determine the gradient projection peak position according to the gradient projection value in the gradient projection map of the target QR code image in different directions; Determine vertical grid division lines and horizontal grid division lines according to the gradient projection peak positions; Repairing the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain repaired grid division lines; The target QR code image is divided according to the repaired grid division lines to obtain a grid division result of the target QR code image.
2. The QR code sampling grid division method according to claim 1, characterized in that: The directions include horizontal and vertical directions, and the step of determining the gradient projection peak position according to the gradient projection values in the gradient projection map of the target QR code image in different directions includes: Call the opencv library function to calculate the horizontal and vertical gradients of the target QR code to obtain the horizontal gradient value and the vertical gradient value; Normalizing the horizontal gradient value and the vertical gradient value to obtain a first gradient and a second gradient; Projecting the first gradient and the second gradient to obtain a vertical gradient projection value and a horizontal gradient projection value; Determine the vertical gradient projection peak position according to the vertical gradient projection value; The horizontal gradient projection peak position is determined according to the horizontal gradient projection value.
3. The method according to claim 1, characterized in that After the step of determining the vertical grid division lines and the horizontal grid division lines according to the gradient projection peak positions, the method further includes: Determine whether the number of the vertical grid division lines and the number of the horizontal grid division lines are less than a preset division order; If yes, it is determined that the vertical grid division lines and the horizontal grid division lines need to be repaired; If not, it is determined that the vertical grid division lines and the horizontal grid division lines do not need to be repaired.
4. The method according to claim 2, characterized in that The step of determining vertical grid division lines and horizontal grid division lines according to the gradient projection peak positions comprises: Divide the gradient projection image into grids according to a preset division order based on the vertical direction and the horizontal direction, and compare the distances between the peak positions corresponding to the maximum peak values in adjacent grids in the vertical direction and the horizontal direction respectively, to determine whether the distances between the peak positions corresponding to the maximum peak values in adjacent grids are greater than a preset threshold; If so, the vertical gradient projection peak position and the horizontal gradient projection peak position corresponding to the maximum peak value in the adjacent grids are used as the vertical grid division line and the horizontal grid division line; and continue to traverse the next grid until the peak position comparison corresponding to the maximum peak value in all the grids is completed to obtain the vertical grid division line and the horizontal grid division line.
5. The method according to claim 1, characterized in that The step of repairing the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines to obtain the repaired grid division lines comprises: Determine a grid to be repaired according to grid line intervals corresponding to adjacent vertical grid division lines and horizontal grid division lines among the vertical grid division lines and the horizontal grid division lines; Filter out the vertical gradient projection wave peak position and the horizontal gradient projection wave peak position in the grid to be repaired from the gradient projection wave peak position as the repair grid line; The vertical grid division lines and the horizontal grid division lines are repaired based on the repairing grid lines to obtain the repaired grid division lines.
6. The method according to claim 1, characterized in that The step of dividing the target QR code image according to the repaired grid division lines to obtain a grid division result of the target QR code image includes: Dividing the target QR code image according to the repaired grid division lines to obtain division results of the target QR code image in the vertical direction and the horizontal direction; The division results in the vertical direction and the horizontal direction are combined to obtain a grid division result of the target QR code image.
7. A QR code sampling grid division device, characterized in that: The device comprises: An image acquisition module, used to acquire a QR code image; A preprocessing module, used for preprocessing the QR code image to obtain a target QR code image; A gradient projection module, used to determine the gradient projection peak position according to the gradient projection values in the gradient projection map of the target QR code image in different directions; A grid division module, used to determine vertical grid division lines and horizontal grid division lines according to the gradient projection peak position; A grid repair module, used to repair the vertical grid division lines and the horizontal grid division lines according to the grid line intervals corresponding to the vertical grid division lines and the horizontal grid division lines, to obtain repaired grid division lines; The grid division module is further used to divide the target QR code image according to the repaired grid division lines to obtain a grid division result of the target QR code image.
8. A QR code sampling grid division device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the QR code sampling grid division method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the QR code sampling grid division method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the QR code sampling grid division method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Sampling grid partitioning method and sampling grid partitioning device for matrix two-dimensional barcode
CN106909869A
Two-dimensional code image restoration method, device, computer equipment and storage medium
CN111539238A
Display grid repairing method and device, equipment and storage medium
CN116740321A
Printing medium, information processing method and information processing apparatus
JP2014209799A
Image control device, patch chart, and non-transitory computer readable medium
US20180139357A1
Cited By
Two-dimensional code image correction method and device, equipment and storage medium
CN120524965A
Two-dimensional code image correction method, device and equipment and storage medium
CN120524965B
