A fast QR code positioning method

By introducing coarse positioning and fine positioning steps into the QR code positioning method, combined with HOG features and SVM classifier, rapid recognition of QR codes is achieved, solving the problems of slow and non-real-time positioning of QR codes in the existing technology. , improving recognition efficiency and stability.

CN113688649BActive Publication Date: 2024-09-13JIANGSU BOSAIFU MEDICAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110936157.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-16
Publication Date
2024-09-13
Estimated Expiration
2041-08-16

AI Technical Summary

Technical Problem

Existing QR code positioning methods are slow during pathological sectioning and cannot achieve real-time recognition, especially when multiple QR codes exist.

Method used

A step-by-step method of coarse positioning and fine positioning is adopted, HOG features and SVM classifier are used for image preprocessing, edge extraction and classification, the decoding area is initially separated, and rapid QR code positioning is achieved through affine transformation and decoding.

Benefits of technology

It improves the speed and stability of QR code positioning, can effectively handle multiple QR codes, realize real-time recognition, and overcomes the shortcomings of slow speed and non-real-time in traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113688649B
    Figure CN113688649B
Patent Text Reader

Abstract

The present invention discloses a fast QR code positioning method, the steps are: inputting an image with a two-dimensional code; roughly positioning the two-dimensional code in the image, extracting a decoding area from a complex working background of the image, preliminarily separating the working background from the decoding area, and accurately isolating each decoding area when there are multiple areas to be decoded in the input image; accurately finding a positioning pattern in the decoding area, and precisely positioning the two-dimensional code in the image; performing an affine transformation on the precisely positioned two-dimensional code; decoding the two-dimensional code after the affine transformation; and outputting the information in the two-dimensional code in the image. The present invention can effectively reduce the influence of environmental noise, improve the stability of two-dimensional code positioning, reduce the processing area of ​​the precise positioning algorithm, greatly improve the speed of the algorithm, and enable the algorithm to well adapt to the situation where there are multiple two-dimensional codes on a picture, and realize the simultaneous reading of multiple two-dimensional codes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of computer software, and in particular relates to a fast QR code positioning method. Background Art

[0002] The two-dimensional code (QR code) was born in the 1940s and was designed to solve the problem of insufficient information capacity of one-dimensional barcodes. With the introduction of error correction codes in the two-dimensional code encoding technology, the decoding success rate of the two-dimensional code has been greatly increased. Even the information in the stained, defective, and blurred two-dimensional code can be restored through decoding technology. Since the existing two-dimensional code is a mature information interaction protocol based on vision, a relatively mature encoding method, and it makes full use of the information in the two-dimensional space and is based on error correction code encoding, taking into account the advantages of large information volume and high stability, it is widely used in various industries.

[0003] At present, in the process of making pathological sections, especially hard tissue sections, a large number of QR codes are used as the ID of the sections, and the QR code recognition speed is required to be faster, the operation is more stable, and continuous real-time recognition is required. However, most of the traditional QR code recognition libraries are based on single recognition, that is, first search the whole image for the positioning mark of the QR code to locate the QR code, and then recognize the QR code (such as Figure 1 This will result in low code reading efficiency and fail to meet the real-time requirements. Summary of the invention

[0004] In order to overcome the shortcomings of the existing two-dimensional code positioning, which is slow and cannot meet the real-time requirements, the present invention provides a fast QR code positioning method, which increases the coarse positioning step to remove environmental noise to improve the algorithm stability and reduce the positioning pattern search area to improve the algorithm speed. At the same time, it can effectively realize the function of simultaneous positioning of multiple two-dimensional codes.

[0005] In order to solve the above technical problems and achieve the above technical effects, the present invention is implemented through the following technical solutions:

[0006] A fast QR code positioning method includes the following steps:

[0007] S1. Input an image with a QR code;

[0008] S2, roughly locate the QR code in the image, its work content is,

[0009] Extract the decoding area from the complex working background of the image, preliminarily separate the working background from the decoding area, and accurately isolate each decoding area when there are multiple areas to be decoded in the input image, in preparation for the next step of precise positioning;

[0010] S3, accurately find the positioning pattern in the decoding area and accurately locate the QR code in the image;

[0011] S4, performing affine transformation on the precisely positioned QR code;

[0012] S5, decoding the two-dimensional code after affine transformation;

[0013] S6. Output the information in the QR code in the image.

[0014] Furthermore, in step S2, the algorithm for coarse positioning of the QR code is to use HOG as the feature and the SVM classifier to perform a rapid full-image search of the incoming real-time image, preliminarily locate each area to be decoded in the image, and provide a reliable algorithm for the next step of precise positioning and correction of the QR code.

[0015] Furthermore, the implementation method of the coarse positioning of the QR code is as follows:

[0016] S2.1, input image;

[0017] S2.2, preprocessing the input image;

[0018] S2.3, extracting edges from the preprocessed image;

[0019] S2.4, dividing the preprocessed image and the edge-extracted image into small area images respectively;

[0020] S2.5, pre-filtering each small area image of the image after edge extraction to shorten the detection time;

[0021] S2.6, extracting HOG features of edge points of all small area images;

[0022] S2.7, using the SVM classifier to classify the HOG features of the edge points of each small area image into code areas and non-code areas, and obtain the classification results;

[0023] S2.8. Based on the classification results, use connected domain analysis to determine the QR code area;

[0024] S2.9. Output the rough positioning result of the QR code.

[0025] Furthermore, in step S2.2, the image preprocessing method is to convert the input RGB color image into a grayscale image with 256 gray levels to prepare for the next step of image edge extraction.

[0026] Furthermore, in step S2.3, the method for extracting the edge of the image is to perform Canny edge detection on the grayscale image of the preprocessed image to obtain an edge map having edge point information of the entire image.

[0027] Furthermore, in step S2.4, the method for segmenting the image into small block regions is to segment the grayscale image and the edge image of the image into small block region images of the same size and without overlap.

[0028] Furthermore, in step S2.5, the method of pre-filtering the small area image is to draw a conclusion that a threshold is set according to the ratio of edge points in each small area image for identification based on the black and white decoding area characteristics in the two-dimensional code;

[0029] The edge point ratio is calculated as follows:

[0030]

[0031] Among them, BE is the edge point ratio, patch_pixels is the total number of pixels in each small area image, and all_edges is the number of edge points in each small area image.

[0032] Furthermore, in step S2.6, the method for extracting HOG features of edge points of small area images is to use the small area images containing only edge point information obtained by Canny edge detection to perform gradient direction statistics on the pixels containing edge points.

[0033] Furthermore, in step S2.7, the method for classifying the code area and the non-code area is to use the edge point HOG of the small area image as a feature, and use the SVM classifier to train the training data set in advance. After obtaining the training model, the training model can be directly used to classify the sample into the code area and the non-code area when reading the code to obtain the classification result.

[0034] Furthermore, in step S2.8, the method for determining the QR code area is to divide the QR code area marked on the classification result map into blocks according to the method of dividing the connected domain, find the maximum circumscribed rectangle of each connected domain, and thus extract multiple rectangular frames as candidate areas of the QR code.

[0035] The beneficial effects of the present invention are:

[0036] The present invention improves on the traditional two-dimensional code positioning method, splits the original positioning method into two steps of coarse positioning and fine positioning, can effectively reduce the influence of environmental noise, improve the stability of two-dimensional code positioning, and reduce the processing area of ​​the fine positioning algorithm, greatly improve the speed of the algorithm, and at the same time enable the algorithm to adapt well to the situation where there are multiple two-dimensional codes on a picture, and realize simultaneous reading of multiple two-dimensional codes. Therefore, the present invention overcomes the shortcomings of the existing two-dimensional code positioning that the speed is slow and cannot meet the real-time requirements.

[0037] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention and implement it according to the contents of the specification, the preferred embodiments of the present invention are described in detail below. The specific implementation of the present invention is given in detail by the following embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0039] Figure 1 It is a flow chart of the QR code positioning method of the prior art;

[0040] Figure 2 It is a flow chart of the two-dimensional code positioning method of the present invention;

[0041] Figure 3 It is a flow chart of the method for rough positioning of a two-dimensional code in the present invention;

[0042] Figure 4 The present invention shows a regional sample image (a) and an edge point HOG feature map image (b) when extracting edge point HOG features. DETAILED DESCRIPTION

[0043] The present invention will be described in detail below in conjunction with the embodiments. The descriptions herein are used to provide a further understanding of the present invention and constitute a part of this application. The illustrative embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0044] See also Figure 2 As shown, a fast QR code positioning method includes the following steps:

[0045] S1. Input an image with a QR code.

[0046] S2, roughly locate the QR code in the image, its work content is,

[0047] The decoding area is extracted from the complex working background of the image, the working background is initially separated from the decoding area, and when there are multiple areas to be decoded in the input image, each decoding area is accurately isolated to prepare for the next step of precise positioning.

[0048] The algorithm for rough positioning of the QR code is to use HOG as a feature and SVM classifier to quickly search the entire image of the incoming real-time image, preliminarily locate each area to be decoded in the image, and provide a reliable algorithm for the next step of precise positioning and correction of the QR code. Among them, HOG (Histogram of Oriented Gradient) is a description operator that can be based on shape edge features. It has good rotation invariance and illumination invariance, and can describe the local texture features of the image. This feature has good discrimination between the code area and the non-code area of ​​the QR code; its idea is to calculate the direction and amplitude of the pixel point, count its gradient histogram, and use the histogram as a feature value, and directly use it for classification detection on the SVM classifier.

[0049] See also Figure 3 As shown in the figure, the implementation method of the coarse positioning of the QR code is as follows:

[0050] S2.1, input image;

[0051] S2.2, preprocessing the input image;

[0052] Convert the incoming RGB color image into a grayscale image with 256 gray levels to prepare for the next step of edge extraction of the image; this can greatly reduce the memory usage of the algorithm processing while removing some redundant information that is not needed for the algorithm detection, thereby increasing the information density and reducing the computing cost;

[0053] S2.3, extracting edges from the preprocessed image;

[0054] Canny edge detection is performed on the grayscale image of the preprocessed image to obtain an edge map with edge point information of the entire image; the Canny algorithm is a complete edge detection algorithm that uses Gaussian filtering to smooth the image and has strong noise resistance. It uses the finite difference of the first-order partial derivative to calculate the amplitude and direction of the gradient, performs non-maximum suppression on the gradient amplitude, uses dual threshold detection and edge connection, uses two different thresholds to detect strong edges and weak edges respectively, and only includes the weak edge in the output image when it is connected to the strong edge, thereby improving the performance of edge detection;

[0055] S2.4, dividing the preprocessed image and the edge-extracted image into small area images respectively;

[0056] The grayscale image and the edge image of the image are divided into small area images of the same size (32*32) and without overlap;

[0057] S2.5, pre-filtering each small area image of the edge map to shorten the detection time;

[0058] According to the characteristics of the black and white decoding area in the QR code, it is concluded that the threshold is set according to the ratio of edge points in each small area image for identification; the calculation formula of the edge point ratio is as follows:

[0059]

[0060] Among them, BE is the edge point ratio, patch_pixels is the total number of pixels in each small area image, and all_edges is the number of edge points in each small area image;

[0061] S2.6, extracting HOG features of edge points of each small area image of the edge map and grayscale image;

[0062] The classic HOG feature has a lot of redundancy in the feature extraction of the two-dimensional code area, so the present invention further improves the algorithm. The present invention abandons the classic HOG feature and directly performs HOG feature statistics on the edge points of each small area image, see Figure 4 As shown, Figure 4 In the figure, a represents the regional sample image, and b is the edge point HOG feature image; the edge information features with high discriminability are extracted to achieve a more robust positioning of the one-dimensional code area in a complex background; the implementation method is to use the small area image containing only edge point information obtained by Canny edge detection to perform gradient direction statistics on the pixel points containing edge points; if the number of gradient direction intervals is set to 18, (0°, 180°) can be divided into a small area every 10° for summing statistics;

[0063] S2.7, using the SVM classifier to classify the HOG features of the edge points of each small area image into code areas and non-code areas, and obtain the classification results;

[0064] Use the edge point HOG of a small area image as a feature, use the SVM classifier to train the training data set in advance, and after obtaining the training model, you can directly use the training model to classify the sample into the code area and the non-code area when reading the code to obtain the classification result; the SVM classifier can be used for the classification of linear / non-linear features, and can also be used for regression problems. It has a low generalization error rate and good learning ability, and the learned results have good generalizability. The SVM classifier can not only solve machine learning problems in small sample cases, but also solve high-dimensional problems, and can avoid neural network structure selection and local minimum point problems. It is the best ready-made classifier. Ready-made means that it can be used directly without modification, and can obtain a lower error rate, and can make good classification decisions for data points outside the training set;

[0065] S2.8. Based on the classification results, use connected domain analysis to determine the QR code area;

[0066] The QR code area marked on the classification result map is divided into blocks by the method of dividing connected domains, and the maximum circumscribed rectangle of each connected domain is found, so as to extract multiple rectangular frames as candidate areas of the QR code; finally, it is only necessary to read the code in the candidate area, with the purpose of solving the problem of recognizing multiple QR codes in one image, which can greatly reduce the reading time.

[0067] S2.9. Output the rough positioning result of the QR code.

[0068] S3. Accurately search for the positioning pattern in the decoding area and precisely locate the QR code in the image.

[0069] S4. Perform affine transformation on the precisely positioned QR code.

[0070] S5. Decode the two-dimensional code after affine transformation.

[0071] S6. Output the information in the QR code in the image.

[0072] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A fast QR code positioning method, characterized in that: The following steps are involved: S1. Input an image with a QR code; S2, roughly locate the QR code in the image, its work content is, Extract the decoding area from the complex working background of the image, preliminarily separate the working background from the decoding area, and accurately isolate each decoding area when there are multiple areas to be decoded in the input image, in preparation for the next step of precise positioning; The algorithm for rough positioning of the QR code is to use HOG as the feature and SVM classifier to quickly search the entire image of the incoming real-time image, preliminarily locate each area to be decoded in the image, and provide a reliable algorithm for the next step of precise positioning and correction of the QR code; The implementation method of the QR code coarse positioning is as follows: S2.1, input image; S2.2, preprocessing the input image; The image preprocessing method is to convert the incoming RGB color image into a grayscale image with 256 gray levels to prepare for the next step of image edge extraction; S2.3, extracting edges from the preprocessed image; The method of image edge extraction is to perform Canny edge detection on the grayscale image of the preprocessed image to obtain an edge map with edge point information of the entire image; S2.4, dividing the preprocessed image and the edge-extracted image into small area images respectively; The method of image segmentation of small block regions is to segment the grayscale image and the edge image of the image into small block images of the same size and without overlap; S2.5, pre-filtering each small area image of the image after edge extraction; The method of pre-filtering the small area image is to draw the conclusion that the threshold is set according to the ratio of edge points in each small area image for identification based on the black and white decoding area characteristics in the two-dimensional code; The edge point ratio is calculated as follows: ; Among them, BE is the edge point ratio, patch_pixels is the total number of pixels in each small area image, and all_edges is the number of edge points in each small area image; S2.6, extracting HOG features of edge points of all small area images; S2.7, using the SVM classifier to classify the HOG features of the edge points of each small area image into code areas and non-code areas, and obtain the classification results; S2.

8. Based on the classification results, use connected domain analysis to determine the QR code area; S2.9, output the rough positioning result of the QR code; S3, accurately find the positioning pattern in the decoding area and accurately locate the QR code in the image; S4, performing affine transformation on the precisely positioned QR code; S5, decoding the two-dimensional code after affine transformation; S6. Output the information in the QR code in the image.

2. The QR code positioning method according to claim 1, characterized in that: In step S2.6, the method for extracting the HOG features of the edge points of the small area image is to use the small area image containing only edge point information obtained by Canny edge detection to perform gradient direction statistics on the pixel points containing the edge points.

3. The QR code positioning method according to claim 2, characterized in that: In step S2.7, the method for classifying the code area and the non-code area is to use the edge point HOG of the small area image as a feature, use the SVM classifier to train the training data set in advance, and after obtaining the training model, the training model can be directly used to classify the sample into the code area and the non-code area when reading the code to obtain the classification result.

4. The QR code positioning method according to claim 3, characterized in that: In step S2.8, the method for determining the QR code area is to divide the QR code area marked on the classification result map into blocks according to the method of dividing the connected domain, find the maximum circumscribed rectangle of each connected domain, and thus extract multiple rectangular frames as candidate areas of the QR code.