Graphic code positioning method and device, equipment, storage medium and product
By adding a positive and polygon to the graphic outside the graphic code, and using its geometric characteristics to locate the center point, the identification difficulties of the graphic code in the existing technology in the case of lack of light, blurring or noise, and realize the complex background or part of High -efficiency recognition in the case.
Patent Information
- Application Number
- CN202411346228.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2025-01-28
AI Technical Summary
In the prior art, in images with insufficient light, blurred or noisy, the graphic code recognition effect is significantly reduced. Especially in the case of complex backgrounds or partial occlusion, the positioning accuracy of the graphic code is reduced, resulting in the recognition failure.
By adding the graphic of the positive polygon outside the graphic code, the center point of the graphic code is determined by positioning the center point of the external graphics with the geometric characteristics of the external graphics. This method combines deep learning and traditional visual technology to quickly locate the center points to improve fault tolerance and recognition success rate.
In the case of poor image quality, we can accurately identify graphic code, improve the success rate of identification, reduce the difficulty of identification, and maintain a high recognition accuracy in complex background or partial obstruction.
Smart Images

Figure CN119379772A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, device, equipment, storage medium and product for positioning a graphic code. Background Art
[0002] Graphic code is a kind of coding that uses graphics and color elements, arranged and spliced in a certain pattern to form a continuous graphic coding chain for storing and transmitting information data. Graphic code uses specific geometric figures to be distributed in a plane according to a certain pattern to form black and white graphics to record data symbol information. This coding method can store more information and represent more data types. The data recorded by the graphic code can be obtained by scanning the device, thereby realizing automatic processing of information. As an efficient information transmission carrier, graphic code has been widely used in many fields such as payment, logistics and identity authentication.
[0003] However, the current graphic code recognition algorithm is highly dependent on the clarity and contrast of the image. In images with insufficient light, blur or noise, the recognition effect will be significantly reduced. In the case of complex backgrounds or partial occlusion, the positioning of the graphic code becomes difficult and the positioning accuracy is reduced, which may result in the failure to successfully recognize the graphic code. Summary of the invention
[0004] The embodiments of the present application provide a method, device, equipment, storage medium and product for positioning a graphic code, which can improve the accuracy of positioning a graphic code.
[0005] In a first aspect, the present application provides a method for positioning a graphic code, comprising:
[0006] Acquire a graphic code image, wherein the graphic code image includes a graphic code and an external graphic corresponding to the graphic code;
[0007] Performing edge detection on the graphic code image to obtain an edge image;
[0008] Extracting a set of circumscribed graphic line segments in the edge image, wherein the set of circumscribed graphic line segments includes line segments constituting the circumscribed graphic;
[0009] The center point of the circumscribed graphic is determined according to the relative position relationship of the circumscribed graphic line segment set; and the position of the graphic code is determined according to the position of the center point.
[0010] In some possible implementations, acquiring the graphic code image includes:
[0011] Acquire an original image, wherein the original image includes a graphic code;
[0012] Determine the bounding box corresponding to the region of interest in the original image by using a preset target detection algorithm to obtain the original graphic code image;
[0013] The original graphic code image is preprocessed to obtain a graphic code image.
[0014] In some possible implementations, preprocessing the original graphic code image to obtain the graphic code image includes:
[0015] Gray-scale the original graphic code image to obtain a gray-scale image;
[0016] The grayscale image is filtered to obtain a graphic code image.
[0017] In some possible implementations, determining a bounding box corresponding to the region of interest in the original image by a preset target detection algorithm to obtain the original graphic code image includes:
[0018] Determine the bounding box corresponding to the region of interest in the original image by using a preset target detection algorithm to obtain a preliminary position of the graphic code;
[0019] expanding the boundary box according to the preliminary position of the graphic code;
[0020] According to the boundary box range, an original graphic code image is obtained.
[0021] In some possible implementations, extracting a set of circumscribed graphic line segments in the edge image includes:
[0022] Extracting a plurality of line segments from the edge image;
[0023] Taking the line segments whose length is greater than a preset threshold among the plurality of line segments as a first line segment set, wherein the preset threshold corresponds to the side length of the graphic;
[0024] The line segments satisfying the head-to-tail connectivity in the first line segment set are taken as the second line segment set;
[0025] The line segments in the second line segment set whose included angles between the line segments are within a preset range are used as a circumscribed graphic line segment set, where the preset range corresponds to the size of the internal angle of the graphic.
[0026] In some possible implementations, determining the position of the graphic code according to the position of the center point includes:
[0027] Determine the perpendicular bisector corresponding to each line segment according to the slope and center point of each line segment in the set of circumscribed graphic line segments;
[0028] Determine the center point of the graphic code according to the intersection points of the perpendicular midlines;
[0029] Based on the position of the center point, the position of the graphic code is determined.
[0030] In some possible implementations, performing edge detection on the graphic code image to obtain an edge image includes:
[0031] Taking the pixel points in the graphic code image whose brightness exceeds a preset threshold as edge anchor points;
[0032] Based on the edge anchor point, edge drawing is performed according to the brightness of the pixel points in the graphic code image to obtain an edge image.
[0033] In a second aspect, the present application provides a graphical code positioning device, the device comprising:
[0034] An acquisition module, used for acquiring a graphic code image, wherein the graphic code image includes a graphic code and an external graphic corresponding to the graphic code;
[0035] A detection module, used for performing edge detection on the graphic code image to obtain an edge image;
[0036] An extraction module, used for extracting a set of circumscribed graphic line segments in the edge image;
[0037] A determination module, used for determining the center point of the circumscribed figure according to the relative position relationship of the set of line segments of the circumscribed figure;
[0038] The determination module is further used to determine the position of the graphic code according to the position of the center point.
[0039] In a third aspect, the present application provides a graphic code positioning device, the device comprising: a processor, and a memory storing computer program instructions; the processor reads and executes the computer program instructions to implement the graphic code positioning method described above.
[0040] In a fourth aspect, the present application provides a computer-readable storage medium having computer program instructions stored thereon, and the computer program instructions, when executed by a processor, implement the graphic code positioning method as described above.
[0041] In a fifth aspect, the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the graphic code positioning method described above.
[0042] The method, device, equipment, storage medium and product for positioning a graphic code provided in the embodiment of the present application are applied to a graphic code with an external graphic. In this way, when positioning the graphic code, the edge detection is first performed on the graphic code image to obtain an edge image, and then the line segment set constituting the external graphic is extracted from the edge image, and the center point of the external graphic is determined according to the relative position relationship of the line segment set of the external graphic, and finally the position of the graphic code is determined based on the position of the center point. In this way, the embodiment of the present application realizes the positioning of the graphic code by using the external graphic of the graphic code and locating the center point of the external graphic. The positioning of the center point of the external graphic can be realized based on the geometric features of the external graphic. Since the recognition of geometric features does not require high image quality (such as clarity and contrast), the embodiment of the present application can realize accurate recognition of the graphic code even when the image quality is poor. Moreover, the difficulty of recognizing the geometric features of the external graphic is relatively low, so the embodiment of the present application also reduces the difficulty of recognizing the graphic code, and can realize the recognition of the graphic code under the condition of poor image quality, thereby improving the success rate of the recognition of the graphic code. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The present application can be better understood from the following description of the specific embodiments of the present application in conjunction with the accompanying drawings, in which:
[0044] Other features, objects and advantages of the present application will become more apparent by reading the following detailed description of non-limiting embodiments with reference to the accompanying drawings, in which the same or similar reference numerals represent the same or similar features.
[0045] Figure 1 is a flow chart of a method for positioning a graphic code provided by an embodiment of the present application;
[0046] Figure 2 This is a schematic diagram of an image after line segments are extracted from a graphic code image provided by an embodiment of the present application;
[0047] Figure 3 It is an image schematic diagram of determining a graphic code image circumscribed with a graphic code image and obtaining a center point provided by an embodiment of the present application;
[0048] Figure 4 is a structural schematic diagram of a graphic code positioning device provided by an embodiment of the present application;
[0049] Figure 5 It is a schematic diagram of the hardware structure of the graphic code positioning device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0050] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0051] 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 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 device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0052] Edge Drawing (ED) algorithm: An edge detection algorithm that first calculates anchor points in the image and then draws edges by connecting these anchor points. The edge map produced by this method consists of continuous, single-pixel-width edges with actual connectivity, thus solving the shortcomings of traditional methods.
[0053] Region of Interest (ROI): refers to the area that needs special attention or processing, which is delineated from the processed image. These areas can be delineated by boxes, circles, ellipses, irregular polygons, etc. This area is usually the focus of our attention. After delineating the area, further processing can be performed, thereby reducing the workload to a certain extent.
[0054] In digital information management and Internet of Things applications, graphic codes have been widely used as an efficient information transmission carrier. However, in some cases, graphic codes may not be read normally due to damage, blur or partial occlusion. Existing graphic code recognition technology mainly relies on image processing and pattern recognition algorithms. Although the fault tolerance of graphic codes can correct partial damage or occlusion, existing technologies may not be able to successfully recognize and decode when the graphic codes are severely damaged, blurred or partially occluded. Existing graphic code recognition algorithms are highly dependent on the clarity and contrast of the image. In images with poor lighting, blur or noise, the recognition effect will be significantly reduced. In the case of complex background or partial occlusion, the positioning of the graphic code becomes difficult, which may lead to recognition failure. Existing graphic code recognition technology usually only relies on the characteristics of the graphic code itself and lacks an external auxiliary positioning mechanism, which makes it difficult to locate the graphic code in the case of complex background or partial occlusion, and reduces the positioning accuracy.
[0055] The inventors have found that by adding a regular polygon circumscribed graphic outside the graphic code to assist in locating the center point of the graphic code, and by combining deep learning with traditional vision to quickly locate the center point, fault tolerance can be improved, the positioning process can be simplified, and detection time can be reduced.
[0056] In order to solve the problems in the prior art, the embodiments of the present application provide a method, device, equipment, storage medium and product for positioning a graphic code. The following first introduces the method for positioning a graphic code provided by the embodiments of the present application.
[0057] Figure 1 FIG. 1 is a flow chart of a method for locating a graphic code provided by an embodiment of the present application. Figure 1 As shown, the method includes the following steps: S101 to S105.
[0058] S101: Acquire a graphic code image, wherein the graphic code image includes a graphic code and an external graphic corresponding to the graphic code.
[0059] In the specific implementation, this embodiment takes the QR code as an example, and the processing of other types of graphic codes is similar to the QR code. The QR code used in this embodiment is based on the standard QR code, and one or more regular polygonal or circular circumscribed graphics are added to the periphery.
[0060] As an implementation of S101, the graphic code image can be obtained by scanning with an image capture device (such as a camera, scanner, etc.), or by reading the graphic code image from a storage location of the graphic code. The external graphic is used to mark the position and direction of the two-dimensional code.
[0061] S102: Perform edge detection on the graphic code image to obtain an edge image.
[0062] In the specific implementation, the edge detection algorithm is used to process the image to extract the edge information in the image. Taking Canny edge detection as an example, the Canny edge detection algorithm is applied to obtain the edge in the image through steps such as gradient calculation and non-maximum suppression. Thus, an edge image is generated, in which the white part of the image represents the detected edge, and the black part represents the area without edge.
[0063] As another example, the image may be grayscaled and Gaussian blurred before edge detection to reduce the effect of noise.
[0064] S103: extracting a set of circumscribed graphic line segments in the edge image, wherein the set of circumscribed graphic line segments includes line segments constituting the circumscribed graphic.
[0065] In a specific implementation, algorithms such as Hough Transform can be used to detect straight line segments in edge images, map points of edge images to parameter space, identify parameters of straight line segments, and obtain line segments. Filter based on information such as the length and position of the line segments, select the identified line segments, ensure that the identified line segments are edge segments of the circumscribed graphics, and obtain a set of circumscribed graphics line segments in the edge image.
[0066] S104: determining the center point of the circumscribed figure according to the relative position relationship of the set of line segments of the circumscribed figure;
[0067] In a specific implementation, taking the circumscribed figure of a regular quadrilateral as an example, the relative position relationship of the four line segments corresponding to the circumscribed figure is analyzed, and the four vertices of the circumscribed figure are calculated. Then, the coordinates of the center point can be obtained by averaging the coordinates of the four vertices.
[0068] S105: Determine the position of the graphic code according to the position of the center point.
[0069] In a specific implementation, the position of the two-dimensional code is marked in the image according to the calculated center point position, the positioning of the two-dimensional code is completed, and the position of the graphic code is determined.
[0070] The method for positioning a graphic code provided in the embodiment of the present application is applied to a graphic code with an external graphic. In this way, when positioning the graphic code, edge detection is first performed on the graphic code image to obtain an edge image, and then a set of line segments constituting the external graphic is extracted from the edge image, and the center point of the external graphic is determined according to the relative position relationship of the set of line segments of the external graphic, and finally the position of the graphic code is determined based on the position of the center point. In this way, the embodiment of the present application realizes the positioning of the graphic code by using the external graphic of the graphic code and locating the center point of the external graphic. The positioning of the center point of the external graphic can be realized based on the geometric features of the external graphic. Since the recognition of geometric features does not require high image quality (such as clarity and contrast), the embodiment of the present application can realize accurate recognition of the graphic code even when the image quality is poor. Moreover, the difficulty of recognizing the geometric features of the external graphic is relatively low, so the embodiment of the present application also reduces the difficulty of recognizing the graphic code, and can realize the recognition of the graphic code under the condition of poor image quality, thereby improving the success rate of the recognition of the graphic code.
[0071] In order to accurately obtain the graphic code image, in some implementations, the above S101 may include steps A1 to C1:
[0072] Step A1: Acquire an original image, wherein the original image includes a graphic code.
[0073] In the specific implementation, first select the image source, such as a camera, mobile phone, scanner, etc. These devices can transmit the captured image to a computer or processing unit through an image acquisition interface, or can obtain the image from a storage, then it is necessary to specify the path of the image file and read the file. Specifically, the corresponding application programming interface (Application Programming Interface, API) or library function can be used to read the image data from the device or file to obtain the original image.
[0074] Step B1: Determine the boundary box corresponding to the region of interest in the original image by using a preset target detection algorithm to obtain the original graphic code image.
[0075] In the specific implementation, the target detection algorithms that need to be used are preset, such as the You Only LookOnce (YOLO) algorithm, the Single Shot MultiBox Detector (SSD) algorithm and other target detection algorithms. These algorithms can detect specific targets in the image. The acquired original image is input into the target detection algorithm, the algorithm scans the image and marks the area containing the QR code. After that, the algorithm returns a bounding box that identifies the position of the QR code in the image. The bounding box is usually represented by four coordinate values, and then the original QR code image is obtained.
[0076] Step C1: pre-process the original graphic code image to obtain a graphic code image.
[0077] In a specific implementation, the bounding box coordinates generated in step B1 are used to crop the image, and the cropped image is saved as a new image file for subsequent processing. The above image is then preprocessed, and the specific processing may include: grayscale conversion of the color image to a grayscale image to simplify subsequent edge detection and threshold processing; denoising, applying a filter (such as Gaussian blur) to reduce image noise, which helps to improve the accuracy of edge detection; binarization, converting the grayscale image to a binary image to highlight the edge of the QR code; contrast adjustment: adjusting the image contrast to make the QR code pattern clearer, and specifically using the histogram equalization method. After the preprocessing is completed, the QR code image is obtained.
[0078] After acquiring the original image including the graphic code, the above-mentioned implementation method of the embodiment of the present application determines the bounding box corresponding to the region of interest in the above-mentioned original image through a preset target detection algorithm to obtain the original graphic code image, and then pre-processes the above-mentioned original graphic code image to obtain the graphic code image. By dividing the region of interest in the original image and pre-processing the original graphic code image in the region of interest, the graphic code image can be accurately acquired.
[0079] In order to obtain a clear graphic code image, in some embodiments, the above step C1 may include steps C11 to C12:
[0080] Step C11: grayscale the original graphic code image to obtain a grayscale image.
[0081] In the specific implementation, you can use the functions in the computer vision library to convert a color image to a grayscale image. Grayscaling is achieved by removing color information and retaining only brightness information. During the conversion process, the color value of each pixel is converted to a brightness value, which is usually calculated by taking a weighted average of the RGB values to obtain a grayscale image.
[0082] Step C12: Filter the grayscale image to obtain a graphic code image.
[0083] In the specific implementation, Gaussian blur can be used to reduce the noise in the image and smooth the image. Gaussian filtering blurs the image through convolution operation, making the details in the image smoother. Gaussian filtering blurs the noise and small interference in the image, smoothes the overall structure of the image, and makes the edge of the QR code more obvious. The filtered image is used as the QR code image.
[0084] The above implementation of the embodiment of the present application grayscales the original graphic code image to obtain a grayscale image, and then filters the grayscale image to remove noise in the image, thereby obtaining a clear graphic code image.
[0085] In order to ensure that the original graphic code image contains an external graphic corresponding to the graphic code, in some implementations, the above step B1 may include steps B11 to B13:
[0086] Step B11: Determine the boundary box corresponding to the region of interest in the original image by using a preset target detection algorithm to obtain a preliminary position of the graphic code.
[0087] In a specific implementation, by running a preset target detection algorithm, the region of interest in the original image is obtained, and then the bounding box of the QR code is located to obtain the preliminary position of the QR code.
[0088] Step B12: Enlarging the boundary box according to the initial position of the graphic code.
[0089] In a specific implementation, the ratio of the expanded bounding box is first determined, for example, 20% or a certain pixel value is expanded, and then the expanded size is calculated based on the width and height of the original bounding box, and the boundary of the bounding box is expanded.
[0090] Step B13: Obtain the original graphic code image according to the above boundary box range.
[0091] In a specific implementation, the expanded bounding box coordinates are used to define the cropping area, and the original image is cropped according to the calculated bounding box coordinates to obtain the original QR code image.
[0092] The above implementation of the embodiment of the present application determines the bounding box corresponding to the area of interest in the above original image through a preset target detection algorithm, and then expands the above bounding box to determine the original graphic code image. By expanding the bounding box of the area of interest, it is ensured that the external graphic corresponding to the graphic code exists in the original graphic code image.
[0093] In order to accurately obtain the set of line segments of the circumscribed figure, in some embodiments, the circumscribed figure is a regular polygon, and the above S103 may include steps A2 to D2:
[0094] Step A2: extract multiple line segments from the edge image.
[0095] In a specific implementation, all edges in the image are marked by an edge detection algorithm to obtain an edge image, and then the straight line segments in the image are extracted using methods such as Hough transform, thereby extracting multiple line segments in the edge image.
[0096] Step B2: taking the line segments whose lengths are greater than a preset threshold among the above-mentioned multiple line segments as a first line segment set, where the above-mentioned preset threshold corresponds to the side length of the graphic.
[0097] In a specific implementation, a length threshold is determined according to the side length of the circumscribed figure. This threshold is used to filter out short line segments, and then for each line segment, its length is calculated, and based on the calculated length, line segments with a length greater than the threshold are filtered out to obtain a first line segment set.
[0098] Step C2: The line segments satisfying the head-to-tail connectivity in the first line segment set are taken as the second line segment set.
[0099] In a specific implementation, for the line segments in the first line segment set, by detecting the endpoints of the line segments, the adjacent endpoints are matched to determine whether they can be connected to form a closed area, and a geometric method can be used to determine whether the line segments are connected. For example, if the end point of line segment A is close to the starting point of line segment B, the two line segments are considered to be connected. The line segments that meet the connectivity conditions are grouped together to form a second line segment set.
[0100] Step D2: taking the line segments in the second line segment set whose included angles are within a preset range as the circumscribed figure line segment set, wherein the preset range corresponds to the size of the internal angle of the figure.
[0101] In a specific implementation, for the line segments in the second line segment set, vector operations can be used to calculate the angle between two line segments. The direction vector of the line segment can be calculated by the endpoint coordinates, and the angle is obtained by the vector dot product and the arc cosine function. According to the calculated angle, the line segments whose angles are within the preset range are screened out to obtain the circumscribed graphic line segment set.
[0102] The above implementation of the embodiment of the present application extracts multiple line segments in the above edge image when the circumscribed figure is a regular polygon, and then screens the line segments according to the length of the line segments, the connectivity between the end of the line segments and the angle between the line segments, so as to accurately obtain the circumscribed figure line segment set.
[0103] In order to accurately locate the graphic code, in some embodiments, the circumscribed graphic is a regular polygon, and the above S104 may include steps A3 to C3:
[0104] Step A3: According to the slope and center point of each line segment in the above circumscribed graphic line segment set, determine the perpendicular bisector corresponding to each line segment.
[0105] In a specific implementation, for each line segment in the above-mentioned set of circumscribed graphic line segments, its center point is calculated, and the slope of the line segment is calculated. The perpendicular bisector is the perpendicular line of the line segment, and its slope is the negative reciprocal of the slope of the original line segment. The equation of the perpendicular bisector can be determined by the center point and the slope of the perpendicular bisector, and then the perpendicular bisector corresponding to each line segment is determined.
[0106] Step B3: Determine the center point of the graphic code according to the intersection points of the perpendicular bisectors.
[0107] In the specific implementation, the intersection point of different perpendicular bisectors is calculated, and the obtained intersection point is the center point of the QR code.
[0108] Step C3: Based on the position of the above-mentioned center point, determine the position of the graphic code.
[0109] In a specific implementation, the actual position of the QR code is determined, and its position is adjusted according to the center point. The center point of the QR code is marked on the image, and the position of the QR code is adjusted to ensure that it is within the expected area, thereby locating the QR code and determining the position of the graphic code.
[0110] The above-mentioned implementation method of the embodiment of the present application determines the perpendicular bisectors corresponding to each line segment according to the slopes and center points of each line segment in the above-mentioned circumscribed graphic line segment set when the circumscribed graphic is a regular polygon, and determines the center point of the above-mentioned graphic code by the intersection of the perpendicular bisectors, thereby completing the positioning of the graphic code. The center point position of the graphic code is determined by the circumscribed graphic, so as to accurately locate the graphic code.
[0111] In order to accurately obtain the edge image, in some implementations, the above S102 may include steps A4 to B4:
[0112] Step A4: taking the pixel points in the graphic code image whose brightness exceeds a preset threshold as edge anchor points.
[0113] In the specific implementation, a brightness threshold is selected, which is used to distinguish edge and non-edge areas. Usually, the threshold can be selected according to the brightness distribution of the image, or an adaptive threshold method can be used. Each pixel of the grayscale image is traversed to determine whether its brightness exceeds the preset threshold. If it exceeds, the pixel is recorded as an edge anchor point.
[0114] Step B4: Based on the edge anchor points, edge drawing is performed according to the brightness of the pixels in the graphic code image to obtain an edge image.
[0115] In the specific implementation, a completely black image of the same size as the original image can be created to draw the edge. The initial values of all pixels are set to black, and for each edge anchor point, the value of the corresponding pixel is set to white or other significant colors to indicate the edge position. This step is achieved by traversing the edge anchor points to obtain the edge image.
[0116] The above implementation of the embodiment of the present application uses the pixel points in the graphic code image whose brightness exceeds a preset threshold as edge anchor points, and then gradually draws the edge based on the edge anchor points, so as to accurately obtain the edge image.
[0117] In one embodiment of the present application, one or more regular polygon circumscribed graphics are added to the periphery of the standard two-dimensional code, and the number of regular polygon sides is greater than or equal to 5 to increase the fault tolerance rate. Taking the regular polygon as a regular hexagon as an example, after obtaining this two-dimensional code with a regular polygon circumscribed graphic, the image containing the two-dimensional code is first initially positioned using the pruned YOLO model to obtain the initial position of the two-dimensional code. The pruned YOLO can quickly determine the ROI area. Compared with directly performing polygon circumscribed graphic detection on the original image, the time consumption of detecting polygons in the ROI area can be shortened to 1 / 10 to 1 / 15 of the original. After that, the width and height of the two-dimensional code bounding box detected by YOLOv5 are simultaneously expanded by about 1.6 times to ensure that the area containing the external regular polygon circumscribed graphics is included. The enlarged area is grayed. If there is too much noise, binarization and other denoising methods can be added, such as a series of preprocessing techniques such as Gaussian filtering, median filtering, bilateral filtering, expansion, and corrosion. ED edge detection is performed on the preprocessed image. Compared with the traditional Canny edge detection algorithm, the ED algorithm reduces the computational complexity and greatly improves the performance through anchor point detection and edge drawing. After ED edge detection, an edge image is obtained.
[0118] The edge image is further subjected to ED line segment detection to extract the line segments in the image. The extracted line segments are as follows: Figure 2 As shown, Figure 2This is a schematic diagram of an image after line segment extraction of a graphic code image. In the figure, the line represented by line segment 201 is the line segment corresponding to the circumscribed figure of a regular hexagon, and the line represented by line segment 202 is the line segment corresponding to the QR code after line segment extraction. The detected line segments are then screened and judged. Specifically, a threshold is first set according to the length of the side length of the regular polygon in the actual scene, and some lines that do not meet the conditions are screened out. Then a second screening is performed based on the connectivity of the head and tail of the line segment. Finally, a third screening is performed based on the angle between the line segments.
[0119] After three screenings, at most two sets of regular hexagonal sides can be obtained. In these line segment sets, first find the slope k and center point m of each side. The corresponding slope of the perpendicular line of each side is -k, so the expression of the perpendicular median of each side can be obtained. Then determine the intersection of the perpendicular median based on the intersection of the expressions of each adjacent side, and finally take the average of these intersections as the center point of the QR code. The center point obtained is as follows: Figure 3 As shown, Figure 3 The diagram is a schematic diagram of an image of a center point obtained by determining a circumscribed figure of a graphic code image. In the diagram, point 301 represents the center point of a two-dimensional code determined by the intersection of the perpendicular lines of line segment 201 corresponding to the circumscribed figure of a regular hexagon.
[0120] For example, on a 1280×720 image captured by a camera, if the ED algorithm is used directly for edge detection, the average time taken for running 100 times is 131 milliseconds. If the YOLO algorithm is used to initially locate the QR code position and then the ED algorithm is used to detect the edge, the average time taken for 100 times is 11 milliseconds, of which the YOLO algorithm takes an average of 1.5 milliseconds.
[0121] By adding an external regular polygon circumscribed graphic, even if the QR code itself is difficult to read due to damage or obstruction, the system can locate and identify the QR code by identifying the external circumscribed graphic, greatly improving the fault tolerance of the QR code. The regular polygon circumscribed graphic has obvious geometric features, which are highly resistant to fluctuations in image quality. Therefore, even under conditions of insufficient lighting, blurred images, or the presence of noise, a high recognition rate can be maintained.
[0122] Based on the graphic code positioning method provided in the above embodiment, the present application also provides a specific implementation of a graphic code positioning device. Please refer to the following embodiment.
[0123] See first Figure 4 The graphic code positioning device 400 provided in the embodiment of the present application includes the following modules:
[0124] The acquisition module 401 is used to acquire a graphic code image, wherein the graphic code image includes a graphic code and an external graphic corresponding to the graphic code.
[0125] The detection module 402 is used to perform edge detection on the graphic code image to obtain an edge image.
[0126] The extraction module 403 is used to extract the set of circumscribed graphic line segments in the edge image.
[0127] A determination module 404, configured to determine the center point of the circumscribed figure according to the relative position relationship of the circumscribed figure line segment set;
[0128] The determination module 404 is further configured to determine the position of the graphic code according to the position of the center point.
[0129] The graphic code positioning device provided in the embodiment of the present application is applied to a graphic code with an external graphic. In this way, when positioning the graphic code, the edge detection is first performed on the graphic code image to obtain the edge image, and then the line segment set constituting the external graphic is extracted from the edge image, and the center point of the external graphic is determined according to the relative position relationship of the line segment set of the external graphic, and finally the position of the graphic code is determined based on the position of the center point. In this way, the embodiment of the present application realizes the positioning of the graphic code by using the external graphic of the graphic code and locating the center point of the external graphic. The center point positioning of the external graphic can be realized based on the geometric features of the external graphic. Since the recognition of geometric features does not require high image quality (such as clarity and contrast), the embodiment of the present application can realize accurate recognition of the graphic code even when the image quality is poor. Moreover, the difficulty of recognizing the geometric features of the external graphic is relatively low, so the embodiment of the present application also reduces the difficulty of recognizing the graphic code, and can realize the recognition of the graphic code under the condition of poor image quality, thereby improving the success rate of the recognition of the graphic code.
[0130] As an implementation of the present application, the acquisition module 401 may include:
[0131] The acquisition unit is used to acquire an original image, wherein the original image includes a graphic code.
[0132] The determination unit is used to determine the boundary box corresponding to the region of interest in the original image through a preset target detection algorithm to obtain the original graphic code image.
[0133] The processing unit is used to pre-process the original graphic code image to obtain a graphic code image.
[0134] After acquiring the original image including the graphic code, the above-mentioned implementation method of the embodiment of the present application determines the bounding box corresponding to the region of interest in the above-mentioned original image through a preset target detection algorithm to obtain the original graphic code image, and then pre-processes the above-mentioned original graphic code image to obtain the graphic code image. By dividing the region of interest in the original image and pre-processing the original graphic code image in the region of interest, the graphic code image can be accurately acquired.
[0135] As an implementation of the present application, the processing unit may include:
[0136] The grayscale subunit is used to grayscale the original graphic code image to obtain a grayscale image.
[0137] The filtering subunit is used to filter the grayscale image to obtain a graphic code image.
[0138] The above implementation of the embodiment of the present application grayscales the original graphic code image to obtain a grayscale image, and then filters the grayscale image to remove noise in the image, thereby obtaining a clear graphic code image.
[0139] As an implementation of the present application, the determining unit may include:
[0140] The determination subunit is used to determine the boundary box corresponding to the region of interest in the original image through a preset target detection algorithm to obtain a preliminary position of the graphic code.
[0141] The enlarging subunit is used to enlarge the above boundary box according to the preliminary position of the above graphic code.
[0142] The determination subunit is also used to obtain the original graphic code image according to the above boundary box range.
[0143] The above implementation of the embodiment of the present application determines the bounding box corresponding to the area of interest in the above original image through a preset target detection algorithm, and then expands the above bounding box to determine the original graphic code image. By expanding the bounding box of the area of interest, it is ensured that the external graphic corresponding to the graphic code exists in the original graphic code image.
[0144] As an implementation of the present application, the extraction module 403 may include:
[0145] The extraction unit is used to extract multiple line segments from the edge image.
[0146] The determining unit is used to take the line segments whose lengths are greater than a preset threshold among the above-mentioned multiple line segments as a first line segment set, and the above-mentioned preset threshold corresponds to the length of the edge of the figure.
[0147] The determination unit is further configured to use the line segments satisfying the head-to-tail connectivity in the first line segment set as the second line segment set.
[0148] The determination unit is further used to use the line segments in the second line segment set whose angles between the line segments are within a preset range as the circumscribed figure line segment set, and the preset range corresponds to the size of the internal angle of the figure.
[0149] The above implementation of the embodiment of the present application extracts multiple line segments in the above edge image when the circumscribed figure is a regular polygon, and then screens the line segments according to the length of the line segments, the connectivity between the end of the line segments and the angle between the line segments, so as to accurately obtain the circumscribed figure line segment set.
[0150] As an implementation of the present application, the determination module 404 may include:
[0151] The determination unit is used to determine the perpendicular bisector corresponding to each line segment according to the slope and center point of each line segment in the above-mentioned circumscribed graphic line segment set.
[0152] The determination unit is further used to determine the center point of the graphic code according to the intersection points of each of the perpendicular bisectors.
[0153] A positioning unit is used to determine the position of the graphic code based on the position of the central point.
[0154] The above-mentioned implementation method of the embodiment of the present application determines the perpendicular bisectors corresponding to each line segment according to the slopes and center points of each line segment in the above-mentioned circumscribed graphic line segment set when the circumscribed graphic is a regular polygon, and determines the center point of the above-mentioned graphic code by the intersection of the perpendicular bisectors, thereby completing the positioning of the graphic code. The center point position of the graphic code is determined by the circumscribed graphic, so as to accurately locate the graphic code.
[0155] As an implementation of the present application, the detection module 402 may include:
[0156] The determination unit is used to use the pixel points in the graphic code image whose brightness exceeds a preset threshold as edge anchor points.
[0157] The drawing unit is used to draw the edge based on the edge anchor point according to the brightness of the pixel points in the graphic code image to obtain an edge image.
[0158] The above implementation of the embodiment of the present application uses the pixel points in the graphic code image whose brightness exceeds a preset threshold as edge anchor points, and then gradually draws the edge based on the edge anchor points, so as to accurately obtain the edge image.
[0159] Each module in the graphic code positioning device provided in the embodiment of the present application can implement each step in the above-mentioned graphic code positioning method and achieve corresponding effects. For the sake of concise description, it will not be repeated here.
[0160] Figure 5 A schematic diagram of the structure of the graphic code positioning hardware provided in an embodiment of the present application is shown.
[0161] The graphic code positioning device may include a processor 501 and a memory 502 storing computer program instructions.
[0162] Specifically, the processor 501 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0163] The memory 502 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 502 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 502 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 502 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 502 is a non-volatile solid-state memory.
[0164] The memory may include a read-only memory (ROM), a random access memory (RAM), a disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Therefore, generally, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method for locating a graphic code according to any one embodiment of the present disclosure.
[0165] The processor 501 reads and executes the computer program instructions stored in the memory 502 to implement any one of the graphic code positioning methods in the above embodiments.
[0166] In one example, the graphic code positioning device may further include a communication interface 503 and a bus 510. Figure 5As shown, the processor 501, the memory 502, and the communication interface 503 are connected via a bus 510 and communicate with each other.
[0167] The communication interface 503 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0168] Bus 510 includes hardware, software or both, and the parts of online data flow billing equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (AGP) or other graphics bus, enhanced industrial standard architecture (EISA) bus, front-end bus (FSB), hypertransport (HT) interconnection, industrial standard architecture (ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 510 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the present application considers any suitable bus or interconnection.
[0169] In addition, in combination with the method for locating a graphic code in the above embodiment, the present application embodiment can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any one of the methods for locating a graphic code in the above embodiment is implemented.
[0170] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed, implements any one of the graphic code positioning methods in the above embodiments.
[0171] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0172] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0173] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0174] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box 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, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0175] The above is only a specific implementation of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A method for positioning a graphic code, characterized in that: include: Acquire a graphic code image, wherein the graphic code image includes a graphic code and an external graphic corresponding to the graphic code; Performing edge detection on the graphic code image to obtain an edge image; Extracting a set of circumscribed graphic line segments in the edge image, wherein the set of circumscribed graphic line segments includes line segments constituting the circumscribed graphic; Determining the center point of the circumscribed figure according to the relative position relationship of the set of line segments of the circumscribed figure; The position of the graphic code is determined according to the position of the center point.
2. The method for locating a graphic code according to claim 1, characterized in that: The step of obtaining the graphic code image comprises: Acquire an original image, wherein the original image includes a graphic code; Determine the bounding box corresponding to the region of interest in the original image by using a preset target detection algorithm to obtain the original graphic code image; Gray-scale the original graphic code image to obtain a gray-scale image; The grayscale image is filtered to obtain a graphic code image.
3. The method for locating a graphic code according to claim 2, characterized in that: The method of determining a bounding box corresponding to the region of interest in the original image by using a preset target detection algorithm to obtain the original graphic code image includes: Determine the bounding box corresponding to the region of interest in the original image by using a preset target detection algorithm to obtain a preliminary position of the graphic code; expanding the boundary box according to the preliminary position of the graphic code; According to the range of the boundary box, an original graphic code image is obtained.
4. The method for locating a graphic code according to claim 1, characterized in that: The circumscribed figure is a regular polygon, and the step of extracting a set of circumscribed figure line segments in the edge image includes: extracting a plurality of line segments in the edge image; Taking the line segments whose length is greater than a preset threshold among the plurality of line segments as a first line segment set, wherein the preset threshold corresponds to the side length of the graphic; The line segments satisfying the head-to-tail connectivity in the first line segment set are taken as the second line segment set; The line segments in the second line segment set whose included angles are within a preset range are taken as a circumscribed figure line segment set, and the preset range corresponds to the size of the inner angle of the circumscribed figure.
5. The method for locating a graphic code according to claim 1, characterized in that: Determining the position of the graphic code according to the position of the center point includes: Determine the perpendicular bisector corresponding to each line segment according to the slope and center point of each line segment in the circumscribed graphic line segment set; Determine the center point of the graphic code according to the intersection points of the perpendicular midlines; Based on the position of the center point, the position of the graphic code is determined.
6. The method for locating a graphic code according to any one of claims 1 to 5, characterized in that: The step of performing edge detection on the graphic code image to obtain an edge image comprises: Taking the pixel points in the graphic code image whose brightness exceeds a preset threshold as edge anchor points; Based on the edge anchor point, edge drawing is performed according to the brightness of the pixel points in the graphic code image to obtain an edge image.
7. A graphic code positioning device, characterized in that: The device comprises: An acquisition module, used for acquiring a graphic code image, wherein the graphic code image includes a graphic code and an external graphic corresponding to the graphic code; A detection module, used for performing edge detection on the graphic code image to obtain an edge image; An extraction module, used for extracting a set of circumscribed graphic line segments in the edge image; A determination module, used for determining the center point of the circumscribed figure according to the relative position relationship of the set of line segments of the circumscribed figure; The determination module is further used to determine the position of the graphic code according to the position of the center point.
8. A graphic code positioning device, characterized in that: The device comprises: a processor, and a memory storing computer program instructions; the processor reads and executes the computer program instructions to implement the graphic code positioning method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the graphic code positioning method according to any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the graphic code positioning method as described in any one of claims 1-7.