CN117474771A - Two-dimensional code identification method, device and equipment - Google Patents

Two-dimensional code identification method, device and equipment Download PDF

Info

Publication number
CN117474771A
CN117474771A CN202311449489.6A CN202311449489A CN117474771A CN 117474771 A CN117474771 A CN 117474771A CN 202311449489 A CN202311449489 A CN 202311449489A CN 117474771 A CN117474771 A CN 117474771A
Authority
CN
China
Prior art keywords
dimensional code
image
code image
target
pixel point
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311449489.6A
Other languages
Chinese (zh)
Inventor
钱敏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Weipu Technology Co ltd
Original Assignee
Shenzhen Weipu Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Weipu Technology Co ltd filed Critical Shenzhen Weipu Technology Co ltd
Priority to CN202311449489.6A priority Critical patent/CN117474771A/en
Publication of CN117474771A publication Critical patent/CN117474771A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T3/00Geometric image transformations in the plane of the image
    • G06T3/40Scaling of whole images or parts thereof, e.g. expanding or contracting
    • G06T3/4007Scaling of whole images or parts thereof, e.g. expanding or contracting based on interpolation, e.g. bilinear interpolation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K7/00Methods or arrangements for sensing record carriers, e.g. for reading patterns
    • G06K7/10Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
    • G06K7/14Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation using light without selection of wavelength, e.g. sensing reflected white light
    • G06K7/1404Methods for optical code recognition
    • G06K7/1408Methods for optical code recognition the method being specifically adapted for the type of code
    • G06K7/14172D bar codes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/20Image enhancement or restoration using local operators

Landscapes

  • Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Electromagnetism (AREA)
  • General Health & Medical Sciences (AREA)
  • Toxicology (AREA)
  • Artificial Intelligence (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Image Processing (AREA)

Abstract

The application relates to the technical field of image recognition, in particular to a method, a device and equipment for recognizing a two-dimensional code. According to the scheme, the problem that the two-dimensional code cannot be accurately analyzed due to the fact that the acquired two-dimensional code image is defective is solved.

Description

Two-dimensional code identification method, device and equipment
Technical Field
The present disclosure relates to the field of image recognition technologies, and in particular, to a method, an apparatus, and a device for recognizing a two-dimensional code.
Background
The two-dimensional code is a matrix-type two-dimensional bar code for storing data, which can encode data in the vertical and horizontal directions. In computer vision and image processing, two-dimensional codes are graphs which are distributed on a plane according to a certain rule by using a certain specific geometric figure, are black-white and are alternately arranged, and record data symbol information. Two-dimensional codes have become a data storage and identification technology widely used in various fields.
Two-dimensional codes have some commonalities in barcode technology: each code system has a specific character set, and each character occupies a certain width and has a certain verification function and the like. In two-dimensional code image recognition, a computer is used for processing and analyzing the image, and the characteristics in the image are extracted and matched, so that targets and objects in the image are recognized. People decode and read information stored in the two-dimensional code by using a camera device or an application program.
The success rate of two-dimensional code image recognition is mainly determined by the quality of the two-dimensional code in the image, and noise, light source, camera position and other factors can cause the two-dimensional code to be distorted, inclined, missing and other phenomena. In practical application of the two-dimensional code, the two-dimensional code is damaged, polluted, blurred and the like usually caused by various natural unreliability and human factors. If the acquired two-dimensional code image has defects, the two-dimensional code may not be correctly analyzed, and the situation is to be improved.
Disclosure of Invention
In order to improve the situation that the acquired two-dimensional code image is defective and cannot be analyzed correctly, the application provides a two-dimensional code identification method, device and equipment.
In a first aspect, the present application provides a method for identifying a two-dimensional code, including:
performing image preprocessing on the initial two-dimensional code image to obtain a target two-dimensional code image;
determining position information of damaged pixel points in the target two-dimensional code image;
determining an interpolation area corresponding to the damaged pixel point according to the position information;
calculating a target pixel value of the damaged pixel point according to the pixel value of each pixel point in the interpolation area;
repairing the damaged pixel point according to the target pixel value to obtain a repaired two-dimensional code image;
and identifying the repaired two-dimensional code image.
By adopting the technical scheme, in the practical application of the two-dimensional code, the defects of damage, dirt, blurring and the like of the two-dimensional code are usually caused by various natural unreliability and human factors. In order to accurately analyze the two-dimensional code with defects, firstly, performing image preprocessing on an initial two-dimensional code image, and performing image enhancement on the initial two-dimensional code image to obtain a target two-dimensional code image; secondly, determining the position information of damaged pixel points in the target two-dimensional code image, and determining an interpolation area corresponding to the damaged pixel points according to the position information; then, calculating a target pixel value of the damaged pixel point according to the pixel value of each pixel point in the interpolation area, repairing the damaged pixel point according to the target pixel value to obtain a repaired two-dimensional code image, and finally identifying the repaired two-dimensional code image; the method and the device have the advantages that the preprocessing work of image enhancement is carried out on the two-dimensional code image before the two-dimensional code image is identified, the preprocessed image is restored, the restored two-dimensional code image is obtained, the restored two-dimensional code image is identified, and the situation that the two-dimensional code cannot be accurately analyzed due to the fact that the acquired two-dimensional code image is defective can be improved.
Optionally, the determining the location information of the damaged pixel point in the target two-dimensional code image includes:
determining an image average gray value corresponding to the target two-dimensional code image;
judging whether abnormal pixel points exist in the target two-dimensional code image according to the image average gray value;
if the abnormal pixel point exists in the target two-dimensional code image, determining the position information of the abnormal pixel point as the position information of the damaged pixel point
By adopting the technical scheme, in order to determine the position information of the damaged pixel point in the target two-dimensional code image, firstly, determining an image average gray value corresponding to the target two-dimensional code image, and secondly, judging whether an abnormal pixel point exists in the target two-dimensional code image according to the image average gray value, for example, if the difference value between the pixel value of the pixel point and the image average gray value is larger than or smaller than a preset range, determining the pixel point as the abnormal pixel point; and finally, when the abnormal pixel point exists in the target two-dimensional code image, determining the position information of the abnormal pixel point as the position information of the damaged pixel point.
Optionally, the determining whether the abnormal pixel point exists in the target two-dimensional code image according to the image average gray value includes:
determining a pixel value of each pixel point in the target two-dimensional code image;
calculating the difference value between the pixel value of each pixel point and the average gray value of the image to obtain a difference value set;
judging whether a target difference value larger than a preset threshold exists in the difference value set;
if the target difference value larger than a preset threshold exists in the difference value set, determining the pixel point corresponding to the target difference value as an abnormal pixel point.
By adopting the technical scheme, in the link of judging whether the abnormal pixel point exists in the target two-dimensional code image according to the image average gray value, firstly determining the pixel value of each pixel point in the target two-dimensional code image, then calculating the difference value between the pixel value of each pixel point and the image average gray value to obtain a difference value set, and determining the pixel point corresponding to the target difference value as the abnormal pixel point when the target difference value larger than the preset threshold exists in the difference value set; according to the scheme, whether the pixel point is an abnormal pixel point or not is judged by calculating the difference value between each pixel point and the average gray value of the image, so that the accuracy of distinguishing the abnormal pixel point is improved.
Optionally, the determining the location information of the damaged pixel point in the target two-dimensional code image includes:
detecting whether a hole or a corner exists in the target two-dimensional code image;
if the position information of the hole or the corner exists in the target two-dimensional code image, determining the position information of the hole or the corner as the position information of the damaged pixel point.
By adopting the technical scheme, in order to determine the position information of the damaged pixel point in the target two-dimensional code image, whether a hole or a corner exists in the target two-dimensional code image is detected; in image processing, a hole generally refers to a blank area in an image, i.e., an area where the pixel value is zero; corner refers to a salient feature point with an angle in the image; when the hole or the corner exists in the target two-dimensional code image, determining the position information of the hole or the corner as the position information of the damaged pixel point.
Optionally, the performing image preprocessing on the initial two-dimensional code image to obtain a target two-dimensional code image includes:
performing noise reduction treatment on the initial two-dimensional code image to obtain a noise reduction treatment image;
performing contrast enhancement processing on the noise reduction processing image to obtain an enhanced display image;
and sharpening the enhanced display image to obtain the target two-dimensional code image.
By adopting the technical scheme, the process of preprocessing the initial two-dimensional code image to obtain the target two-dimensional code image comprises the following specific processes of: firstly, carrying out noise reduction treatment on an initial two-dimensional code image to obtain a noise reduction treatment image, secondly, carrying out contrast enhancement treatment on the noise reduction treatment image to obtain an enhanced display image, and carrying out sharpening on the enhanced display image to obtain a target two-dimensional code image.
Optionally, before performing image preprocessing on the initial two-dimensional code image to obtain the target two-dimensional code image, the method includes:
acquiring an image to be identified containing a two-dimensional code;
and extracting the initial two-dimensional code image in the image to be identified.
By adopting the technical scheme, the image to be identified containing the two-dimension code is firstly obtained, an initial two-dimension code image in the image to be identified is extracted, and then the initial two-dimension code image is subjected to image preprocessing to obtain a target two-dimension code image; the image to be identified can be a two-dimensional code image, or a partial area in the image to be identified is a two-dimensional code image.
Optionally, the identifying the repair two-dimensional code image includes:
searching a positioning pattern and a calibration pattern from the repair two-dimensional code image;
determining a data area of the repair two-dimensional code image according to the positioning pattern and the calibration pattern;
analyzing the data area to obtain initial binary area data corresponding to the data area;
analyzing the initial binary data according to a preset error correction code and a two-dimensional code coding rule to obtain the original data corresponding to the initial two-dimensional code image.
By adopting the technical scheme, in the process of identifying the repaired two-dimensional code image, firstly, searching a positioning pattern and a calibration pattern from the repaired two-dimensional code image, determining a data area of the repaired two-dimensional code image based on the positioning pattern and the calibration pattern, wherein the data area refers to a part of the two-dimensional code image containing actual coding information, secondly, analyzing the data area to obtain initial binary area data, wherein the initial binary area data corresponds to the data area, and finally, analyzing the initial binary data according to a preset error correction code and a two-dimensional code coding rule to obtain original data corresponding to the initial two-dimensional code image.
Optionally, the parsing the data area to obtain initial binary area data corresponding to the data area includes:
dividing a module in the data area into a plurality of cells;
and determining the initial binary data corresponding to the cells according to the color information and the coding rule of the module.
By adopting the technical scheme, the module in the data area is divided into a plurality of cells, each cell has the same size, but the representative data are different, the specific content comprises but is not limited to format information, version information, error correction codes, data codes and the like, then each cell is analyzed, namely the two-dimensional code is analyzed, and specifically, the initial binary data corresponding to the cells is determined according to the color information and the coding rule of the module.
In a second aspect, the present application provides a device for identifying a two-dimensional code, including:
the preprocessing module is used for preprocessing the initial two-dimensional code image to obtain a target two-dimensional code image;
the first positioning module is used for determining the position information of the damaged pixel point in the target two-dimensional code image;
the second positioning module is used for determining an interpolation area corresponding to the damaged pixel point according to the position information;
the processing module is used for calculating the target pixel value of the damaged pixel point according to the pixel value of each pixel point in the interpolation area;
the repair module is used for repairing the damaged pixel points according to the target pixel values so as to obtain a repaired two-dimensional code image;
and the identification module is used for identifying the repair two-dimensional code image.
By adopting the technical scheme, in order to accurately analyze the two-dimensional code with the defects, firstly, an initial two-dimensional code image is subjected to image preprocessing by a preprocessing module, namely, the initial two-dimensional code image is subjected to image enhancement, so that a target two-dimensional code image is obtained; secondly, determining the position information of damaged pixel points in the target two-dimensional code image through a first positioning module, and determining an interpolation area corresponding to the damaged pixel points through a second positioning module according to the position information; then, calculating a target pixel value of the damaged pixel point according to the pixel value of each pixel point in the interpolation region by a processing module, repairing the damaged pixel point according to the target pixel value by a repairing module to obtain a repaired two-dimensional code image, and finally identifying the repaired two-dimensional code image by an identification module; the method and the device have the advantages that the preprocessing work of image enhancement is carried out on the two-dimensional code image before the two-dimensional code image is identified, the preprocessed image is repaired, the repaired two-dimensional code image is obtained, and the repaired two-dimensional code image is identified, so that the two-dimensional code image with defects can still be analyzed, and therefore the situation that the two-dimensional code cannot be analyzed correctly due to the fact that the acquired two-dimensional code image is defective can be improved.
In a third aspect, the present application provides an electronic device comprising a memory and a processor, the memory having stored thereon a computer program capable of being loaded by the processor and performing the method of two-dimensional code identification according to the first aspect.
In summary, it can be seen that in the embodiment provided by the present application, in practical application of the two-dimensional code, defects such as breakage, dirt, and blurring may occur in the two-dimensional code generally due to various natural unreliability and human factors. In order to accurately analyze the two-dimensional code with defects, preprocessing the two-dimensional code image for image enhancement is performed before the two-dimensional code image is identified, then position information of damaged pixel points and interpolation areas corresponding to the damaged pixel points are determined, target pixel values of the damaged pixel points are calculated through pixel values in the interpolation areas, the damaged pixel points are repaired according to the target pixel values, so that damaged pixel points are obtained, and the damaged pixel points are identified; compared with the prior art, the method and the device have the advantages that the two-dimensional code image with the defects is difficult to analyze, and the situation that the two-dimensional code cannot be accurately analyzed due to the fact that the acquired two-dimensional code image is defective can be improved.
Drawings
Fig. 1 is a flow chart of a two-dimensional code identification method provided in an embodiment of the present application;
FIG. 2 is a schematic diagram of image preprocessing provided by an embodiment of the present application;
FIG. 3 is a schematic view of a hole and a corner according to an embodiment of the present application;
FIG. 4 is a schematic illustration of image restoration provided by an embodiment of the present application;
fig. 5 is a schematic diagram of a basic structure of a two-dimensional code provided in an embodiment of the present application;
fig. 6 is a schematic diagram of two-dimensional code dividing cells provided in an embodiment of the present application;
fig. 7 is a schematic diagram of a virtual structure of a two-dimensional code recognition device according to an embodiment of the present application.
Detailed Description
The terminology used in the following embodiments of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification and the appended claims, the singular forms "a," "an," "the," and "the" are intended to include the plural forms as well, unless the context clearly indicates to the contrary. It should also be understood that the term "and/or" as used in this application is intended to encompass any or all possible combinations of one or more of the listed items.
The terms "first," "second," and the like, are used below for descriptive purposes only and are not to be construed as implying or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include one or more such feature, and in the description of embodiments of the present application, unless otherwise indicated, the meaning of "a plurality" is two or more.
The embodiment of the application discloses a two-dimensional code identification method.
Referring to fig. 1, fig. 1 is a flowchart of a two-dimensional code identification method provided in an embodiment of the present application, where the method includes the following steps:
s10, performing image preprocessing on an initial two-dimensional code image to obtain a target two-dimensional code image;
the initial two-dimensional code image is blurred due to the fact that the initial two-dimensional code image may have interference of image noise points and the like, definition of the initial two-dimensional code image is affected, and image preprocessing is performed on the initial two-dimensional code image before the two-dimensional code image is identified in order to eliminate or reduce noise points in the image, so that a target two-dimensional code image is obtained.
It is noted that when only the two-dimensional code is stored in the initial two-dimensional code image, only the two-dimensional code is preprocessed when the initial two-dimensional code image is subjected to image preprocessing, so that a target two-dimensional code image is obtained, the target two-dimensional code image is only the preprocessed two-dimensional code, and only the two-dimensional code is repaired when the initial two-dimensional code image is repaired subsequently;
when the partial area of the initial two-dimensional code image is the two-dimensional code, when the initial two-dimensional code image is subjected to image preprocessing, all the areas of the initial two-dimensional code image can be preprocessed to obtain a target two-dimensional code image, the target two-dimensional code image is the preprocessed initial two-dimensional code image, and the whole target two-dimensional code image can be repaired in a subsequent repairing process, namely, other areas of the non-two-dimensional code are repaired together. Of course, when the partial area in the initial two-dimensional code image is a two-dimensional code, the image may be cut, an area only including the two-dimensional code may be extracted, and only the area only including the two-dimensional code may be preprocessed to obtain the target two-dimensional code image, which is not particularly limited.
In one embodiment, step S10 includes:
carrying out noise reduction treatment on the initial two-dimensional code image to obtain a noise reduction treatment image;
contrast enhancement processing is carried out on the noise reduction processed image, and an enhanced display image is obtained;
and sharpening the enhanced display image to obtain a target two-dimensional code image.
In a possible implementation manner, the performing noise reduction processing on the initial two-dimensional code image to obtain a noise reduction processed image includes:
determining a domain pixel corresponding to the initial two-dimensional code image;
and carrying out weighted average on the field pixels corresponding to the initial two-dimensional code image to obtain a noise reduction processing image.
In a possible implementation manner, the performing contrast enhancement processing on the noise reduction processing image to obtain an enhanced display image includes:
image filtering is carried out on the noise reduction processed image by using low-pass filtering so as to obtain an average gray value and an original gray value;
obtaining a target gray value according to the average gray value and the original gray value;
and filling the noise reduction processing image according to the target gray value to obtain an enhanced display image.
In a possible implementation manner, the sharpening the enhanced display image to obtain the target two-dimensional code image includes:
and sharpening the enhanced display image by using a Laplacian algorithm to form a target two-dimensional code image.
In an embodiment, the specific process of image preprocessing is: the method comprises the steps of firstly carrying out noise reduction treatment on an initial two-dimensional code image to obtain a noise reduction treatment image, then carrying out contrast enhancement treatment on the noise reduction treatment image to obtain an enhanced display image, and then carrying out image sharpening, specifically, carrying out sharpening on the enhanced display image to obtain a target two-dimensional code image.
As shown in fig. 2, fig. 2 is a schematic diagram of image preprocessing provided in the embodiment of the present application, specifically, noise reduction processing is performed on an initial two-dimensional code image, that is, gaussian filtering processing is performed on the initial two-dimensional code image, 201 in fig. 2 is an original image not interfered by noise, 202 in fig. 2 is an image interfered by noise, 203 in fig. 2 is an image after gaussian filtering processing, and the gaussian filtering processing effectively removes noise and details in the image, and retains main features of the image, so as to achieve the purpose of smoothing the image.
Specifically, the image sharpening is to compensate the outline of the image, and enhance the edge and the gray jump part of the image, so that the image becomes clear, and the image sharpening is divided into two types of spatial domain processing and frequency domain processing. Image sharpening is to highlight edges, contours, or features of some linear target elements of features on an image. This filtering method improves the contrast between the feature edges and surrounding picture elements and is therefore also referred to as edge enhancement.
In one embodiment, before step S10, the following operations are also performed:
acquiring an image to be identified containing a two-dimensional code;
and extracting an initial two-dimensional code image in the image to be identified.
In an embodiment, the image to be identified contains an identifiable two-dimensional code, before the two-dimensional code is identified, it is required to ensure that the input image actually contains the identifiable two-dimensional code, an initial two-dimensional code image in the image to be identified is extracted, and then the initial two-dimensional code image is subjected to image preprocessing to obtain a target two-dimensional code image.
S20, determining position information of damaged pixel points in a target two-dimensional code image;
judging whether the target two-dimensional code image has damaged pixels, and if the target two-dimensional code image does not have damaged pixels, directly identifying the target two-dimensional code image; if the damaged pixel point exists in the target two-dimensional code image, the position information of the damaged pixel point in the target two-dimensional code image can be determined, and the subsequent targeted image restoration of the damaged pixel point is facilitated.
In the application, the following description is made on the position information of the damaged pixel point in the target two-dimensional code image by two different modes:
in the first mode, the position information of damaged pixel points is determined according to the gray value of the pixel points in the target two-dimensional code image:
the determining of the position information of the damaged pixel point in the target two-dimensional code image comprises the following steps:
step 1, determining an image average gray value corresponding to a target two-dimensional code image;
the average gray value of the image is the gray value of each pixel point of the target two-dimensional code image, and the gray value is added and divided by the pixel number; in order to improve the accuracy of the average gray value of the image, when the average gray value of the image is calculated, the pixel point of the maximum gray value and the pixel point of the minimum gray value in the target two-dimensional code image can be removed first, and then the gray value of the rest pixel points is subjected to average processing so as to obtain the average gray value of the image.
Step 2, judging whether abnormal pixel points exist in the target two-dimensional code image according to the average gray value of the image;
whether an abnormal pixel point exists in the target two-dimensional code image is judged according to the image average gray value, for example, if the difference value between the pixel value of the pixel point and the image average gray value is larger or smaller than a preset range, the pixel point is determined to be the abnormal pixel point, and if the difference value between the pixel value of the pixel point and the image average gray value falls within the preset range, the pixel point is determined to be the normal pixel point. Specifically, whether an abnormal pixel value exists in the target two-dimensional code image can be judged by the following mode:
determining a pixel value of each pixel point in the target two-dimensional code image;
calculating the difference value between the pixel value of each pixel point and the average gray value of the image to obtain a difference value set;
judging whether a target difference value larger than a preset threshold exists in the difference value set;
if the difference value set has a target difference value larger than a preset threshold value, determining the pixel point corresponding to the target difference value as an abnormal pixel point.
In the embodiment, in the step of judging whether an abnormal pixel exists in the target two-dimensional code image according to the image average gray value, determining the pixel value of each pixel in the target two-dimensional code image, and then calculating the difference value between the pixel value of each pixel and the image average gray value to obtain a difference value set, and determining the pixel corresponding to the target difference value as the abnormal pixel when the target difference value larger than a preset threshold exists in the difference value set. The following is illustrative:
for example, when the preset threshold is 50, the target difference in the difference set is greater than 50 (the target difference is 51, 60, 100, 1000, and is determined according to the actual situation) and is an abnormal pixel. According to the scheme, whether the pixel point is an abnormal pixel point or not is judged by calculating the difference value between each pixel point and the average gray value of the image, so that the accuracy of distinguishing the abnormal pixel point is improved.
And step 3, if the abnormal pixel points exist in the target two-dimensional code image, determining the position information of the abnormal pixel points as the position information of the damaged pixel points.
When an abnormal pixel point exists in the target two-dimensional code image, determining the position information of the abnormal pixel point as the position information of the damaged pixel point; and determining the position coordinates (position information) of the abnormal pixel points as the position coordinates of the damaged pixel points.
Secondly, determining the position information of damaged pixel points by identifying whether the target two-dimensional code image comprises holes or corners or not:
the determining of the position information of the damaged pixel point in the target two-dimensional code image comprises the following steps:
detecting whether a hole or a corner exists in the target two-dimensional code image;
if the position information of the hole or the corner exists in the target two-dimensional code image, the position information of the hole or the corner is determined to be the position information of the damaged pixel point.
In an embodiment, in order to determine position information of a damaged pixel point in a target two-dimensional code image, detecting whether a hole or a corner exists in the target two-dimensional code image; when the hole or the corner exists in the target two-dimensional code image, determining the position information of the hole or the corner as the position information of the damaged pixel point.
Specifically, as shown in fig. 3, fig. 3 is a schematic view of a hole and a corner provided in the embodiment of the present application, in the image processing, the hole generally refers to a blank area in the image, that is, an area with a pixel value of zero; and performing morphological closing operation on the target two-dimensional code image to form a hole, and determining the hole area as a damaged pixel point, namely determining the position information of the hole as the position information of the damaged pixel point. In image processing, corners refer to salient, angular feature points in an image. The corner may be a pixel point with two edges or a pixel point with two main directions in the neighborhood, and the corner detection method is adopted to detect whether the corner exists in the target two-dimensional code image.
S30, determining an interpolation area corresponding to the damaged pixel point according to the position information;
determining an interpolation area corresponding to the damaged pixel point through the position information of the damaged pixel point, and generally selecting a plurality of normal pixel points around the damaged pixel point as the interpolation area; or, an area adjacent to the damaged pixel point in the target two-dimensional code image is used as an interpolation area.
S40, calculating a target pixel value of the damaged pixel point according to the pixel value of each pixel point in the interpolation area;
and calculating a target pixel value of each damaged pixel point by adopting a bilinear interpolation algorithm, wherein the bilinear interpolation algorithm considers the weight and the pixel value of each pixel point in the calculated interpolation area, and calculates the target pixel value of the damaged pixel point.
S50, repairing the damaged pixel point according to the target pixel value to obtain a repaired two-dimensional code image;
and filling and repairing the damaged pixel points according to the target pixel value to obtain a repaired two-dimensional code image. As shown in fig. 4, fig. 4 is a schematic diagram of image restoration provided in the embodiment of the present application, 401 in fig. 4 is a normal two-dimensional code image, 402 in fig. 4 is a damaged area of the normal two-dimensional code image, 403 in fig. 4 is a restoration area after restoration of the damaged area, when there are many damaged areas in the normal two-dimensional code image, the damaged pixel points are filled according to the target pixel values to obtain the restoration area, and multiple iterative restoration can be performed to obtain the restored two-dimensional code image.
Specifically, in the bilinear interpolation algorithm, the weight coefficient is obtained by calculating the distance ratio between the damaged pixel point and the known four surrounding pixel points. Then, according to the pixel values of the four surrounding pixel points and the corresponding weight coefficients, the target pixel value of the damaged pixel point is calculated. The final target pixel value is the pixel value of the damaged pixel point estimated by bilinear interpolation algorithm.
S60, identifying the repaired two-dimensional code image.
After the repair two-dimensional code image is obtained, the repair two-dimensional code image is identified, and for convenience of understanding, the following details of the identification process of the repair two-dimensional code image are described in connection with steps S61 to S64:
s61, searching a positioning pattern and a calibration pattern from the repaired two-dimensional code image;
as shown in fig. 5, fig. 5 is a schematic diagram of a basic structure of a two-dimensional code provided in an embodiment of the present application, 501 in fig. 5 is a positioning pattern, 502 in fig. 5 is a calibration pattern, first, the positioning pattern and the calibration pattern are searched from a repaired two-dimensional code image, and a boundary and a pixel mapping relationship of the two-dimensional code are determined, so that it is beneficial to determine whether the repaired two-dimensional code image has distortion through the boundary and the pixel mapping relationship of the two-dimensional code, the distortion does not affect the imaging definition, but the image can be deformed, for example, the repaired two-dimensional code image is inclined or deformed.
S61, determining a data area for repairing the two-dimensional code image according to the positioning pattern and the calibration pattern;
wherein, by positioning the positioning pattern and the calibration pattern in the two-dimensional code image, the data area of the two-dimensional code image can be determined, as shown in fig. 5, and 503 in fig. 5 is the data area
S63, analyzing the data area to obtain initial binary area data corresponding to the data area;
the method comprises the steps of analyzing a data area of a repaired two-dimensional code image to obtain initial binary area data, wherein the data area contains format information, version information, error correction codes and the like. As shown in fig. 5, 504 in fig. 5 is format information, 505 in fig. 5 is version information, and as shown in fig. 5, 505 in fig. 5 is error correction code.
In one embodiment, step S63 includes:
dividing a module in a data area into a plurality of cells;
and determining initial binary data corresponding to the cells according to the color information and the coding rule of the module.
In an embodiment, as shown in fig. 6, fig. 6 is a schematic diagram of two-dimensional code dividing cells provided in the embodiment of the present application, where a module in a data area is divided into a plurality of cells, each cell has the same size, but represents different data, and specific contents include, but are not limited to, format information, version information, error correction codes, data codes, and the like, then each cell is parsed, that is, the two-dimensional code is parsed, and specifically, initial binary data corresponding to the plurality of cells is determined according to color information and coding rules of the module.
Specifically, firstly, reading format information and reading version information, determining the version of the repaired two-dimensional code image, secondly, reading symbol characters, recovering information data and error correction code words according to the color information and coding rules of the module, detecting errors by using error correction codes corresponding to error correction level information, immediately correcting errors if errors are found, dividing the data code words into a plurality of parts according to a mode indicator and a character count indicator, and finally, decoding according to a used mode to obtain characters corresponding to initial binary region data and outputting results.
S64, analyzing the initial binary data according to a preset error correction code and a two-dimensional code coding rule to obtain the original data corresponding to the initial two-dimensional code image.
The method comprises the steps of carrying out error detection on initial binary data through a preset error correction code and a two-dimensional code coding rule, wherein the preset error correction code can detect and correct errors of the initial binary data so as to obtain original data corresponding to an initial two-dimensional code image; if the initial binary data is found to have errors, the preset error correction code immediately corrects the errors.
The two-dimensional code decoding algorithm sequentially comprises a BCH error correction code (BCH is an abbreviation of Bose, ray-Chaudhuri and Hocquenghem, and is an encoding method which is researched more in an encoding theory, particularly an error correction code), an RS error correction code and a decoding format, wherein the BCH code is a commonly used two-dimensional code error correction code technology, and redundancy information is added to binary data to improve fault tolerance. RS (Reed-Solomon) codes are an error-correcting coding technique that is commonly used for error correction and recovery of data of two-dimensional codes. The decoding format is used for analyzing binary data according to the specification of the two-dimensional code standard and converting the binary data into corresponding formats such as characters, numbers, texts and the like.
The embodiments of the present application are described above from the perspective of a two-dimensional code recognition method, and the embodiments of the present application are described below from the perspective of a two-dimensional code recognition device, referring to fig. 7, fig. 7 is a schematic diagram of a virtual structure of the two-dimensional code recognition device provided in the embodiments of the present application, where the two-dimensional code recognition device 700 includes:
the preprocessing module 701 is configured to perform image preprocessing on the initial two-dimensional code image to obtain a target two-dimensional code image;
the first positioning module 702 is configured to determine location information of a damaged pixel point in the target two-dimensional code image;
a second positioning module 703, configured to determine an interpolation region corresponding to the damaged pixel according to the position information;
a processing module 704, configured to calculate a target pixel value of the damaged pixel according to the pixel values of the pixel points in the interpolation region;
the repair module 705 is configured to repair the damaged pixel point according to the target pixel value, so as to obtain a repaired two-dimensional code image;
and the identification module 706 is used for identifying the repair two-dimensional code image.
In a possible implementation manner, the first positioning module 702 is specifically configured to:
determining an image average gray value corresponding to the target two-dimensional code image;
judging whether abnormal pixel points exist in the target two-dimensional code image according to the average gray value of the image;
if the abnormal pixel points exist in the target two-dimensional code image, determining the position information of the abnormal pixel points as the position information of the damaged pixel points.
In a possible implementation manner, the first positioning module 702 is further specifically configured to:
determining a pixel value of each pixel point in the target two-dimensional code image;
calculating the difference value between the pixel value of each pixel point and the average gray value of the image to obtain a difference value set;
judging whether a target difference value larger than a preset threshold exists in the difference value set;
if the difference value set has a target difference value larger than a preset threshold value, determining the pixel point corresponding to the target difference value as an abnormal pixel point.
In a possible implementation manner, the first positioning module 702 is further specifically configured to:
detecting whether a hole or a corner exists in the target two-dimensional code image;
if the position information of the hole or the corner exists in the target two-dimensional code image, the position information of the hole or the corner is determined to be the position information of the damaged pixel point.
In a possible implementation manner, the preprocessing module 701 is specifically configured to:
carrying out noise reduction treatment on the initial two-dimensional code image to obtain a noise reduction treatment image;
contrast enhancement processing is carried out on the noise reduction processed image, and an enhanced display image is obtained;
and sharpening the enhanced display image to obtain a target two-dimensional code image.
In a possible implementation manner, the preprocessing module 701 is further specifically configured to:
acquiring an image to be identified containing a two-dimensional code;
and extracting an initial two-dimensional code image in the image to be identified.
In a possible implementation manner, the identification module 706 is specifically configured to:
searching a positioning pattern and a calibration pattern from the repaired two-dimensional code image;
determining a data area for repairing the two-dimensional code image according to the positioning pattern and the calibration pattern;
analyzing the data area to obtain initial binary area data corresponding to the data area;
and analyzing the initial binary data according to the preset error correction code and the two-dimensional code coding rule to obtain the original data corresponding to the initial two-dimensional code image.
In a possible implementation manner, the identification module 706 is further specifically configured to:
dividing a module in a data area into a plurality of cells;
and determining initial binary data corresponding to the cells according to the color information and the coding rule of the module.
In the embodiment of the application, in order to accurately analyze the two-dimensional code with defects, firstly, an initial two-dimensional code image is subjected to image preprocessing through a preprocessing module, namely, the initial two-dimensional code image is subjected to image enhancement to obtain a target two-dimensional code image; secondly, determining the position information of damaged pixel points in the target two-dimensional code image through a first positioning module, and determining an interpolation area corresponding to the damaged pixel points through a second positioning module according to the position information; then, calculating a target pixel value of the damaged pixel point according to the pixel value of each pixel point in the interpolation region by a processing module, repairing the damaged pixel point according to the target pixel value by a repairing module to obtain a repaired two-dimensional code image, and finally identifying the repaired two-dimensional code image by an identification module; the method and the device have the advantages that the preprocessing work of image enhancement is carried out on the two-dimensional code image before the two-dimensional code image is identified, the preprocessed image is repaired, the repaired two-dimensional code image is obtained, and the repaired two-dimensional code image is identified, so that the two-dimensional code image with defects can still be analyzed, and therefore the situation that the two-dimensional code cannot be analyzed correctly due to the fact that the acquired two-dimensional code image is defective can be improved.
In an embodiment, there is also provided a computer device comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the method embodiments described above when the computer program is executed.
Those skilled in the art will appreciate that implementing all or part of the above-described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, or the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory. By way of illustration, and not limitation, RAM can be in the form of a variety of forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), and the like.
The foregoing are all preferred embodiments of the present application, and are not intended to limit the scope of the present application in any way, therefore: all equivalent changes in structure, shape and principle of this application should be covered in the protection scope of this application.

Claims (10)

1. The two-dimensional code identification method is characterized by comprising the following steps of:
performing image preprocessing on the initial two-dimensional code image to obtain a target two-dimensional code image;
determining position information of damaged pixel points in the target two-dimensional code image;
determining an interpolation area corresponding to the damaged pixel point according to the position information;
calculating a target pixel value of the damaged pixel point according to the pixel value of each pixel point in the interpolation area;
repairing the damaged pixel point according to the target pixel value to obtain a repaired two-dimensional code image;
and identifying the repaired two-dimensional code image.
2. The method of claim 1, wherein determining the location information of the damaged pixel point in the target two-dimensional code image comprises:
determining an image average gray value corresponding to the target two-dimensional code image;
judging whether abnormal pixel points exist in the target two-dimensional code image according to the image average gray value;
if the abnormal pixel point exists in the target two-dimensional code image, determining the position information of the abnormal pixel point as the position information of the damaged pixel point.
3. The method according to claim 2, wherein the determining whether the abnormal pixel exists in the target two-dimensional code image according to the image average gray value comprises:
determining a pixel value of each pixel point in the target two-dimensional code image;
calculating the difference value between the pixel value of each pixel point and the average gray value of the image to obtain a difference value set;
judging whether a target difference value larger than a preset threshold exists in the difference value set;
if the target difference value larger than a preset threshold exists in the difference value set, determining the pixel point corresponding to the target difference value as an abnormal pixel point.
4. The method of claim 1, wherein determining the location information of the damaged pixel point in the target two-dimensional code image comprises:
detecting whether a hole or a corner exists in the target two-dimensional code image;
if the position information of the hole or the corner exists in the target two-dimensional code image, determining the position information of the hole or the corner as the position information of the damaged pixel point.
5. The method of claim 1, wherein the performing image preprocessing on the initial two-dimensional code image to obtain a target two-dimensional code image comprises:
performing noise reduction treatment on the initial two-dimensional code image to obtain a noise reduction treatment image;
performing contrast enhancement processing on the noise reduction processing image to obtain an enhanced display image;
and sharpening the enhanced display image to obtain the target two-dimensional code image.
6. The method according to any one of claims 1 to 5, wherein before performing image preprocessing on the initial two-dimensional code image to obtain the target two-dimensional code image, the method includes:
acquiring an image to be identified containing a two-dimensional code;
and extracting the initial two-dimensional code image in the image to be identified.
7. The method of claim 1, wherein the identifying the repair two-dimensional code image comprises:
searching a positioning pattern and a calibration pattern from the repair two-dimensional code image;
determining a data area of the repair two-dimensional code image according to the positioning pattern and the calibration pattern;
analyzing the data area to obtain initial binary area data corresponding to the data area;
analyzing the initial binary data according to a preset error correction code and a two-dimensional code coding rule to obtain the original data corresponding to the initial two-dimensional code image.
8. The method of claim 7, wherein parsing the data region to obtain initial binary region data corresponding to the data region comprises:
dividing a module in the data area into a plurality of cells;
and determining the initial binary data corresponding to the cells according to the color information and the coding rule of the module.
9. The utility model provides a device of two-dimensional code discernment which characterized in that includes:
the preprocessing module is used for preprocessing the initial two-dimensional code image to obtain a target two-dimensional code image;
the first positioning module is used for determining the position information of the damaged pixel point in the target two-dimensional code image;
the second positioning module is used for determining an interpolation area corresponding to the damaged pixel point according to the position information;
the processing module is used for calculating the target pixel value of the damaged pixel point according to the pixel value of each pixel point in the interpolation area;
the repair module is used for repairing the damaged pixel points according to the target pixel values so as to obtain a repaired two-dimensional code image;
and the identification module is used for identifying the repair two-dimensional code image.
10. An electronic device, comprising:
a memory and a processor, the memory having stored thereon a computer program capable of being loaded by the processor and performing the method according to any of claims 1 to 8.
CN202311449489.6A 2023-11-02 2023-11-02 Two-dimensional code identification method, device and equipment Pending CN117474771A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311449489.6A CN117474771A (en) 2023-11-02 2023-11-02 Two-dimensional code identification method, device and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311449489.6A CN117474771A (en) 2023-11-02 2023-11-02 Two-dimensional code identification method, device and equipment

Publications (1)

Publication Number Publication Date
CN117474771A true CN117474771A (en) 2024-01-30

Family

ID=89625176

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311449489.6A Pending CN117474771A (en) 2023-11-02 2023-11-02 Two-dimensional code identification method, device and equipment

Country Status (1)

Country Link
CN (1) CN117474771A (en)

Similar Documents

Publication Publication Date Title
EP3309704B1 (en) Two-dimensional code partitioning and decoding method and system
CN109522816B (en) Table identification method and device and computer storage medium
CN106778996B (en) It is embedded with the generation system and method for the two dimensional code of visual pattern and reads system
US9892300B2 (en) Two-dimensional code
EP2921998B1 (en) Two-dimensional code, system for creation of two-dimensional code, and analysis program
US7543753B2 (en) Reconstruction of virtual raster
US7672474B2 (en) Electronic watermark embedding device, electronic watermark detection device, method thereof, and program
CN101978380B (en) Two-dimensional symensional symbol and read method thereof
CN105989317B (en) Two-dimensional code identification method and device
US6758399B1 (en) Distortion correction method in optical code reading
BR102012033723B1 (en) method for restoring blurred barcode images
CN109948393B (en) Method and device for positioning one-dimensional bar code
CN111626941A (en) Document correction method based on deep learning semantic segmentation
CN111814673B (en) Method, device, equipment and storage medium for correcting text detection bounding box
CN115660933B (en) Watermark information identification method, device and equipment
CN111582000A (en) Bar code positioning method and device and related equipment
CN109508571B (en) Strip-space positioning method and device, electronic equipment and storage medium
CN110889304A (en) Two-dimensional code quality evaluation method and device, storage medium, electronic device and system
CN109740403B (en) Method and device for reading one-dimensional bar code
CN112733855B (en) Table structuring method, table recovering device and device with storage function
JP3099771B2 (en) Character recognition method and apparatus, and recording medium storing character recognition program
CN117474771A (en) Two-dimensional code identification method, device and equipment
CN111652011A (en) Method and device for reading two-dimensional code
CN114937023A (en) Defect identification method and device for pressure-bearing equipment
CN115034245A (en) System and method for locating and decoding unreadable data matrices

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination