A two-dimensional code positioning method, device, electronic device, and machine-readable medium

By binarizing and expanding the image, searching for the connected area and the area that meets the characteristics, and using the overlap rate to determine the location of the QR code, the problem of low QR code positioning efficiency in the existing technology is solved, and the complex image is realized efficient and accurate positioning.

CN113283262BActive Publication Date: 2024-12-03SHENZHEN YIHUA COMP +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011603091.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-29
Publication Date
2024-12-03
Estimated Expiration
2040-12-29

AI Technical Summary

Technical Problem

In the process of QR code recognition, the QR code needs to occupy a large proportion of the image and match the position, making it difficult to quickly locate the QR code in the image, especially when the image acquisition device is difficult to get close to the object to be photographed. The proportion is small and there is redundant content, which leads to difficulty in positioning.

Method used

By performing binary processing and expansion processing on the image to be processed, binary images are generated, connected areas are searched and target image areas with grayscale values ​​are found, and QR codes are determined based on the overlap rate of the connected areas and target image areas. Location.

Benefits of technology

It improves the rapid positioning efficiency and accuracy of QR codes in complex images, and can accurately locate the QR code position when the QR code occupies a small proportion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113283262B_ABST
    Figure CN113283262B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a two-dimensional code positioning method, device, electronic device, and machine-readable medium, which are applied to the field of image recognition technology. The method includes: performing binarization and expansion processing on a preset image to be processed to generate a binary image; searching for a connected area in the binary image; searching for a target image area in the binary image whose grayscale value meets the preset two-dimensional code characteristics; for a connected area, determining the overlap rate between the connected area and the target image area in the binary image; when the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, determining the connected area as a target connected area, and using the position information of the target connected area as the position information of the two-dimensional code, so that the two-dimensional code position can be quickly positioned in the binary image with high accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image recognition technology, and in particular to a two-dimensional code positioning method and a two-dimensional code positioning device, an electronic device, and a machine-readable medium. Background Art

[0002] In the prior art, during the QR code recognition process, it is necessary to locate the position of the QR code in the image. However, the prior art usually requires that the QR code occupies a large proportion of the image before the position of the QR code can be correctly located. For example, during the process of scanning a QR code with a mobile phone, it is usually necessary to bring the mobile phone close to the QR code, and the size and position of the QR code in the image must match the preset recognition box in the mobile phone interface as much as possible before the QR code can be correctly located.

[0003] However, in some scenarios where QR codes need to be recognized, it may be difficult for the image acquisition device to get close to the photographed object, resulting in the QR code accounting for a smaller proportion of the image captured by the image acquisition device. In addition, there may be more other content in the image, making it difficult to quickly find the location of the QR code in the image. Summary of the invention

[0004] In view of the above problems, embodiments of the present invention are proposed to provide a two-dimensional code positioning method and a corresponding two-dimensional code positioning device for improving the efficiency of searching for the position of a two-dimensional code in an image.

[0005] In order to solve the above problem, an embodiment of the present invention discloses a two-dimensional code positioning method, including:

[0006] Performing binarization and expansion processing on the preset image to be processed to generate a binary image;

[0007] Find connected regions in binary images;

[0008] Searching for a target image area in the binary image whose grayscale value meets a preset two-dimensional code feature;

[0009] For a connected region, determining an overlap ratio between the connected region and the target image region in a binary image;

[0010] When the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, the connected area is determined as a target connected area, and the position information of the target connected area is used as the position information of the QR code.

[0011] Optionally, the step of searching for connected regions in the binary image includes:

[0012] In the binary image, based on a preset operation space, an edge pixel point located at the edge of a connected region is searched, and a storage space is created to store the position information of the edge pixel point;

[0013] For a current edge pixel point, based on the operation space, searching for adjacent edge pixel points located around the current edge pixel point, and using the storage space to store position information of the adjacent edge pixel points;

[0014] Taking the adjacent edge pixel point as the current edge pixel point, repeatedly performing the steps of searching for adjacent edge pixels located around the current edge pixel point based on the operation space, and using the storage space to store the position information of the adjacent edge pixels for the current edge pixel point, until the adjacent edge pixels around the current edge pixel point are the edge pixels that have been found, and clearing the operation space;

[0015] The connected area is determined according to the position information of the edge pixels.

[0016] Optionally, the step of searching for a target image region in the binary image whose grayscale value meets a preset two-dimensional code feature includes:

[0017] Performing integration processing on the binary image to generate an integral image;

[0018] The integral image is traversed using a preset sliding window to find a target image region whose grayscale value meets the preset two-dimensional code characteristics.

[0019] Optionally, the step of performing integration processing on the binary image to generate an integral image includes:

[0020] For a pixel point in the integral image, the sum of all pixel point values ​​in a rectangle formed between the pixel point at the same position as the pixel point in the binary image and the origin of the binary image is taken as the value of the pixel point in the integral image;

[0021] The value of each pixel in the integral image is determined in sequence to generate an integral image.

[0022] Optionally, the step of using a preset sliding window to traverse the integral image and searching for a target image region whose grayscale value meets a preset two-dimensional code feature includes:

[0023] A preset sliding window is used, with the origin of the binary image as the starting point, and the integral image is traversed in a preset order to find a target image area whose grayscale value meets the preset two-dimensional code characteristics.

[0024] Optionally, before the step of performing binarization and dilation processing on the preset image to be processed to generate a binary image, the method further includes:

[0025] The preset image to be identified is grayed to generate a grayed image;

[0026] The grayscale image is filtered to generate a filtered image.

[0027] The embodiment of the present invention also discloses a two-dimensional code positioning device, including:

[0028] The first image processing module is used to perform binarization and dilation processing on the preset image to be processed to generate a binary image;

[0029] A connected region search module, used for searching connected regions in a binary image;

[0030] A target image area search module, used to search for a target image area in the binary image whose grayscale value meets the preset two-dimensional code characteristics;

[0031] An overlap rate determination module, used for determining, for a connected region, an overlap rate between the connected region and the target image region in the binary image;

[0032] The two-dimensional code determination module is used to determine the connected area as the target connected area when the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, and use the position information of the target connected area as the position information of the two-dimensional code.

[0033] Optionally, the connected area search module includes:

[0034] The edge pixel search submodule is used to search for an edge pixel located at the edge of a connected area in a binary image based on a preset operation space, and create a storage space to store the position information of the edge pixel;

[0035] A first adjacent edge pixel point search submodule is used to search for adjacent edge pixel points located around the current edge pixel point based on the operation space, and use the storage space to store the position information of the adjacent edge pixel points;

[0036] A second adjacent edge pixel search submodule is used to use the adjacent edge pixel as the current edge pixel, repeatedly perform the steps of searching for adjacent edge pixels around the current edge pixel based on the operation space, and using the storage space to store the position information of the adjacent edge pixels, until the adjacent edge pixels around the current edge pixel are the edge pixels that have been found, and clear the operation space;

[0037] The connected area determination submodule is used to determine the connected area according to the position information of the edge pixels.

[0038] Optionally, the target image area search module includes:

[0039] An integral image generation submodule, used for performing integral processing on the binary image to generate an integral image;

[0040] The traversal submodule is used to traverse the integral image using a preset sliding window to find a target image area whose grayscale value meets the preset two-dimensional code characteristics.

[0041] Optionally, the integral image generation submodule includes:

[0042] a pixel value determination unit, configured to, for a pixel in the integral image, take the sum of all pixel values ​​in a rectangle formed between a pixel at the same position as the pixel in the binary image and an origin of the binary image as the value of the pixel in the integral image;

[0043] The integral image generating unit is used to determine the value of each pixel point in the integral image in sequence to generate an integral image.

[0044] Optionally, the traversal submodule includes:

[0045] The traversal subunit is used to use a preset sliding window, take the origin of the binary image as the starting point, traverse the integral image in a preset order, and search for a target image area whose grayscale value meets the preset two-dimensional code characteristics.

[0046] Optionally, the device further comprises:

[0047] A grayscale image generation module is used to perform grayscale processing on a preset image to be identified to generate a grayscale image;

[0048] The filtered image generation module is used to perform filtering processing on the grayscale image to generate a filtered image.

[0049] The embodiment of the present invention further discloses an electronic device, including:

[0050] one or more processors; and

[0051] One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, enable the electronic device to perform one or more methods as described in the embodiments of the present invention.

[0052] The embodiment of the present invention further discloses one or more machine-readable media on which instructions are stored, and when executed by one or more processors, the processors execute one or more methods as described in the embodiment of the present invention.

[0053] The embodiments of the present invention include the following advantages:

[0054] Through the two-dimensional code positioning method of the embodiment of the present invention, the preset image to be processed is binarized and expanded to generate a binary image, so that the two-dimensional code area can be covered by the pixel points of the target value as much as possible, and then the connected area is searched in the binary image to find the area that may be the two-dimensional code based on connectivity, and the target image area whose grayscale meets the preset two-dimensional code characteristics in the binary image is searched, so that the area that may contain the two-dimensional code can be searched in the binary image based on the grayscale value. Afterwards, according to the overlap rate of the connected area and the target image area in the binary image, when the overlap rate of the connected area and the target image area in the binary image is greater than a preset threshold, the connected area can be determined as the target connected area, and the position information of the target connected area is used as the position information of the two-dimensional code, so that the position of the two-dimensional code can be quickly located in the binary image with a high accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] Figure 1 is a flowchart of the steps of a two-dimensional code positioning method according to an embodiment of the present invention;

[0056] Figure 2 is a flowchart of another two-dimensional code positioning method according to an embodiment of the present invention;

[0057] Figure 3 is a schematic diagram of an adjacent area in an embodiment of the present invention;

[0058] Figure 4 is a schematic diagram of a binary image according to an embodiment of the present invention;

[0059] Figure 5 It is a structural block diagram of a two-dimensional code positioning device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0060] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0061] The core concept of an embodiment of the present invention is that, for an image with more content and a smaller proportion of the QR code, after binarizing and dilating the preset image to be processed, a connected area that may be a QR code is searched in the binary image, and a target image area whose grayscale value meets the preset QR code characteristics is searched in the binary image. The position of the QR code is determined based on the overlap rate of the connected area and the target image area in the binary image, so that the position of the QR code in the image can be quickly determined based on the connectivity and grayscale value, thereby improving the efficiency of locating the QR code in complex images.

[0062] Reference Figure 1 , shows a flowchart of a two-dimensional code positioning method according to an embodiment of the present invention, which may specifically include the following steps:

[0063] Step 101, performing binarization and dilation processing on a preset image to be processed to generate a binary image;

[0064] In the embodiment of the present invention, an image to be identified that needs to be identified by a two-dimensional code may be preset. The image to be identified may be acquired by an image acquisition device, or by intercepting a portion of a display area on a display screen, etc., and the present invention does not limit this.

[0065] In an embodiment of the present invention, in order to reduce unnecessary information in the image to be identified, the image to be identified may be binarized so that the image contains only two pixels with different values. For example, the pixel is only black or white, and the value of the pixel can be (255, 255, 255) or (0, 0, 0). For another example, the pixel can be only black or red, and the value of the pixel can be (255, 0, 0) or (0, 0, 0).

[0066] Subsequently, since in the image to be identified, the two-dimensional code can usually contain pixels of at least two colors, the area of ​​the two-dimensional code can usually contain pixels of two different values ​​in the binary image. As a result, the area of ​​the two-dimensional code may have pixels at the edge and inside of the two-dimensional code with the same values ​​as the pixels in the non-two-dimensional code area, resulting in the connection between the internal and external areas of the two-dimensional code, resulting in possible errors 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 pixels of the target value as much as possible, so that the area where the two-dimensional code is located can be found more accurately later.

[0067] In a specific implementation, the image to be processed may be binarized first. Specifically, the filtered image may be binarized using a fixed threshold or an adaptive binarization method, which is not limited in the present invention.

[0068] After the binarization process is completed, the image after the binarization process can be further expanded by using a preset convolution template or convolution kernel to perform a convolution operation on the image after the binarization process. Specifically, the preset convolution template or convolution kernel can be used to determine the maximum value of the pixel points in the image area covered by it, and the maximum value is assigned to the pixel points corresponding to the reference points in the convolution template or convolution kernel in the image area, thereby completing the expansion process of the image.

[0069] Step 102, searching for connected regions in the binary image;

[0070] In a binary image, if there are several pixels with target values ​​adjacent to each other, it can be considered that the pixels with target values ​​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 coordinates (1,1), (1,2), and (1,3) are all white, it can be considered that the pixels with coordinates (1,1), (1,2), and (1,3) form a connected region.

[0071] In the embodiment of the present invention, generally speaking, a two-dimensional code can usually form a connected region in a binary image. Therefore, at least one connected region can be searched in the binary image to find the possible position of the two-dimensional code.

[0072] Step 103, searching for a target image region in the binary image whose grayscale value meets a preset two-dimensional code feature;

[0073] In the embodiment of the present invention, the binary image can be divided into several image regions, and the grayscale values ​​of the image regions can be calculated. Based on the grayscale values, it can be found whether there is at least one target image region in the binary image whose grayscale value meets the preset two-dimensional code characteristics.

[0074] The grayscale value of the image area may be the sum of the values ​​of the pixels in the image area.

[0075] In a specific implementation, the pixels in the binary image can be divided into background pixels and effective pixels. Among them, the background pixels can be the pixels corresponding to the background area in the image. The effective pixels can usually be the pixels corresponding to the effective information area in the image. Among them, the effective information can be a two-dimensional code, a character, an image, a shape, etc., and the present invention does not limit this. For example, the binary image contains a number of white characters on a black background, then the pixels in the area corresponding to the black background are background pixels, and the pixels corresponding to the white characters are effective pixels.

[0076] Thus, for an image region with a two-dimensional code, the image region may generally have more effective pixels. In the case where the image region has more effective pixels and fewer background pixels, the grayscale value of the image region may be more inclined to the grayscale value of the effective pixels multiplied by the number of pixels in the image region. For example, if the grayscale value of the effective pixels is 255, the grayscale value of the image region may be close to 255 multiplied by the number of pixels in the image region.

[0077] Thus, a gray value threshold can be set as a preset QR code feature. When the gray value of the image area is greater than the preset QR code feature, it can be considered that there are more valid pixels in the image area, the image area is more likely to contain a QR code, and the image area is used as the target image area.

[0078] Step 104, for a connected region, determining an overlap ratio between the connected region and the target image region in the binary image;

[0079] In the embodiment of the present invention, since the connected area may be a two-dimensional code, a character, an image, a shape, etc., it is necessary to further determine whether the connected area is a two-dimensional code. Therefore, the position of the connected area can be compared with the position of the target image area, and according to the positional relationship between the connected area and the image area, the target connected area is selected as the two-dimensional code in the connected area.

[0080] In the embodiment of the present invention, at least one connected region can be found in the binary image, and it can be further determined whether the connected region is a two-dimensional code. As for the target image region, it can be a region containing the two-dimensional code. Thus, the overlap rate between the connected region and the target image region in the binary image can be determined, so as to determine whether the connected region contains the two-dimensional code based on the overlap rate, thereby determining whether the connected region is the region where the two-dimensional code is located.

[0081] In a specific implementation, the overlap ratio between the connected region and the target image region in the binary image may be determined by calculating the intersection-and-union ratio. Specifically, the intersection-and-union ratio may be calculated by the following formula:

[0082]

[0083] Among them, C is the area where the connected area is located in the binary image, and G is the area where the target image area is located in the image.

[0084] Step 105: when the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, the connected area is determined as a target connected area, and the position information of the target connected area is used as the position information of the QR code.

[0085] In an embodiment of the present invention, when the overlap rate between the connected area and the image area in the binary image is greater than a preset threshold, it can be considered that the connected area and the image area mostly overlap with each other in the binary image, that is, the connected area contains the two-dimensional code content in the target image area, and thus it can be considered that the connected area is the location of the two-dimensional code, the connected area is determined as the target connected area, and the position information of the target connected area is used as the position information of the two-dimensional code, thereby completing the positioning of the two-dimensional code.

[0086] In an embodiment of the present invention, for a scene where the camera position is fixed, such as in a bill storage device, the bill can be photographed during storage or issuance, and the QR code on the bill can be identified. However, in the image captured by the camera, the position of the bill is usually not fixed, and the proportion of the QR code in the image captured by the camera is small. Other information of the bill and the mechanical structure in the bill storage device may also be captured in the image, resulting in difficulty in identifying the QR code. In this case, a binary image is generated by binarizing and dilating the preset image to be processed; a connected area is searched in the binary image; a target image area whose grayscale value meets the preset QR code feature is searched in the binary image; for a connected area, the overlap rate between the connected area and the target image area in the binary image is determined; when the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, the connected area is determined as a target connected area, and the position information of the target connected area is used as the position information of the QR code, so that the position information of the QR code can be efficiently determined in the image, so that the positioning of the QR code can be quickly completed during the storage or issuance of the bill, thereby improving the processing efficiency of the bill storage device.

[0087] Through the two-dimensional code positioning method of the embodiment of the present invention, the preset image to be processed is binarized and expanded to generate a binary image, so that the two-dimensional code area can be covered by the pixel points of the target value as much as possible, and then the connected area is searched in the binary image to find the area that may be the two-dimensional code based on connectivity, and the target image area whose grayscale meets the preset two-dimensional code characteristics in the binary image is searched, so that the area that may contain the two-dimensional code can be searched in the binary image based on the grayscale value. Afterwards, according to the overlap rate of the connected area and the target image area in the binary image, when the overlap rate of the connected area and the target image area in the binary image is greater than a preset threshold, the connected area can be determined as the target connected area, and the position information of the target connected area is used as the position information of the two-dimensional code, so that the position of the two-dimensional code can be quickly located in the binary image with a high accuracy.

[0088] Reference Figure 2 , shows a flowchart of a two-dimensional code positioning method according to an embodiment of the present invention, which may specifically include the following steps:

[0089] Step 201, performing binarization and dilation processing on a preset image to be processed to generate a binary image;

[0090] In the embodiment of the present invention, an image to be identified that needs to be identified by a two-dimensional code may be preset. The image to be identified may be acquired by an image acquisition device, or by intercepting a portion of a display area on a display screen, etc., and the present invention does not limit this.

[0091] In an embodiment of the present invention, in order to reduce unnecessary information in the image to be identified, the image to be identified may be binarized so that the image contains only two pixels with different values. For example, the pixel is only black or white, and the value of the pixel can be (255, 255, 255) or (0, 0, 0). For another example, the pixel can be only black or red, and the value of the pixel can be (255, 0, 0) or (0, 0, 0).

[0092] Subsequently, since in the image to be identified, the two-dimensional code can usually contain pixels of at least two colors, the area of ​​the two-dimensional code can usually contain pixels of two different values ​​in the binary image. As a result, the area of ​​the two-dimensional code may have pixels at the edge and inside of the two-dimensional code with the same values ​​as the pixels in the non-two-dimensional code area, resulting in the connection between the internal and external areas of the two-dimensional code, resulting in possible errors 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 pixels of the target value as much as possible, so that the area where the two-dimensional code is located can be found more accurately later.

[0093] In a specific implementation, the image to be processed may be binarized first. Specifically, the filtered image may be binarized using a fixed threshold or an adaptive binarization method, which is not limited in the present invention.

[0094] After the binarization process is completed, the image after the binarization process can be further expanded by using a preset convolution template or convolution kernel to perform a convolution operation on the image after the binarization process. Specifically, the preset convolution template or convolution kernel can be used to determine the maximum value of the pixel points in the image area covered by it, and the maximum value is assigned to the pixel points corresponding to the reference points in the convolution template or convolution kernel in the image area, thereby completing the expansion process of the image.

[0095] In one embodiment of the present invention, before the step of performing binarization and dilation processing on the preset image to be processed to generate a binary image, the method further includes:

[0096] S11, graying the preset image to be recognized to generate a grayed image;

[0097] In an embodiment of the present invention, in order to reduce unnecessary information in the image to be identified, the image to be identified may be grayed to generate a grayed image. Specifically, the graying process may adopt an average value method, taking the average value of the three RGB components of each pixel in the color image as the gray value, thereby obtaining a grayed image; or adopt a weighted average method, taking the weighted average value of the three RGB components of each pixel in the color image as the gray value, thereby obtaining a grayed image; or adopt a maximum value method, taking the maximum value of the three RGB components of each pixel in the color image as the gray value, thereby obtaining a grayed image, and the present invention is not limited thereto.

[0098] S12, performing filtering processing on the grayscale image to generate a filtered image;

[0099] In the embodiment of the present invention, after the grayscale processing, the grayscale image may be further filtered to remove noise points in the grayscale image and reduce interference with subsequent two-dimensional code positioning.

[0100] In a specific implementation, a convolution kernel of a preset size may be used to perform convolution processing on the grayscale image to obtain the filtered image. The size of the convolution kernel may be 5×5, 10×10, etc., and the present invention does not limit this.

[0101] Afterwards, the filtered image may be binarized and expanded to obtain a binary image. The binary image obtained based on the filtered image may include fewer noise points, making the positioning of the two-dimensional code more accurate.

[0102] Step 202, searching for connected regions in the binary image;

[0103] In an embodiment of the present invention, a binary image containing a two-dimensional code may be preset. In the binary image, the value of a pixel point may have only two possible values. In the binary image, if there are several pixel points of target values ​​adjacent to each other, it can be considered that the pixel points of the target value form a connected area. Generally speaking, a two-dimensional code can usually form a connected area in a binary image. Therefore, at least one connected area can be searched in the binary image to find the possible location of the two-dimensional code.

[0104] In one embodiment of the present invention, the step of searching for connected regions in a binary image comprises:

[0105] S21, in the binary image, based on a preset operation space, searching for an edge pixel point located at the edge of a connected region, and creating a storage space to store position information of the edge pixel point;

[0106] In the embodiment of the present invention, a computing space can be created in advance to perform the operations required for image processing. Generally speaking, for a binary image, the computing space can be created before preparing to process the binary image. The computing space can then be directly used to perform image processing operations.

[0107] In an embodiment of the present invention, a binary image containing characters may be preset. In the binary image, the value of a pixel may have only two possible values. In the binary image, if there are several pixel points of target values ​​adjacent to each other, it can be considered that the pixel points of the target value form a connected area.

[0108] In the embodiment of the present invention, generally speaking, characters can usually form a connected area in a binary image. Therefore, the edge pixel points located at the edge of the connected area can be considered to be the edge outline of a certain character. Therefore, the outline of a certain character can be determined by finding the edge pixel points at the edge of the connected area. After that, after finding the edge pixel points at the edge of the connected area, a storage space can be created to store the position information of the edge pixel points of the connected area.

[0109] In order to efficiently find edge pixel points located at the edge of a connected area in the binary image, an edge pixel point located at the edge of a connected area can be first found in the binary image, so that other edge pixel points of the connected area can be further found based on the edge pixel point.

[0110] In one embodiment of the present invention, the step of searching an edge pixel point located at the edge of a connected region in a binary image based on a preset operation space and creating a storage space to store the position information of the edge pixel point comprises:

[0111] S211, in the binary image, based on a preset operation space, searching row by row whether there are valid pixels adjacent to the background pixels;

[0112] In an embodiment of the present invention, the pixels in the binary image can be divided into background pixels and valid pixels. The background pixels can be pixels corresponding to the background area in the image. The valid pixels can usually be pixels corresponding to the valid information area in the image. The valid information can be characters, images, shapes, etc., and the present invention does not limit this. For example, if the binary image contains a number of white characters on a black background, the pixels in the area corresponding to the black background are background pixels, and the pixels corresponding to the white characters are valid pixels.

[0113] In an embodiment of the present invention, the pixel points corresponding to the connected region may be valid pixel points, and the valid pixel points adjacent to the background pixel points may generally be pixel points located at the edge of the connected region. Thus, image processing operations may be performed in a binary image based on a preset operation space, and a row-by-row search method may be used to sequentially determine whether there are pixel points adjacent to the background pixel points, so as to determine whether there are edge pixel points located at the edge of the connected region. Thus, the binary image may be efficiently and standardizedly traversed, and the efficiency of searching for edge pixel points may be improved.

[0114] S212: If there are valid pixels adjacent to the background pixel, use the valid pixels adjacent to the background pixel as edge pixels at the edge of the connected area, and create a storage space to store position information of the edge pixels.

[0115] In the embodiment of the present invention, when a valid pixel point adjacent to the background pixel point is found, the valid pixel point adjacent to the background pixel point can be considered as a pixel point located at the edge of the connected area. Therefore, the valid pixel point adjacent to the background pixel point can be used as an edge pixel point at the edge of the connected area, and a storage space is created to store the position information of the edge pixel point. Subsequently, based on the edge pixel point, the search for other edge pixels of the connected area can be completed.

[0116] S22, for the current edge pixel point, based on the operation space, searching for adjacent edge pixel points located around the current edge pixel point, and using the storage space to store position information of the adjacent edge pixel points;

[0117] In the embodiment of the present invention, since the edge pixel points of the connected area surround the edge of the connected area, there may be other pixel points that are the edge of the connected area in the adjacent area of ​​the adjacent pixel point. Therefore, after searching for an edge pixel point, based on the position of the current edge pixel point, image processing operations can be performed based on the operation space to further search for adjacent edge pixel points located around the current edge pixel point, and the storage space is used to store the position information of the adjacent edge pixel points found in real time.

[0118] In the specific implementation, Figure 3 A schematic diagram of an adjacent area of ​​an embodiment of the present invention. For pixel point a, the pixel points 0 to 7 located around it can all be considered to be adjacent to pixel point a. Image processing operations can be performed based on the operation space, and in the adjacent area of ​​the current edge pixel point, it is determined in turn whether there are other pixel points that also have the target value, and at least one of the other adjacent pixel points around it is not the target value. When other pixel points adjacent to the current pixel point are found to meet the conditions of the edge pixel point, the pixel point is used as an adjacent edge pixel point around the current edge pixel point, and the storage space is used to store the position information of the adjacent edge pixel point.

[0119] In a specific implementation, in the adjacent area of ​​the current pixel point, there may be multiple pixel points that are edge pixel points of the connected area. In this case, an edge pixel point may be selected as the adjacent edge pixel point of the current pixel point.

[0120] Optionally, when searching for adjacent edge pixels around the current edge pixel, an image processing operation can be performed based on the operation space, with a preset adjacent position as the starting point, and pixels in the adjacent area of ​​the current pixel are identified in sequence according to a preset selection direction. The first edge pixel found is used as the adjacent edge pixel of the current pixel, and the storage space is used to store the position information of the adjacent edge pixel. Figure 3 The position of pixel 3 in the middle is taken as the starting point, and the pixels in the adjacent area of ​​the current pixel are identified in a counterclockwise direction to see if they are edge pixels. Figure 3 The position of the middle pixel 7 is taken as the starting point, and the pixel points in the adjacent area of ​​the current pixel point are identified in a clockwise direction to determine whether they are edge pixels, etc. The present invention does not impose any limitation on this.

[0121] In one embodiment of the present invention, the step of searching, for a current edge pixel point, adjacent edge pixels located around the current edge pixel point based on the operation space, and using the storage space to store the position information of the adjacent edge pixels includes:

[0122] S221, for a current edge pixel point, based on the operation space and in a preset direction, sequentially determine whether pixel points adjacent to the current edge pixel point are also the edge pixel points;

[0123] In an embodiment of the present invention, for the current edge pixel point found, image processing operations can be performed based on the operation space, and a preset direction can be used to determine in turn whether the current edge pixel point is the edge pixel point, so that the edge pixel points can be searched in sequence in the order of surrounding the edge of the connected area, thereby improving the search efficiency and avoiding missing the edge pixel points.

[0124] The preset direction may be to start from a certain position in the adjacent area and search for adjacent edge pixel points located at the current edge pixel point in a clockwise or counterclockwise direction.

[0125] In an embodiment of the present invention, the step of determining, for a current edge pixel point, based on the operation space and in a preset direction, in sequence whether pixel points adjacent to the current edge pixel point are also the edge pixel points comprises:

[0126] S2211, for the current edge pixel point, based on the operation space, taking the pixel point in the adjacent area with the same direction as the starting point of the row-by-row search as the starting point, determine in clockwise or counterclockwise order whether the pixel points adjacent to the current edge pixel point are also the edge pixel points.

[0127] In an embodiment of the present invention, the preset direction may be associated with the starting direction of searching row by row in the step of searching for adjacent edge pixels located around the current edge pixel for the current edge pixel. When the preset direction is the same as the starting direction of searching row by row, the edge pixel can be found as comprehensively and efficiently as possible. Thus, for the current edge pixel, an image processing operation can be performed based on the operation space, and the pixel in the adjacent area with the same starting direction as the row by row search is used as the starting point, and the pixel adjacent to the current edge pixel is determined in clockwise or counterclockwise order to determine whether it is also the edge pixel.

[0128] Specifically, in the case where the starting point direction of the row-by-row search is to search row-by-row with a certain corner in the image as the starting point, for the current edge pixel point, the pixel points in its adjacent area at the same position as the starting point direction of the row-by-row search can be confirmed not to be edge pixels in the step of searching for adjacent edge pixels around the current edge pixel point for the current edge pixel point. The pixel points in the adjacent area other than the pixel points at the same position as the starting point direction of the row-by-row search have not yet been confirmed to be edge pixels. Thus, in the case where the preset direction is the same as the starting point direction of the row-by-row search, the edge pixel points in the adjacent area of ​​the current edge pixel point can be found as comprehensively and efficiently as possible, and thereafter, it can be determined in clockwise or counterclockwise order whether the pixel points adjacent to the current edge pixel point are also the edge pixel points.

[0129] As an example of the present invention, when the starting point direction of the row-by-row search is to start from the upper left corner and search row-by-row from top to bottom, for the current edge pixel point, the pixel point at the upper left corner position in its adjacent area, that is, Figure 3 The pixel point at the pixel point 3 position in the adjacent pixel point may have been confirmed not to be an edge pixel point in the step of searching for adjacent edge pixel points around the current edge pixel point for the current edge pixel point. However, the pixel points at other positions other than the upper left corner position in the adjacent area have not yet been determined to be edge pixel points. Therefore, in the case where the starting point direction of the row-by-row search is the upper left corner as the starting point and the row-by-row search is performed from top to bottom, the pixel point adjacent to the current edge pixel point may be used as the starting point, and the pixel points may be determined in a clockwise or counterclockwise manner in sequence from the upper left corner pixel point in the adjacent area to determine whether the pixel points are also the edge pixel points.

[0130] As an example of the present invention, when the starting point direction of the row-by-row search is to start from the upper left corner and search row-by-row from left to right, the pixel point at the upper left corner of the adjacent area of ​​the current pixel point can be used as the starting point, and the pixel points adjacent to the current edge pixel point can be determined clockwise or counterclockwise to determine whether they are also the edge pixel points.

[0131] As an example of the present invention, when the starting point direction of the row-by-row search is to start from the upper right corner and search row by row from right to left, the pixel point at the upper right corner of the adjacent area of ​​the current pixel point can be used as the starting point, and the pixel points adjacent to the current edge pixel point can be determined clockwise or counterclockwise to determine whether they are also the edge pixel points.

[0132] As an example of the present invention, when the starting point direction of the row-by-row search is to start from the lower left corner and search row by row from bottom to top, the pixel point at the lower left corner of the adjacent area of ​​the current pixel point can be used as the starting point, and the pixel points adjacent to the current edge pixel point can be determined clockwise or counterclockwise to determine whether they are also the edge pixel points.

[0133] As an example of the present invention, when the starting point direction of the row-by-row search is to start from the lower right corner and search row by row from bottom to top, the pixel point at the lower right corner of the adjacent area of ​​the current pixel point can be used as the starting point, and the pixel points adjacent to the current edge pixel point can be determined clockwise or counterclockwise to determine whether they are also the edge pixel points.

[0134] S222: When a pixel point adjacent to the current edge pixel point is also the edge pixel point, the pixel point adjacent to the current edge pixel point is used as an adjacent edge pixel point, and the storage space is used to store position information of the adjacent edge pixel point.

[0135] In an embodiment of the present invention, when a pixel point adjacent to the current edge pixel point is found to be an edge pixel point, the edge pixel point found is an edge pixel point adjacent to the current edge pixel point. The pixel point adjacent to the current edge pixel point can be used as an adjacent edge pixel point, and the storage space is used to store the position information of the adjacent edge pixel point. Therefore, based on the adjacency relationship, the edge pixel points of the connected area can be quickly found and the real-time storage of the position information of the adjacent edge pixel points can be completed.

[0136] S23, taking the adjacent edge pixel point as the current edge pixel point, repeatedly performing the steps of searching for adjacent edge pixels located around the current edge pixel point based on the operation space, and using the storage space to store the position information of the adjacent edge pixels, until the adjacent edge pixels around the current edge pixel point are the edge pixels that have been found, and clearing the operation space;

[0137] In an embodiment of the present invention, after searching for the adjacent edge pixel point, the adjacent area of ​​the adjacent edge pixel point may also have edge pixel points as the edge of the connected area. Therefore, the adjacent edge pixel point can be used as the current edge pixel point, and the steps of searching for the adjacent edge pixel points around the current edge pixel point based on the operation space and using the storage space to store the position information of the adjacent edge pixel points are repeated, so that the edge pixel points of the edge of the connected area can be continuously searched in sequence based on the adjacency relationship, and the position information of the adjacent edge pixel points is stored in the storage space in real time, until the adjacent edge pixel points around the current edge pixel point are the edge pixel points that have been found, then it can be considered that the edge pixel points that form the edge of the connected area have been basically found. Therefore, the binary image has completed the search for the edge pixel points of a connected area, and the data in the operation space can be cleared, so that the operation space can be used to search for the next connected area in the future, without having to re-apply for a new operation space to process the new connected area.

[0138] In a specific implementation, there may be multiple pixels in the adjacent area of ​​the current pixel point, all of which are edge pixels of the connected area. In this case, based on the operation space, an edge pixel point that has not been found can be selected as the adjacent edge pixel point of the current pixel point, and the storage space can be used to store the position information of the adjacent edge pixel point.

[0139] As an example of the present invention, Figure 4 FIG. 1 is a schematic diagram of a binary image according to an embodiment of the present invention. Figure 4An edge pixel located at the edge of a connected region is searched in the connected region, so that pixel 1 can be found as an edge pixel. Thereafter, pixel 1 can be used as the current pixel, and an adjacent edge pixel located around the current edge pixel can be searched. It can be found that in the adjacent region of pixel 1, pixel 2 is also an edge pixel, so that pixel 2 is the adjacent edge pixel of pixel 1. Thereafter, pixel 2 can be used as the current pixel, and the adjacent edge pixel around pixel 2 as the current pixel can be found as pixel 3. Thereafter, pixel 3 can be used as the current pixel, and the adjacent edge pixel around pixel 3 as the current pixel can be found as pixel 4. Thereafter, pixel 4 can be used as the current pixel, and the adjacent edge pixel around pixel 4 as the current pixel can be found as pixel 5. Thereafter, pixel 5 can be used as the current pixel, and the adjacent edge pixel around pixel 5 as the current pixel can be found as pixel 6. Thereafter, pixel 6 can be used as the current pixel, and the adjacent edge pixel around pixel 6 as the current pixel is found to be pixel 7. Thereafter, pixel 7 can be used as the current pixel, and the adjacent edge pixel around pixel 7 as the current pixel is found to be pixel 8. Thereafter, pixel 8 can be used as the current pixel, and the adjacent edge pixel around pixel 8 as the current pixel is found to be pixel 9. Thereafter, pixel 9 can be used as the current pixel, and it is found that pixel 1, 2, 7, and 8 in the adjacent area around pixel 9 that can be used as adjacent edge pixels are all the edge pixels that have been found. Thus, it can be considered that the edge pixels that form the edge of the connected area have been basically found.

[0140] S24: Determine the connected area according to the position information of the edge pixels.

[0141] 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 can be determined according to the position information of the edge pixel point in the storage space, so that at least one connected region that may be a two-dimensional code can be determined in the binary image.

[0142] In a specific implementation, the edge pixel points of the connected area can surround the edge of the connected area. Therefore, when the position information of the edge pixel points of the connected area is determined, the edge position information of the area occupied by the connected area in the binary image can be obtained, thereby determining the position of the connected area in the binary image.

[0143] In one embodiment of the present invention, the method further comprises:

[0144] S31, determining a bounding box of the connected area according to the position information of the edge pixels.

[0145] Since the connected area can be a QR code or other content besides characters, such as characters, tables, patterns, noise, etc. After determining the position information of the edge pixels of the connected area, it can be further determined whether the connected area is a QR code. The bounding box of the connected area can usually indicate the size of the connected area, so the bounding box of the connected area can be determined according to the position information of the edge pixels, so as to determine whether the connected area is a QR code based on the bounding box of the connected area.

[0146] The shape of the external frame may be a rectangle, a circle, an irregular polygon, etc., and the present invention does not limit this.

[0147] In a specific implementation, the bounding box of the connected area can usually be aligned with the edge of the connected area. Thus, the edge position of the connected area can be determined based on the position information of the edge pixel points, and an bounding box that can accommodate the connected area and whose frame line is aligned with the edge of the connected area can be determined.

[0148] In an embodiment of the present invention, the step of determining the bounding box of the connected area according to the position information of the edge pixels includes:

[0149] S311, determining a first endpoint and a second endpoint of a diagonal line of a circumscribed frame according to the position information of the edge pixel point;

[0150] In an embodiment of the present invention, the shape of the external frame of the connected area can be a rectangle, so that the external frame can have a diagonal line. For a rectangular external frame, when the positions of the two end points of a diagonal line are known, the external frame can be generated, and the generated external frame can be aligned with the edge pixel points of the connected 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.

[0151] In a specific implementation, when the shape of the connected region's bounding box is a rectangle, the connected region may have two diagonals. One diagonal may be formed by connecting the upper left corner endpoint and the lower right corner endpoint of the bounding box, and the other diagonal may be formed by connecting the upper right corner endpoint and the lower left corner endpoint of the bounding box. At the same time, the binary image may use the upper left corner of the image as the coordinate origin.

[0152] The minimum x value, the minimum y value, the maximum x value, and the maximum y value may be searched for in the position information of the edge pixel point. In the case where the bounding box is determined based on the diagonal line formed by connecting the upper left corner endpoint and the lower right corner 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 corner 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 corner. 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 used as the coordinates of the first endpoint, i.e., the upper right corner, and the minimum x value and the maximum y value may be used as the coordinates of the second endpoint, i.e., the lower left corner.

[0153] S312: Determine a bounding box of the connected area according to the position information of the first endpoint and the position information of the second endpoint.

[0154] In an embodiment of the present invention, for a rectangular bounding box, after determining the position information of the first endpoint and the position information of the second endpoint located at the diagonal endpoints, a unique bounding box can be determined based on the position information of the first endpoint and the position information of the second endpoint, and the bounding box can be aligned with the edge of the connected area, so as to facilitate determining the size of the connected area based on the bounding box.

[0155] S32: Select at least one candidate two-dimensional code region in the connected area according to the size of the bounding box.

[0156] In the embodiment of the present invention, after the size of the circumscribed frame is determined, at least one candidate QR code region that may be the region where the QR code is located may be determined in the connected region according to the size of the circumscribed frame.

[0157] In a specific implementation, the two-dimensional code may be generally square or circular. In this case, if the size of the outer frame meets the characteristics of a square, such as when the width and height of the outer frame are the same, the connected area may be generally square or circular, and thus, the connected area with a square outer frame may be used as a candidate two-dimensional code area.

[0158] Optionally, when processing images of the same type and the camera position is fixed, the size of the QR code can generally be within a preset size range. For example, in a bill storage device, the position of the camera is fixed, and the bills are all of the same type. In the image to be identified captured by the camera, the size of the QR code of the bill can generally be within a preset size range. In this case, based on the size of the external frame, the connected area can be further screened as a candidate QR code area.

[0159] Step 203, performing integration processing on the binary image to generate an integral image;

[0160] In the embodiment of the present invention, in order to quickly find the image region whose grayscale value meets the preset two-dimensional code feature, the binary image may be integrated to generate an integral image.

[0161] In one embodiment of the present invention, the step of performing integration processing on the binary image to generate an integral image includes:

[0162] S41, for a pixel point in the integral image, taking the sum of all pixel point values ​​in a rectangle formed between a pixel point at the same position as the pixel point in the binary image and the origin of the binary image as the value of the pixel point in the integral image;

[0163] In an embodiment of the present invention, the value of each pixel in the integral image can be obtained based on the calculation of the pixel in the binary image. For a pixel in the integral image, the sum of the values ​​of all pixels in a rectangle formed between the pixel in the binary image with the same position and the origin of the binary image can be used as the value of the pixel in the integral image.

[0164] In a specific implementation, when the upper left corner of the binary image is used as the origin, the value of each pixel in the integral image may be the sum of all pixels in a rectangle formed by the pixel at the same position in the binary image and the origin.

[0165] As an example of the present invention, the following formula is used to calculate the value of a pixel in the integral image:

[0166]

[0167] Among them, SAT(x,y) represents the value of the pixel at position (x,y) in the integral image, and I(x i ,y i ) represents the binary image (x i ,y i )The value of the pixel at the position.

[0168] Optionally, the integral image can be calculated incrementally using the following formula:

[0169] SAT(x,y)=SAT(x,y-1)-SAT(x-1,y-1)+I(x,y)

[0170] Thereafter, in order to facilitate the calculation of the grayscale values ​​of different regions based on the integral image, the values ​​of the pixels in the integral image may be normalized to a range of grayscale values ​​according to actual needs. For example, when the grayscale value ranges from 0 to 255, the values ​​of the pixels in the integral image may be normalized to a range of 0 to 255.

[0171] S42, determining the value of each pixel in the integral image in sequence to generate an integral image.

[0172] In an embodiment of the present invention, the size of the integral image is the same as that of the binary image, so that the pixel arrangement of the integral image is the same as that of the binary image. After determining the value of each pixel in the integral image in sequence, the integral image can be generated.

[0173] Step 204, using a preset sliding window to traverse the integral image, and searching for a target image region whose grayscale value meets the preset two-dimensional code feature;

[0174] In the embodiment of the present invention, the grayscale value of the image region may be the sum of the values ​​of the pixels in the image region. The integral image is traversed using a preset sliding window to search for a target image region whose grayscale value meets the preset two-dimensional code feature.

[0175] In a specific implementation, the pixels in the binary image can be divided into background pixels and effective pixels. Among them, the background pixels can be the pixels corresponding to the background area in the image. The effective pixels can usually be the pixels corresponding to the effective information area in the image. Among them, the effective information can be a two-dimensional code, a character, an image, a shape, etc., and the present invention does not limit this. For example, the binary image contains a number of white characters on a black background, then the pixels in the area corresponding to the black background are background pixels, and the pixels corresponding to the white characters are effective pixels.

[0176] Thus, for an image region with a two-dimensional code, the image region may generally have more effective pixels. In the case where the image region has more effective pixels and fewer background pixels, the grayscale value of the image region may be more inclined to the grayscale value of the effective pixels multiplied by the number of pixels in the image region. For example, if the grayscale value of the effective pixels is 255, the grayscale value of the image region may be close to 255 multiplied by the number of pixels in the image region.

[0177] Thus, a gray value threshold can be set as a preset QR code feature. When the gray value of the image area is greater than the preset QR code feature, it can be considered that there are more valid pixels in the image area, the image area is more likely to contain a QR code, and the image area is used as the target image area.

[0178] In one embodiment of the present invention, the step of traversing the integral image using a preset sliding window to search for a target image region whose grayscale value meets the preset two-dimensional code feature includes:

[0179] S51, using a preset sliding window, taking the origin of the binary image as the starting point, traversing the integral image in a preset order, and searching for a target image area whose grayscale value meets the preset two-dimensional code characteristics.

[0180] In an embodiment of the present invention, an origin is set in the binary image. The origin can 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 midpoint of the edge of the binary image, etc. The present invention does not impose any limitation on this.

[0181] In an embodiment of the present invention, a preset sliding window can be used, with the origin of the binary image as the starting point, and the integral image can be traversed in a preset order to find the target image area whose grayscale value meets the preset QR code characteristics, so that the target image area whose grayscale value meets the preset QR code characteristics can be efficiently found.

[0182] The preset order may be from left to right, from top to bottom, etc., and the present invention does not limit this.

[0183] In a specific implementation, a sliding window of a preset size can be used, with the origin of the binary image as the starting point, and the integral image can be traversed in a preset order to calculate the grayscale values ​​of different areas in the binary image, and to find the image area whose grayscale value meets the preset two-dimensional code characteristics. Since in the integral image, when the origin is the upper left corner, the value of each pixel is equal to the sum of the grayscale values ​​of all pixels in its upper left corner, the grayscale value of the corresponding area in the binary image can be quickly calculated based on the values ​​of the pixels at the four corners of the sliding window in the integral image. Thereafter, it is determined whether the image area corresponding to the sliding window meets the preset two-dimensional code characteristics. If it meets the preset two-dimensional code characteristics, the image area is used as a target image area that may contain a two-dimensional code.

[0184] The size of the sliding window can be determined according to actual needs. The size of the sliding window can be equal to the size of the two-dimensional code in the image, or can be smaller than the size of the two-dimensional code in the image, etc., and the present invention does not limit this.

[0185] As an example of the present invention, the gray value I of the area corresponding to the sliding window in the binary image can be calculated by the following formula: ABCD :

[0186] I ABCD =I A +I B -I C-I D

[0187] Among them, I A ,I B ,I C ,I D are respectively the values ​​of the pixel points at the four corners of the sliding window in the integral image.

[0188] Thereafter, when the gray value of the effective pixel is 255, the gray value I corresponding to the sliding window in the binary image can be determined and calculated. ABCD , and the pixel area S of the region ABCD Is the ratio between ×255 greater than a preset threshold of 0.95? In the binary image, the gray value I of the area corresponding to the sliding window ABCD , and the pixel area S of the region ABCD When the ratio between ×255 is greater than the preset threshold value of 0.95, it can be considered that the area contains more valid pixels and is more likely to contain a two-dimensional code area, so the area is taken as the target image area.

[0189] Step 205, for a connected region, determining an overlap ratio between the connected region and the target image region in the binary image;

[0190] In the embodiment of the present invention, since the connected area may be a two-dimensional code, a character, an image, a shape, etc., it is necessary to further determine whether the connected area is a two-dimensional code. Therefore, the position of the connected area can be compared with the position of the target image area, and according to the positional relationship between the connected area and the image area, the target connected area is selected as the two-dimensional code in the connected area.

[0191] In the embodiment of the present invention, at least one connected region can be found in the binary image, and it can be further determined whether the connected region is a two-dimensional code. As for the target image region, it can be a region containing the two-dimensional code. Thus, the overlap rate between the connected region and the target image region in the binary image can be determined, so as to determine whether the connected region contains the two-dimensional code based on the overlap rate, thereby determining whether the connected region is the region where the two-dimensional code is located.

[0192] In a specific implementation, the overlap ratio between the connected region and the target image region in the binary image may be determined by calculating the intersection-and-union ratio. Specifically, the intersection-and-union ratio may be calculated by the following formula:

[0193]

[0194] Among them, C is the area where the connected area is located in the binary image, and G is the area where the target image area is located in the image.

[0195] Step 206: when the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, the connected area is determined as a target connected area, and the position information of the target connected area is used as the position information of the QR code.

[0196] In an embodiment of the present invention, when the overlap rate between the connected area and the image area in the binary image is greater than a preset threshold, it can be considered that the connected area and the image area mostly overlap with each other in the binary image, that is, the connected area contains the two-dimensional code content in the target image area, and thus it can be considered that the connected area is the location of the two-dimensional code, the connected area is determined as the target connected area, and the position information of the target connected area is used as the position information of the two-dimensional code, thereby completing the positioning of the two-dimensional code.

[0197] Through the two-dimensional code positioning method of the embodiment of the present invention, the preset image to be processed is binarized and expanded to generate a binary image, so that the two-dimensional code area can be covered by the pixel points of the target value as much as possible, and then the connected area is searched in the binary image to find the area that may be the two-dimensional code based on connectivity, and the binary image is integrated to generate an integral image; the integral image is traversed by a preset sliding window to find the target image area whose grayscale value meets the preset two-dimensional code characteristics, so that the area that may contain the two-dimensional code can be found in the binary image based on the grayscale value. Afterwards, according to the overlap rate of the connected area and the target image area in the binary image, when the overlap rate of the connected area and the target image area in the binary image is greater than a preset threshold, the connected area can be determined as the target connected area, and the position information of the target connected area is used as the position information of the two-dimensional code, so that the two-dimensional code position can be quickly located in the binary image with a high accuracy.

[0198] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0199] Reference Figure 5 , shows a structural block diagram of an embodiment of a two-dimensional code positioning device of the present invention, which may specifically include the following modules:

[0200] The first image processing module 501 is used to perform binarization and dilation processing on a preset image to be processed to generate a binary image;

[0201] A connected region search module 502, used for searching connected regions in a binary image;

[0202] A target image region searching module 503 is used to search for a target image region in the binary image whose grayscale value meets the preset two-dimensional code characteristics;

[0203] An overlap ratio determination module 504 is used to determine, for a connected region, an overlap ratio between the connected region and the target image region in the binary image;

[0204] The two-dimensional code determination module 505 is used to determine the connected area as the target connected area when the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, and use the position information of the target connected area as the position information of the two-dimensional code.

[0205] In one embodiment of the present invention, the connected area search module includes:

[0206] The edge pixel search submodule is used to search for an edge pixel located at the edge of a connected area in a binary image based on a preset operation space, and create a storage space to store the position information of the edge pixel;

[0207] A first adjacent edge pixel point search submodule is used to search for adjacent edge pixel points located around the current edge pixel point based on the operation space, and use the storage space to store the position information of the adjacent edge pixel points;

[0208] A second adjacent edge pixel search submodule is used to use the adjacent edge pixel as the current edge pixel, repeatedly perform the steps of searching for adjacent edge pixels around the current edge pixel based on the operation space, and using the storage space to store the position information of the adjacent edge pixels, until the adjacent edge pixels around the current edge pixel are the edge pixels that have been found, and clear the operation space;

[0209] The connected area determination submodule is used to determine the connected area according to the position information of the edge pixels.

[0210] In one embodiment of the present invention, the target image area search module includes:

[0211] An integral image generation submodule, used for performing integral processing on the binary image to generate an integral image;

[0212] The traversal submodule is used to traverse the integral image using a preset sliding window to find a target image area whose grayscale value meets the preset two-dimensional code characteristics.

[0213] In one embodiment of the present invention, the integral image generation submodule includes:

[0214] a pixel value determination unit, configured to, for a pixel in the integral image, take the sum of all pixel values ​​in a rectangle formed between a pixel at the same position as the pixel in the binary image and an origin of the binary image as the value of the pixel in the integral image;

[0215] The integral image generating unit is used to determine the value of each pixel point in the integral image in sequence to generate an integral image.

[0216] In one embodiment of the present invention, the traversal submodule includes:

[0217] The traversal subunit is used to use a preset sliding window, take the origin of the binary image as the starting point, traverse the integral image in a preset order, and search for a target image area whose grayscale value meets the preset two-dimensional code characteristics.

[0218] In one embodiment of the present invention, the device further comprises:

[0219] A grayscale image generation module is used to perform grayscale processing on a preset image to be identified to generate a grayscale image;

[0220] The filtered image generation module is used to perform filtering processing on the grayscale image to generate a filtered image.

[0221] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0222] An embodiment of the present invention further provides an electronic device, including:

[0223] one or more processors; and

[0224] One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, enable the electronic device to perform the method described in the embodiment of the present invention.

[0225] The embodiment of the present invention further provides one or more machine-readable media having instructions stored thereon, which, when executed by one or more processors, enable the processors to execute the method described in the embodiment of the present invention.

[0226] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0227] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0228] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0229] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0230] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0231] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0232] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0233] The above is a detailed introduction to a two-dimensional code positioning method and a two-dimensional code positioning device, an electronic device, and a machine-readable medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for a general technician in this field, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A two-dimensional code positioning method, characterized in that: include: Performing binarization and expansion processing on the preset image to be processed to generate a binary image; Find connected regions in binary images; Searching for a target image area in the binary image whose grayscale value meets a preset two-dimensional code feature; For a connected region, determining an overlap ratio between the connected region and the target image region in the binary image; the overlap ratio is determined by calculating an intersection-and-union ratio between the connected region and the target image region in the binary image; When the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, the connected area is determined as a target connected area, and the position information of the target connected area is used as the position information of the QR code; Before the step of performing binarization and dilation processing on the preset image to be processed to generate a binary image, the method further includes: The preset image to be identified is grayed to generate a grayed image; Performing filtering on the grayscale image to generate a filtered image; The filtering process is performed on the grayscale image to generate a filtered image, including: using a convolution kernel of a preset size to perform convolution process on the grayscale image to obtain the filtered image.

2. The method according to claim 1, characterized in that The step of searching for connected areas in the binary image comprises: In the binary image, based on a preset operation space, an edge pixel point located at the edge of a connected region is searched, and a storage space is created to store the position information of the edge pixel point; For a current edge pixel point, based on the operation space, searching for adjacent edge pixel points located around the current edge pixel point, and using the storage space to store position information of the adjacent edge pixel points; Taking the adjacent edge pixel point as the current edge pixel point, repeatedly performing the steps of searching for adjacent edge pixels located around the current edge pixel point based on the operation space, and using the storage space to store the position information of the adjacent edge pixels for the current edge pixel point, until the adjacent edge pixels around the current edge pixel point are the edge pixels that have been found, and clearing the operation space; The connected area is determined according to the position information of the edge pixels.

3. The method according to claim 1, characterized in that The step of searching for a target image region in the binary image whose grayscale value meets the preset two-dimensional code feature comprises: Performing integration processing on the binary image to generate an integral image; The integral image is traversed using a preset sliding window to find a target image region whose grayscale value meets the preset two-dimensional code characteristics.

4. The method according to claim 3, characterized in that The step of performing integration processing on the binary image to generate an integral image comprises: For a pixel point in the integral image, the sum of all pixel point values ​​in a rectangle formed between the pixel point at the same position as the pixel point in the binary image and the origin of the binary image is taken as the value of the pixel point in the integral image; The value of each pixel in the integral image is determined in sequence to generate an integral image.

5. The method according to claim 3, characterized in that: The step of using a preset sliding window to traverse the integral image and searching for a target image area whose grayscale value meets the preset two-dimensional code feature includes: A preset sliding window is used, with the origin of the binary image as the starting point, and the integral image is traversed in a preset order to find a target image area whose grayscale value meets the preset two-dimensional code characteristics.

6. A two-dimensional code positioning device, characterized in that: include: The first image processing module is used to perform binarization and dilation processing on the preset image to be processed to generate a binary image; A connected region search module, used for searching connected regions in a binary image; A target image area search module, used to search for a target image area in the binary image whose grayscale value meets the preset two-dimensional code characteristics; An overlap ratio determination module, for determining, for a connected region, an overlap ratio between the connected region and the target image region in the binary image; the overlap ratio is determined by calculating an intersection-and-union ratio between the connected region and the target image region in the binary image; A two-dimensional code determination module, configured to determine the connected area as a target connected area when the overlap rate between the connected area and the target image area in the binary image is greater than a preset threshold, and use the position information of the target connected area as the position information of the two-dimensional code; The device also includes: A grayscale image generation module is used to perform grayscale processing on a preset image to be recognized to generate a grayscale image; A filtered image generation module is used to filter the grayscale image to generate a filtered image; the filtering of the grayscale image to generate a filtered image includes: using a convolution kernel of a preset size to convolve the grayscale image to obtain the filtered image.

7. The device according to claim 6, characterized in that The connected area search module includes: The edge pixel search submodule is used to search for an edge pixel located at the edge of a connected area in a binary image based on a preset operation space, and create a storage space to store the position information of the edge pixel; A first adjacent edge pixel point search submodule is used to search for adjacent edge pixel points located around the current edge pixel point based on the operation space, and use the storage space to store the position information of the adjacent edge pixel points; A second adjacent edge pixel search submodule is used to use the adjacent edge pixel as the current edge pixel, repeatedly perform the steps of searching for adjacent edge pixels around the current edge pixel based on the operation space, and using the storage space to store the position information of the adjacent edge pixels, until the adjacent edge pixels around the current edge pixel are the edge pixels that have been found, and clear the operation space; The connected area determination submodule is used to determine the connected area according to the position information of the edge pixels.

8. An electronic device, characterized in that: include: one or more processors; and One or more machine-readable media having instructions stored thereon, when executed by the one or more processors, cause the electronic device to perform one or more of the methods of claims 1-5.

9. One or more machine-readable media, characterized in that Instructions are stored thereon, which, when executed by one or more processors, cause the processors to perform one or more of the methods as claimed in claims 1-5.