CN113283262A - Two-dimensional code positioning method and device, electronic equipment and machine readable medium - Google Patents

Two-dimensional code positioning method and device, electronic equipment and machine readable medium Download PDF

Info

Publication number
CN113283262A
CN113283262A CN202011603091.XA CN202011603091A CN113283262A CN 113283262 A CN113283262 A CN 113283262A CN 202011603091 A CN202011603091 A CN 202011603091A CN 113283262 A CN113283262 A CN 113283262A
Authority
CN
China
Prior art keywords
image
pixel point
edge pixel
connected region
dimensional code
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
CN202011603091.XA
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.)
Nanjing Yihua Information Technology Co ltd
Shenzhen Yihua Computer Co Ltd
Shenzhen Yihua Time Technology Co Ltd
Original Assignee
Nanjing Yihua Information Technology Co ltd
Shenzhen Yihua Computer Co Ltd
Shenzhen Yihua Time 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 Nanjing Yihua Information Technology Co ltd, Shenzhen Yihua Computer Co Ltd, Shenzhen Yihua Time Technology Co Ltd filed Critical Nanjing Yihua Information Technology Co ltd
Priority to CN202011603091.XA priority Critical patent/CN113283262A/en
Publication of CN113283262A publication Critical patent/CN113283262A/en
Pending legal-status Critical Current

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
    • 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/1452Methods for optical code recognition including a method step for retrieval of the optical code detecting bar code edges
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/20Image enhancement or restoration by the use of local operators
    • G06T5/30Erosion or dilatation, e.g. thinning
    • G06T5/70
    • G06T5/90

Abstract

The embodiment of the invention provides a two-dimensional code positioning method, a two-dimensional code positioning device, electronic equipment and a machine readable medium, which are applied to the technical field of image recognition, wherein the method comprises the following steps: carrying out binarization processing and expansion processing on a preset image to be processed to generate a binary image; searching a connected region in the binary image; searching a target image area of which the gray value accords with the preset two-dimensional code characteristic in the binary image; for one connected region, determining the overlapping rate of the connected region and the target image region in a binary image; when the overlapping rate of the connected region and the target image region in the binary image is larger than a preset threshold value, the connected region is determined as a target connected region, and the position information of the target connected region is used as the position information of the two-dimensional code, so that the position of the two-dimensional code can be quickly positioned in the binary image, and the accuracy is high.

Description

Two-dimensional code positioning method and device, electronic equipment and machine readable medium
Technical Field
The present invention relates to the field of image recognition technologies, and in particular, to a two-dimensional code positioning method, a two-dimensional code positioning apparatus, an electronic device, and a machine-readable medium.
Background
In the prior art, in the process of identifying the two-dimensional code, the position of the two-dimensional code needs to be located in an image. However, in the prior art, the two-dimensional code usually needs to be correctly positioned under the condition that the two-dimensional code occupies a large proportion of the image. For example, in the process of scanning a two-dimensional code by a mobile phone, the mobile phone is usually required to be close to the two-dimensional code, and the size and the position of the two-dimensional code in an image are matched with a preset identification frame in a mobile phone interface as much as possible, so that the two-dimensional code can be correctly positioned.
In some scenes needing to identify the two-dimensional code, the image acquisition equipment is difficult to approach the shot object, so that the proportion of the two-dimensional code in the image acquired by the image acquisition equipment is small, and more other contents possibly exist in the image, so that the position of the two-dimensional code is difficult to find quickly in the image.
Disclosure of Invention
In view of the foregoing problems, embodiments of the present invention are provided to provide a two-dimensional code positioning method and a corresponding two-dimensional code positioning apparatus for improving the efficiency of searching for a two-dimensional code position in an image.
In order to solve the above problem, an embodiment of the present invention discloses a two-dimensional code positioning method, including:
carrying out binarization processing and expansion processing on a preset image to be processed to generate a binary image;
searching a connected region in the binary image;
searching a target image area of which the gray value accords with the preset two-dimensional code characteristic in the binary image;
for one connected region, determining the overlapping rate of the connected region and the target image region in a binary image;
when the overlapping rate of the connected region and the target image region in the binary image is larger than a preset threshold value, determining the connected region as a target connected region, and using the position information of the target connected region as the position information of the two-dimensional code.
Optionally, the step of searching for a connected region in the binary image includes:
in the binary image, based on a preset operation space, searching an edge pixel point located at the edge of a connected region, and creating a storage space to store the position information of the edge pixel point;
for the current edge pixel point, based on the operation space, searching an adjacent edge pixel point located at the periphery of the current edge pixel point, and storing the position information of the adjacent edge pixel point by adopting the storage space;
taking the adjacent edge pixel point as the current edge pixel point, repeatedly executing the step of searching the adjacent edge pixel point located at the periphery of the current edge pixel point based on the operation space for the current edge pixel point, storing the position information of the adjacent edge pixel point by adopting the storage space until the adjacent edge pixel point at the periphery of the current edge pixel point is the searched edge pixel point, and emptying the operation space;
and determining the connected region according to the position information of the edge pixel points.
Optionally, the step of searching for the target image region in the binary image, where the gray scale value meets a preset two-dimensional code feature, includes:
performing integral processing on the binary image to generate an integral image;
traversing the integral image by adopting a preset sliding window, and searching a target image area with a gray value according with the characteristics of a preset two-dimensional code.
Optionally, the step of performing integration processing on the binary image to generate an integrated image includes:
for a pixel point in the integral image, taking the sum of all pixel point values in a rectangle formed between a pixel point in the binary image and the origin of the binary image, wherein the pixel point is the same as the binary image in position, as the value of the pixel point in the integral image;
and sequentially determining the value of each pixel point in the integral image to generate the integral image.
Optionally, the step of traversing the integral image by using a preset sliding window and searching for a target image area with a gray value according with a preset two-dimensional code characteristic includes:
and traversing the integral image by adopting a preset sequence by adopting a preset sliding window and taking the original point of the binary image as a starting point, and searching a target image area with a gray value according with the characteristics of a preset two-dimensional code.
Optionally, before the step of performing binarization processing and dilation processing on the preset image to be processed to generate a binary image, the method further includes:
carrying out graying processing on a preset image to be identified to generate a grayed image;
and carrying out filtering processing on the grayed image to generate a filtering image.
The embodiment of the invention also discloses a two-dimensional code positioning device, which comprises:
the first image processing module is used for carrying out binarization processing and expansion processing on a preset image to be processed to generate a binary image;
the connected region searching module is used for searching a connected region in the binary image;
the target image area searching module is used for searching a target image area of which the gray value accords with the preset two-dimensional code characteristics in the binary image;
the overlapping rate determining module is used for determining the overlapping rate of the connected region and the target image region in the binary image aiming at the connected region;
and the two-dimensional code determining module is used for determining the connected region as a target connected region and taking the position information of the target connected region as the position information of the two-dimensional code when the overlapping rate of the connected region and the target image region in the binary image is greater than a preset threshold value.
Optionally, the connected region searching module includes:
the edge pixel point searching submodule is used for searching an edge pixel point positioned at the edge of the connected region in the binary image based on a preset operation space, and establishing a storage space to store the position information of the edge pixel point;
the first adjacent edge pixel point searching submodule is used for searching adjacent edge pixel points positioned at the periphery of the current edge pixel point on the basis of the operation space for the current edge pixel point and storing the position information of the adjacent edge pixel points by adopting the storage space;
a second adjacent edge pixel point searching submodule, configured to use the adjacent edge pixel point as the current edge pixel point, repeatedly execute the step of searching for an adjacent edge pixel point located around the current edge pixel point based on the operation space, store the position information of the adjacent edge pixel point in the storage space until the adjacent edge pixel point around the current edge pixel point is the searched edge pixel point, and empty the operation space;
and the connected region determining submodule is used for determining the connected region according to the position information of the edge pixel points.
Optionally, the target image area searching module includes:
the integral image generation submodule is used for carrying out integral processing on the binary image to generate an integral image;
and the traversing submodule is used for traversing the integral image by adopting a preset sliding window and searching a target image area with the gray value according with the preset two-dimensional code characteristics.
Optionally, the integral image generation sub-module comprises:
a pixel point value determining unit, configured to, for a pixel point in the integral image, use a sum of pixel point values in a rectangle formed between a pixel point in the binary image and an origin of the binary image, the pixel point value being at the same position as the pixel point in the binary image, as a value of the pixel point in the integral image;
and the integral image generation unit is used for sequentially determining the value of each pixel point in the integral image and generating the integral image.
Optionally, the traversal submodule includes:
and the traversal subunit is used for traversing the integral image by adopting a preset sequence by adopting a preset sliding window and taking the original point of the binary image as a starting point, and searching a target image area with a gray value according with the preset two-dimensional code characteristic.
Optionally, the apparatus further comprises:
the grayscale image generation module is used for carrying out grayscale processing on a preset image to be identified to generate a grayscale image;
and the filtering image generating module is used for carrying out filtering processing on the gray images to generate filtering images.
The embodiment of the invention also discloses an electronic device, which comprises:
one or more processors; and
one or more machine-readable media having instructions stored thereon, which when executed by the one or more processors, cause the electronic device to perform one or more methods as described in embodiments of the invention.
Embodiments of the invention also disclose one or more machine-readable media having instructions stored thereon, which when executed by one or more processors, cause the processors to perform one or more methods as described in embodiments of the invention.
The embodiment of the invention has the following advantages:
according to the two-dimensional code positioning method provided by the embodiment of the invention, the preset image to be processed is subjected to binarization processing and expansion processing to generate a binary image, so that a two-dimensional code region can be covered by pixel points of a target value as much as possible, then a connected region is searched in the binary image to search a region which is possibly a two-dimensional code based on connectivity, and a target image region with the gray level meeting the characteristics of the preset two-dimensional code in the binary image is searched, so that the region which possibly contains the two-dimensional code can be searched in the binary image based on the gray level. Then, according to the overlapping rate of the connected region and the target image region in the binary image, when the overlapping rate of the connected region and the target image region in the binary image is greater than a preset threshold value, the connected region is determined as the target connected region, and the position information of the target connected region is used as the position information of the two-dimensional code, so that the position of the two-dimensional code can be quickly positioned in the binary image, and the accuracy is high.
Drawings
Fig. 1 is a flowchart illustrating steps of a two-dimensional code positioning method according to an embodiment of the present invention;
fig. 2 is a flowchart illustrating steps of another two-dimensional code positioning method according to an embodiment of the present invention;
FIG. 3 is a schematic view of a border region of an embodiment of the present invention;
FIG. 4 is a schematic diagram of a binary image according to an embodiment of the present invention;
fig. 5 is a block diagram of a two-dimensional code positioning device according to an embodiment of the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
The core concept of the embodiment of the invention is that for an image with more content and a smaller proportion of two-dimensional codes in the image, after binarization processing and expansion processing are performed on a preset image to be processed, a connected region which may be a two-dimensional code is searched in a binary image, a target image region with a gray value which accords with the characteristics of the preset two-dimensional code is searched in the binary image, and the position of the two-dimensional code is determined based on the overlapping rate of the connected region and the target image region in the binary image, so that the position of the two-dimensional code in the image can be quickly determined based on connectivity and the gray value, and the efficiency of positioning the position of the two-dimensional code in a complex image is improved.
Referring to fig. 1, a flowchart illustrating steps of a two-dimensional code positioning method according to an embodiment of the present invention is shown, which may specifically include the following steps:
101, performing binarization processing and expansion processing on a preset image to be processed to generate a binary image;
in the embodiment of the invention, the image to be recognized, which needs to be subjected to two-dimensional code recognition, can be preset. The image to be recognized may be acquired by an image acquisition device, may be acquired by intercepting a part of a display area in a display screen, and the like, which is not limited in the present invention.
In the embodiment of the invention, in order to reduce unnecessary information in the image to be recognized, binarization processing can be performed on the image to be recognized, so that the image only contains two pixel points with different numerical values. For example, the pixel is only black or white, and the value of the pixel may be (255 ) or (0,0, 0). For another example, the pixel point may be only black or red, and the value of the pixel point may be (255,0,0) or (0,0, 0).
Then, in the image to be identified, the two-dimensional code may generally include pixel points of at least two colors, so that in the binary image, the region of the two-dimensional code may generally include pixel points of two different numerical values. The area of the two-dimensional code is likely to have the pixel points located at the edge of the two-dimensional code and inside the two-dimensional code and the pixel points in the non-two-dimensional code area to have the same value, so that the condition that the inside of the two-dimensional code is communicated with the outside area appears, and errors are likely to exist in the positioning of the two-dimensional code. Therefore, the image to be processed can be expanded, so that the two-dimensional code area can be covered by the pixel points of the target value as much as possible, and the area where the two-dimensional code is located can be conveniently and accurately searched in the follow-up process.
In a specific implementation, the image to be processed may be binarized first. Specifically, a fixed threshold value mode may be adopted to perform binarization processing on the filtered image; the filtering image may also be binarized in a self-adaptive binarization manner, which is not limited in the present invention.
After the binarization processing is finished, the image after the binarization processing can be further subjected to expansion processing, and a preset convolution template or convolution kernel is adopted to perform convolution operation on the image after the binarization processing is finished, so that the image is obtained. Specifically, a preset convolution template or convolution kernel may be adopted to determine a maximum value of a pixel point of the image region covered by the preset convolution template or convolution kernel, and the maximum value is assigned to a pixel point corresponding to a reference point in the convolution template or convolution kernel in the image region, thereby completing expansion processing on the image.
Step 102, searching a connected region in a binary image;
in the binary image, if a plurality of target-valued pixel points are adjacent to each other, the target-valued pixel points can be considered to form a connected region. For example, in a binary image with only black or white pixels, if the target value is white and the values of the pixels with the coordinates (1,1), (1,2), and (1,3) are all white, it can be considered that the pixels with the coordinates (1,1), (1,2), and (1,3) form a connected region.
In the embodiment of the present invention, in general, a two-dimensional code may generally form a connected region in a binary image. Therefore, at least one connected region can be searched in the binary image to search possible positions of the two-dimensional code.
103, searching a target image area of which the gray value accords with the preset two-dimensional code characteristics in the binary image;
in the embodiment of the invention, the binary image can be divided into a plurality of image areas, and the gray values of the image areas are obtained. Therefore, whether at least one target image area with the gray value meeting the preset two-dimensional code characteristics exists in the binary image or not can be searched based on the gray value.
The gray value of the image area may be the sum of values of pixel points in the image area.
In a specific implementation, the pixels in the binary image can be divided into background pixels and effective pixels. The background pixel points may be pixel points corresponding to a background region in the image. The effective pixel points may be pixel points corresponding to an effective information area in the image. The valid information may be a two-dimensional code, a character, an image, a shape, and the like, which is not limited in the present invention. For example, if the binary image includes a plurality of white characters of a black background, the pixel points in the area corresponding to the black background are background pixel points, and the pixel points corresponding to the white characters are effective pixel points.
Therefore, for an image area with a two-dimensional code, the image area can usually have more effective pixel points. Under the condition that the image area has more effective pixel points and less background pixel points, the gray value of the image area can be more inclined to the numerical value of multiplying the gray value of the effective pixel points by the number of the pixel points in the image area. For example, if the gray-level value of the effective pixel is 255, the gray-level value of the image region may be a value obtained by multiplying 255 by the number of pixels in the image region.
Therefore, a gray value threshold value can be set as the preset two-dimensional code characteristic. Under the condition that the gray value of the image area is larger than the preset two-dimensional code characteristic, the image area is considered to have more effective pixel points, the image area has a larger area which is probably a two-dimensional code, and the image area is used as a target image area.
Step 104, aiming at one connected region, determining the overlapping rate of the connected region and the target image region in a binary image;
in the embodiment of the present invention, since the connected region may be a two-dimensional code, a character, an image, a shape, or the like, it is necessary to further determine whether the connected region is a two-dimensional code. Therefore, the position of the connected region can be compared with the position of the target image region, and the target connected region is selected from the connected region as the two-dimensional code according to the position relation between the connected region and the image region.
In the embodiment of the present invention, at least one connected region may be found in the binary image, and whether the connected region is a two-dimensional code may be further determined. And for the target image area, it may be an area containing the two-dimensional code. Therefore, the overlapping rate of the connected region and the target image region in the binary image can be determined, so as to determine whether the two-dimensional code is contained in the connected region based on the overlapping rate, and thus determine whether the connected region is the region where the two-dimensional code is located.
In a specific implementation, the overlapping rate of the connected region and the target image region in the binary image may be determined by calculating an intersection ratio. Specifically, the intersection-to-parallel ratio can be calculated using the following formula:
Figure BDA0002869405150000081
wherein C is the region of the connected region in the binary image, and G is the region of the target image region in the image.
And 105, when the overlapping rate of the connected region and the target image region in the binary image is greater than a preset threshold value, determining the connected region as a target connected region, and using the position information of the target connected region as the position information of the two-dimensional code.
In the embodiment of the present invention, when the overlapping rate of the connected region and the image region in the binary image is greater than a preset threshold, most of the connected region and the image region in the binary image may be considered to overlap with each other, that is, the connected region includes the two-dimensional code content in the target image region, so that the connected region may be considered as the position of the two-dimensional code, the connected region is determined as the target connected region, and the position information of the target connected region is used as the position information of the two-dimensional code, thereby completing the positioning of the two-dimensional code.
In the embodiment of the invention, for a scene with a fixed camera position, for example, in a bill storage device, a bill can be shot during storage or distribution, and the two-dimensional code on the bill can be identified. However, in the image captured by the camera, the position of the bill is not always fixed, and the two-dimensional code has a small proportion in the image captured by the camera, and other information of the bill and a mechanical structure in the bill storage device may be captured in the image, which makes recognition of the two-dimensional code difficult. Under the condition, generating a binary image by performing binarization processing and expansion processing on a preset image to be processed; searching a connected region in the binary image; searching a target image area of which the gray value accords with the preset two-dimensional code characteristic in the binary image; for one connected region, determining the overlapping rate of the connected region and the target image region in a binary image; when the overlapping rate of the connected region and the target image region in the binary image is larger than a preset threshold value, the connected region is determined as the target connected region, the position information of the target connected region is used as the position information of the two-dimensional code, and the position information of the two-dimensional code can be efficiently determined in the image, so that the positioning of the two-dimensional code can be rapidly completed in the process of storing or issuing the bill, and the processing efficiency of the bill storage device is improved.
According to the two-dimensional code positioning method provided by the embodiment of the invention, the preset image to be processed is subjected to binarization processing and expansion processing to generate a binary image, so that a two-dimensional code region can be covered by pixel points of a target value as much as possible, then a connected region is searched in the binary image to search a region which is possibly a two-dimensional code based on connectivity, and a target image region with the gray level meeting the characteristics of the preset two-dimensional code in the binary image is searched, so that the region which possibly contains the two-dimensional code can be searched in the binary image based on the gray level. Then, according to the overlapping rate of the connected region and the target image region in the binary image, when the overlapping rate of the connected region and the target image region in the binary image is greater than a preset threshold value, the connected region is determined as the target connected region, and the position information of the target connected region is used as the position information of the two-dimensional code, so that the position of the two-dimensional code can be quickly positioned in the binary image, and the accuracy is high.
Referring to fig. 2, a flowchart illustrating steps of a two-dimensional code positioning method according to an embodiment of the present invention is shown, which may specifically include the following steps:
step 201, performing binarization processing and expansion processing on a preset image to be processed to generate a binary image;
in the embodiment of the invention, the image to be recognized, which needs to be subjected to two-dimensional code recognition, can be preset. The image to be recognized may be acquired by an image acquisition device, may be acquired by intercepting a part of a display area in a display screen, and the like, which is not limited in the present invention.
In the embodiment of the invention, in order to reduce unnecessary information in the image to be recognized, binarization processing can be performed on the image to be recognized, so that the image only contains two pixel points with different numerical values. For example, the pixel is only black or white, and the value of the pixel may be (255 ) or (0,0, 0). For another example, the pixel point may be only black or red, and the value of the pixel point may be (255,0,0) or (0,0, 0).
Then, in the image to be identified, the two-dimensional code may generally include pixel points of at least two colors, so that in the binary image, the region of the two-dimensional code may generally include pixel points of two different numerical values. The area of the two-dimensional code is likely to have the pixel points located at the edge of the two-dimensional code and inside the two-dimensional code and the pixel points in the non-two-dimensional code area to have the same value, so that the condition that the inside of the two-dimensional code is communicated with the outside area appears, and errors are likely to exist in the positioning of the two-dimensional code. Therefore, the image to be processed can be expanded, so that the two-dimensional code area can be covered by the pixel points of the target value as much as possible, and the area where the two-dimensional code is located can be conveniently and accurately searched in the follow-up process.
In a specific implementation, the image to be processed may be binarized first. Specifically, a fixed threshold value mode may be adopted to perform binarization processing on the filtered image; the filtering image may also be binarized in a self-adaptive binarization manner, which is not limited in the present invention.
After the binarization processing is finished, the image after the binarization processing can be further subjected to expansion processing, and a preset convolution template or convolution kernel is adopted to perform convolution operation on the image after the binarization processing is finished, so that the image is obtained. Specifically, a preset convolution template or convolution kernel may be adopted to determine a maximum value of a pixel point of the image region covered by the preset convolution template or convolution kernel, and the maximum value is assigned to a pixel point corresponding to a reference point in the convolution template or convolution kernel in the image region, thereby completing expansion processing on the image.
In an embodiment of the present invention, before the step of performing binarization processing and dilation processing on the preset image to be processed to generate a binary image, the method further includes:
s11, carrying out graying processing on a preset image to be identified to generate a grayed image;
in the embodiment of the present invention, in order to reduce unnecessary information in the image to be recognized, a graying process may be performed on the image to be recognized to generate a grayed image. Specifically, the graying process may adopt an average value method, and an average value of RGB three components of each pixel point in the color image is used as a gray value, so as to obtain a grayed image; or a weighted average method can be adopted, and the weighted average value of the RGB three components of each pixel point in the color image is used as a gray value, so that a gray image is obtained; the maximum value method may also be adopted, and the maximum value in the RGB three-components of each pixel point in the color image is taken as the gray value, so as to obtain a grayed image, which is not limited by the present invention.
S12, filtering the grayed image to generate a filtered image;
in the embodiment of the invention, after the graying processing, the grayed image can be further subjected to filtering processing to remove noise in the grayed image and reduce interference on subsequent two-dimensional code positioning.
In a specific implementation, a convolution kernel with a preset size may be used to perform convolution processing on the grayed image, so as to obtain the filtered image. The size of the convolution kernel may be 5 × 5, 10 × 10, and the like, which is not limited in the present invention.
Thereafter, binarization processing and expansion processing may be performed on the filtered image to obtain a binary image. The binary image obtained based on the filtered image can include fewer noise points, so that the two-dimensional code is positioned more accurately.
Step 202, searching a connected region in the binary image;
in the embodiment of the present invention, a binary image including a two-dimensional code may be preset. In the binary image, the values of the pixel points may have only two possible values. In the binary image, if a plurality of target-valued pixel points are adjacent to each other, the target-valued pixel points can be considered to form a connected region. In general, a two-dimensional code can generally form a connected region in a binary image. Therefore, at least one connected region can be searched in the binary image to search possible positions of the two-dimensional code.
In an embodiment of the present invention, the step of searching for a connected component in the binary image includes:
s21, searching an edge pixel point located at the edge of the connected region in the binary image based on a preset operation space, and creating a storage space to store the position information of the edge pixel point;
in the embodiment of the present invention, an operation space may be created in advance to perform operations required for image processing. In general, for a binary image, it may create the computation space before preparing to process the binary image. The computation space can then be directly used for image processing operations.
In the embodiment of the present invention, a binary image including characters may be preset. In the binary image, the values of the pixel points may have only two possible values. In the binary image, if a plurality of target-valued pixel points are adjacent to each other, the target-valued pixel points can be considered to form a connected region.
In the embodiment of the present invention, generally, characters may generally form connected regions in a binary image. Therefore, the edge pixel points at the edge of the connected region can be considered as the edge outline of a certain character. Therefore, the outline of a certain character can be determined by searching the edge pixel points at the edge of the connected region, and then after the edge pixel points at the edge of the connected region are searched, a storage space can be created for storing the position information of the edge pixel points of the connected region.
In order to efficiently find the edge pixel point located at the edge of the connected region in the binary image, an edge pixel point located at the edge of the connected region may be first found in the binary image, so that other edge pixel points of the connected region may be further found based on the edge pixel point in the following.
In an embodiment of the present invention, the step of searching for an edge pixel point located at an edge of a connected region in the binary image based on a preset operation space, and creating a storage space to store the location information of the edge pixel point includes:
s211, searching whether effective pixel points adjacent to background pixel points exist in the binary image line by line based on a preset operation space;
in the embodiment of the invention, the pixel points in the binary image can be divided into background pixel points and effective pixel points. The background pixel points may be pixel points corresponding to a background region in the image. The effective pixel points may be pixel points corresponding to an effective information area in the image. The valid information may be a character, an image, a shape, etc., which is not limited in this respect. For example, if the binary image includes a plurality of white characters of a black background, the pixel points in the area corresponding to the black background are background pixel points, and the pixel points corresponding to the white characters are effective pixel points.
In the embodiment of the present invention, the pixel point corresponding to the connected region may be an effective pixel point, and the effective pixel point adjacent to the background pixel point may be a pixel point located at an edge position of the connected region. Therefore, image processing operation can be carried out in the binary image based on a preset operation space, whether pixel points adjacent to background pixel points exist or not is determined in sequence in a line-by-line searching mode, and whether edge pixel points located at the edge of a communicated region exist or not is determined. Therefore, the binary image can be efficiently and normatively traversed, and the searching efficiency of the edge pixel points is improved.
S212, under the condition that the effective pixel points adjacent to the background pixel points exist, the effective pixel points adjacent to the background pixel points are used as edge pixel points of the edges of the communicated region, and a storage space is created to store the position information of the edge pixel points.
In the embodiment of the present invention, when an effective pixel point adjacent to the background pixel point is found, the effective pixel point adjacent to the background pixel point can be regarded as a pixel point located at an edge in the connected region. Therefore, the effective pixel points adjacent to the background pixel points can be used as edge pixel points of the edge of the connected region, and a storage space is created to store the position information of the edge pixel points. And subsequently, based on the edge pixel point, searching other edge pixel points of the connected region is completed.
S22, for the current edge pixel point, based on the operation space, searching the adjacent edge pixel point around the current edge pixel point, and storing the position information of the adjacent edge pixel point by adopting the storage space;
in the embodiment of the present invention, since the edge pixel point of the communication area surrounds the edge of the communication area for a circle, in the adjacent area of the adjacent pixel point, other pixel points serving as the edge of the communication area may exist. Therefore, after searching for an edge pixel point, based on the position of the current edge pixel point, image processing operation is performed in the operation space, so that adjacent edge pixel points around the current edge pixel point are further searched, and the searched position information of the adjacent edge pixel points is stored in real time by adopting the storage space.
In a specific implementation, fig. 3 is a schematic diagram of a neighboring region according to an embodiment of the present invention. For pixel a, pixels 0-7 located at the periphery of pixel a can be considered as being adjacent to pixel a. The image processing operation can be performed based on the operation space, and whether other pixel points have the same value as the target value or not is sequentially determined in the adjacent area of the current edge pixel point, and at least one value of other adjacent pixel points is not the target value. And under the condition that other adjacent pixels to the current pixel meet the condition of the edge pixel, taking the pixel as the adjacent edge pixel around the current edge pixel, and storing the position information of the adjacent edge pixel by adopting the storage space.
In a specific implementation, in the adjacent region of the current pixel, there may exist a plurality of pixels that are all edge pixels of the communication region, and at this time, an edge pixel may be selected as an adjacent edge pixel of the current pixel.
Optionally, when searching for an adjacent edge pixel point located at the periphery of the current edge pixel point, image processing operation may be performed in the operation space, with a preset adjacent position as a starting point, and according to a preset selection direction, whether a pixel point in an adjacent region of the current pixel point is an edge pixel point is sequentially identified, and the first found edge pixel point is used as an adjacent edge pixel point of the current pixel point, and the storage space is used to store the position information of the adjacent edge pixel point. For example, it may be determined whether the pixels in the adjacent region to the current pixel are edge pixels sequentially in the counterclockwise direction from the position of the pixel 3 in fig. 3, or it may be determined whether the pixels in the adjacent region to the current pixel are edge pixels sequentially in the clockwise direction from the position of the pixel 7 in fig. 3.
In an embodiment of the present invention, the step of searching, for the current edge pixel, an adjacent edge pixel located around the current edge pixel based on the operation space, and storing the position information of the adjacent edge pixel by using the storage space includes:
s221, sequentially determining whether the pixels adjacent to the current edge pixel are the same as the edge pixels or not by adopting a preset direction based on the operation space for the current edge pixel;
in the embodiment of the present invention, for the found current edge pixel, image processing operation may be performed based on the operation space, and whether the current edge pixel is the edge pixel is sequentially determined in a preset direction, so that the edge pixels may be sequentially found in a sequence surrounding the edge of the communication area by one circle, and the missing detection of the edge pixel is avoided while the finding efficiency is improved.
The preset direction may be that an adjacent edge pixel point located at the current edge pixel point is sequentially searched clockwise or counterclockwise by using a certain position in the adjacent region as a starting point.
In an embodiment of the present invention, the step of sequentially determining, based on the operation space and in a preset direction, whether a pixel point adjacent to the current edge pixel point is the edge pixel point includes:
s2211, for the current edge pixel, based on the operation space, sequentially determining whether pixels adjacent to the current edge pixel are the same as the edge pixel clockwise or counterclockwise, with pixels in the adjacent region having the same direction as the line-by-line search starting point as the starting point.
In the embodiment of the present invention, the preset direction may be associated with a direction in which the starting point is searched line by line in the step of searching for the adjacent edge pixel point located around the current edge pixel point for the current edge pixel point. Under the condition that the preset direction is the same as the direction of the line-by-line searching starting point, the edge pixel points can be searched as comprehensively and efficiently as possible. Therefore, for the current edge pixel point, image processing operation can be carried out based on the operation space, and whether the pixel points adjacent to the current edge pixel point are the same as the edge pixel point or not is sequentially determined clockwise or anticlockwise by taking the pixel points in the adjacent area and the pixel points which are searched for in the same direction from line to line as starting points.
Specifically, when the progressive search starting point direction is a progressive search starting point from a certain angle in the image, for the current edge pixel point, the pixel point in the adjacent region at the same position as the progressive search starting point direction may be determined not to be an edge pixel point in the step of searching for the adjacent edge pixel point located at the periphery of the current edge pixel point for the current edge pixel point. And whether the pixel points except the pixel points at the same position as the starting point direction searched line by line in the adjacent area are edge pixel points is not determined. Therefore, under the condition that the preset direction is the same as the direction of the line-by-line searching starting point, the edge pixel points in the adjacent area of the current edge pixel point can be searched as comprehensively and efficiently as possible, and then whether the pixel points adjacent to the current edge pixel point are the same as the edge pixel points can be sequentially determined clockwise or anticlockwise.
As an example of the present invention, when the line-by-line searching direction is to search line-by-line from top to bottom with the top left corner as a starting point, for a current edge pixel point, a pixel point at the top left corner in an adjacent region, that is, a pixel point at the pixel point 3 in fig. 3, may already be determined as not being an edge pixel point in the step of searching for an adjacent edge pixel point located at the periphery of the current edge pixel point for the current edge pixel point. And the pixel points at other positions except the upper left corner position in the adjacent region are not determined to be edge pixel points. Therefore, when the line-by-line searching starting point direction is the upper left corner, and line-by-line searching is performed from top to bottom, whether the pixel points adjacent to the current edge pixel point are the same as the edge pixel point can be determined clockwise or anticlockwise sequentially by using the upper left corner pixel point in the adjacent area as the starting point.
As an example of the present invention, when the line-by-line search starting point direction is a starting point at the upper left corner, and the line-by-line search is performed from left to right, it may be determined clockwise or counterclockwise sequentially from the pixel point at the upper left corner of the current pixel point adjacent region as the starting point whether the pixel point adjacent to the current edge pixel point is the same as the edge pixel point.
As an example of the present invention, when the line-by-line search starting point direction is to use the upper right corner as a starting point, and search line by line from right to left, it may be determined clockwise or counterclockwise sequentially, using a pixel point at the upper right corner of the current pixel point adjacent region as a starting point, whether a pixel point adjacent to the current edge pixel point is also the edge pixel point.
As an example of the present invention, when the line-by-line search starting point direction is a starting point at a lower left corner, and the line-by-line search is performed from bottom to top, it may be determined clockwise or counterclockwise sequentially, using a pixel point at a lower left corner of a current pixel point adjacent region as a starting point, whether a pixel point adjacent to the current edge pixel point is also the edge pixel point.
As an example of the present invention, when the line-by-line search starting point direction is a starting point which is a lower right corner, and the line-by-line search is performed from bottom to top, it may be determined clockwise or counterclockwise sequentially, using a pixel point at a lower right corner of the current pixel point adjacent region as a starting point, whether a pixel point adjacent to the current edge pixel point is also the edge pixel point.
And S222, when the pixel point adjacent to the current edge pixel point is also the edge pixel point, taking the pixel point adjacent to the current edge pixel point as an adjacent edge pixel point, and storing the position information of the adjacent edge pixel point by using the storage space.
In the embodiment of the present invention, when the pixel point adjacent to the current edge pixel point is found to be the edge pixel point, the found edge pixel point and the edge pixel point adjacent to the current edge pixel point can use the pixel point adjacent to the current edge pixel point as the adjacent edge pixel point, and the storage space is used to store the position information of the adjacent edge pixel point, so that the edge pixel point in the communication area can be quickly found based on the adjacent relationship, and the real-time storage of the position information of the adjacent edge pixel point can be completed.
S23, taking the adjacent edge pixel point as the current edge pixel point, repeatedly executing the steps of searching for an adjacent edge pixel point located around the current edge pixel point based on the operation space, storing the position information of the adjacent edge pixel point by using the storage space until the adjacent edge pixel point around the current edge pixel point is the searched edge pixel point, and clearing the operation space;
in the embodiment of the present invention, after the adjacent edge pixel is searched, the adjacent region of the adjacent edge pixel may also have an edge pixel serving as the edge of the connected region. Therefore, the adjacent edge pixel point can be used as the current edge pixel point, the step of searching the adjacent edge pixel point located at the periphery of the current edge pixel point based on the operation space is repeatedly executed, the storage space is adopted to store the position information of the adjacent edge pixel point, so that the edge pixel points at the edge of the connected region can be continuously searched in sequence based on the adjacent relation, the position information of the adjacent edge pixel point is stored into the storage space in real time, and the edge pixel points forming the edge of the connected region can be considered to be basically searched at this moment until the adjacent edge pixel point at the periphery of the current edge pixel point is the searched edge pixel point. Therefore, the binary image finishes searching the edge pixel points of a communication area, data in the operation space can be cleared, the operation space is conveniently adopted for searching the next communication area subsequently, and a new operation space does not need to be applied again to process a new communication area.
In a specific implementation, in the adjacent region of the current pixel, there may be a plurality of pixels that are all edge pixels of the communication region, and then, based on the operation space, an edge pixel that is not found may be selected as an adjacent edge pixel of the current pixel, and the storage space is used to store the position information of the adjacent edge pixel.
Fig. 4 is a schematic diagram of a binary image according to an embodiment of the present invention. An edge pixel located at the edge of the connected region can be found in fig. 4, so that pixel 1 can be found as an edge pixel. Then, the pixel 1 can be used as the current pixel, and an adjacent edge pixel located at the periphery of the current edge pixel is searched. In the adjacent area of the pixel point 1, the pixel point 2 is also an edge pixel point, so that the pixel point 2 is the adjacent edge pixel point of the pixel point 1. Then, the pixel point 2 can be used as the current pixel point, and the adjacent edge pixel point around the pixel point 2 used as the current pixel point is found to be the pixel point 3. Then, the pixel point 3 can be used as the current pixel point, and the adjacent edge pixel point around the pixel point 3 used as the current pixel point is found to be the pixel point 4. Then, the pixel 4 can be used as the current pixel, and the adjacent edge pixel around the pixel 4 as the current pixel is found to be the pixel 5. Then, the pixel point 5 can be used as the current pixel point, and the adjacent edge pixel point around the pixel point 5 used as the current pixel point is found to be the pixel point 6. Then, the pixel 6 can be used as the current pixel, and the adjacent edge pixel around the pixel 6 as the current pixel is found to be the pixel 7. Then, the pixel 7 can be used as the current pixel, and the adjacent edge pixel around the pixel 7 as the current pixel is found to be the pixel 8. Then, the pixel 8 can be used as the current pixel, and the adjacent edge pixel around the pixel 8 used as the current pixel is found to be the pixel 9. Then, the pixel point 9 can be used as the current pixel point, and it is found that the pixel points 1,2, 7, and 8 which can be used as the adjacent edge pixel points in the adjacent area around the pixel point 9 are all the found edge pixel points. Thus, it can be considered that the edge pixel points forming the edge of the connected region are basically found.
And S24, determining the connected region according to the position information of the edge pixel points.
In the embodiment of the present invention, after the position of the edge pixel point in the two-dimensional image is determined, the position of the connected region in the binary image may be determined according to the position information of the edge pixel point in the storage space. So that at least one connected region, which may be a two-dimensional code, can be determined in the binary image.
In a specific implementation, the edge pixel point of the connected region may surround the edge of the connected region for a circle, so that when the position information of the edge pixel point of the connected region is determined, the edge position information of the region occupied by the connected region in the binary image can be obtained, and thus the position of the connected region in the binary image can be determined.
In one embodiment of the invention, the method further comprises:
and S31, determining the outer frame of the connected region according to the position information of the edge pixel points.
The connected region may be a two-dimensional code, or may be contents other than characters, such as characters, tables, patterns, noise, and the like. After determining the position information of the edge pixel points of the connected region, it may be further determined whether the connected region is a two-dimensional code. The outer frame of the connected region can generally indicate the size of the connected region, so that the outer frame of the connected region can be determined according to the position information of the edge pixel points, and whether the connected region is a two-dimensional code or not can be determined based on the outer frame of the connected region.
The shape of the external frame may be a rectangle, a circle, an irregular polygon, etc., which is not limited in the present invention.
In a specific implementation, the outer frame of the communication area may be generally attached to the edge of the communication area, so that the edge position of the communication area may be determined according to the position information of the edge pixel point, and an outer frame that can accommodate the communication area and has a frame line attached to the edge of the communication area may be determined.
In an embodiment of the present invention, the step of determining the bounding box of the connected region according to the position information of the edge pixel point includes:
s311, determining a first end point and a second end point of a diagonal line of the external frame according to the position information of the edge pixel points;
in an embodiment of the present invention, the shape of the outer frame of the connected region may be rectangular, so that the outer frame may have a diagonal line. For a rectangular external frame, when the positions of the end points at the two ends of a diagonal line are known, the external frame can be generated, and the generated external frame can be attached to the edge pixel points of the communication area. Therefore, the first end point and the second end point of the diagonal line of the external frame can be determined according to the position information of the edge pixel points.
In a specific implementation, in the case that the shape of the outer frame of the connected region is a rectangle, the connected region may have two diagonal lines. One diagonal line may be formed by connecting the top left corner endpoint and the bottom right corner endpoint of the external frame, and the other diagonal line may be formed by connecting the top right corner endpoint and the bottom left corner endpoint of the external frame. Meanwhile, the binary image may have the upper left corner of the image as the origin of coordinates.
The minimum x value, the minimum y value, the maximum x value, and the maximum y value can be searched in the position information of the edge pixel point. In the case where the bounding box is determined based on a diagonal line formed by connecting the upper-left endpoint and the lower-right endpoint, the minimum x value and the minimum y value may be used as the coordinates of the first endpoint, i.e., the upper-left endpoint, and the maximum x value and the maximum y value may be used as the coordinates of the second endpoint, i.e., the lower-right endpoint. In the case where the bounding box is determined based on the diagonal line formed by connecting the upper-right corner endpoint and the lower-left corner endpoint, the maximum x value and the minimum y value may be set as the coordinates of the first endpoint, i.e., the upper-right corner, and the minimum x value and the maximum y may be set as the coordinates of the second endpoint, i.e., the lower-left corner.
And S312, determining an outer frame of the connected region according to the position information of the first endpoint and the position information of the second endpoint.
In the embodiment of the present invention, for a rectangular bounding box, after determining the position information of a first endpoint and the position information of a second endpoint located at diagonal endpoints, a unique bounding box may be determined according to the position information of the first endpoint and the position information of the second endpoint, and the bounding box may be attached to an edge of the connection region, so as to determine the size of the connection region according to the bounding box.
S32, selecting at least one candidate two-dimensional code area in the connected area according to the size of the external frame.
In the embodiment of the present invention, after the size of the external frame is determined, at least one candidate two-dimensional code area that may be an area where a two-dimensional code is located may be determined in the connection area according to the size of the external frame.
In a specific implementation, the two-dimensional code may be generally square or circular. In this case, in the case where the size of the outline frame conforms to the characteristics of a square, such as the width and the height of the outline frame are the same, the connected region may be generally a square or a circle, and thus, the connected region in which the outline frame is a square may be used as a candidate two-dimensional code region.
Alternatively, in the case of processing the same type of image and fixing the camera position, the size of the two-dimensional code may be generally in a preset size range. For example, in a bill storage device, the position of a camera is fixed, and bills are all of the same type, so that in an image to be recognized captured by the camera, the size of a two-dimensional code of the bill can be generally in a preset size range. In this case, a connected region having a size within a preset size range may be further screened from the connected regions based on the size of the circumscribed frame as a candidate two-dimensional code region.
Step 203, performing integral processing on the binary image to generate an integral image;
in the embodiment of the invention, in order to quickly find the area of the image with the gray value according with the preset two-dimensional code characteristics, the integration processing can be carried out on the binary image to generate the integral image.
In an embodiment of the present invention, the integrating the binary image to generate an integral image includes:
s41, regarding a pixel point in the integral image, taking the sum of pixel point values in a rectangle formed between a pixel point in the binary image and the origin of the binary image, wherein the pixel point is the same as the binary image in position, as the value of the pixel point in the integral image;
in the embodiment of the present invention, the value of each pixel point in the integral image may be obtained based on the calculation of the pixel point in the binary image. For a pixel point in the integral image, the sum of all pixel point values in a rectangle formed between a pixel point in the binary image and the origin of the binary image, the pixel point having the same position as the pixel point in the binary image, may be used as the value of the pixel point in the integral image.
In a specific implementation, in a case where the upper left corner of the binary image is used as an origin, the value of each pixel point in the integral image may be the sum of all pixels in a rectangle formed by the pixel point and the origin, the pixel point and the origin being the same in position in the binary image.
As an example of the present invention, the following formula is used to calculate the value of a pixel point in an integral image;
Figure BDA0002869405150000211
wherein SAT (x, y) represents the value of a pixel at the (x, y) position in the integral image, I (x)i,yi) Representing (x) in a binary imagei,yi) The value of the location pixel.
Alternatively, the integral image may be incrementally calculated using the following equation:
SAT(x,y)=SAT(x,y-1)-SAT(x-1,y-1)+I(x,y)
then, in order to facilitate the calculation of the gray values of different areas based on the integral image, the values of the pixel points in the integral image can be normalized to the range of the gray values according to actual needs. For example, under the condition that the range of the gray value is 0-255, the value of the pixel point in the integral image is normalized to be in the range of 0-255.
And S42, sequentially determining the value of each pixel point in the integral image to generate the integral image.
In the embodiment of the present invention, the size of the integral image is the same as that of the binary image, so that the arrangement of the pixel points of the integral image is the same as that of the binary image. After the value of each pixel point in the integral image is determined in sequence, the integral image can be generated.
Step 204, traversing the integral image by adopting a preset sliding window, and searching a target image area with a gray value according with the characteristics of a preset two-dimensional code;
in the embodiment of the present invention, the gray-scale value of the image region may be the sum of values of the pixel points in the image region. Traversing the integral image by adopting a preset sliding window, and searching a target image area with a gray value according with the characteristics of a preset two-dimensional code.
In a specific implementation, the pixels in the binary image can be divided into background pixels and effective pixels. The background pixel points may be pixel points corresponding to a background region in the image. The effective pixel points may be pixel points corresponding to an effective information area in the image. The valid information may be a two-dimensional code, a character, an image, a shape, and the like, which is not limited in the present invention. For example, if the binary image includes a plurality of white characters of a black background, the pixel points in the area corresponding to the black background are background pixel points, and the pixel points corresponding to the white characters are effective pixel points.
Therefore, for an image area with a two-dimensional code, the image area can usually have more effective pixel points. Under the condition that the image area has more effective pixel points and less background pixel points, the gray value of the image area can be more inclined to the numerical value of multiplying the gray value of the effective pixel points by the number of the pixel points in the image area. For example, if the gray-level value of the effective pixel is 255, the gray-level value of the image region may be a value obtained by multiplying 255 by the number of pixels in the image region.
Therefore, a gray value threshold value can be set as the preset two-dimensional code characteristic. Under the condition that the gray value of the image area is larger than the preset two-dimensional code characteristic, the image area is considered to have more effective pixel points, the image area has a larger area which is probably a two-dimensional code, and the image area is used as a target image area.
In an embodiment of the present invention, the step of traversing the integral image by using a preset sliding window and searching for a target image region with a gray value according with a preset two-dimensional code feature includes:
and S51, traversing the integral image by adopting a preset sequence by adopting a preset sliding window and taking the original point of the binary image as a starting point, and searching a target image area with a gray value according with the preset two-dimensional code characteristic.
In the embodiment of the present invention, an origin is set in the binary image, and the origin may be located at the upper left corner of the binary image, the upper right corner of the binary image, the center point of the binary image, the edge midpoint of the binary image, and the like, which is not limited in this respect.
In the embodiment of the invention, a preset sliding window can be adopted, the integral image is traversed by adopting a preset sequence by taking the original point of the binary image as a starting point, and the target image area with the gray value according with the preset two-dimensional code characteristic is searched, so that the target image area with the gray value according with the preset two-dimensional code characteristic can be efficiently searched.
The preset sequence may be from left to right, from top to bottom, and the like, which is not limited in the present invention.
In a specific implementation, a sliding window with a preset size may be adopted, the integral image is traversed by adopting a preset sequence with the origin of the binary image as a starting point, gray values of different regions in the binary image are calculated, and an image region where the gray values meet preset two-dimensional code characteristics is searched. In the integral image, under the condition that the origin point is the upper left corner, the value of each pixel point is equal to the sum of the gray values of all the pixel points at the upper left corner, so that the gray value of the corresponding area in the binary image can be quickly calculated and obtained based on the values of the pixel points at the four corners of the sliding window in the integral image. And then, determining whether the image area corresponding to the sliding window accords with the preset two-dimensional code characteristic, and taking the image area as a target image area possibly containing the two-dimensional code under the condition of conforming to the preset two-dimensional code characteristic.
Wherein, the size of the sliding window can be determined according to actual needs. The size of the sliding window may be equal to the size of the two-dimensional code in the image, or may be smaller than the size of the two-dimensional code in the image, and the like, which is not limited in the present invention.
As an example of the present invention, the following formula can be used to calculate the sliding window corresponding region in the binary imageGray value of the field IABCD
IABCD=IA+IB-IC-ID
Wherein, IA、IB、IC、IDAnd the values of the pixel points at the four corners of the sliding window in the integral image are respectively.
Then, under the condition that the gray value of the effective pixel point is 255, the gray value I of the corresponding area of the sliding window in the binary image can be determined and calculatedABCDAnd the pixel area S of the regionABCDWhether the ratio between x 255 is greater than a preset threshold of 0.95. Gray value I of corresponding area of sliding window in binary imageABCDAnd the pixel area S of the regionABCDWhen the ratio of x 255 is greater than the preset threshold value of 0.95, it may be considered that the region includes more effective pixel points, and it has a larger possibility of including a two-dimensional code region, so that the region is used as a target image region.
Step 205, determining, for one of the connected regions, an overlapping rate of the connected region and the target image region in a binary image;
in the embodiment of the present invention, since the connected region may be a two-dimensional code, a character, an image, a shape, or the like, it is necessary to further determine whether the connected region is a two-dimensional code. Therefore, the position of the connected region can be compared with the position of the target image region, and the target connected region is selected from the connected region as the two-dimensional code according to the position relation between the connected region and the image region.
In the embodiment of the present invention, at least one connected region may be found in the binary image, and whether the connected region is a two-dimensional code may be further determined. And for the target image area, it may be an area containing the two-dimensional code. Therefore, the overlapping rate of the connected region and the target image region in the binary image can be determined, so as to determine whether the two-dimensional code is contained in the connected region based on the overlapping rate, and thus determine whether the connected region is the region where the two-dimensional code is located.
In a specific implementation, the overlapping rate of the connected region and the target image region in the binary image may be determined by calculating an intersection ratio. Specifically, the intersection-to-parallel ratio can be calculated using the following formula:
Figure BDA0002869405150000241
wherein C is the region of the connected region in the binary image, and G is the region of the target image region in the image.
And step 206, when the overlapping rate of the connected region and the target image region in the binary image is greater than a preset threshold value, determining the connected region as a target connected region, and using the position information of the target connected region as the position information of the two-dimensional code.
In the embodiment of the present invention, when the overlapping rate of the connected region and the image region in the binary image is greater than a preset threshold, most of the connected region and the image region in the binary image may be considered to overlap with each other, that is, the connected region includes the two-dimensional code content in the target image region, so that the connected region may be considered as the position of the two-dimensional code, the connected region is determined as the target connected region, and the position information of the target connected region is used as the position information of the two-dimensional code, thereby completing the positioning of the two-dimensional code.
According to the two-dimensional code positioning method, binarization processing and expansion processing are carried out on a preset image to be processed to generate a binary image, so that a two-dimensional code region can be covered by pixel points of a target value as much as possible, then a connected region is searched in the binary image to search a region which is possibly a two-dimensional code based on connectivity, integration processing is carried out on the binary image, and an integral image is generated; and traversing the integral image by adopting a preset sliding window, and searching a target image area with the gray value according with the characteristics of a preset two-dimensional code, so that an area possibly containing the two-dimensional code can be searched in the binary image based on the gray value. Then, according to the overlapping rate of the connected region and the target image region in the binary image, when the overlapping rate of the connected region and the target image region in the binary image is greater than a preset threshold value, the connected region is determined as the target connected region, and the position information of the target connected region is used as the position information of the two-dimensional code, so that the position of the two-dimensional code can be quickly positioned in the binary image, and the accuracy is high.
It should be noted that, for simplicity of description, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the illustrated order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments of the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no particular act is required to implement the invention.
Referring to fig. 5, a structural block diagram of an embodiment of a two-dimensional code positioning apparatus of the present invention is shown, which may specifically include the following modules:
the first image processing module 501 is configured to perform binarization processing and expansion processing on a preset image to be processed to generate a binary image;
a connected region searching module 502, configured to search a connected region in the binary image;
a target image area searching module 503, configured to search a target image area in the binary image, where a gray scale value of the target image area conforms to a preset two-dimensional code characteristic;
an overlap ratio determining module 504, configured to determine, for one of the connected regions, an overlap ratio of the connected region and the target image region in a binary image;
and a two-dimensional code determining module 505, configured to determine the connected region as a target connected region when an overlapping rate of the connected region and the target image region in the binary image is greater than a preset threshold, and use position information of the target connected region as position information of the two-dimensional code.
In an embodiment of the present invention, the connected region searching module includes:
the edge pixel point searching submodule is used for searching an edge pixel point positioned at the edge of the connected region in the binary image based on a preset operation space, and establishing a storage space to store the position information of the edge pixel point;
the first adjacent edge pixel point searching submodule is used for searching adjacent edge pixel points positioned at the periphery of the current edge pixel point on the basis of the operation space for the current edge pixel point and storing the position information of the adjacent edge pixel points by adopting the storage space;
a second adjacent edge pixel point searching submodule, configured to use the adjacent edge pixel point as the current edge pixel point, repeatedly execute the step of searching for an adjacent edge pixel point located around the current edge pixel point based on the operation space, store the position information of the adjacent edge pixel point in the storage space until the adjacent edge pixel point around the current edge pixel point is the searched edge pixel point, and empty the operation space;
and the connected region determining submodule is used for determining the connected region according to the position information of the edge pixel points.
In an embodiment of the present invention, the target image area searching module includes:
the integral image generation submodule is used for carrying out integral processing on the binary image to generate an integral image;
and the traversing submodule is used for traversing the integral image by adopting a preset sliding window and searching a target image area with the gray value according with the preset two-dimensional code characteristics.
In one embodiment of the invention, the integral image generation submodule includes:
a pixel point value determining unit, configured to, for a pixel point in the integral image, use a sum of pixel point values in a rectangle formed between a pixel point in the binary image and an origin of the binary image, the pixel point value being at the same position as the pixel point in the binary image, as a value of the pixel point in the integral image;
and the integral image generation unit is used for sequentially determining the value of each pixel point in the integral image and generating the integral image.
In one embodiment of the present invention, the traversal submodule includes:
and the traversal subunit is used for traversing the integral image by adopting a preset sequence by adopting a preset sliding window and taking the original point of the binary image as a starting point, and searching a target image area with a gray value according with the preset two-dimensional code characteristic.
In one embodiment of the invention, the apparatus further comprises:
the grayscale image generation module is used for carrying out grayscale processing on a preset image to be identified to generate a grayscale image;
and the filtering image generating module is used for carrying out filtering processing on the gray images to generate filtering images.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
An embodiment of the present invention further provides an electronic device, including:
one or more processors; and
one or more machine-readable media having instructions stored thereon, which when executed by the one or more processors, cause the electronic device to perform methods as described in embodiments of the invention.
Embodiments of the invention also provide one or more machine-readable media having instructions stored thereon, which when executed by one or more processors, cause the processors to perform the methods described in embodiments of the invention.
The embodiments in the present specification 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.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.
The two-dimensional code positioning method, the two-dimensional code positioning device, the electronic device and the machine-readable medium provided by the invention are introduced in detail, specific examples are applied in the text to explain the principle and the implementation of the invention, and the description of the above embodiments is only used for helping to understand the method and the core idea of the invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (10)

1. A two-dimensional code positioning method is characterized by comprising the following steps:
carrying out binarization processing and expansion processing on a preset image to be processed to generate a binary image;
searching a connected region in the binary image;
searching a target image area of which the gray value accords with the preset two-dimensional code characteristic in the binary image;
for one connected region, determining the overlapping rate of the connected region and the target image region in a binary image;
when the overlapping rate of the connected region and the target image region in the binary image is larger than a preset threshold value, determining the connected region as a target connected region, and using the position information of the target connected region as the position information of the two-dimensional code.
2. The method according to claim 1, wherein the step of searching for connected components in the binary image comprises:
in the binary image, based on a preset operation space, searching an edge pixel point located at the edge of a connected region, and creating a storage space to store the position information of the edge pixel point;
for the current edge pixel point, based on the operation space, searching an adjacent edge pixel point located at the periphery of the current edge pixel point, and storing the position information of the adjacent edge pixel point by adopting the storage space;
taking the adjacent edge pixel point as the current edge pixel point, repeatedly executing the step of searching the adjacent edge pixel point located at the periphery of the current edge pixel point based on the operation space for the current edge pixel point, storing the position information of the adjacent edge pixel point by adopting the storage space until the adjacent edge pixel point at the periphery of the current edge pixel point is the searched edge pixel point, and emptying the operation space;
and determining the connected region according to the position information of the edge pixel points.
3. The method according to claim 1, wherein the step of searching for the target image area with the gray scale value conforming to the preset two-dimensional code feature in the binary image comprises:
performing integral processing on the binary image to generate an integral image;
traversing the integral image by adopting a preset sliding window, and searching a target image area with a gray value according with the characteristics of a preset two-dimensional code.
4. The method according to claim 3, wherein the step of performing integration processing on the binary image to generate an integrated image comprises:
for a pixel point in the integral image, taking the sum of all pixel point values in a rectangle formed between a pixel point in the binary image and the origin of the binary image, wherein the pixel point is the same as the binary image in position, as the value of the pixel point in the integral image;
and sequentially determining the value of each pixel point in the integral image to generate the integral image.
5. The method according to claim 3, wherein the step of traversing the integral image by using a preset sliding window and searching for the target image area with the gray value according with the preset two-dimensional code characteristics comprises:
and traversing the integral image by adopting a preset sequence by adopting a preset sliding window and taking the original point of the binary image as a starting point, and searching a target image area with a gray value according with the characteristics of a preset two-dimensional code.
6. The method according to claim 1, wherein before the step of generating the binary image by performing binarization processing and dilation processing on the preset image to be processed, the method further comprises:
carrying out graying processing on a preset image to be identified to generate a grayed image;
and carrying out filtering processing on the grayed image to generate a filtering image.
7. The utility model provides a two-dimensional code positioner which characterized in that includes:
the first image processing module is used for carrying out binarization processing and expansion processing on a preset image to be processed to generate a binary image;
the connected region searching module is used for searching a connected region in the binary image;
the target image area searching module is used for searching a target image area of which the gray value accords with the preset two-dimensional code characteristics in the binary image;
the overlapping rate determining module is used for determining the overlapping rate of the connected region and the target image region in the binary image aiming at the connected region;
and the two-dimensional code determining module is used for determining the connected region as a target connected region and taking the position information of the target connected region as the position information of the two-dimensional code when the overlapping rate of the connected region and the target image region in the binary image is greater than a preset threshold value.
8. The apparatus of claim 7, wherein the connected component lookup module comprises:
the edge pixel point searching submodule is used for searching an edge pixel point positioned at the edge of the connected region in the binary image based on a preset operation space, and establishing a storage space to store the position information of the edge pixel point;
the first adjacent edge pixel point searching submodule is used for searching adjacent edge pixel points positioned at the periphery of the current edge pixel point on the basis of the operation space for the current edge pixel point and storing the position information of the adjacent edge pixel points by adopting the storage space;
a second adjacent edge pixel point searching submodule, configured to use the adjacent edge pixel point as the current edge pixel point, repeatedly execute the step of searching for an adjacent edge pixel point located around the current edge pixel point based on the operation space, store the position information of the adjacent edge pixel point in the storage space until the adjacent edge pixel point around the current edge pixel point is the searched edge pixel point, and empty the operation space;
and the connected region determining submodule is used for determining the connected region according to the position information of the edge pixel points.
9. An electronic device, comprising:
one or more processors; and
one or more machine-readable media having instructions stored thereon that, when executed by the one or more processors, cause the electronic device to perform the method of one or more of claims 1-7.
10. One or more machine readable media having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the method of one or more of claims 1-7.
CN202011603091.XA 2020-12-29 2020-12-29 Two-dimensional code positioning method and device, electronic equipment and machine readable medium Pending CN113283262A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011603091.XA CN113283262A (en) 2020-12-29 2020-12-29 Two-dimensional code positioning method and device, electronic equipment and machine readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011603091.XA CN113283262A (en) 2020-12-29 2020-12-29 Two-dimensional code positioning method and device, electronic equipment and machine readable medium

Publications (1)

Publication Number Publication Date
CN113283262A true CN113283262A (en) 2021-08-20

Family

ID=77275391

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011603091.XA Pending CN113283262A (en) 2020-12-29 2020-12-29 Two-dimensional code positioning method and device, electronic equipment and machine readable medium

Country Status (1)

Country Link
CN (1) CN113283262A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113673518A (en) * 2021-08-24 2021-11-19 凌云光技术股份有限公司 Target positioning candidate position screening strategy method

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070140564A1 (en) * 2004-03-04 2007-06-21 Sharp Kabushiki Kaisha 2-Dimensional code region extraction method, 2-dimensional code region extraction device, electronic device, 2-dimensional code region extraction program, and recording medium containing the program
JP2011014012A (en) * 2009-07-03 2011-01-20 Fujitsu Computer Technologies Ltd Two-dimensional code reading method, two-dimensional code extraction method, two-dimensional code recognition method and two-dimensional code reader
CN103839058A (en) * 2012-11-21 2014-06-04 方正国际软件(北京)有限公司 Information locating method for document image based on standard template
CN104700062A (en) * 2015-03-20 2015-06-10 中国联合网络通信集团有限公司 Method and equipment for identifying two-dimension code
CN109101856A (en) * 2018-09-25 2018-12-28 广东工业大学 A kind of image in 2 D code recognition methods and device
CN109785353A (en) * 2019-01-15 2019-05-21 佛山市顺德区中山大学研究院 A kind of secondary traversal binarization method, device and the storage medium of two dimensional code
CN109800615A (en) * 2018-12-28 2019-05-24 新大陆数字技术股份有限公司 The detection localization method and system of two-dimension code area
CN109815762A (en) * 2018-12-29 2019-05-28 福建天泉教育科技有限公司 The method of remote identification two dimensional code, storage medium
CN110263595A (en) * 2019-06-25 2019-09-20 北京慧眼智行科技有限公司 A kind of two dimensional code detection method and device
CN110276229A (en) * 2018-03-14 2019-09-24 京东方科技集团股份有限公司 Target object regional center localization method and device
CN111222356A (en) * 2020-01-14 2020-06-02 河北省烟草公司沧州市公司 Image recognition method, code scanning terminal and commodity sales management system

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070140564A1 (en) * 2004-03-04 2007-06-21 Sharp Kabushiki Kaisha 2-Dimensional code region extraction method, 2-dimensional code region extraction device, electronic device, 2-dimensional code region extraction program, and recording medium containing the program
JP2011014012A (en) * 2009-07-03 2011-01-20 Fujitsu Computer Technologies Ltd Two-dimensional code reading method, two-dimensional code extraction method, two-dimensional code recognition method and two-dimensional code reader
CN103839058A (en) * 2012-11-21 2014-06-04 方正国际软件(北京)有限公司 Information locating method for document image based on standard template
CN104700062A (en) * 2015-03-20 2015-06-10 中国联合网络通信集团有限公司 Method and equipment for identifying two-dimension code
CN110276229A (en) * 2018-03-14 2019-09-24 京东方科技集团股份有限公司 Target object regional center localization 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
CN109815762A (en) * 2018-12-29 2019-05-28 福建天泉教育科技有限公司 The method of remote identification two dimensional code, storage medium
CN109785353A (en) * 2019-01-15 2019-05-21 佛山市顺德区中山大学研究院 A kind of secondary traversal binarization method, device and the storage medium of two dimensional code
CN110263595A (en) * 2019-06-25 2019-09-20 北京慧眼智行科技有限公司 A kind of two dimensional code detection method and device
CN111222356A (en) * 2020-01-14 2020-06-02 河北省烟草公司沧州市公司 Image recognition method, code scanning terminal and commodity sales management system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113673518A (en) * 2021-08-24 2021-11-19 凌云光技术股份有限公司 Target positioning candidate position screening strategy method
CN113673518B (en) * 2021-08-24 2024-02-06 凌云光技术股份有限公司 Target positioning candidate position screening strategy method

Similar Documents

Publication Publication Date Title
CN110046529B (en) Two-dimensional code identification method, device and equipment
CN106447721B (en) Image shadow detection method and device
CN108304814B (en) Method for constructing character type detection model and computing equipment
CN111612781A (en) Screen defect detection method and device and head-mounted display equipment
CN110210440B (en) Table image layout analysis method and system
CN110717489A (en) Method and device for identifying character area of OSD (on screen display) and storage medium
RU2631765C1 (en) Method and system of correcting perspective distortions in images occupying double-page spread
CN110009615B (en) Image corner detection method and detection device
JP6177541B2 (en) Character recognition device, character recognition method and program
CN108665495B (en) Image processing method and device and mobile terminal
CN106919883B (en) QR code positioning method and device
JP2019528543A (en) Digital object unique identifier (DOI) recognition method and apparatus
CN112101386B (en) Text detection method, device, computer equipment and storage medium
CN112419207A (en) Image correction method, device and system
JP4062987B2 (en) Image area dividing method, image area dividing apparatus, and image area dividing program
CN110210467B (en) Formula positioning method of text image, image processing device and storage medium
CN110751156A (en) Method, system, device and medium for table line bulk interference removal
CN113283439B (en) Intelligent counting method, device and system based on image recognition
CN113283262A (en) Two-dimensional code positioning method and device, electronic equipment and machine readable medium
CN106663317B (en) Morphological processing method and digital image processing device for digital image
WO2020186900A1 (en) Narrow-strip two-dimensional barcode, and method, apparatus and device for generating and recognizing narrow-strip two-dimensional barcode
CN115713556A (en) Two-dimensional code positioning method and device and computer readable storage medium
JP2010191767A (en) Device and method for recognizing character
CN114529922A (en) Method for identifying table structure of wireless frame table image
CN110349111B (en) Correction method and device for two-dimensional code image

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