Decoding method of dm code, electronic device, storage medium and program product
By calculating the gradient value and direction of each pixel in the DM code image, the actual edge is determined. The parallelogram rule is used to quickly and accurately locate the DM code region, solving the problem of low DM code decoding efficiency in existing technologies and achieving efficient and accurate DM code decoding.
Patent Information
- Application Number
- CN202211276828.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-18
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2042-10-18
AI Technical Summary
Existing technologies are inefficient and inaccurate in identifying the image region where the DM code is located, resulting in low efficiency in the DM code decoding process.
By calculating the gradient value and gradient direction of each pixel in the original image, the two solid sides of the DM code are determined, and the image region is determined using the parallelogram rule, and the image region is directly decoded.
It achieves efficient and accurate identification of the image region where the DM code is located, improving the efficiency and accuracy of DM code decoding, and reaching sub-pixel level precision.
Smart Images

Figure CN115879488B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a DM code decoding method, electronic device, storage medium, and program product. Background Technology
[0002] DM (Datamatrix) codes are matrix QR codes characterized by high information density, small size, high fault tolerance, and strong resistance to contamination, making them widely used in industrial fields. To obtain the information contained in a DM code, it is necessary to identify the image region containing the DM code and then decode the identified DM code.
[0003] Existing methods for identifying the image region containing the DM code suffer from low efficiency and accuracy. For example, they often require preprocessing the original image, such as filtering and binarization, followed by searching for straight lines in the binarized image. However, the accuracy of line location is low, the binarized image is prone to jagged edges, and the process involves numerous complex steps, resulting in low efficiency. Another example is the need to extract feature maps from the image and perform feature detection within those maps, which is also inefficient. Therefore, there is an urgent need for a fast and accurate method to identify the region containing the DM code and then decode it. Summary of the Invention
[0004] In view of the above problems, this disclosure provides a DM code decoding method, electronic device, storage medium, and program product to overcome or at least partially solve the above problems.
[0005] A first aspect of this disclosure provides a method for decoding DM codes, comprising:
[0006] Based on the gradient of each pixel in the original image, determine the two solid edges of the DM code;
[0007] The image region where the DM code is located is determined based on the two solid edges of the DM code;
[0008] The image region containing the DM code is decoded to obtain the decoding result of the DM code.
[0009] Optionally, it also includes:
[0010] Detect the target image region in the original image, wherein the target image region is the image region containing the DM code;
[0011] Calculate the gradient value and gradient direction of each pixel in the target image region;
[0012] Each solid edge of the DM code is determined according to the following steps:
[0013] Based on the gradient value and gradient direction of each pixel in the target image region, a target seed point is determined on each solid edge, wherein the gradient value of the target seed point is greater than the gradient values of the two pixels before and after the target seed point in the gradient direction;
[0014] For each target seed point located on a solid edge, multiple pixels are searched along the tangential direction of the gradient direction of the target seed point to obtain a pixel chain composed of the multiple pixels. The gradient values of the multiple pixels are greater than the gradient threshold and belong to the regional extrema.
[0015] A solid edge of the DM code is determined based on a target seed point and the pixel chain corresponding to the target seed point.
[0016] Optionally, multiple pixels are searched along the tangential direction of the gradient direction of the target seed point to obtain a pixel chain composed of the multiple pixels, including:
[0017] Multiple pixels are searched along the tangential direction of the gradient of the target seed point, and the gradient direction of each pixel is obtained.
[0018] If the gradient direction of a found pixel differs from the gradient direction of the target seed point by more than or equal to 90 degrees, the search is stopped, and a pixel chain composed of the multiple pixels is obtained.
[0019] Optionally, determining a solid edge of the DM code based on a target seed point and the pixel chain corresponding to the target seed point includes:
[0020] Obtain the multiple pixels closest to the target seed point in the pixel chain corresponding to the target seed point;
[0021] A coarse positioning line is obtained by fitting a straight line between the target seed point and the nearest multiple pixels.
[0022] Along the pixel chain corresponding to the target seed point, find the pixel in the target image region whose distance from the target seed point changes abruptly, and determine the previous pixel of the pixel as the endpoint of the solid edge where the target seed point is located;
[0023] Based on the coarse positioning line and the endpoint, a solid edge of the DM code is determined.
[0024] Optionally, it also includes:
[0025] Based on the distance from each pixel in the pixel chain corresponding to the target seed point to the coarse positioning line, each pixel in the pixel chain corresponding to the target seed point is filtered.
[0026] Linear fitting is performed on the remaining pixels after filtering to obtain the fine positioning line;
[0027] Based on the coarse positioning line and the endpoints, a solid edge of the DM code is determined, including:
[0028] Based on the precise positioning line and the endpoint, a solid edge of the DM code is determined.
[0029] Optionally, calculating the gradient value and gradient direction of each pixel in the target image region includes:
[0030] Calculate the horizontal and vertical gradient values for each pixel in the target image region;
[0031] The sum of the horizontal gradient value and the vertical gradient value of each pixel in the target image region is taken as the gradient value of that pixel.
[0032] The gradient direction of a pixel is obtained by estimating its horizontal and vertical gradient values for each pixel in the target image region.
[0033] Optionally, based on the gradient value and gradient direction of each pixel in the target image region, the target seed point located on each solid edge is determined, including:
[0034] Determine multiple seed points whose horizontal gradient values are greater than the horizontal gradient values of the two preceding and following pixels in the horizontal direction, and determine multiple seed points whose vertical gradient values are greater than the vertical gradient values of the two preceding and following pixels in the vertical direction.
[0035] Edge detection is performed on the target image region to obtain the edges;
[0036] Among all seed points, the seed point located at the edge is determined as the target seed point.
[0037] Optionally, the image region where the DM code is located is determined based on the two solid edges of the DM code, including:
[0038] Based on the parallelogram law and the two solid sides of the DM code, the two virtual sides of the DM code are obtained.
[0039] The image region enclosed by the two solid edges and two dashed edges of the DM code in the original image is determined as the image region where the DM code is located.
[0040] Optionally, the image region containing the DM code is decoded to obtain the decoding result of the DM code, including:
[0041] The pattern of the DM code is determined based on the number of black and white changes of the two virtual edges that enclose the image region containing the DM code.
[0042] The image region containing the DM code is binarized to obtain the processed image region;
[0043] According to the pattern of the DM code, the processed image region is decoded to obtain the decoding result of the DM code.
[0044] A second aspect of this disclosure provides an electronic device including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the DM code decoding method disclosed in this disclosure.
[0045] A third aspect of this disclosure provides a computer-readable storage medium having a computer program / instructions stored thereon, which, when executed by a processor, implements the DM code decoding method disclosed in the embodiments of this disclosure.
[0046] A fourth aspect of this disclosure provides a computer program product including a computer program / instructions that, when executed by a processor, implement the DM code decoding method disclosed in this disclosure.
[0047] The embodiments disclosed herein have the following advantages:
[0048] In this embodiment, the two solid edges of the DM code are determined based on the gradient of each pixel in the original image; the image region containing the DM code is determined based on the two solid edges of the DM code; and the image region containing the DM code is decoded to obtain the decoding result of the DM code. Directly processing the original image has the advantage of high efficiency, while determining the solid edges of the DM code based on the gradient of each pixel in the original image has the advantage of high accuracy. Therefore, efficient and accurate decoding of the image region containing the DM code is achieved, yielding the decoding result of the DM code. Attached Figure Description
[0049] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments of this disclosure will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1 This is a flowchart of the steps of a DM code decoding method according to an embodiment of the present disclosure;
[0051] Figure 2 The image of the DM code and the border image of the DM code are shown;
[0052] Figure 3 The digital decoding area of the DM code is shown;
[0053] Figure 4 This is a flowchart illustrating the decoding method of DM code in an embodiment of this disclosure;
[0054] Figure 5 This is a schematic diagram of the structure of a DM code decoding device according to an embodiment of the present disclosure;
[0055] Figure 6 This is a schematic diagram of an electronic device according to an embodiment of the present disclosure. Detailed Implementation
[0056] To make the above-mentioned objectives, features and advantages of this disclosure more apparent and understandable, the disclosure will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0057] In recent years, significant progress has been made in research on technologies based on artificial intelligence, such as computer vision, deep learning, machine learning, image processing, and image recognition. Artificial intelligence (AI) is an emerging science and technology that studies and develops theories, methods, technologies, and application systems to simulate and extend human intelligence. AI is a comprehensive discipline involving numerous technologies, including chips, big data, cloud computing, the Internet of Things, distributed storage, deep learning, machine learning, and neural networks. Computer vision, as an important branch of AI, specifically enables machines to recognize the world. Computer vision technologies typically include face recognition, liveness detection, fingerprint recognition and anti-counterfeiting verification, biometric recognition, face detection, pedestrian detection, object detection, image processing, image recognition, image semantic understanding, image retrieval, text recognition, video processing, video content recognition, 3D reconstruction, virtual reality, augmented reality, simultaneous localization and mapping (SLAM), computational photography, and robot navigation and localization. With the research and advancement of artificial intelligence technology, this technology has been applied in numerous fields, such as security and prevention, urban management, traffic management, building management, park management, facial recognition access control, facial recognition attendance, logistics management, warehouse management, robotics, intelligent marketing, computational photography, mobile imaging, cloud services, smart homes, wearable devices, autonomous driving, autonomous driving, smart healthcare, facial recognition payment, facial recognition unlocking, fingerprint unlocking, identity verification, smart screens, smart TVs, cameras, mobile internet, live streaming, beauty filters, cosmetics, medical aesthetics, and intelligent temperature measurement.
[0058] Reference Figure 1 As shown, a flowchart illustrating the steps of a DM code decoding method according to an embodiment of this disclosure is presented, as follows: Figure 1 As shown, the decoding method for this DM code includes the following steps:
[0059] Step S11: Determine the two solid edges of the DM code based on the gradient of each pixel in the original image;
[0060] Step S12: Determine the image region where the DM code is located based on the two solid edges of the DM code;
[0061] Step S13: Decode the image region where the DM is located to obtain the decoding result of the DM code.
[0062] Figure 2 The images show the DM code image and its border image, with the left image being the DM code image and the right image being the DM code border image. The DM code has two solid edges and two dashed edges, which together constitute the DM code's border. The solid edges consist of dark image blocks, and the L-shaped pattern formed by the two solid edges is called the alignment pattern, which can be used to define the physical size of the DM and determine the image area where the DM code is located. The dashed edges consist of alternating dark and light image blocks, and the pattern formed by the two dashed edges is called the clock pattern, which can be used to determine the DM code's pattern and help determine the image area where the DM code is located.
[0063] A gradient is a vector that has both direction and magnitude. The direction of the gradient of a pixel refers to the direction along which the pixel value changes the fastest; the gradient value of a pixel refers to the rate of change of the pixel value along the direction of the gradient.
[0064] The closer a pixel is to the edge of the DM code, the larger its gradient value. Therefore, the two solid edges of the DM code can be determined based on the gradient of each pixel in the original image. Furthermore, when determining the two solid edges of the DM code based on the pixel gradient, the coordinates of the solid edges can be accurate to one decimal place, achieving sub-pixel precision. Consequently, the image region containing the DM code, determined based on its two solid edges, also achieves sub-pixel precision.
[0065] Optionally, determining the image region where the DM code is located based on the two solid edges of the DM code can be achieved by: obtaining the two dashed edges of the DM code based on the parallelogram rule and the two solid edges of the DM code; and determining the image region enclosed by the two solid edges and two dashed edges of the DM code in the original image as the image region where the DM code is located.
[0066] according to Figure 2 As can be seen, the two solid sides and two dashed sides of the DM code form a rectangle. Therefore, after determining the two solid sides of the DM code, the two dashed sides can be directly obtained according to the parallelogram rule. The image area enclosed by the two solid sides and two dashed sides of the DM code is the image area where the DM code is located.
[0067] In this way, there is no need to identify the virtual edges of the DM code in the original image. Instead, the virtual edges can be obtained quickly based on the determined solid edges, thereby quickly determining the image region where the DM code is located.
[0068] Once the image region containing the DM code is determined, the virtual edges of the DM code are also determined. The image region containing the DM code can then be directly decoded to obtain the decoded DM code result. Decoding the image region containing the DM code is to obtain the information contained within the DM code; the decoded DM code result can be the string information contained within the DM code.
[0069] Optionally, the decoding process may include the following steps: determining the pattern of the DM code based on the number of black and white changes of the two virtual edges that enclose the image region where the DM code is located; performing binarization processing on the image region where the DM code is located to obtain the processed image region; and decoding the processed image region according to the pattern of the DM code to obtain the decoding result of the DM code.
[0070] Binarizing the image region containing the DM code facilitates subsequent decoding. The DM code mode refers to the type of DM code, such as ECC000, ECC050, ECC080, and ECC200. Different modes of DM codes may require different decoding methods. After determining the DM code mode, open-source libraries can be used to decode the digital decoding area of the DM code according to the standard DM code protocol to obtain the decoding result. Examples of open-source libraries include ZBar and ZXing. Figure 3 The digital decoding area of the DM code is shown, where the lighter-colored region surrounded by solid and dashed edges is the digital decoding area. This allows for the decoding of the DM code, thereby obtaining the information contained within it.
[0071] The technical solution of this disclosure directly processes the original image, which has the advantage of high efficiency. It also determines the solid edges of the DM code based on the gradient of each pixel in the original image, which has the advantage of high accuracy. Therefore, it achieves efficient and accurate decoding of the image region containing the DM code, obtaining the decoding result of the DM code.
[0072] Optionally, based on the above technical solution, the target image region in the original image can be detected first, and then processed. The target image region is the image region containing the DM code. If the target image region is not detected in the original image, the decoding process can be directly exited, and a decoding failure result can be returned.
[0073] Detecting the target image region in the original image can be done using image recognition methods from related technologies. However, the accuracy of the detected target image region is not high, so it cannot be directly used as the image region where the DM code is located.
[0074] After detecting the target image region, only the gradient value and gradient direction of each pixel in the target image region need to be calculated, without having to calculate the gradients of other pixels outside the target image region in the original image, thus saving computational resources.
[0075] Optionally, calculating the gradient value and gradient direction of a pixel may include: calculating the horizontal gradient value and the vertical gradient value of each pixel in the target image region; taking the sum of the horizontal gradient value and the vertical gradient value of each pixel in the target image region as the gradient value of that pixel; and estimating the gradient direction of that pixel based on the horizontal gradient value and the vertical gradient value of each pixel in the target image region.
[0076] Because gradients have direction, a gradient can be decomposed into a horizontal gradient value and a vertical gradient value. The Sobel gradient operator can be used to calculate the horizontal and vertical gradient values. For a pixel with image coordinates [i, i], v... i,i The pixel value at that location can be represented by the following formulas to calculate the horizontal and vertical gradient values:
[0077] Grad i,x =|v i+1,i-1 +2*v i+1,i +v i+1,i+1 -v i-1,i-1 -2*v i-1,i -v i-1,i+1 |
[0078] Grad i,y =|v i-1,i+1 +2*v i,i+1 +v i+1,i+1 -v i-1,i-1 -2*v i,i-1 -v i+1,i-1 |
[0079] Among them, Grad i,x and Grad i,y These represent the horizontal gradient value and the vertical gradient value, respectively.
[0080] Because each image block in a DM code is horizontally and vertically straight and lacks rounded corners, the sum of the horizontal and vertical gradient values of a pixel can be directly used as the gradient value of that pixel. That is, Grad... i =Gradi,x +Grad i,y Among them, Grad i This represents the gradient value of a pixel.
[0081] The gradient direction of a pixel can be calculated using trigonometric functions based on its horizontal and vertical gradient values. However, calculating the gradient direction using trigonometric functions is slow and complex. Therefore, this embodiment estimates the gradient direction using the horizontal and vertical gradient values, and the estimation process can be expressed by the following formula:
[0082]
[0083] Estimating the gradient direction using horizontal and vertical gradient values can improve computational performance by nearly 100 times compared to calculating the direct gradient direction using trigonometric functions.
[0084] After calculating the gradient value and gradient direction of each pixel in the target image region, each solid edge of the DM code can be determined by following these steps:
[0085] Step S21: Based on the gradient value and gradient direction of each pixel in the target image region, determine the target seed point located on each solid edge, wherein the gradient value of the target seed point is greater than the gradient values of the two pixels before and after the target seed point in the gradient direction;
[0086] Step S22: For the target seed point located on each solid edge, find multiple pixel points along the tangential direction of the gradient direction of the target seed point to obtain a pixel chain composed of the multiple pixel points;
[0087] Step S23: Determine a solid edge of the DM code based on a target seed point and the pixel chain corresponding to the target seed point.
[0088] Because pixels closer to the edge of the DM code have larger gradient values, the gradient value of the target seed point located on the solid edge is greater than the gradient values of the two pixels immediately before and after it in the gradient direction. It's understandable that although the solid edge is determined based on the target seed point, the solid edge objectively exists. Therefore, even though the specific location of the solid edge has not yet been determined, the target seed point on the solid edge can be determined first.
[0089] Optionally, in step S21, multiple seed points in the target image region can be determined first, and then the target seed point located on the real edge can be determined from the multiple seed points.
[0090] Because there are many edges inside the DM code when processing the image, seed points can also be identified for other edges. Specifically, pixels with horizontal gradient values greater than the horizontal gradient values of the two pixels before and after them in the horizontal direction, and pixels with vertical gradient values greater than the vertical gradient values of the two pixels before and after them in the vertical direction, are all used as seed points.
[0091] Edge detection of the target image region can yield the edges of the DM code. The edge of the DM code refers to the location of the solid edge. Edge detection accuracy is not high, only identifying the approximate location of the solid edge. However, since other seed points are relatively far from the solid edge, the seed points located at the edge can be identified as target seed points. Thus, target seed points located on the solid edge can be obtained.
[0092] The target seed point is a pixel located on a solid edge, so its gradient direction is perpendicular to the solid edge and outwards. Therefore, the tangent direction of the gradient direction of the target seed point is the direction of the solid edge. Thus, by searching for multiple pixels along the tangent direction of the gradient direction of the target seed point, the found pixels are those within the region of the solid edge.
[0093] To ensure that pixels in the pixel chain are as close to solid edges as possible, and considering that pixels closer to the edge have larger gradient values, when searching for pixels, it's necessary to ensure that the gradient value of a pixel is greater than a gradient threshold and belongs to a regional extremum. A pixel's gradient value belonging to a regional extremum is characterized by being the maximum gradient value compared to all pixels in its neighborhood. The gradient threshold can be set according to requirements.
[0094] Optionally, in step S22, when searching for multiple pixels along the tangential direction of the gradient direction of the target seed point, the gradient direction of each found pixel can also be obtained. If the gradient direction of a found pixel differs from the gradient direction of the target seed point by more than or equal to 90 degrees, the search is stopped, and a pixel chain composed of multiple pixels is obtained.
[0095] If the gradient direction of a pixel differs from the gradient direction of the target seed point by 90 degrees or more, it proves that the pixel is not located on the solid edge where the target seed point is located, and therefore, the search is stopped.
[0096] In this way, it can be guaranteed that the pixels forming the pixel chain are pixels on the same edge.
[0097] Optionally, in step S23, determining a solid edge of the DM code based on a target seed point and the pixel chain corresponding to the target seed point may include:
[0098] Step S231: Obtain the multiple pixels closest to the target seed point on the pixel chain corresponding to the target seed point;
[0099] Step S232: Perform line fitting on the target seed point and the nearest multiple pixels to obtain a coarse positioning line;
[0100] Step S233: Along the pixel chain corresponding to the target seed point, find the pixel in the target image region whose distance from the target seed point changes abruptly, and determine the previous pixel of the pixel as the endpoint of the solid edge where the target seed point is located;
[0101] Step S234: Determine a solid edge of the DM code based on the coarse positioning line and the endpoint.
[0102] The number of nearest pixels in the pixel chain corresponding to the target seed point can be set according to requirements, for example, it can be ten. Using the target seed point and the nearest pixels, a coarse positioning line can be obtained by employing the Random Sample Consensus (RANSAC) algorithm and a line fitting method. The coarse positioning line is the line containing the solid edge.
[0103] After determining the line containing the solid edge, the endpoints of the solid edge need to be determined to pinpoint its location. This can be done by calculating the distances from pixels in the target image region to the target seed point, sequentially from nearest to farthest along the pixel chain corresponding to the seed point. If the distance between a pixel and the seed point changes abruptly, it proves that the pixel does not belong to the solid edge. Therefore, the pixel preceding the seed point can be taken as the endpoint of the solid edge.
[0104] Thus, since the individual pixels on the pixel chain may not be on a straight line, the coarse positioning line is fitted based on the target seed point and the multiple pixels on the pixel chain corresponding to the target seed point that are closest to the target seed point. Therefore, a solid edge of the DM code can be determined based on the coarse positioning line and the endpoints.
[0105] Optionally, based on the above technical solution, considering that the fitting of the coarse positioning line only uses a portion of the pixels in the pixel chain, the accuracy still needs to be improved. If all the pixels in the pixel chain are used, the accuracy will also need to be improved because some pixels may not actually be located on the solid edge.
[0106] Therefore, a coarse positioning line can be used to filter pixels in the pixel chain. Then, line fitting is performed using these filtered pixels to obtain a more accurate fine positioning line. Specifically, the distance from each pixel in the pixel chain corresponding to the target seed point to the coarse positioning line can be calculated. Pixels with distances greater than a set distance are excluded, resulting in the remaining pixels in the pixel chain after filtering. Line fitting is then performed using these remaining pixels to obtain the fine positioning line.
[0107] Thus, the solid edges of the DM code can be determined based on the precise positioning line and endpoints, improving the accuracy of the determined solid edges of the DM code.
[0108] Theoretically, a straight line has no width, but it's understandable that in a real image, a straight line occupies a certain area. In related technologies, the existence of a straight line is represented by multiple pixels located in the same direction. In this embodiment, the existence of the fitted coarse / fine positioning straight line is not represented by multiple pixels; for each pixel, the area occupied by the coarse / fine positioning straight line is not a complete pixel. For example, for a single pixel, the coarse / fine positioning straight line only occupies half the area of that pixel. Therefore, the accuracy of the solid edge of the DM code determined by the technical solution of this embodiment reaches the sub-pixel level.
[0109] The technical solution adopted in this disclosure ensures the accuracy of the determined solid edges of the DM code. Therefore, the accuracy of the image region where the DM code is located, determined based on the solid edges, is also high. Furthermore, because the process of determining the solid edges of the DM code involves relatively simple calculations of pixels in the target image region and does not involve complex processing, it has the advantage of high efficiency.
[0110] Figure 4 This is a flowchart illustrating the decoding method of the DM code in this embodiment. For the original image, the target image region can be extracted first. If the target image region is not extracted, a decoding failure message is returned. If the target image region is extracted, the gradient of each pixel in the target image region is calculated. Based on the gradient of each pixel in the target image region, the target seed point can be determined, and the pixel chain can be located based on the target seed point. Based on the target seed point and the pixels on the pixel chain, a coarse positioning line and a fine positioning line can be fitted. By calculating the distance from the pixel to the target seed point, the endpoints of the solid edges can be determined, thereby determining the solid edges of the DM code. Based on the solid edges of the DM code, the virtual edges of the DM code can be determined, and the DM code can be decoded to obtain the decoding result. A decoding success message is returned.
[0111] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this disclosure are not limited to the described order of actions, because according to the embodiments of this disclosure, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of this disclosure.
[0112] Figure 5 This is a schematic diagram of the structure of a DM code decoding device according to an embodiment of this disclosure, as shown below. Figure 5 As shown, the decoding device for the DM code includes a solid edge determination module, a region determination module, and a decoding module, wherein:
[0113] The solid edge determination module is used to determine the two solid edges of the DM code based on the gradient of each pixel in the original image.
[0114] The region determination module is used to determine the image region where the DM code is located based on the two solid edges of the DM code;
[0115] The decoding module is used to decode the image region where the DM code is located to obtain the decoding result of the DM code.
[0116] Optionally, it also includes:
[0117] The detection module is used to detect the target image region in the original image, wherein the target image region is the image region containing the DM code;
[0118] The calculation module is used to calculate the gradient value and gradient direction of each pixel in the target image region;
[0119] Each solid edge of the DM code is determined according to the following steps:
[0120] Based on the gradient value and gradient direction of each pixel in the target image region, a target seed point is determined on each solid edge, wherein the gradient value of the target seed point is greater than the gradient values of the two pixels before and after the target seed point in the gradient direction;
[0121] For each target seed point located on a solid edge, multiple pixels are searched along the tangential direction of the gradient direction of the target seed point to obtain a pixel chain composed of the multiple pixels. The gradient values of the multiple pixels are greater than the gradient threshold and belong to the regional extrema.
[0122] A solid edge of the DM code is determined based on a target seed point and the pixel chain corresponding to the target seed point.
[0123] Optionally, multiple pixels are searched along the tangential direction of the gradient direction of the target seed point to obtain a pixel chain composed of the multiple pixels, including:
[0124] Multiple pixels are searched along the tangential direction of the gradient of the target seed point, and the gradient direction of each pixel is obtained.
[0125] If the gradient direction of a found pixel differs from the gradient direction of the target seed point by more than or equal to 90 degrees, the search is stopped, and a pixel chain composed of the multiple pixels is obtained.
[0126] Optionally, determining a solid edge of the DM code based on a target seed point and the pixel chain corresponding to the target seed point includes:
[0127] Obtain the multiple pixels closest to the target seed point in the pixel chain corresponding to the target seed point;
[0128] A coarse positioning line is obtained by fitting a straight line between the target seed point and the nearest multiple pixels.
[0129] Along the pixel chain corresponding to the target seed point, find the pixel in the target image region whose distance from the target seed point changes abruptly, and determine the previous pixel of the pixel as the endpoint of the solid edge where the target seed point is located;
[0130] Based on the coarse positioning line and the endpoint, a solid edge of the DM code is determined.
[0131] Optionally, it also includes:
[0132] Based on the distance from each pixel in the pixel chain corresponding to the target seed point to the coarse positioning line, each pixel in the pixel chain corresponding to the target seed point is filtered.
[0133] Linear fitting is performed on the remaining pixels after filtering to obtain the fine positioning line;
[0134] Based on the coarse positioning line and the endpoints, a solid edge of the DM code is determined, including:
[0135] Based on the precise positioning line and the endpoint, a solid edge of the DM code is determined.
[0136] Optionally, the computing module includes:
[0137] The calculation unit is used to calculate the horizontal and vertical gradient values of each pixel in the target image region;
[0138] The summation unit is used to sum the horizontal gradient value and the vertical gradient value of each pixel in the target image region as the gradient value of that pixel.
[0139] The orientation determination unit is used to estimate the gradient direction of each pixel based on the horizontal and vertical gradient values of each pixel in the target image region.
[0140] Optionally, based on the gradient value and gradient direction of each pixel in the target image region, the target seed point located on each solid edge is determined, including:
[0141] Determine multiple seed points whose horizontal gradient values are greater than the horizontal gradient values of the two preceding and following pixels in the horizontal direction, and determine multiple seed points whose vertical gradient values are greater than the vertical gradient values of the two preceding and following pixels in the vertical direction.
[0142] Edge detection is performed on the target image region to obtain the edges;
[0143] Among all seed points, the seed point located at the edge is determined as the target seed point.
[0144] Optionally, the region determination module includes:
[0145] The virtual edge determination unit is used to obtain the two virtual edges of the DM code according to the parallelogram law and the two real edges of the DM code.
[0146] The region determination unit is used to determine the image region enclosed by the two solid edges and two dashed edges of the DM code in the original image as the image region where the DM code is located.
[0147] Optionally, the decoding module includes:
[0148] The pattern determination unit is used to determine the pattern of the DM code based on the number of black and white changes of the two virtual edges that enclose the image region where the DM code is located.
[0149] The processing unit is used to perform binarization processing on the image region where the DM code is located to obtain the processed image region;
[0150] The decoding unit is used to decode the processed image region according to the pattern of the DM code to obtain the decoding result of the DM code.
[0151] It should be noted that the device embodiments are similar to the method embodiments, so the description is relatively simple. For relevant details, please refer to the method embodiments.
[0152] This disclosure also provides an electronic device, with reference to... Figure 6 , Figure 6This is a schematic diagram of an electronic device proposed in an embodiment of this disclosure. (As shown...) Figure 6 As shown, the electronic device 100 includes a memory 110 and a processor 120. The memory 110 and the processor 120 are connected via a bus for communication. The memory 110 stores a computer program that can run on the processor 120 to implement the steps in the DM code decoding method disclosed in this embodiment.
[0153] This disclosure also provides a computer-readable storage medium storing a computer program / instructions thereon, which, when executed by a processor, implements the DM code decoding method disclosed in this disclosure.
[0154] This disclosure also provides a computer program product, including a computer program / instruction that, when executed by a processor, implements the DM code decoding method disclosed in this disclosure.
[0155] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0156] Those skilled in the art will understand that embodiments of this disclosure can be provided as methods, apparatus, or computer program products. Therefore, embodiments of this disclosure can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of this disclosure can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0157] This disclosure describes embodiments of methods, apparatus, electronic devices, and computer program products according to embodiments of this disclosure with reference to flowchart illustrations and / or block diagrams. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0158] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0159] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0160] While preferred embodiments of the present disclosure have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the present disclosure.
[0161] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0162] The foregoing has provided a detailed description of a DM code decoding method, electronic device, storage medium, and program product provided by this disclosure. Specific examples have been used to illustrate the principles and implementation methods of this disclosure. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this disclosure. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this disclosure. Therefore, the content of this specification should not be construed as a limitation of this disclosure.
Claims
1. A method for decoding DM codes, characterized in that, include: Based on the gradient of each pixel in the original image, determine the two solid edges of the DM code; The image region where the DM code is located is determined based on the two solid edges of the DM code; The image region containing the DM code is decoded to obtain the decoding result of the DM code; Each solid edge of the DM code is determined according to the following steps: Based on the gradient value and gradient direction of each pixel in the target image region, a target seed point is determined on each solid edge. The target image region is the image region containing the DM code obtained by detecting the original image. The gradient value of the target seed point is greater than the gradient values of the two pixels before and after the target seed point in the gradient direction. For each target seed point located on a solid edge, multiple pixels are searched along the tangential direction of the gradient direction of the target seed point to obtain a pixel chain composed of the multiple pixels. The gradient values of the multiple pixels are greater than the gradient threshold and belong to the regional extrema. A solid edge of the DM code is determined based on a target seed point and the pixel chain corresponding to the target seed point.
2. The method according to claim 1, characterized in that, Searching for multiple pixels along the tangential direction of the gradient direction of the target seed point to obtain a pixel chain composed of the multiple pixels, including: Multiple pixels are searched along the tangential direction of the gradient of the target seed point, and the gradient direction of each pixel is obtained. If the gradient direction of a found pixel differs from the gradient direction of the target seed point by more than or equal to 90 degrees, the search is stopped, and a pixel chain composed of the multiple pixels is obtained.
3. The method according to claim 1 or 2, characterized in that, Based on a target seed point and the pixel chain corresponding to that target seed point, a solid edge of the DM code is determined, including: Obtain the multiple pixels closest to the target seed point in the pixel chain corresponding to the target seed point; A coarse positioning line is obtained by fitting a straight line between the target seed point and the nearest multiple pixels. Along the pixel chain corresponding to the target seed point, find the pixel in the target image region whose distance from the target seed point changes abruptly, and determine the previous pixel of the pixel as the endpoint of the solid edge where the target seed point is located; Based on the coarse positioning line and the endpoint, a solid edge of the DM code is determined.
4. The method according to claim 3, characterized in that, Also includes: Based on the distance from each pixel in the pixel chain corresponding to the target seed point to the coarse positioning line, each pixel in the pixel chain corresponding to the target seed point is filtered. Linear fitting is performed on the remaining pixels after filtering to obtain the fine positioning line; Based on the coarse positioning line and the endpoints, a solid edge of the DM code is determined, including: Based on the precise positioning line and the endpoint, a solid edge of the DM code is determined.
5. The method according to any one of claims 1-4, characterized in that, Calculating the gradient value and gradient direction of each pixel in the target image region includes: Calculate the horizontal and vertical gradient values for each pixel in the target image region; The sum of the horizontal gradient value and the vertical gradient value of each pixel in the target image region is taken as the gradient value of that pixel. The gradient direction of a pixel is obtained by estimating its horizontal and vertical gradient values for each pixel in the target image region.
6. The method according to claim 5, characterized in that, Based on the gradient value and gradient direction of each pixel in the target image region, the target seed point located on each solid edge is determined, including: Determine multiple seed points whose horizontal gradient values are greater than the horizontal gradient values of the two preceding and following pixels in the horizontal direction, and determine multiple seed points whose vertical gradient values are greater than the vertical gradient values of the two preceding and following pixels in the vertical direction. Edge detection is performed on the target image region to obtain the edges; Among all seed points, the seed point located at the edge is determined as the target seed point.
7. The method according to any one of claims 1-6, characterized in that, The image region containing the DM code is determined based on its two solid edges, including: Based on the parallelogram law and the two solid sides of the DM code, the two virtual sides of the DM code are obtained. The image region enclosed by the two solid edges and two dashed edges of the DM code in the original image is determined as the image region where the DM code is located.
8. The method according to any one of claims 1-7, characterized in that, Decoding the image region containing the DM code to obtain the decoding result of the DM code includes: The pattern of the DM code is determined based on the number of black and white changes of the two virtual edges that enclose the image region containing the DM code. The image region containing the DM code is binarized to obtain the processed image region; According to the pattern of the DM code, the processed image region is decoded to obtain the decoding result of the DM code.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the DM code decoding method according to any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that, When the computer program / instruction is executed by the processor, it implements the decoding method of the DM code as described in any one of claims 1 to 8.
11. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the decoding method of the DM code as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Sub-pixel precision of DataMatrix two-dimensional code location method
CN109086644A
DM code positioning method and device, terminal and storage medium
CN110414649A
Barcode recognition device and method based on artificial intelligence semantic segmentation
CN110532826A