[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN110263595B - Two-dimensional code detection method and device - Google Patents

Two-dimensional code detection method and device Download PDF

Info

Publication number
CN110263595B
CN110263595B CN201910553935.5A CN201910553935A CN110263595B CN 110263595 B CN110263595 B CN 110263595B CN 201910553935 A CN201910553935 A CN 201910553935A CN 110263595 B CN110263595 B CN 110263595B
Authority
CN
China
Prior art keywords
image
energy
area
window
parameter
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.)
Active
Application number
CN201910553935.5A
Other languages
Chinese (zh)
Other versions
CN110263595A (en
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.)
Beijing Huiyan Zhixing Technology Co ltd
Original Assignee
Beijing Huiyan Zhixing 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 Beijing Huiyan Zhixing Technology Co ltd filed Critical Beijing Huiyan Zhixing Technology Co ltd
Priority to CN201910553935.5A priority Critical patent/CN110263595B/en
Publication of CN110263595A publication Critical patent/CN110263595A/en
Application granted granted Critical
Publication of CN110263595B publication Critical patent/CN110263595B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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
    • 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/1439Methods for optical code recognition including a method step for retrieval of the optical code
    • G06K7/1443Methods for optical code recognition including a method step for retrieval of the optical code locating of the code in an image

Landscapes

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

Abstract

The invention discloses a two-dimensional code detection method and a device, wherein the method comprises the following steps: obtaining a target image; carrying out gray processing on the target image to obtain a gray image; carrying out binarization processing on the gray level image to obtain a binarization image; and obtaining at least one identification area in the binary image based on the image energy parameter of the binary image, wherein the identification area comprises a two-dimensional code area. Therefore, in the invention, after the image is binarized, the image energy parameter is acquired, and then the region containing the two-dimension code area in the binarized image is found, so that the rapid positioning of the region where the two-dimension code is located is realized, and therefore, in the subsequent identification of the two-dimension code, the two-dimension code identification is only carried out on the region containing the two-dimension code area, so that the identification time is reduced, and the aim of improving the identification efficiency is fulfilled.

Description

Two-dimensional code detection method and device
Technical Field
The invention relates to the technical field of two-dimension code detection, in particular to a two-dimension code detection method and device.
Background
In the present two-dimensional code detection scheme, the code area of the two-dimensional code needs to be artificially selected and placed in the appointed reading area, so that the two-dimensional code detection and identification can be realized, and when the code area occupies too low proportion in the reading area or the background of the code area is complex, the situation that the identification is time-consuming and long and even cannot be identified for a long time can occur.
Therefore, a technical solution capable of rapidly detecting the area of the two-dimensional code is needed.
Disclosure of Invention
In view of this, the present invention provides a two-dimensional code detection method and apparatus, so as to solve the technical problem in the prior art that the area where the two-dimensional code is located needs to be detected quickly.
The invention provides a two-dimensional code detection method, which comprises the following steps:
obtaining a target image;
carrying out gray level processing on the target image to obtain a gray level image;
carrying out binarization processing on the gray level image to obtain a binarized image;
and obtaining at least one identification area in the binary image based on the image energy parameter of the binary image, wherein the identification area comprises a two-dimensional code area.
The above method, preferably, obtaining at least one identification region in the binarized image based on an image energy parameter of the binarized image, includes:
performing image traversal on the binary image by using sliding windows to obtain an image energy parameter of a window area under each sliding window;
determining at least one target window area based on the image energy parameters, wherein the target window area contains a two-dimensional code area;
and merging the target window areas with the area intersection to obtain at least one identification area.
Preferably, the method for binarizing the grayscale image to obtain a binarized image includes:
obtaining the whole image gray average value of the gray image;
obtaining a threshold interval corresponding to the whole image gray level mean value and a threshold interval value corresponding to the threshold interval;
determining a binarization threshold value of the gray level image based on the threshold interval and the threshold interval value;
and carrying out binarization processing on the gray level image by using the binarization threshold value to obtain a binarization image.
Preferably, the method for binarizing the grayscale image to obtain a binarized image includes:
partitioning the gray level image to obtain a plurality of partitioned images;
obtaining the partition gray level mean value of each partition image and the corresponding threshold coefficient thereof;
multiplying the partition gray average value by a corresponding threshold coefficient to obtain a binaryzation threshold of the partition image;
and performing binarization processing on the partitioned images corresponding to the binarization threshold values respectively by using the binarization threshold values to obtain binarization images.
The above method, preferably, obtaining an image energy parameter of a window region under each sliding window includes:
calculating the image energy parameter of the window area under each sliding window by using an integral image calculation method to obtain the image energy parameter of each window area;
wherein the image energy parameters include: an image energy value of the window region or an image energy density of the window region.
The above method, preferably, determining a target window region based on the image energy parameter, includes:
under the condition that the image energy parameter meets the energy range of a preset standard code region, calculating a corrosion energy parameter of the window region after corrosion treatment;
partitioning the window area where the image energy parameter and the corrosion energy parameter meet a preset corrosion rule to obtain a plurality of area sub-blocks;
calculating sub-block energy parameters of the region sub-blocks;
and determining the window area of which the sub-block energy parameters of the sub-blocks in the area meet the preset sub-block energy rule as a target window area containing the two-dimensional code area.
In the above method, preferably, the image energy parameter and the erosion energy parameter satisfy a preset erosion rule, and the method includes:
the image energy parameter is in a first parameter range, the corrosion energy parameter is in a second parameter range, and the difference value between the image energy parameter and the corrosion energy parameter is in a third parameter range;
preferably, in the method, the sub-block energy parameter of the region sub-block satisfies a preset sub-block energy rule, and the method includes:
the subblock energy parameters of the region subblocks are in the first parameter range, and the difference value of the subblock energy parameters between the region subblocks symmetrical about a preset datum line in the window region is in a fourth parameter range.
The above method, preferably, further comprises:
filtering the binary image by using a morphological algorithm;
wherein the morphological algorithm comprises: and the operation algorithm is formed by one or more of opening operation, closing operation, expansion operation and corrosion operation.
The invention provides a two-dimensional code detection device, which comprises:
an image obtaining unit for obtaining a target image;
the gray processing unit is used for carrying out gray processing on the target image to obtain a gray image;
a binarization processing unit, configured to perform binarization processing on the grayscale image to obtain a binarized image;
and the energy detection unit is used for obtaining at least one identification area in the binary image based on the image energy parameter of the binary image, wherein the identification area comprises a two-dimensional code area.
According to the two-dimensional code detection method and device disclosed by the invention, after the gray level and binarization processing is performed on the image, the identification area containing the two-dimensional code area in the binarized image is detected by using the image energy parameter of the binarized image, and then the two-dimensional code identification is performed on the image of the identification area after the identification area containing the two-dimensional code area is determined, so that the identification result is obtained. Therefore, in the invention, after the image is binarized, the energy parameter of the image is acquired, the area containing the two-dimension code area in the binarized image is further found, the area where the two-dimension code is located is rapidly positioned, and therefore, only the area containing the two-dimension code area is subjected to two-dimension code identification in subsequent two-dimension code identification, so that the identification time is reduced, and the aim of improving the identification efficiency is fulfilled.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a flowchart of a two-dimensional code detection method according to an embodiment of the present invention;
fig. 2 is a partial flowchart of a two-dimensional code detection method according to an embodiment of the present invention;
fig. 3 is a structural diagram of a two-dimensional code detection apparatus according to a second embodiment of the present invention;
fig. 4 is another structural diagram of a two-dimensional code detection apparatus according to a second embodiment of the present invention;
FIG. 5 is an exemplary flow chart of an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a flowchart of an implementation of a two-dimensional code detection method according to an embodiment of the present invention is provided, where the method is applied to a device capable of performing image processing, such as a computer or a server. The method in the embodiment is mainly used for quickly and effectively identifying the two-dimensional code.
Specifically, the method in this embodiment may include the following steps:
step 101: a target image is obtained.
The target image may be an image acquired by a camera or a camera, such as a mobile phone camera or a POS scanner, for example, an image acquired by acquiring an image in an area or a scene where two-dimensional code identification is required, and the target image includes a two-dimensional code area image to be identified and may also include a background area image.
Step 102: and carrying out gray level processing on the target image to obtain a gray level image.
In this embodiment, the target image may be subjected to gray scale processing by using an algorithm such as a component method, a maximum value method, an average value method, or a weighted average method, so that three RGB data in the target image are consistent to obtain a gray scale image.
Note that the pixel value of a pixel in the grayscale image may be any value from 0 to 255.
Step 103: and carrying out binarization processing on the gray level image to obtain a binarized image.
In this embodiment, different binarization processing algorithms may be used according to a definition value in the grayscale image or a diversity degree of image elements or a complexity degree of pixels in the grayscale image to binarize the grayscale image. For example, if the definition of the gray image is high, or the image elements of the gray image are few, or the pixel complexity is low, a global threshold-based binarization processing algorithm may be used, and conversely, a local threshold-based binarization processing algorithm may be used.
The pixel value of the pixel in the binarized image is 0 or 255.
Step 104: and obtaining at least one identification area in the binary image based on the image energy parameter of the binary image.
The identification area obtained in this embodiment is an area including a two-dimensional code area. That is to say, in this embodiment, the two-dimensional code area in the binarized image is screened and determined based on the image energy parameter of the binarized image, so as to obtain the identification area including the two-dimensional code area in the binarized image.
It should be noted that in this embodiment, the image energy parameter of the binarized image can represent the distribution and the pixel value of each pixel in the binarized image, and in this embodiment, the image energy parameter of the binarized image is analyzed by using the specific image energy characteristics of the two-dimensional code region image, so as to obtain the identification region including the two-dimensional code region in the binarized image, and thus, the rapid positioning of the region where the two-dimensional code is located is realized.
The identification area containing the two-dimensional code area may be one or more, that is, the target image may contain one or more two-dimensional codes.
Step 105: and carrying out two-dimensional code recognition on the image of the recognition area to obtain a recognition result.
In this embodiment, the two-dimensional code recognition algorithm may be used to recognize the image of the recognition area including the two-dimensional code area, so as to obtain a recognition result, such as a result of a web page link, a business card, or the like. Therefore, in the embodiment, only the identification area containing the two-dimensional code area in the binary image is subjected to two-dimensional code identification, and the images in other areas are not subjected to identification, so that the time consumption for identification is reduced.
It should be noted that, after obtaining the identification area in this embodiment, the identification area may be used for the two-dimensional code identification as described above, and may also be used in other scenarios, such as two-dimensional code printout or code block modification, which is not limited to the two-dimensional code identification scenario. Based on the identification area obtained in the embodiment, the technical schemes under various scenes can be realized within the protection scope of the application.
As can be seen from the foregoing solution, in the two-dimensional code detection method provided in the first embodiment of the present invention, after performing grayscale and binarization processing on an image, an identification area including a two-dimensional code area in the binarized image is detected by using an image energy parameter of the binarized image, and after determining the identification area including the two-dimensional code area, two-dimensional code identification is performed on the image in the identification area, so as to obtain an identification result. Therefore, in the embodiment, after the image is binarized, the image energy parameters are acquired, the region containing the two-dimension code area in the binarized image is found, the region where the two-dimension code is located is rapidly positioned, and therefore, in the subsequent two-dimension code identification, the two-dimension code identification is only carried out on the region containing the two-dimension code area, the identification time is reduced, and the purpose of improving the identification efficiency is achieved.
In one implementation, step 104 in fig. 1 can be implemented by the following manner when obtaining the identification region based on the image energy parameter of the binarized image, as shown in fig. 2:
step 201: and traversing the binary image by utilizing the sliding windows to obtain the image energy parameter of the window area under each sliding window.
In this embodiment, the binary image is traversed by using the sliding window with the gradually changing size to obtain a plurality of traversed window regions, and the image energy parameter of each window region is calculated.
Specifically, in this embodiment, the fast integral image calculation method may be used to calculate the image energy parameter of the window region under each sliding window, so as to obtain the image energy parameter of each window region.
The image energy parameter may include: an image energy value of the window region or an image energy density of the window region. The image energy value of the window region refers to an energy value based on pixels in the window region, such as a gray value, and the image energy density is a ratio of the image energy value to the number of pixels.
Step 202: at least one target window region is determined based on the image energy parameter.
The target window region includes a two-dimensional code region, that is, the target window region may include the two-dimensional code region in a prediction mode, and other window regions do not include the two-dimensional code region.
Specifically, in this embodiment, after obtaining the image energy parameter of the window region, it may first be determined whether the image energy parameter meets a preset standard code region energy range, where the standard code region energy range refers to: the range corresponding to the code image energy or energy density of a standard code region can be obtained by calculation according to printed pixels in a two-dimensional code printing standard, and is corrected by a large number of samples (samples under different types and different scenes), and an upper limit and a lower limit in the energy range are set, so that in the embodiment, whether the energy value or the energy density in the image energy parameter is in the corresponding standard code region energy value range or density range can be judged, and whether the image energy parameter meets the standard code region energy range can be judged;
if the image energy parameter meets the preset standard code area energy range, calculating the corrosion energy parameter of the window area after corrosion treatment, wherein the calculation of the corrosion energy parameter can be specifically as follows: carrying out corrosion operation on the window area, and then calculating the image of the corroded window area to obtain a corrosion energy value or corrosion energy density so as to obtain a corrosion energy parameter; it should be noted that the etching process may remove the smaller pixels in the pixel region by etching, and leave the larger pixels in the pixel region, that is, the etching process in this embodiment may be understood as removing the punctiform pixel regions in the window region by etching, and leaving the blocky pixel regions, and accordingly, if the window region is subjected to the etching process, the energy parameter of the window region changes, and has a larger difference from the energy parameter before etching, for example, the energy value or energy density of the window region after the etching process may decrease.
Then, partitioning the window area (the window area which is not subjected to corrosion processing) with the image energy parameter and the corrosion energy parameter meeting the preset corrosion rule to obtain a plurality of area sub-blocks, wherein the image energy parameter and the corrosion energy parameter meeting the corrosion rule refer to: the image energy parameter is in a first parameter range, the erosion energy parameter is in a second parameter range, the difference value between the image energy parameter and the erosion energy parameter is in a third parameter range, for example, the first parameter range is an energy value range of 30-150, the second parameter range is an energy value range of 10-40, the third parameter range can be an energy value range of 10-60, for the energy value before erosion is in a range of 30-150, the energy value after erosion is in a range of 10-40, and a window area with an energy difference before erosion in a range of 10-60 can be considered as an area containing a two-dimensional code area, and for other areas, the window area can be considered as an area containing noise or other situations, for example: if the average value of the gray scale of the image before corrosion of a certain window area is 40, and the average value of the gray scale of the image after corrosion is 20, the difference value 20 is greater than 10 and less than 60, the window area is considered to be an area containing the two-dimensional code area, and if the average value of the gray scale of the image before corrosion of a certain window area is 150, and the average value of the gray scale of the image after corrosion is 20, the difference value 130 is beyond the range of 10-60, the window area is considered to belong to an area with more noise, but not to an area containing the two-dimensional code area, and the like, so that the window area with the image energy value in the first parameter range, the corrosion energy value in the second parameter range and the energy value difference in the third parameter range is partitioned, and each window area can be divided into a plurality of area sub-blocks;
specifically, the partitioning of the window area may be performed according to a certain rule, for example, the window area is divided into four sub-blocks averagely, and the middle part is added to five sub-blocks, and further the middle cross area and the area sub-blocks of the peripheral frame are taken, and so on;
then, calculating sub-block energy parameters, such as sub-block energy values or sub-block energy densities, of the sub-blocks in the partitioned areas respectively, wherein the sub-block energy values and the sub-block energy densities can be calculated by a quick integral diagram calculation method specifically;
and finally, determining a window area, in which the subblock energy parameters of the regional subblocks meet a preset subblock energy rule, as a target window area containing a two-dimensional code area, wherein the subblock energy parameters of the regional subblocks meet the preset subblock energy rule and can be: the subblock energy parameters of the subblocks in the region are in the first parameter range, the difference value of the subblock energy parameters between the subblocks in the region which is symmetrical relative to a preset reference line in the window region is in a fourth parameter range, namely, the subblock energy values or the subblock energy densities between the subblocks in the window region are the same or similar to each other and are in the fourth parameter range with smaller values, such as the energy value range of 0-10, and the subblock energy values of the subblocks in the region are still in the first parameter range where the image energy values of the window region are located, at the moment, the window region is determined to contain the two-dimensional code region, and the window region is marked as a target window region.
It should be noted that the target window area may be one or more, that is, one or more window areas containing the two-dimensional code area may exist in each window area under the sliding window.
Step 203: and merging the target window areas with the area intersection to obtain at least one identification area.
In this embodiment, the target window areas in the horizontal direction, the numerical value direction, the inclined direction, and the like may be determined by determining the target window areas in the intersection in each direction, and the target window areas in the intersection are combined, that is, the target window areas in the intersection are combined: and (3) taking a collection between the target window areas to obtain the target window areas which can belong to the same image area, namely, are connected into a piece, and finally obtaining a combined area, namely, the combined area is the identification area, and the target window area which can not be combined is reserved as a single identification area, so that the identification area can be one or more.
In one implementation, step 103 in fig. 1 may adopt different binarization processing manners according to the definition of the grayscale image or the complexity of elements in the grayscale image when performing binarization processing on the grayscale image, as follows:
in one processing mode, step 103 may be implemented by a binarization algorithm of a global threshold, as follows:
firstly, obtaining the average value of the gray values of the whole image of the gray image, such as calculating the average value of the gray values of all pixels of the whole image;
then, obtaining a threshold interval corresponding to the whole graph gray level mean value and a threshold interval value corresponding to the threshold interval, wherein in this embodiment, a plurality of threshold intervals and threshold interval values thereof may be preset by using historical empirical data, for example, threshold intervals corresponding to different global gray level mean values and threshold intervals corresponding to iteration are determined by collecting a plurality of historical threshold values converged in binarization processing based on a global threshold value, and in this embodiment, after obtaining the whole graph gray level mean value, the threshold intervals corresponding to the whole graph gray level mean value and the threshold interval values corresponding to the threshold intervals are determined in the threshold intervals;
then, based on the threshold interval and the threshold interval value, determining a binary threshold of the gray-scale image, for example, in the threshold interval, taking a threshold every other threshold interval value to perform iterative computation on the gray-scale image, and finally determining the binary threshold of the gray-scale image;
finally, the gray image is binarized by using the binarization threshold of the gray image to obtain a binarized image, for example, a pixel value of 255, namely a white pixel, is set for a pixel with a gray value larger than the binarization threshold, and a pixel value of 0, namely a black pixel, is set for a pixel with a gray value smaller than the binarization threshold.
In another processing manner, step 103 may be implemented by a binarization algorithm of a local threshold, as follows:
firstly, partitioning a gray level image to obtain a plurality of partitioned images;
then, obtaining a partition gray average value of each partition image and a corresponding threshold coefficient thereof, where the partition gray average value may be obtained by performing summation and re-averaging calculation on gray values of pixels of each partition image, the threshold coefficient is a preset value, different partition gray average values correspond to different threshold coefficients, such as 0.1, 0.3, or 0.6, and the sum of the preset threshold coefficients is 1, that is, the weights occupied by different partition gray average values in the threshold calculation are different;
then, multiplying the partition gray level average value by a corresponding threshold coefficient to obtain a binarization threshold value of the partition image, namely, multiplying the partition gray level average value of the partition image by the corresponding threshold coefficient to obtain a product, namely the binarization threshold value of the partition image;
finally, with the binary threshold, the partition images corresponding to the binary threshold are respectively subjected to binarization processing to obtain binary images, for example, in each partition image, pixels with gray values larger than the binary threshold of the partition image are set to have pixel values of 255, that is, white pixels, and pixels with gray values smaller than the binary threshold of the partition image are set to have pixel values of 0, that is, black pixels.
In a specific implementation, in order to improve the accuracy of the identification region including the two-dimensional code region, the binarized image may be filtered after the binarized image is obtained, for example, the binarized image is filtered by using a morphological algorithm, and then the binarized image after filtering is subjected to image energy parameter calculation and subsequent region identification, so as to obtain the identification region including the two-dimensional code region, and perform two-dimensional code identification, so as to obtain an identification result.
Specifically, the morphological algorithm in this embodiment may be: an operation algorithm formed by one or more of the open operation, the close operation, the expansion operation and the corrosion operation in combination, for example: the method has the advantages that the binary image can be subjected to one-time opening operation, the noise can be eliminated, the code points are kept unchanged, one-time closing operation is carried out, the code area can be enabled to be substantial, combined operation of expansion operation and corrosion operation is alternately added to the binary image in the opening operation and closing operation processes, operation results of a plurality of times are compounded, and the filtered binary image is obtained, so that the noise in the binary image is eliminated, and a clearer code image in the binary image can also be obtained.
Referring to fig. 3, a schematic structural diagram of a two-dimensional code detection apparatus according to a second embodiment of the present invention is shown, where the apparatus is suitable for use in a device capable of performing image processing, such as a computer or a server. The device in the embodiment is mainly used for quickly and effectively identifying the two-dimensional code.
Specifically, the apparatus in this embodiment may include the following functional units:
an image obtaining unit 301 for obtaining a target image.
The image obtaining unit 301 may be a functional unit on a device such as a camera or a camera, and is configured to collect a target image, where the target image may be an image obtained by collecting an image in an area or a scene where two-dimensional code recognition is required, such as a mobile phone camera or a scanning port of a POS machine, and the target image includes an image of a two-dimensional code area to be recognized and may also include an image of a background area.
A gray processing unit 302, configured to perform gray processing on the target image to obtain a gray image.
In this embodiment, the grayscale processing unit 302 may perform grayscale processing on the target image by using an algorithm such as a component method, a maximum value method, an average value method, or a weighted average method, so that three RGB data in the target image are consistent, and a grayscale image is obtained.
Note that the pixel value of a pixel in the grayscale image may be any value from 0 to 255.
A binarization processing unit 303, configured to perform binarization processing on the grayscale image to obtain a binarized image.
In this embodiment, the binarization processing unit 303 may binarize the grayscale image by using different binarization processing algorithms according to a definition value in the grayscale image or a diversity degree of image elements or a complexity degree of pixels in the grayscale image. For example, if the definition of the grayscale image is high, or the image elements in the grayscale image are few, or the pixel complexity is low, a global threshold-based binarization processing algorithm may be used, whereas a local threshold-based binarization processing algorithm may be used.
The pixel value of the pixel in the binarized image is 0 or 255.
An energy detection unit 304, configured to obtain at least one identification area in the binarized image based on an image energy parameter of the binarized image.
The identification area obtained in this embodiment is an area including a two-dimensional code area. That is to say, in this embodiment, the energy detection unit 304 screens and determines the two-dimensional code region in the binarized image based on the image energy parameter of the binarized image, so as to obtain the identification region including the two-dimensional code region in the binarized image.
It should be noted that in this embodiment, the image energy parameter of the binarized image can represent the distribution and the pixel value of each pixel in the binarized image, and in this embodiment, the energy detection unit 304 analyzes the image energy parameter of the binarized image by using the specific image energy characteristic of the image of the two-dimensional code region, so as to obtain the identification region including the two-dimensional code region in the binarized image, and realize the rapid positioning of the region where the two-dimensional code is located.
The identification area containing the two-dimensional code area may be one or more, that is, the target image may contain one or more two-dimensional codes.
And an area identification unit 305, configured to perform two-dimensional code identification on the image of the identification area, so as to obtain an identification result.
In this embodiment, the area identification unit 305 may identify the image of the identification area including the two-dimensional code area by using a two-dimensional code identification algorithm, so as to obtain an identification result, such as a result of a web page link, a business card, and the like. Therefore, in the embodiment, only the identification area containing the two-dimensional code area in the binary image is subjected to two-dimensional code identification, and the images in other areas are not subjected to identification, so that the time consumption for identification is reduced.
As can be seen from the foregoing solution, in the two-dimensional code detection device provided in the second embodiment of the present invention, after the grayscale and binarization processing is performed on the image, the identification area including the two-dimensional code area in the binarized image is detected by using the image energy parameter of the binarized image, and after the identification area including the two-dimensional code area is determined, the two-dimensional code identification is performed on the image in the identification area, so as to obtain the identification result. Therefore, in the embodiment, after the image is binarized, the image energy parameters are acquired, the region containing the two-dimension code area in the binarized image is found, the region where the two-dimension code is located is rapidly positioned, and therefore, in the subsequent two-dimension code identification, the two-dimension code identification is only carried out on the region containing the two-dimension code area, the identification time is reduced, and the purpose of improving the identification efficiency is achieved.
In one implementation, the binarization processing unit 303 may perform binarization processing on the grayscale image by:
obtaining the whole image gray average value of the gray image; obtaining a threshold interval corresponding to the whole image gray level mean value and a threshold interval value corresponding to the threshold interval; determining a binarization threshold value of the gray level image based on the threshold interval and the threshold interval value; and carrying out binarization processing on the gray level image by using the binarization threshold value to obtain a binarization image.
Alternatively, the binarization processing unit 303 may perform binarization processing on the grayscale image by:
partitioning the gray level image to obtain a plurality of partitioned images; obtaining the partition gray level mean value of each partition image and the corresponding threshold coefficient thereof; multiplying the partition gray average value by a corresponding threshold coefficient to obtain a binaryzation threshold of the partition image; and respectively carrying out binarization processing on the partitioned images corresponding to the binarization threshold values by using the binarization threshold values to obtain binarization images.
In one implementation, the energy detection unit 304, when obtaining at least one identification region in the binarized image based on the image energy parameter of the binarized image, may be implemented by:
firstly, performing image traversal on the binary image by using a sliding window to obtain an image energy parameter of a window region under each sliding window, for example, calculating the image energy parameter of the window region under each sliding window by using an integral image calculation method to obtain the image energy parameter of each window region; wherein the image energy parameters include: an image energy value of the window region or an image energy density of the window region;
secondly, determining at least one target window area based on the image energy parameters, wherein the target window area comprises a two-dimensional code area, for example, under the condition that the image energy parameters meet the energy range of a preset standard code area, calculating corrosion energy parameters of the window area after corrosion treatment; partitioning a window area in which the image energy parameter and the corrosion energy parameter meet a preset corrosion rule (if the image energy parameter is in a first parameter range, the corrosion energy parameter is in a second parameter range, and a difference value between the image energy parameter and the corrosion energy parameter is in a third parameter range) to obtain a plurality of area sub-blocks; calculating sub-block energy parameters of the region sub-blocks; determining the window area, in which the sub-block energy parameters of the sub-blocks of the area meet a preset sub-block energy rule (if the sub-block energy parameters of the sub-blocks of the area are in the first parameter range and the difference value of the sub-block energy parameters between the sub-blocks of the area symmetrical about a preset reference line in the window area is in a fourth parameter range), as a target window area containing a two-dimensional code area;
finally, merging the target window areas with the area intersection to obtain at least one identification area;
further, the apparatus in this embodiment may further include a filtering unit 306, as shown in fig. 4, where the filtering unit 306 is mainly configured to:
after the binarization processing unit 303 obtains the binarized image, filtering the binarized image by using a morphological algorithm, and transmitting the filtered binarized image to the energy detection unit 304;
wherein the morphological algorithm comprises: and the operation algorithm is formed by combining one or more of opening operation, closing operation, expansion operation and corrosion operation, so that after the binary image is filtered by using a morphological algorithm, the noise in the binary image is eliminated, and a clearer code image in the binary image can be obtained.
The following describes, by taking the example that the mobile phone of the user identifies the two-dimensional code on the building wall, with reference to the flowchart in fig. 5, a scheme in this embodiment is illustrated:
step 1, obtaining an image, wherein the image is a gray image, and the gray image is subjected to binarization processing:
in practical application, two conditions are divided, a picture shot by a mobile phone is clear, interference factors are few, a code image is clear and has a large difference with a background, a binary algorithm based on a global threshold value is good in effect and low in time consumption in the condition, the size of the global threshold value is obtained through a large number of sample experiments of different types of different scenes, and iteration is carried out through a certain increment; the other shot picture has certain interference factors (a background, surrounding pattern influence, noise, shadow, exposure and the like are printed on the code picture), at the moment, a self-adaptive local binarization effect is better, the picture field is divided firstly, the gray level mean value in the current pixel field is obtained through a fast integral picture calculation method, a threshold value coefficient is determined according to the mean value (different threshold value intervals are set according to different gray levels), therefore, the threshold value coefficient in each field is related to the gray level in the current block, the threshold value coefficient is a self-adaptive threshold value, and the product of the gray level mean value and the threshold value coefficient determines the current binary threshold value.
Step 2, adopting morphological filtering to the binary image: a small number of images containing noise points are generated in the images generated by binaryzation, the noise points are much smaller than the code images and are distributed irregularly, the noise can be eliminated by utilizing open operation at first, the code images are kept unchanged, meanwhile, the close operation is carried out, the code images in the code image area can become full and remarkable, expansion corrosion combination is alternately added in the two processes, and the results of a plurality of times are compounded to eliminate the noise and obtain clear code images.
And 3, traversing the binary image by using a sliding window with a gradually changed size after the process of the step 2, calculating the energy value or the energy density of a lower window area of the sliding window by using a quick integral graph method, comparing the energy value or the energy density with the code image energy or the energy density of a standard code area, wherein the code image energy or the energy density of one standard code area can be obtained by calculation according to a two-dimensional code printing standard, correcting the code image energy or the energy density by using a large number of samples (different types and different scenes and the like), setting the upper limit and the lower limit of the threshold value of the energy value or the density, carrying out corrosion operation on the area meeting the requirement, calculating the energy value or the energy density of the corroded area at the moment, and obtaining the size of the current corroded morphological element by calculation. If the window area contains the two-dimensional code area, the code pattern in the code area is completely corroded after the corrosion operation, and the energy is reduced to be below a certain threshold value (the threshold value is also obtained by a large number of experimental samples), so that the window area meeting the energy requirements of the two times is considered to be an area possibly containing the two-dimensional code area, and the step 4 is carried out.
And 4, carrying out secondary judgment on the frame selected in the step 3, namely the window area, equally dividing the frame into four subframes, taking five parts in total of the middle part as the five subframes, simultaneously taking the subframe in the middle cross area and the subframe in the four peripheries, judging whether the energy density of each subframe is close to that of the whole frame area, judging whether the energy densities of the subframes are close, and recording the frame (the window area) if the energy densities of the subframes are close, wherein the frame is the area containing the two-dimensional code area. Wherein, similar means that the difference between subframes is smaller than a threshold value, and the threshold value is obtained by a large number of experimental samples. The selection of the sub-frame depends on the type of the code, and is not limited to the above shapes, and the determination method can be determined according to the similarity symmetry.
And step 5, taking the frame obtained in the step 4 as a candidate frame, temporarily recording the candidate frame, comparing each newly generated frame with the generated candidate frame, merging the frames in the horizontal, vertical and inclined directions by intersecting, updating the recording position of the history frame, and taking the frames as an independent candidate frame if the frames cannot be merged, namely, merging the frames containing the two-dimension code area according to the similar photographic fusion principle to obtain the largest candidate frame possibly containing the two-dimension code area.
And finally, performing two-dimension code identification on the candidate frame containing the two-dimension code area to obtain an identification result.
In the present specification, the embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (8)

1. A two-dimensional code detection method is characterized by comprising the following steps:
obtaining a target image;
carrying out gray level processing on the target image to obtain a gray level image;
carrying out binarization processing on the gray level image to obtain a binarization image;
obtaining at least one identification area in the binary image based on the image energy parameter of the binary image, wherein the identification area comprises a two-dimensional code area;
the obtaining of at least one identification region in the binarized image based on the image energy parameter of the binarized image comprises:
performing image traversal on the binary image by using sliding windows to obtain an image energy parameter of a window area under each sliding window;
judging whether the image energy parameter meets a preset standard code area energy range or not based on the image energy parameter, and determining at least one target window area, wherein the target window area comprises a two-dimensional code area;
the preset energy range of the standard code region is as follows: the range corresponding to the code image energy or energy density of a standard code area can be obtained by calculation according to printing pixels in a two-dimensional code printing standard, and is corrected by samples in different types and different scenes, and the upper limit and the lower limit in the energy range are set;
the obtaining of the image energy parameter of the window region under each sliding window includes:
calculating the image energy parameter of the window area under each sliding window by using an integral image calculation method to obtain the image energy parameter of each window area;
wherein the image energy parameters include: an image energy value of the window region or an image energy density of the window region.
2. The method according to claim 1, wherein the binarizing processing the grayscale image to obtain a binarized image comprises:
obtaining the whole image gray average value of the gray image;
obtaining a threshold interval corresponding to the whole image gray level mean value and a threshold interval value corresponding to the threshold interval;
determining a binarization threshold value of the gray level image based on the threshold interval and the threshold interval value;
and carrying out binarization processing on the gray level image by using the binarization threshold value to obtain a binarization image.
3. The method according to claim 1, wherein the binarizing processing the grayscale image to obtain a binarized image comprises:
partitioning the gray level image to obtain a plurality of partitioned images;
obtaining the partition gray level mean value of each partition image and the corresponding threshold coefficient thereof;
multiplying the partition gray level mean value by a corresponding threshold coefficient to obtain a binarization threshold of the partition image;
and respectively carrying out binarization processing on the partitioned images corresponding to the binarization threshold values by using the binarization threshold values to obtain binarization images.
4. The method of claim 1, wherein determining a target window region based on the image energy parameter comprises:
under the condition that the image energy parameter meets the energy range of a preset standard code region, calculating a corrosion energy parameter of the window region after corrosion treatment;
partitioning the image energy parameters and the window area of which the corrosion energy parameters meet the preset corrosion rule to obtain a plurality of area sub-blocks;
calculating sub-block energy parameters of the region sub-blocks;
and determining the window area of which the sub-block energy parameters of the sub-blocks in the area meet the preset sub-block energy rule as a target window area containing the two-dimensional code area.
5. The method of claim 4, wherein the image energy parameter and the erosion energy parameter satisfy a preset erosion rule comprising:
the image energy parameter is in a first parameter range, the erosion energy parameter is in a second parameter range, and a difference value between the image energy parameter and the erosion energy parameter is in a third parameter range.
6. The method of claim 5, wherein the sub-block energy parameter of the region sub-block satisfies a preset sub-block energy rule, and comprises:
the sub-block energy parameters of the region sub-blocks are in the first parameter range, and the difference value of the sub-block energy parameters between the region sub-blocks which are symmetrical about a preset datum line in the window region is in a fourth parameter range.
7. The method of claim 1, further comprising:
filtering the binary image by using a morphological algorithm;
wherein the morphological algorithm comprises: and the operation algorithm is formed by one or more of open operation, close operation, expansion operation and corrosion operation.
8. The utility model provides a two-dimensional code detection device which characterized in that includes:
an image obtaining unit for obtaining a target image;
the gray processing unit is used for carrying out gray processing on the target image to obtain a gray image;
a binarization processing unit, configured to perform binarization processing on the grayscale image to obtain a binarized image;
the energy detection unit is used for obtaining at least one identification area in the binary image based on the image energy parameter of the binary image, wherein the identification area comprises a two-dimensional code area;
the obtaining of at least one identification region in the binarized image based on the image energy parameter of the binarized image comprises:
performing image traversal on the binary image by using sliding windows to obtain image energy parameters of a window area under each sliding window;
judging whether the image energy parameter meets a preset standard code area energy range or not based on the image energy parameter, and determining at least one target window area, wherein the target window area comprises a two-dimensional code area;
the preset energy range of the standard code region is as follows: the range corresponding to the code image energy or energy density of a standard code area can be obtained by calculation according to printing pixels in a two-dimensional code printing standard, and is corrected by a large number of samples under different types and different scenes, so that the upper limit and the lower limit in the energy range are set;
the obtaining of the image energy parameter of the window area under each sliding window includes:
calculating the image energy parameter of the window area under each sliding window by using an integral image calculation method to obtain the image energy parameter of each window area;
wherein the image energy parameters include: an image energy value of the window region or an image energy density of the window region.
CN201910553935.5A 2019-06-25 2019-06-25 Two-dimensional code detection method and device Active CN110263595B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910553935.5A CN110263595B (en) 2019-06-25 2019-06-25 Two-dimensional code detection method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910553935.5A CN110263595B (en) 2019-06-25 2019-06-25 Two-dimensional code detection method and device

Publications (2)

Publication Number Publication Date
CN110263595A CN110263595A (en) 2019-09-20
CN110263595B true CN110263595B (en) 2023-02-17

Family

ID=67921220

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910553935.5A Active CN110263595B (en) 2019-06-25 2019-06-25 Two-dimensional code detection method and device

Country Status (1)

Country Link
CN (1) CN110263595B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110245538A (en) * 2019-06-26 2019-09-17 北京慧眼智行科技有限公司 A kind of horizontal and vertical parity check code localization method and system
CN111368573A (en) * 2020-03-02 2020-07-03 凌云光技术集团有限责任公司 Positioning method based on geometric feature constraint
CN111462099B (en) * 2020-04-05 2024-01-23 中国人民解放军总医院 Image cell area positioning method based on rapid integral graph monitoring
CN112085651B (en) * 2020-09-23 2021-06-29 中国空气动力研究与发展中心高速空气动力研究所 Automatic shock wave detection and tracking algorithm based on image self-adaptive threshold and feature extraction
CN113283262A (en) * 2020-12-29 2021-08-20 深圳怡化电脑股份有限公司 Two-dimensional code positioning method and device, electronic equipment and machine readable medium
CN114359238A (en) * 2022-01-07 2022-04-15 自然资源部第三海洋研究所 Method, device and storage medium for identifying micro-plastic
CN114330408A (en) * 2022-03-14 2022-04-12 深圳市联志光电科技有限公司 Image enhancement method and image enhancement device
CN117021809B (en) * 2023-08-15 2024-06-25 深圳市大满包装有限公司 Digital printing-based two-dimensional anti-fake code printing regulation and control method and system

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103093225A (en) * 2013-01-05 2013-05-08 武汉矽感科技有限公司 Binaryzation method of two-dimension code image
CN104504662A (en) * 2014-12-26 2015-04-08 北京慧眼智行科技有限公司 Homomorphic filtering based image processing method and system
CN105260694A (en) * 2015-10-22 2016-01-20 佛山科学技术学院 Two-dimension code area locating method based on multistage backbone extraction and analysis
CN106709394A (en) * 2016-12-12 2017-05-24 北京慧眼智行科技有限公司 Image processing method and device
CN109101856A (en) * 2018-09-25 2018-12-28 广东工业大学 A kind of image in 2 D code recognition methods and device
CN109800615A (en) * 2018-12-28 2019-05-24 新大陆数字技术股份有限公司 The detection localization method and system of two-dimension code area

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4208481B2 (en) * 2002-04-30 2009-01-14 トッパン・フォームズ株式会社 Two-dimensional code reading method, two-dimensional code reading system, and article with a two-dimensional code used therein
DE60328923D1 (en) * 2003-04-15 2009-10-01 Fujitsu Ltd CODE RECOGNITION AND DEVICE
JP3957734B1 (en) * 2006-08-25 2007-08-15 株式会社バンダイナムコゲームス Program, information storage medium, 2D code generation system, 2D code
JP5057560B2 (en) * 2006-12-14 2012-10-24 株式会社バンダイナムコゲームス Program, information storage medium, two-dimensional code, printed matter, two-dimensional code image, two-dimensional code image display control method, two-dimensional code generation system
CN105069389B (en) * 2015-07-27 2017-10-31 福建联迪商用设备有限公司 Quick Response Code piecemeal coding/decoding method and system
CN105160339B (en) * 2015-08-06 2018-05-04 四川大学 A kind of Quick Response Code print quality online evaluation method
CN106709393B (en) * 2015-11-13 2020-07-24 航天信息股份有限公司 QR two-dimensional code binarization method and system
CN109902530B (en) * 2019-03-04 2022-04-19 厦门商集网络科技有限责任公司 Two-dimensional code decoding method and terminal

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103093225A (en) * 2013-01-05 2013-05-08 武汉矽感科技有限公司 Binaryzation method of two-dimension code image
CN104504662A (en) * 2014-12-26 2015-04-08 北京慧眼智行科技有限公司 Homomorphic filtering based image processing method and system
CN105260694A (en) * 2015-10-22 2016-01-20 佛山科学技术学院 Two-dimension code area locating method based on multistage backbone extraction and analysis
CN106709394A (en) * 2016-12-12 2017-05-24 北京慧眼智行科技有限公司 Image processing method and device
CN109101856A (en) * 2018-09-25 2018-12-28 广东工业大学 A kind of image in 2 D code recognition methods and device
CN109800615A (en) * 2018-12-28 2019-05-24 新大陆数字技术股份有限公司 The detection localization method and system of two-dimension code area

Also Published As

Publication number Publication date
CN110263595A (en) 2019-09-20

Similar Documents

Publication Publication Date Title
CN110263595B (en) Two-dimensional code detection method and device
CN114418957B (en) Global and local binary pattern image crack segmentation method based on robot vision
CN109658424B (en) Improved robust two-dimensional OTSU threshold image segmentation method
CN105740876B (en) A kind of image pre-processing method and device
CN107784669A (en) A kind of method that hot spot extraction and its barycenter determine
CN112261403B (en) Device and method for detecting dirt of vehicle-mounted camera
CN110378893B (en) Image quality evaluation method and device and electronic equipment
CN110913243A (en) Video auditing method, device and equipment
CN111696064B (en) Image processing method, device, electronic equipment and computer readable medium
CN109815762B (en) Method and storage medium for remotely identifying two-dimensional code
CN111027546A (en) Character segmentation method and device and computer readable storage medium
CN113379739B (en) Ultrasonic image identification method, device, equipment and storage medium
CN110502977B (en) Building change classification detection method, system, device and storage medium
CN117094975A (en) Method and device for detecting surface defects of steel and electronic equipment
CN110287752B (en) Lattice code detection method and device
CN110555863A (en) moving object detection method and device and computer readable storage medium
JP2008210387A (en) Noise elimination device and noise elimination program for improving binarization performance of document image
CN114820394A (en) Image noise filtering method and device based on robust parameter estimation
Khellah Textured image denoising using dominant neighborhood structure
CN111951254B (en) Edge-guided weighted-average-based source camera identification method and system
JPH10285399A (en) Binarization method for image
JP2003216953A (en) Method and device for extracting object from image
CN107491746B (en) Face pre-screening method based on large gradient pixel analysis
CN117423113B (en) Adaptive denoising method for archive OCR (optical character recognition) image
CN118095971B (en) AD calcium milk beverage processing technology assessment method, system and medium

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
GR01 Patent grant
GR01 Patent grant