A barcode positioning method based on EDLines straight line detection
By combining EDLines line detection with HDBSCAN and RANSAC algorithms, the accuracy and real-time performance issues of existing barcode positioning methods in complex backgrounds and low-quality images are solved, achieving efficient and stable barcode positioning suitable for various application scenarios.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- FUJIAN NETPOWER TECH DEV CO LTD
- Filing Date
- 2026-01-20
- Publication Date
- 2026-06-16
AI Technical Summary
Existing barcode positioning methods struggle to balance accuracy, robustness, and real-time performance in real-world applications with complex backgrounds, multi-scale conditions, and low-quality images. In particular, positioning accuracy drops significantly and computational overhead is high in complex backgrounds, making it difficult to meet the real-time requirements of industrial sites.
By employing EDLines line detection combined with HDBSCAN clustering and RANSAC algorithms, precise positioning of barcode regions is achieved through edge detection, line segment fitting, clustering, and orientation consistency screening.
It improves the accuracy and stability of barcode positioning, is applicable to various complex backgrounds and low-quality images, reduces dependence on ambient lighting, and enhances the adaptability and real-time performance of the algorithm.
Smart Images

Figure CN122223375A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of barcode positioning technology, and specifically relates to a barcode positioning method based on EDLines line detection. Background Technology
[0002] Currently, barcode positioning methods are mainly divided into methods based on classical geometric features and methods based on deep learning.
[0003] In classical methods, frequency domain methods (such as wavelet transform, discrete cosine transform combined with high-pass filtering) utilize the high-frequency texture features of barcodes for localization. However, they are easily interfered with in complex backgrounds (such as barcode-like structures containing text, stripes, etc.), resulting in a significant decrease in localization accuracy. Spatial domain methods are more diverse: one is based on mathematical morphology operations (such as bottom-hat filtering, dilation and erosion), which can enhance the connectivity of barcode regions, but are sensitive to scale, have weak generalization ability, and are easily affected by background interference. They require frequent adjustment of dilation / erosion parameters to adapt to barcodes of different scales, making it difficult to maintain stable performance in multiple scales and scenarios; and they are prone to generating a large number of false detections in textured backgrounds. For example, Chinese patent CN105335744B discloses a one-dimensional barcode region localization method based on the strip distribution features extracted from image backbone. This invention uses traditional image processing techniques such as grayscale conversion, filtering, and multi-level backbone extraction for localization, but its generalization ability is limited when facing complex scenes. Second, image segmentation combined with features such as gradients, corners, MSER (maximum stable extremum region), or template matching to select candidate regions is difficult to adapt to varying barcode scales and complex scenarios: fixed segment sizes make it difficult to meet the detection needs of barcodes of different sizes; the local features relied upon (such as gradients, corners, MSER, etc.) are unreliable in complex or low-contrast images, leading to missed detections or misjudgments. Third, edge and line detection-based methods, such as Hough transform or LSD (Line Segment Detector), detect parallel line segments to locate barcodes, but their computational overhead is high: although LSD and Hough transform can utilize the parallel line characteristics of barcodes, their algorithm complexity is high, especially in high-resolution images where their operating efficiency is low, making it difficult to meet real-time requirements.
[0004] In recent years, deep learning methods (such as YOLO-based object detection, CNN multi-scale feature fusion, semantic segmentation, etc.) have made some progress in barcode localization tasks. However, they rely on a large amount of labeled data, have poor model interpretability, and face challenges such as computing power, generalization and real-time performance when deployed in industrial fields. Their generalization ability is limited in real-world industrial scenarios such as lighting changes, occlusion, and low-quality images. They also have high hardware resource requirements, which is not conducive to deployment on embedded or edge devices and makes it difficult to meet the needs of practical applications.
[0005] In summary, existing technologies struggle to balance accuracy, robustness, real-time performance, and practicality. In particular, in real-world application scenarios involving complex backgrounds, multiple scales, and low-quality images, there is still a lack of an efficient, stable barcode localization method that does not require a large amount of training data. Summary of the Invention
[0006] To address the problems existing in the prior art, this invention proposes a barcode positioning method based on EDLines line detection.
[0007] The technical solution of the present invention is as follows: On the one hand, the present invention provides a barcode positioning method based on EDLines line detection, comprising the following steps: Edge detection is performed on the input image to generate an edge image. The edge image is traversed to generate and merge line segment fragments. The merged line segment fragments are fitted with straight line segments. The fitted straight line segments are filtered by a set minimum line segment length threshold, and a set of straight line segments is output. Cluster the set of line segments using the HDBSCAN clustering algorithm and output a set of point clusters that satisfy a given threshold. Perform a preliminary screening of the number of cluster points in the point cluster set, calculate the directional consistency coefficient of the remaining point clusters after the preliminary screening, perform a second screening, and output the point cluster set that meets the given directional consistency threshold. The selected point cluster set is filtered based on line fitting to obtain the barcode point cluster set. The barcode point cluster set is then precisely located to obtain the barcode location result.
[0008] Preferably, the step of traversing the edge image to generate and merge line segment fragments, and then fitting the merged line segment fragments with straight line segments, specifically involves: Traverse the edge image and divide the edge pixels into line segments based on the continuity of the pixels; For each edge pixel, if it does not belong to any existing line segment, create a new line segment; otherwise, add it to the corresponding line segment. The process involves merging adjacent line segments by calculating the similarity score between them. After merging the line segment fragments, the RANSAC algorithm is used to fit the line segments.
[0009] Preferably, the step of clustering the set of line segments based on the HDBSCAN clustering algorithm and outputting a set of point clusters that satisfy a given threshold specifically involves: For each line segment in the set of line segments, the midpoint is calculated, and the calculated midpoints are clustered using the HDBSCAN clustering algorithm to obtain high-density barcode-related point clusters; Cluster the high-density barcode-related point clusters and output the set of point clusters that meet a given threshold.
[0010] Preferably, the formula for calculating the directional consistency coefficient is:
[0011] In the formula, For point clusters The directional consistency coefficient; For point clusters The index corresponding to the inner square vector; It is a square vector; The formula for calculating the squared vector is:
[0012] In the formula, The coordinates of the line segment within the point cluster are given.
[0013] Preferably, the step of performing line-fit-based filtering on the selected dot cluster set to obtain the barcode dot cluster set specifically involves: The RANSAC algorithm is used to fit the selected point cluster set to a straight line. The intersection points of the fitted line with the line segments in each point cluster are calculated. The line segments with intersection points in each point cluster are saved and their directional consistency coefficient is calculated. Each point cluster belonging to the point cluster set is then subjected to a double screening of the number of intersection points threshold and the directional consistency coefficient threshold to obtain the barcode point cluster set.
[0014] Preferably, the barcode positioning result obtained by performing precise positioning on the barcode dot cluster set is as follows: Calculate the average line segment length of all line segments in the barcode dot cluster set that intersect with the fitted line, and filter out the error line segments based on the preset length threshold range of the average line segment length to obtain the effective line segments; From the intersections of the valid line segments and the fitted straight line, select the two intersections with the greatest Euclidean distance as the two endpoints of the barcode area; The distance between the two endpoints is taken as the length of the barcode area, the average line segment length is taken as the width of the barcode area, the midpoint of the two endpoints is taken as the center point of the barcode area, and the direction of the fitted line is taken as the orientation of the barcode. Based on the calculated length, width, center point, and orientation, the precise bounding box of the barcode is determined, and the barcode positioning result is output, including position coordinates, size, and rotation angle.
[0015] On the other hand, the present invention provides a barcode positioning system based on EDLines line detection, including a line detection module, a dot cluster set clustering module, a dot cluster set filtering module, and a barcode positioning module; The line detection module is used to perform edge detection on the input image to generate an edge image, traverse the edge image to generate and merge line segment fragments, fit the merged line segment fragments into line segments, filter the fitted line segments by a set minimum line segment length threshold, and output a set of line segments. The point cluster set clustering module is used to cluster the set of line segments based on the HDBSCAN clustering algorithm and output the point cluster set that meets a given threshold. The point cluster set filtering module is used to perform preliminary filtering of the number of cluster points in the point cluster set, calculate the directional consistency coefficient of the remaining point clusters after the preliminary filtering, perform secondary filtering, and output the point cluster set that meets the given directional consistency threshold. The barcode positioning module is used to filter the selected point cluster set based on line fitting to obtain the barcode point cluster set, and to perform fine positioning on the barcode point cluster set to obtain the barcode positioning result.
[0016] In another aspect, the present invention also provides an electronic device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method as described in any embodiment of the present invention.
[0017] In another aspect, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any embodiment of the present invention.
[0018] Compared with the prior art, the present invention has the following technical effects: 1. This invention proposes an improved EDLines algorithm: by replacing the gradient operator (such as the Scharr operator) in the original algorithm and optimizing the parameter settings under non-uniform illumination conditions, the robustness in complex backgrounds is improved.
[0019] 2. This invention introduces the HDBSCAN algorithm to determine barcode-related point clusters, which can effectively distinguish barcode areas from other background information even in the presence of a large amount of interference.
[0020] 3. By calculating the directional consistency coefficient of line segment vectors, this invention can accurately filter out the set of line segments containing barcodes, thus eliminating most irrelevant background line segments.
[0021] 4. This invention employs a line-fitting-based screening strategy, which not only further distinguishes barcode areas from background interference but also achieves precise barcode positioning. This strategy fully utilizes the geometric characteristic that barcodes are composed of a set of parallel line segments, and through the robustness of the RANSAC (Random Sample Consensus) algorithm and dual screening conditions, effectively improves the accuracy and stability of barcode positioning.
[0022] 5. This invention achieves fast and accurate barcode positioning through a series of efficient image processing and feature selection steps, including line detection, clustering screening, screening based on line segment direction consistency, and screening based on line fitting. It is applicable to various application scenarios, improves the accuracy of barcode positioning in complex backgrounds and low-quality images, reduces dependence on ambient light, and enhances the adaptability of the algorithm. Attached Figure Description
[0023] Figure 1 This is an overall flowchart of the barcode positioning method based on EDLines line detection described in this invention. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with specific embodiments of the present application and with reference to the accompanying drawings.
[0025] Example 1 This embodiment provides a barcode positioning method based on EDLines line detection. (See attached document.) Figure 1 As shown, it includes the following steps: Edge detection is performed on the input image to generate an edge image. The edge image is traversed to generate and merge line segment fragments. The merged line segment fragments are fitted with straight line segments. The fitted straight line segments are filtered by a set minimum line segment length threshold, and a set of straight line segments is output.
[0026] In a preferred embodiment of this invention, the edge detection step processes the input image using the Edge Drawing algorithm or other edge detection algorithms. This step generates an initial edge image, providing a foundation for subsequent line segment detection. Under non-uniform lighting conditions, improved gradient operators (such as the Scharr operator) can be used to improve detection performance.
[0027] In a preferred embodiment of this invention, the step of traversing the edge image to generate and merge line segment fragments, and then fitting the merged line segment fragments with straight line segments, specifically involves: The detected edge pixels are converted into a specific data structure, organizing the edge points into segments. The edge image is traversed, and edge pixels are grouped into segments based on pixel continuity.
[0028] For each edge pixel, if it does not belong to any existing line segment, create a new line segment; otherwise, add it to the corresponding line segment.
[0029] Adjacent line segments are merged by calculating a similarity score. This similarity score is calculated based on features such as gradient direction, length, and distance of the line segments. This step connects broken edges into longer, more complete line segments.
[0030] After merging line segment fragments, the RANSAC algorithm is used to fit the line segments. RANSAC finds the optimal line model parameters through random sampling and least squares fitting. This algorithm effectively eliminates the interference of outliers and improves the robustness of line detection. It is suitable for image processing with noisy and complex backgrounds.
[0031] Furthermore, this embodiment sets a minimum line segment length threshold (the threshold can be set according to the actual application scenario; in this embodiment, it is preferably set to 20 pixels) to filter out all line segments shorter than this threshold. This parameter setting is optimized for barcode features because barcodes typically contain relatively long parallel lines. By reasonably setting this parameter, noise and irrelevant edges can be effectively eliminated, while retaining the relevant line segments of the barcode.
[0032] The final output is a set of line segments obtained after the above processing. These line segments can be used for subsequent barcode positioning and recognition steps. Under non-uniform lighting conditions, a more complete image of line segments can be obtained through downsampling and parameter optimization.
[0033] Cluster the set of line segments using the HDBSCAN clustering algorithm, and output a set of point clusters that meet a given threshold.
[0034] In a preferred embodiment of this practice, the step of clustering the set of line segments using the HDBSCAN clustering algorithm to output a set of point clusters that satisfy a given threshold specifically involves: For all line segments detected by the EDLines algorithm, calculate the midpoint of each segment. Use the coordinates of these midpoints as input for subsequent cluster analysis.
[0035] The extracted midpoints are clustered using the Hierarchical Density-Based Spatial Clustering (HDBSCAN) algorithm. In this step, a minimum cluster number is set based on the specific application scenario; for example, setting it to 5 means that a new cluster is formed only when there are at least 5 points within a given region. The HDBSCAN algorithm measures and classifies points based on Euclidean distance, effectively identifying meaningful clusters in environments with varying densities.
[0036] Based on the results of the HDBSCAN algorithm, high-density barcode-related point clusters are identified. In barcode images, because the line segments in the barcode region are usually denser and parallel to each other, their corresponding point clusters tend to have higher density. Through this process, potential regions containing barcodes can be preliminarily screened out, while most non-barcode-related background line segments are excluded.
[0037] Clustering and filtering of high-density barcode-related point clusters yields a set of point clusters that meet a given threshold (e.g., minimum cluster size). These point clusters represent potential barcode regions, providing foundational data for further barcode localization and identification.
[0038] The density-based clustering screening process described above can effectively separate regions that may contain barcodes from complex backgrounds, improving the accuracy and efficiency of subsequent barcode positioning. This step is particularly suitable for handling noisy and complex backgrounds because it can utilize the distribution characteristics of midpoints in line segments for effective clustering analysis.
[0039] The system performs an initial screening of the cluster set based on the number of clustered points. Then, it calculates the directional consistency coefficient of the remaining clusters after the initial screening for a second screening, outputting a set of clusters that meet a given directional consistency threshold. This line segment directional consistency-based screening strategy effectively identifies and filters out areas containing barcodes, thereby improving the accuracy and efficiency of barcode positioning.
[0040] Specifically, all clusters are first preliminarily screened, removing those clusters with a number of points within a set threshold range (the threshold range can be determined according to the actual application scenario and is not limited; in this embodiment, it is preferred to be less than 20 but greater than 5). For example, for different types of barcodes, the number of line segments should be more than 20, and clusters with a number of points between 5 and 20 are screened out because these clusters are likely not part of the barcode area.
[0041] For the remaining point clusters after the initial screening, calculate the directional consistency coefficient Coh(C) of the line segments within each point cluster. Treat each line segment as a vector and convert these vectors to polar coordinates to facilitate the calculation of directional consistency.
[0042] In a preferred embodiment of this invention, for the line segment vector A=T, the vector is transformed from Cartesian coordinates to polar coordinates:
[0043] In the formula, These are polar coordinates.
[0044] The polar coordinate transformation to Cartesian coordinate transformation is as follows:
[0045] In the formula, Use Cartesian coordinates.
[0046] Because the angle of a vector doubles after squaring, and its magnitude becomes the square of its original magnitude, the formula for calculating a squared vector is:
[0047] The formula for calculating the directional consistency coefficient is as follows:
[0048] In the formula, For point clusters The directional consistency coefficient; For point clusters The index corresponding to the inner square vector; It is a square vector; For point clusters The number of points within.
[0049] The formula for calculating the squared vector is:
[0050] In the formula, The coordinates of the line segment within the point cluster are given.
[0051] A set directional consistency threshold (which can be determined according to the actual application scenario and is not limited here, such as being set to 0.7) is used to further filter point clusters. If the directional consistency coefficient of a point cluster exceeds the set threshold (e.g., 0.7), it is considered that the point cluster may contain line segments within the barcode area; otherwise, it is considered background noise and excluded. When the line segment vectors represented by the same cluster all belong to the same direction, the sum of the magnitudes of the line segment vectors is equal to the magnitude of the sum of the line segment vectors, and the value of the directional consistency coefficient is at most 1; if the line segment vectors are uniformly distributed in all directions, the length of the vector sum is equal to 0, and the value of the directional consistency calculation is 0.
[0052] The final output is a set of point clusters that meet the orientation consistency filtering criteria. These point clusters serve as the basis for the next step of barcode positioning. For example, in the application experiment of this embodiment, there were 14 clusters before orientation consistency filtering, and only 5 clusters remained after filtering, including 1 target barcode cluster and 4 background clusters.
[0053] The selected point cluster set is filtered based on line fitting to obtain the barcode point cluster set. The barcode point cluster set is then precisely located to obtain the barcode location result.
[0054] In a preferred embodiment of this invention, the step of performing line-fit-based filtering on the selected dot cluster set to obtain the barcode dot cluster set specifically involves: The RANSAC algorithm is used to fit a straight line to the filtered cluster set. The RANSAC algorithm effectively avoids the influence of outliers on the line fitting. The fitted line is formed along the densest part of the cluster, accurately reflecting the distribution trend of the barcode area.
[0055] For each line segment belonging to the point cluster, calculate its intersection point with the fitted line. Count the number of line segments with valid intersection points and record the coordinates of all intersection points.
[0056] Save all line segments that intersect with the fitted line, and calculate the directional consistency coefficient of these line segments.
[0057] Each point cluster belonging to the point cluster set undergoes a dual screening process using both an intersection number threshold and a direction consistency coefficient threshold. Point clusters that pass both screening criteria (intersection number and direction consistency) are identified as barcode point clusters, resulting in a barcode point cluster set. These point clusters then proceed to the precise positioning stage. Specifically, the intersection number and direction consistency thresholds are set according to the actual application scenario, as preferred in this embodiment: Check if the number of line segments intersecting the fitted line exceeds half the number of line segments in the cluster. If the number of intersections is insufficient, the cluster is considered not a barcode area and is excluded. If the number of intersections is sufficient, proceed to the next screening step.
[0058] Check if the directional consistency coefficient of the set of line segments with intersections exceeds 0.95. This threshold is higher than the 0.7 of the previous screening step because the remaining line segments should have higher consistency after the intersection screening. If the condition is not met, the point cluster is excluded; if it is met, it is identified as a barcode point cluster.
[0059] As a preferred embodiment of this practice, the barcode positioning result is obtained by precisely locating the barcode dot cluster set as follows: Calculate the average length of all line segments in the barcode dot cluster set that intersect with the fitted line. This average length will be used as a measure of the width of the barcode area and as a benchmark for subsequent filtering of error segments.
[0060] Based on a preset length threshold range for the average line segment length, error-prone straight segments are filtered out (the length threshold range is set according to the actual application scenario, such as filtering out excessively long line segments with a length exceeding 1 / 3 of the average length, and filtering out excessively short line segments with a length less than 1 / 2 of the average length). These abnormal line segments are usually generated by noise or background interference, thus obtaining valid line segments.
[0061] From the intersections of the valid line segments and the fitted straight lines, the two intersections with the greatest Euclidean distance are selected as the two endpoints of the barcode area. These two endpoints define the length direction of the barcode area.
[0062] The distance between the two endpoints is taken as the length of the barcode area, the average line segment length is taken as the width of the barcode area, the midpoint between the two endpoints is taken as the center point of the barcode area, and the direction of the fitted line is taken as the orientation of the barcode.
[0063] Based on the calculated length, width, center point, and orientation, the precise bounding box of the barcode is determined, and the barcode positioning result is output, including position coordinates, size, and rotation angle.
[0064] To verify the effectiveness and superiority of the method provided in this embodiment, some specific examples are provided below: The experimental environment was configured as follows: a computer with Ubuntu 22.04 installed, configured with an Intel Core i6-6400 CPU and 8GB of RAM.
[0065] The experiment used three barcode image datasets. The first dataset was the Arte-Lab barcode dataset, which included 365 EAN barcode images of 640×480 pixels taken by different mobile phones. The second dataset was the WWUMuenster barcode dataset, which included 1055 barcode images of different sizes taken by N95 mobile phones. The third dataset consisted of a self-made barcode dataset with complex backgrounds and non-uniform lighting conditions, as well as barcode images from actual barcode recognition scenarios. It included 117 barcode images of 1080×1920 and 3472×4620 pixels taken by smartphone cameras, and 153 barcode images affected by complex backgrounds and non-uniform lighting, as well as barcode images from actual barcode recognition scenarios.
[0066] To accurately test the effectiveness of the barcode positioning algorithm proposed in this embodiment, a unified barcode positioning accuracy measurement method is introduced and compared with positioning algorithms. That is, the Jaccard(A,B) coefficient is used to evaluate the accuracy of the barcode positioning algorithm. Jaccard(A,B) is defined as follows:
[0067] Where A is the true boundary region of the barcode in the image, and B is the localization region of the localization algorithm. When J > 0.5, the localization result is considered accurate, and D(J > 0.5) represents the algorithm detection rate when the threshold is 0.5. J and D represent the average values calculated by the localization algorithm on a certain dataset.
[0068] This embodiment and previous localization algorithms were tested on three barcode datasets. Algorithm 1 is the barcode localization scheme proposed in the paper titled "Barcode Localization Method Based on Edge Expansion in Complex Environments" by Aida, Ma Yuhao, et al. Algorithm 2 is the real-time barcode detection method proposed in the conference paper titled "Real-time barcode detection in the wild" by C. Creusot and A. Munawar. Algorithm 3 is the barcode detection method proposed in the conference paper titled "Robust Angle Invariant 1D Barcode Detection" by Zamberletti A, Gallo I, and Albertini S.
[0069] The experimental results are shown in Table 1, where D represents the detection rate of the localization algorithm when J>0.5. As can be seen from the data in the table, the barcode localization algorithm proposed in this embodiment achieves a localization accuracy of 86.8% on the ArTe-Lab dataset when the Jaccard coefficient threshold is greater than 0.5, slightly lower than the 89.3% of Algorithm 2. On the WWU Muenster dataset, it achieves an accuracy of 97.7%, and the advantage over existing algorithms is not significant. However, the barcode localization accuracy on the barcode dataset under complex background and non-uniform lighting conditions presented in this embodiment reaches 88.9%. That is, the experimental results of the method described in this embodiment on public datasets are not significantly different from existing algorithms, but the experimental results on barcode image datasets under non-uniform lighting conditions are superior to existing algorithms. Compared to Algorithm 1, the localization accuracy of the method described in this embodiment is improved by 4.8%, and compared to Algorithm 2, the localization accuracy of the method described in this embodiment is improved by 17.2%.
[0070] Table 1. Test results of different localization algorithms on the dataset.
[0071] Example 2 Accordingly, this embodiment provides a barcode positioning system based on EDLines line detection, used to implement the method described in any embodiment of the present invention, including a line detection module, a point cluster set clustering module, a point cluster set filtering module, and a barcode positioning module.
[0072] The line detection module is used to perform edge detection on the input image to generate an edge image, traverse the edge image to generate and merge line segment fragments, fit the merged line segment fragments into line segments, filter the fitted line segments by a set minimum line segment length threshold, and output a set of line segments.
[0073] The point clustering module is used to cluster the set of line segments based on the HDBSCAN clustering algorithm, and output a set of point clusters that meet a given threshold.
[0074] The point cluster set filtering module is used to perform preliminary filtering of the number of cluster points in the point cluster set, calculate the directional consistency coefficient of the remaining point clusters after the preliminary filtering, perform secondary filtering, and output the point cluster set that meets the given directional consistency threshold.
[0075] The barcode positioning module is used to filter the selected point cluster set based on line fitting to obtain the barcode point cluster set, and to perform fine positioning on the barcode point cluster set to obtain the barcode positioning result.
[0076] Example 3 This embodiment provides an electronic device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the method described in any embodiment of the present invention.
[0077] Example 4 This embodiment provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any embodiment of the present invention.
[0078] In this application embodiment, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent the existence of A alone, A and B simultaneously, or B alone. A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of singular or plural items. For example, at least one of a, b, and c can represent: a, b, c, a and b, a and c, b and c, or a and b and c, where a, b, and c can be single or multiple.
[0079] Those skilled in the art will recognize that the units and algorithm steps described in the embodiments disclosed herein can be implemented using electronic hardware, computer software, or a combination of electronic hardware and software. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0080] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0081] In the several embodiments provided in this application, any function, if implemented as a software functional unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0082] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A barcode positioning method based on EDLines line detection, characterized in that, Includes the following steps: Edge detection is performed on the input image to generate an edge image. The edge image is traversed to generate and merge line segment fragments. The merged line segment fragments are fitted with straight line segments. The fitted straight line segments are filtered by a set minimum line segment length threshold, and a set of straight line segments is output. Cluster the set of line segments using the HDBSCAN clustering algorithm and output a set of point clusters that satisfy a given threshold. Perform a preliminary screening of the number of cluster points in the point cluster set, calculate the directional consistency coefficient of the remaining point clusters after the preliminary screening, perform a second screening, and output the point cluster set that meets the given directional consistency threshold. The selected point cluster set is filtered based on line fitting to obtain the barcode point cluster set. The barcode point cluster set is then precisely located to obtain the barcode location result.
2. The barcode positioning method based on EDLines line detection according to claim 1, characterized in that, The process of traversing the edge image to generate and merge line segment fragments, and then fitting the merged line segment fragments with straight line segments, specifically involves: Traverse the edge image and divide the edge pixels into line segments based on the continuity of the pixels; For each edge pixel, if it does not belong to any existing line segment, create a new line segment; otherwise, add it to the corresponding line segment. The process involves merging adjacent line segments by calculating the similarity score between them. After merging the line segment fragments, the RANSAC algorithm is used to fit the line segments.
3. The barcode positioning method based on EDLines line detection according to claim 1, characterized in that, The specific steps of clustering the set of line segments using the HDBSCAN clustering algorithm to output a set of point clusters that satisfy a given threshold are as follows: For each line segment in the set of line segments, the midpoint is calculated, and the calculated midpoints are clustered using the HDBSCAN clustering algorithm to obtain high-density barcode-related point clusters; Cluster the high-density barcode-related point clusters and output the set of point clusters that meet a given threshold.
4. The barcode positioning method based on EDLines line detection according to claim 1, characterized in that, The formula for calculating the directional consistency coefficient is as follows: In the formula, For point clusters The directional consistency coefficient; For point clusters The index corresponding to the inner square vector; It is a square vector; The formula for calculating the squared vector is: In the formula, The coordinates of the line segment within the point cluster are given.
5. The barcode positioning method based on EDLines line detection according to claim 1, characterized in that, The specific steps of filtering the selected dot cluster set based on line fitting to obtain the barcode dot cluster set are as follows: The RANSAC algorithm is used to fit the selected point cluster set to a straight line. The intersection points of the fitted line with the line segments in each point cluster are calculated. The line segments with intersection points in each point cluster are saved and their directional consistency coefficient is calculated. Each point cluster belonging to the point cluster set is then subjected to a double screening of the number of intersection points threshold and the directional consistency coefficient threshold to obtain the barcode point cluster set.
6. The barcode positioning method based on EDLines line detection according to claim 1, characterized in that, The barcode positioning result obtained by precisely locating the barcode dot cluster set is as follows: Calculate the average line segment length of all line segments in the barcode dot cluster set that intersect with the fitted line, and filter out the error line segments based on the preset length threshold range of the average line segment length to obtain the effective line segments; From the intersections of the valid line segments and the fitted straight line, select the two intersections with the greatest Euclidean distance as the two endpoints of the barcode area; The distance between the two endpoints is taken as the length of the barcode area, the average line segment length is taken as the width of the barcode area, the midpoint of the two endpoints is taken as the center point of the barcode area, and the direction of the fitted line is taken as the orientation of the barcode. Based on the calculated length, width, center point, and orientation, the precise bounding box of the barcode is determined, and the barcode positioning result is output, including position coordinates, size, and rotation angle.
7. A barcode positioning system based on EDLines line detection, characterized in that, The system is used to implement the method as described in any one of claims 1 to 6, and includes a line detection module, a point cluster set clustering module, a point cluster set filtering module, and a barcode positioning module; The line detection module is used to perform edge detection on the input image to generate an edge image, traverse the edge image to generate and merge line segment fragments, fit the merged line segment fragments into line segments, filter the fitted line segments by a set minimum line segment length threshold, and output a set of line segments. The point clustering module is used to cluster the set of line segments based on the HDBSCAN clustering algorithm and output a set of point clusters that meet a given threshold. The point cluster set filtering module is used to perform preliminary filtering of the number of cluster points in the point cluster set, calculate the directional consistency coefficient of the remaining point clusters after the preliminary filtering, perform secondary filtering, and output the point cluster set that meets the given directional consistency threshold. The barcode positioning module is used to filter the selected point cluster set based on line fitting to obtain the barcode point cluster set, and to perform fine positioning on the barcode point cluster set to obtain the barcode positioning result.
8. An electronic device, the electronic device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor, when executing the computer program, implements the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 6.