Barcode recognition and positioning method, electronic device and computer-readable storage medium
By extracting the candidate line set and combining candidate boxes that match the locator, determining the initial and target borders of the barcode are solved, and the problem of low barcode recognition accuracy in the prior art is achieved, and higher recognition accuracy is achieved.
Patent Information
- Application Number
- CN202411795260.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-04-08
AI Technical Summary
The prior art is difficult to accurately locate barcodes that are damaged, wrinkled or background-interferenced, resulting in low recognition accuracy.
By obtaining the image to be identified, the candidate line set matching the locator line features are extracted, the locator candidate box of the candidate line set is determined, the candidate box is combined to locate the initial barcode border, and the high-precision barcode target border is determined based on the image characteristics of the border points.
Improve the accuracy of barcode identification and positioning, and reduce identification errors caused by defilement and background interference.
Smart Images

Figure CN119783706A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image recognition technology, and in particular to a barcode recognition and positioning method, an electronic device, and a computer-readable storage medium. Background Art
[0002] With the development of information technology, barcodes that can store information have been widely used in many fields. However, barcodes may have many problems during use, such as barcode contamination, barcode wrinkles, and background interference. Conventional barcode recognition and positioning methods are difficult to accurately locate the position of the barcode, resulting in the inability to effectively obtain the information stored in the barcode. In view of this, how to improve the accuracy of barcode recognition and positioning has become an urgent problem to be solved. Summary of the invention
[0003] The main technical problem solved by the present application is to provide a barcode recognition and positioning method, an electronic device and a computer-readable storage medium, which can improve the accuracy of barcode recognition and positioning.
[0004] In order to solve the above technical problems, the first aspect of the present application provides a barcode recognition and positioning method, including: obtaining an image to be recognized, extracting multiple candidate line sets that match the line features of the locator from the image to be recognized; determining the locator candidate frame that matches each candidate line set based on the image features of each candidate line set; determining a candidate frame combination that matches each other among all the locator candidate frames, and obtaining a barcode initial border corresponding to the barcode based on the position of the locator candidate frame in the candidate frame combination; obtaining border points on the barcode initial border, and determining the barcode target border corresponding to the barcode based on the border points and the image features within a preset range thereof.
[0005] To solve the above technical problems, the second aspect of the present application provides an electronic device, which includes: a memory and a processor coupled to each other, wherein the memory stores program data, and the processor calls the program data to execute the method described in the first aspect.
[0006] In order to solve the above technical problem, the third aspect of the present application provides a computer-readable storage medium on which program data is stored. When the program data is executed by a processor, the method described in the first aspect is implemented.
[0007] The above scheme obtains an image to be identified, extracts lines that meet the line features of the locator from the image to be identified, and obtains a candidate line set composed of multiple candidate lines, wherein the number of candidate line sets is multiple, thereby obtaining a candidate line set with a certain probability of being a locator, and reducing the probability of missing the locator due to factors such as stains and wrinkles. Based on the image features of each candidate line set, the area corresponding to the candidate line set is located, and the locator candidate frame matching each candidate line set is obtained. All locator candidate frames are combined to determine a candidate frame combination composed of matching locator candidate frames, thereby screening out mutually compatible locator candidate frames, reducing the influence of interference factors, and increasing the probability that the locator candidate frames in the candidate frame combination belong to the same barcode. Based on the position of the locator candidate frame in the candidate frame combination, the initial rough position of the barcode is located to obtain the barcode initial frame corresponding to the barcode. Get the border points on the initial border of the barcode, and analyze the rough position of the barcode within a higher precision range based on the border points and the image features within the preset range, so as to determine the barcode target border with high precision corresponding to the barcode and improve the accuracy of barcode recognition and positioning. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0009] Figure 1 It is a flowchart of an implementation method of the barcode recognition and positioning method of the present application;
[0010] Figure 2 This is a schematic diagram of an application scenario of an implementation method of PDF417 code;
[0011] Figure 3 It is a flowchart of another implementation method of the barcode recognition and positioning method of the present application;
[0012] Figure 4 It is a schematic diagram of an application scenario of an implementation method of scanning an image to be identified in the present application;
[0013] Figure 5 This is a schematic diagram of an application scenario of an implementation method of obtaining a candidate line set in this application;
[0014] Figure 6 This is a schematic diagram of an application scenario of an implementation method of the locator extension direction of the present application;
[0015] Figure 7This is a schematic diagram of an application scenario of an implementation method of obtaining a locator candidate frame in the present application;
[0016] Figure 8 This is a schematic diagram of an application scenario of an implementation method of obtaining an initial border of a barcode in the present application;
[0017] Fig. 9 This is a schematic diagram of an application scenario of an implementation method of obtaining a barcode target frame in the present application;
[0018] Fig.10 It is a structural schematic diagram of an embodiment of the electronic device of the present application;
[0019] Fig.11 It is a structural schematic diagram of an implementation method of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments, and different implementation methods can be adaptively combined. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0021] The terms "system" and "network" are often used interchangeably in this article. The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship. In addition, "many" in this article means two or more than two.
[0022] The barcode recognition and positioning method provided by the present application is used to recognize and locate a barcode, and is particularly suitable for recognizing a barcode with multiple locators, such as a PDF417 code. Therefore, the execution subject corresponding to the barcode recognition and positioning method improved by the present application is a processing unit capable of image processing. For ease of explanation, the present application takes the PDF417 code as an example to illustrate the solution of the present application.
[0023] See also Figure 1 , Figure 1 This is a flow chart of an implementation method of a barcode recognition and positioning method of the present application, the method comprising:
[0024] S101: Acquire an image to be recognized, and extract a plurality of candidate line sets matching the line features of the locator from the image to be recognized.
[0025] Specifically, an image to be identified is obtained, and lines that meet the line features of the locator are extracted from the image to be identified to obtain a candidate line set consisting of multiple candidate lines, wherein the number of candidate line sets is multiple, thereby obtaining a candidate line set that has a certain probability of being a locator, thereby reducing the probability of missing the locator due to factors such as stains and wrinkles.
[0026] Understandably, see Figure 2 , Figure 2 1 is a schematic diagram of an application scenario of an implementation method of PDF417 code, wherein the PDF417 code includes two locators and a data area between the two locators. In addition, the image to be identified is preprocessed, and the preprocessing process at least includes filtering and binarization processing, so as to obtain the image to be identified.
[0027] In some implementation scenarios, an image to be identified is obtained, and the line features of the locator are determined. The line features correspond to the line distribution ratio of the locator. The image to be identified is scanned line by line horizontally and vertically, and candidate lines that meet at least part of the line distribution ratio of the line features of the locator are extracted from the image to be identified to form a candidate line set.
[0028] In some implementation scenarios, an image to be identified is obtained, line features of the locator are determined, the line features correspond to the pixel features of the locator, the image to be identified is scanned in regions, and candidate lines whose similarity with the line features of the locator meets a similarity threshold are extracted from the image to be identified to form a candidate line set. The similarity is determined based on the cosine value between the pixel features of at least some of the candidate lines in the candidate line set and the pixel features of the standard locator.
[0029] It is understandable that if Figure 2 As shown in , assume that the locator on the left is marked as locator A and the locator on the right is marked as locator B, wherein the black and white module ratio in the line distribution ratio of locator A is 1:2:1:1:1:3:1:1:8, and the black and white module ratio in the line distribution ratio of locator B is 1:1:1:1:1:1:8.
[0030] It should be noted that the candidate lines in the candidate line set can be at least partially continuous lines that meet some of the proportions, or can be partially spaced lines that meet some of the proportions, and the candidate lines in the candidate line set can be positive or directional lines that meet at least some of the proportion values in the above-mentioned line distribution ratio.
[0031] S102: Determine a locator candidate box matching each candidate line set based on the image features of each candidate line set.
[0032] Specifically, based on the image features of each candidate line set, the area corresponding to the candidate line set is located to obtain a locator candidate frame matching each candidate line set.
[0033] In some implementation scenarios, based on the image features of the candidate line set, the endpoints corresponding to the lines at the beginning and end of the candidate line set in a preset scanning direction are obtained, and based on the positions of the endpoints and the scanning direction, the extension direction of the locator candidate frame corresponding to the candidate line set is determined, and based on the endpoints and the extension direction of the locator candidate frame, the locator candidate frame matching the candidate line set is obtained.
[0034] In some implementation scenarios, based on the image features of the candidate line set, the area where the candidate line set is located is estimated to obtain an estimated frame corresponding to the candidate line set, and the estimated frame is used as a locator candidate frame for matching the candidate line set.
[0035] S103: Determine a candidate frame combination that matches each other among all locator candidate frames, and obtain a barcode initial frame corresponding to the barcode based on the position of the locator candidate frame in the candidate frame combination.
[0036] Specifically, all locator candidate frames are combined to determine a candidate frame combination composed of matching locator candidate frames, thereby screening out mutually compatible locator candidate frames, reducing the influence of interference factors, and increasing the probability that the locator candidate frames in the candidate frame combination belong to the same barcode. Based on the position of the locator candidate frames in the candidate frame combination, the initial rough position of the barcode is located to obtain the barcode initial bounding box corresponding to the barcode.
[0037] In some implementation scenarios, all locator candidate frames are combined in pairs to obtain multiple combinations to be confirmed. Based on the image features within the locator frame in the combination to be confirmed, the combination score corresponding to each combination to be confirmed is determined. The combination to be confirmed whose combination score meets the scoring rules is used as a mutually matching candidate frame combination. Based on the position of the locator candidate frame in the candidate frame combination, the position of the barcode is estimated to obtain the barcode initial bounding box corresponding to the barcode.
[0038] In some implementation scenarios, based on the distribution ratio of candidate lines in the candidate line set, the type of locator matched by the candidate line set is determined, and the locator candidate frames of different locator types are combined in pairs to obtain multiple combinations to be confirmed. Based on the extension direction and pixel distance of the locator candidate frames in the combinations to be confirmed, the multiple combinations to be confirmed are screened to obtain candidate frame combinations that match each other in all the combinations to be confirmed. Based on the position of the locator candidate frames in the candidate frame combinations, the outermost corner points of the locator candidate frames are determined, and the corresponding corner points are connected in sequence with straight lines to obtain the barcode initial border corresponding to the barcode.
[0039] It can be understood that based on the positions of the two candidate frame locators in the candidate frame combination, the barcode can be roughly located, thereby determining whether there is a barcode to be identified on the image to be identified and the approximate area where the barcode to be identified is located.
[0040] S104: Obtain frame points on the initial frame of the barcode, and determine a barcode target frame corresponding to the barcode based on the frame points and image features within a preset range.
[0041] Specifically, the frame points located on the initial frame of the barcode are obtained, and based on the frame points and the image features within a preset range, the rough position of the barcode is analyzed within a higher precision range, so as to determine the barcode target frame with high precision corresponding to the barcode, thereby improving the accuracy of barcode recognition and positioning.
[0042] In some implementation scenarios, some points corresponding to the positions of the locator candidate frames are selected in the initial barcode frame as frame points, wherein each edge of the initial barcode frame corresponds to a plurality of frame points. Image features within a preset range of the frame points are obtained, and based on the frame points and the image features within the preset range, edge points located at the edge of the barcode are determined, and the edge points are fitted to obtain the barcode target frame.
[0043] In some implementation scenarios, each corner point is selected on the initial border of the barcode, and multiple extension points on the initial border of the barcode are obtained by expanding the corner points based on a preset pixel size. The corner point and the multiple extension points are used as border points on the initial border of the barcode, and the border points are expanded to the surrounding areas according to a preset range. Based on the pixel features within the preset range, a range to be confirmed that meets the pixel change scale around the border point is determined, and the edge points located at the edge of the barcode are determined from the range to be confirmed, and the edge points are fitted to obtain the target border of the barcode.
[0044] It is understandable that further analysis of the position of the barcode based on the initial positioning of the barcode can obtain a barcode target frame with higher accuracy corresponding to the barcode, thereby identifying the barcode and accurately positioning the barcode.
[0045] The above scheme obtains an image to be identified, extracts lines that meet the line features of the locator from the image to be identified, and obtains a candidate line set composed of multiple candidate lines, wherein the number of candidate line sets is multiple, thereby obtaining a candidate line set with a certain probability of being a locator, and reducing the probability of missing the locator due to factors such as stains and wrinkles. Based on the image features of each candidate line set, the area corresponding to the candidate line set is located, and the locator candidate frame matching each candidate line set is obtained. All locator candidate frames are combined to determine a candidate frame combination composed of matching locator candidate frames, thereby screening out mutually compatible locator candidate frames, reducing the influence of interference factors, and increasing the probability that the locator candidate frames in the candidate frame combination belong to the same barcode. Based on the position of the locator candidate frame in the candidate frame combination, the initial rough position of the barcode is located to obtain the barcode initial frame corresponding to the barcode. Get the border points on the initial border of the barcode, and analyze the rough position of the barcode within a higher precision range based on the border points and the image features within the preset range, so as to determine the barcode target border with high precision corresponding to the barcode and improve the accuracy of barcode recognition and positioning.
[0046] See also Figure 3 , Figure 3 : is a flow chart of another embodiment of the barcode identification and positioning method of the present application, the method comprising:
[0047] S201: Acquire an image to be recognized, scan the image to be recognized in a first scanning direction and a second scanning direction respectively, and extract a plurality of candidate line sets matching the line features of the locator.
[0048] Specifically, an image to be identified is obtained, and the image to be identified is scanned in a first scanning direction and a second scanning direction, respectively, and a candidate line set matching the line features of the locator is extracted during the scanning process. For a barcode including multiple locators, multiple candidate line sets can usually be scanned, and when no candidate line set is obtained or the number of candidate line sets is one, it can be determined that the image to be identified does not include the barcode to be identified.
[0049] It should be noted that the image to be identified is obtained through preprocessing, in which the original image is smoothed and filtered to reduce noise interference, and the image is binarized using an adaptive threshold segmentation algorithm to obtain the image to be identified. The binarization process can be expressed by the following formula:
[0050]
[0051] in, For each pixel srcA(x,y), calculate the average pixel value Area(x,y) in its neighborhood within the range of N×M, and output the result pixel value dstA(x,y) at that position according to the size relationship between srcA(x,y) and Area(x,y). Process each pixel in turn to obtain a binary image result.
[0052] It can be understood that the first scanning direction and the second scanning direction are usually the horizontal and vertical directions on the image to be identified. In other specific scenarios, two different directions can also be set. This application does not impose specific restrictions on this.
[0053] See also Figure 4 , Figure 4 This is a schematic diagram of an application scenario of an implementation method of the present application for scanning on an image to be identified. Taking horizontal and vertical scanning as an example, the image to be identified is scanned line by line according to a preset pixel step size, so as to extract a set of candidate lines that match the line features of the locator during the scanning process, thereby improving the scanning accuracy.
[0054] It should be noted that the locators on the barcode correspond to the first position type and the second position type. The locators of the first position type and the locators of the second position type are matched with their respective line features. The line features correspond to the line distribution ratio of the locators. At least some of the candidate lines in the candidate line set satisfy some of the proportion values in the line distribution ratio.
[0055] For details, please refer to Figure 2 , the locator on the barcode corresponds to the first position type and the second position type. For the convenience of explanation, Figure 2 The locator on the left is marked as the first position type as locator A, and the locator on the right is marked as the second position type as locator B. The line distribution ratio of locator A is 1:2:1:1:1:3:1:1:8, and the line distribution ratio of locator B is 1:1:1:1:1:1:8.
[0056] It can be understood that the line features of the locator correspond to the line distribution ratio of the locator, and when scanning in the image to be identified, the black and white changes on the image to be identified are analyzed to see if they meet the line features. Therefore, in the process of line-by-line scanning, when the lines on the image to be identified meet the line features matched by the locator of a certain position type, they can be used as a candidate line set, and the corresponding candidate line set can be classified into the corresponding position type. Among them, at least part of the candidate lines in the candidate line set meet the partial ratio values in the line distribution ratio, that is, the candidate lines in the candidate line set can be at least partially continuous lines that meet the partial ratio, or partially spaced lines that meet the partial ratio, and the candidate lines in the candidate line set can be positive or directional lines that meet at least part of the ratio values in the above-mentioned line distribution ratio.
[0057] In some implementation scenarios, see Figure 5 , Figure 5 is a schematic diagram of an application scenario of an implementation method of obtaining a candidate line set in the present application, wherein the first position type of locator sequentially records the coordinate positions of 10 adjacent black and white edges when scanning the entire image horizontally or vertically, {PtA 1(x,y) ,PtA 2(x,y) ,PtA 3(x,y) ,......,PtA 10(x,y)}, calculate the black and white module ratio, that is, the pixel width of each line can be obtained by subtracting adjacent coordinates in sequence, [PtA 2(x) -PtA1x,PtA3(x,y)-PtA2(x),......,PtA10(x)-PtA9(x), thereby saving the candidate line sets of line features that match all the locators of the first position type, and recording all the candidate line sets corresponding to the locators of the first position type obtained after scanning as {SegA1,SegA2,SegA3,......,SegAn}.
[0058] It can be understood that the second position type locator sequentially records the coordinate positions of eight adjacent black and white edges when scanning the entire image horizontally or vertically. 1(x,y) ,PtB 2(x,y) ,PtB 3(x,y) ,......,PtB 8(x,y)}, calculate the black and white module ratio, that is, the adjacent coordinates are subtracted in sequence to get the pixel width of each line, {PtB 2(x) -PtB 1(x) ,PtB 3(x,y) -PtB 2(x) ,......,PtB 8(x) -PtB 7(x)}, thereby saving all candidate line sets of line features that match the locators of the second position type, and recording all candidate line sets corresponding to the locators of the second position type obtained after scanning as {SegB1, SegB2, SegB3, ..., SegBn}.
[0059] S202: Obtain the line center corresponding to the candidate line at the specified position in the candidate line set, and determine the head coordinates corresponding to the candidate line at the head position, the tail coordinates corresponding to the candidate line at the tail position, and the center coordinates corresponding to the line center in the candidate line set based on the scanning direction matched by the line center and the candidate line set.
[0060] Specifically, the line center corresponding to the candidate line at the specified position in the candidate line set is obtained, wherein the specified position is usually the line with the most significant features in the locator. Taking the PDF417 code as an example, the candidate line at the specified position corresponds to the line corresponding to the largest black module.
[0061] Furthermore, based on the scanning direction matched by the line center and the candidate line set, the head coordinates corresponding to the candidate lines at the head position in the candidate line set, the tail coordinates corresponding to the candidate lines at the tail position, and the center coordinates corresponding to the line center are obtained in the scanning direction, so as to obtain some representative points on the candidate line set, so as to facilitate the positioning of the candidate line set.
[0062] Please refer again Figure 5 ,exist Figure 5 In the middle area of the first position type, the locator from left to right is the head coordinate, center coordinate and tail coordinate as key parameters. Taking the candidate line set SegA1 as an example, the key parameters are recorded as [PtA1 Top ,PtA1 Tail ,PtA1 Center ]. Similarly, the locator of the second position type has the head coordinate, center coordinate and tail coordinate as key parameters from left to right. Taking the candidate line set SegB1 as an example, the key parameters are recorded as [PtB1 Top ,PtB1 Tail ,PtB1 Center ].
[0063] S203: Determine a locator candidate box matching each candidate line set based on the image features of each candidate line set.
[0064] Specifically, based on the image features of each candidate line set, the area corresponding to the candidate line set is located to obtain a locator candidate frame matching each candidate line set.
[0065] In some implementation scenarios, based on the image features of each candidate line set, a locator candidate frame matching each candidate line set is determined, including performing the following steps for each candidate line set: based on the head coordinates and tail coordinates corresponding to the candidate line set, and the image features of the candidate line set, determining the edge angle of the candidate line set and a first extension direction matching the edge angle; wherein the first extension direction is matched with a second extension direction perpendicular thereto; based on the center coordinates and the second extension direction corresponding to the candidate line set, and the image features of the candidate line set, determining the boundary points corresponding to the candidate lines at the specified positions, and based on the boundary points, the head coordinates and the tail coordinates, and the first extension direction and the second extension direction, obtaining a locator candidate frame matching the candidate line set.
[0066] Specifically, edge detection is performed on the head coordinates, the tail coordinates and image features around them using an edge detection operator to determine the edge angle of the candidate line set and the first extension direction of the edge angle matching.
[0067] For illustration purposes, see Figure 6 , Figure 6 This is a schematic diagram of an application scenario of an embodiment of the locator extension direction of the present application. Taking the candidate line set SegA1 of the locator A as an example, the head coordinate PtA1 is obtained. Top and tail coordinate PtA1 Tail , use the image basic operator sobel to calculate the current edge rotation angle, the calculation formula is:
[0068]
[0069] GY=pix (x-1,y+1) +pix (x+1,y+1) -pix (x-1,y-1) -pix (x+1,y-1) +2*(pix (x,y+1) -pix (x,y-1) ) (3)
[0070] GX=pix (x+1,y-1) +pix (x+1,y+1) -pix (x-1,y-1) -pix (x-1,y+1) +2*(pix (x+1,y) -pix (x-1,y) ) (4)
[0071] Among them, pix (x,y) Represents the pixel value of the current point in the image, using the sobel operator to calculate PtA1 in sequence Top and PtA1 Tail The edge angle of AngA1 top and AngA1 tailFinally, the average of the two is taken as the rotation angle of the current locator in the first extension direction, which is recorded as Ang1, where Ang1 = (AngA1 top +AngA1 tail ) / 2.
[0072] Furthermore, the first extension direction is matched with a second extension direction perpendicular thereto, that is, the rotation angle Ang2 in the second extension direction is Ang1+90.
[0073] Understandably, see Figure 7 , Figure 7 This is a schematic diagram of an application scenario of obtaining a candidate frame of a locator in the present application. With the center coordinate as the center and the search direction as Ang2, the boundary is searched upward and downward based on the image features to obtain the boundary points corresponding to the candidate lines at the specified position {PtA1 up ,PtA1 down}, with PtA1 up and PtA1 down As the reference point, with Ang1 as the rotation direction, we get two straight lines {LineA1 up ,lineA1 down}, as the upper and lower edge straight lines of the locator, with the head coordinate PtA1 Top and tail coordinate PtA1 Tail As the reference point, the rotation direction is AngA2, and two straight lines {LineA1 left ,lineA1 right}, as the left and right edge lines of the locator, so that the edge lines intersect each other, and we get Figure 7 Therefore, by locating the candidate line set, the candidate locator frame corresponding to the area with the probability of being a locator can be obtained, so as to match the locator.
[0074] S204: Determine a candidate frame combination that matches each other among all locator candidate frames, and obtain a barcode initial frame corresponding to the barcode based on the position of the locator candidate frame in the candidate frame combination.
[0075] Specifically, all locator candidate frames are combined to determine a candidate frame combination composed of matching locator candidate frames, thereby screening out mutually compatible locator candidate frames, and based on the positions of the locator candidate frames in the candidate frame combination, the initial rough position of the barcode is located to obtain the barcode initial border corresponding to the barcode.
[0076] It is understandable that the locator candidate boxes of the first position type and the locator candidate boxes of the second position type are combined to obtain the combination to be confirmed. That is, when the candidate line set is marked with the position type, the locator candidate boxes corresponding to the first position type can be combined with the locator candidate boxes of the second position type respectively to obtain all possible combinations to be confirmed.
[0077] In some implementation scenarios, a combination of candidate frames that match each other among all locator candidate frames is determined, and based on the position of the locator candidate frame in the candidate frame combination, an initial barcode bounding box corresponding to the barcode is obtained, including: obtaining bounding box features corresponding to the locator candidate frame, and determining a combination score corresponding to the combination to be confirmed based on the bounding box features of the locator candidate frame in the combination to be confirmed; wherein the combination to be confirmed that meets the scoring rules is used as the candidate frame combination; based on the position of the locator candidate frame in the candidate frame combination, the corner points of the locator candidate frame in the candidate frame combination are connected to obtain the initial barcode bounding box.
[0078] Specifically, the bounding box features corresponding to the locator candidate box are obtained, and based on the bounding box features of the locator candidate box in the combination to be confirmed, the matching degree of the locator candidate box in the combination to be confirmed is scored, and the combination score corresponding to the combination to be confirmed is determined, and all the combinations to be confirmed are screened based on the combination score, and the combinations to be confirmed that meet the scoring rules are obtained as candidate box combinations.
[0079] Optionally, the scoring rule may be to give priority to the combination to be confirmed with the highest combination score corresponding to the locator as the candidate frame combination. That is to say, when there is a conflict in the locator in the combination to be confirmed, the conflicting locator is preferentially assigned to the combination to be confirmed with a higher combination score, so as to further obtain the highest combination score among the remaining combinations to be confirmed. For example, when locator 1 and locator 2 are respectively combined with locator 3 to form a combination to be confirmed, the combination score of the combination to be confirmed between locator 1 and locator 3 is 0.98, and the combination score of the combination to be confirmed between locator 2 and locator 3 is 0.95, then locator 1 and locator 3 are used as the candidate frame combination, and for locator 2, the group with the highest combination score is obtained from the combination to be confirmed composed of locator 2 and other locators as the candidate frame combination.
[0080] It is understandable that the scoring rule may also include setting a scoring threshold for the combined score, thereby filtering out falsely detected locator candidate boxes, and the specific scoring rule may be customized based on specific scenarios, and this application does not impose any specific restrictions on this.
[0081] For further information, see Figure 8 , Figure 8 This is a schematic diagram of an application scenario of obtaining an initial barcode frame in the present application. Based on the position of the locator candidate frame in the candidate frame combination, the corner point of the locator candidate frame is determined to be located at the corner, that is, Figure 8The dots shown in are corner points. The corner points of the locator candidate boxes in the candidate box combination are connected to obtain the initial border of the barcode, thereby locating the initial rough position of the barcode.
[0082] It should be noted that the bounding box features corresponding to the locator candidate box are obtained, and the combination score corresponding to the combination to be confirmed is determined based on the bounding box features of the locator candidate box in the combination to be confirmed, including: determining the bounding box features corresponding to the locator candidate box based on the area and extension direction of the locator candidate box; determining the area deviation score and extension direction deviation score between the two locator candidate boxes in the combination to be confirmed based on the bounding box features corresponding to the locator candidate box in the combination to be confirmed, and determining the combination score corresponding to the combination to be confirmed based on the area deviation score and the extension direction deviation score.
[0083] Specifically, based on the coordinates of the upper locator corner point of the locator candidate box, the area enclosed by the locator candidate box is determined; based on the rotation angle of the locator candidate box, the extension direction of the locator candidate box is determined; based on the area and extension direction of the locator candidate box, the frame features corresponding to the locator candidate box are determined, and the frame features include the area feature Sign area And direction angle feature Sign angle .
[0084] Furthermore, based on the area features corresponding to the locator candidate box in the combination to be confirmed, the area deviation score of the combination to be confirmed is determined, and based on the direction angle features corresponding to the locator candidate box in the combination to be confirmed, the extension direction deviation score of the combination to be confirmed is determined. Finally, based on the area deviation score and the extension direction deviation score, the combination score corresponding to the combination to be confirmed is determined, so that the combination score has higher accuracy and confidence.
[0085] Optionally, the area error Area1-Area2 between locator A and locator B cannot be greater than a preset threshold Thre area , the area error is converted into the area deviation score Dif area , expressed as:
[0086]
[0087] Optionally, the angle error Angle1-Angle2 between locator A and locator B cannot be greater than a preset threshold Thre angle , the angle error is converted into the extension direction deviation score Dif angle , expressed as:
[0088]
[0089] It is understandable that the preset threshold range of the area deviation score and the extension direction deviation score is 0% to 100%, and the specific value is adjusted according to the actual situation. score , expressed as:
[0090] Box score =2-Dif angle -Dif area (7)
[0091] The combined score may also be based on other specific numerical conversion methods, for example, using a constant to directly subtract the area deviation and the angle deviation, and this application does not impose any specific restrictions on this.
[0092] S205: Obtain frame points on the initial frame of the barcode, and determine a barcode target frame corresponding to the barcode based on the frame points and image features within a preset range.
[0093] Specifically, the frame points located on the initial frame of the barcode are obtained, and based on the frame points and the image features within a preset range, the rough position of the barcode is analyzed within a higher precision range, so as to determine the barcode target frame with high precision corresponding to the barcode, thereby improving the accuracy of barcode recognition and positioning.
[0094] In some implementation scenarios, frame points on the initial frame of the barcode are obtained, and based on the frame points and image features within a preset range thereof, a barcode target frame corresponding to the barcode is determined, including: based on the center coordinates and the first side length direction and the second side length direction of the initial frame of the barcode, frame points in the first side length direction and the second side length direction are determined; wherein, the first side length direction corresponds to other areas except the locator, and the second side length direction only corresponds to the locator, and the frame points in the first side length direction include the intersection of the locating reference line passing through the center coordinate and the first side length direction; based on all frame points on the initial frame of the barcode and image features within a preset range thereof, edge points to be fitted corresponding to the barcode are determined, and the edge points to be fitted are fitted to obtain the barcode target frame.
[0095] Specifically, see Fig. 9 , Fig. 9 This is a schematic diagram of an application scenario of obtaining a barcode target frame in the present application, wherein the first side length direction corresponds to other areas except the locator, and the first side length direction is Fig. 9 In the long side direction, there is only a locator corresponding to the second side length direction. The second side length direction is Fig. 9 Get the positioning reference line passing through the center coordinates, determine the intersection of the positioning reference line and the first side length direction within the range of the locator candidate box, and use the intersection as the border point in the first side length direction.
[0096] Furthermore, points other than the intersection points in the first side length direction and the second side length direction are obtained as border points, and multiple border points are selected in the first side length direction and the second side length direction, so that multiple border points are selected on each side of the initial border of the barcode, and for the first side length direction that is more difficult to identify, the intersection point of the positioning reference line and the first side length direction is selected as the border point, so as to ensure that the border point is selected near the line at the specified position with significant features, thereby reducing the difficulty of recognition.
[0097] Understandably, see Fig. 9 Based on the local enlarged image in the barcode, all the border points on the initial border of the barcode and the image features within the preset range of the border points are searched for the area where the black and white changes sharply, and the edge points to be fitted that fall on the edge of the barcode are determined, that is, Fig. 9 The lightest point in the middle is used to fit the edge points to be fitted, and the straight lines obtained after fitting the edge points to be fitted on each side intersect each other to obtain a high-precision barcode target border.
[0098] It should be noted that based on the center coordinates and the first and second side length directions of the initial border of the barcode, determining the border points in the first and second side length directions includes: determining a positioning reference line passing through the center coordinates based on the rotation angle corresponding to the center coordinates and the extension direction of the locator candidate frame; obtaining the intersection of the positioning reference line and the first side length direction, determining multiple extension points obtained by extending the intersection in the first side length direction by a preset number of pixels, and using the intersection and the extension points as border points in the first side length direction; obtaining multiple points in the second side length direction as border points in the second side length direction.
[0099] Specifically, for ease of explanation, taking the locator of the first position type as an example, a positioning reference line is generated with the center coordinate as the center and the rotation angle corresponding to the extension direction of the locator candidate box, wherein the rotation angle can correspond to the rotation angle Ang1 in the first extension direction mentioned above.
[0100] Further, the intersection of the positioning reference line and the upper and lower edges of the initial border of the barcode is obtained, which is recorded as {PtA clp_up ,PtA clp_down}, with the intersection as the center, the preset number of pixels is expanded along the edge direction in the first side length direction to both ends to obtain multiple expansion points, wherein the number of expansions can be multiple times, and this application does not impose specific restrictions on this. For the sake of convenience, taking the expansion points of a single edge as 2 as an example, 4 expansion points can be obtained at the upper and lower edges of the initial border of the barcode, which are recorded as {PtA clp_up_left ,PtA clp_up_right ,PtA clp_down_left ,PtA clp_down_right}, and use the intersection point and the extension point as the border points in the direction of the first side length.
[0101] It is understandable that the intersection point {PtB clpup ,PtB clp_down}, and the extension points {PtB clp_up_left ,PtB clp_up_right ,PtB clp_down_left ,PtB clp_down_right Therefore, at the upper and lower edges of the initial border of the barcode, the border points corresponding to the two position type locators can be obtained, and each edge has 6 border points in total.
[0102] Furthermore, in the second side length direction, since the edge of the locator is a solid line, a plurality of border points may be directly arranged at intervals on the edge, preferably at equal intervals.
[0103] It can be understood that each border point corresponds to an area near the locator, and the border points near the locator of a single position type are equivalent to setting caliper points on the initial border of the barcode, thereby fitting the final position of the barcode within a high-precision range, thereby improving the accuracy and confidence of barcode recognition and positioning.
[0104] In this embodiment, an image to be identified is acquired, and the image to be identified is scanned in a first scanning direction and a second scanning direction, respectively. During the scanning process, a candidate line set matching the line features of the locator is extracted. The line center corresponding to the candidate line at a specified position in the candidate line set is acquired, and based on the scanning direction matched by the line center and the candidate line set, the head coordinates corresponding to the candidate line at the head position in the candidate line set, the tail coordinates corresponding to the candidate line at the tail position, and the center coordinates corresponding to the line center are acquired in the scanning direction, so that some representative points on the candidate line set can be obtained, so as to facilitate the positioning of the candidate line set. Based on the image features of each candidate line set, the area corresponding to the candidate line set is located to obtain the locator candidate frame matching each candidate line set, the locator candidate frame of the first position type and the candidate frame of the second position type are combined to obtain the combination to be confirmed, the matching degree of the locator candidate frame in the combination to be confirmed is scored based on the frame features of the locator candidate frame in the combination to be confirmed, and the combination score corresponding to the combination to be confirmed is determined, all the combinations to be confirmed are screened based on the combination score, and the combination to be confirmed that meets the scoring rules is obtained as the candidate frame combination, and the initial rough position of the barcode is located based on the position of the locator candidate frame in the candidate frame combination to obtain the initial barcode frame corresponding to the barcode. The frame points located on the initial barcode frame are obtained, and the rough position of the barcode is analyzed within a higher precision range based on the frame points and the image features within the preset range, so as to determine the barcode target frame with high precision corresponding to the barcode, and improve the accuracy and confidence of barcode recognition positioning.
[0105] See also Fig.10 , Fig.10 It is a structural diagram of an embodiment of an electronic device of the present application, wherein the electronic device 30 includes a memory 301 and a processor 302 coupled to each other, wherein the memory 301 stores program data (not shown), and the processor 302 calls the program data to implement the method in any of the above embodiments. For descriptions of related contents, please refer to the detailed description of the above method embodiments, which will not be repeated here.
[0106] See also Fig.11 , Fig.11 It is a structural diagram of an embodiment of a computer-readable storage medium of the present application. The computer-readable storage medium 40 stores program data 400. When the program data 400 is executed by a processor, the method in any of the above embodiments is implemented. For descriptions of related contents, please refer to the detailed description of the above method embodiments, which will not be repeated here.
[0107] It should be noted that the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present implementation scheme.
[0108] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0109] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0110] The above description is only an implementation method of the present application, and does not limit the protection scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the protection scope of the present application.
Claims
1. A barcode recognition and positioning method, characterized in that: The method comprises: Acquire an image to be identified, and extract multiple candidate line sets matching the line features of the locator from the image to be identified; Determine, based on the image features of each of the candidate line sets, a locator candidate frame that matches each of the candidate line sets; Determine a candidate frame combination that matches each other among all the locator candidate frames, and obtain a barcode initial frame corresponding to the barcode based on the position of the locator candidate frame in the candidate frame combination; The frame points on the initial frame of the barcode are obtained, and based on the frame points and image features within a preset range thereof, a barcode target frame corresponding to the barcode is determined.
2. The barcode recognition and positioning method according to claim 1, characterized in that: The step of obtaining an image to be identified and extracting a plurality of candidate line sets matching the line features of the locator from the image to be identified includes: Acquire an image to be identified, scan the image to be identified in a first scanning direction and a second scanning direction of the image to be identified respectively, and extract a plurality of candidate line sets matching the line features of the locator; Obtain the line center corresponding to the candidate line at the specified position in the candidate line set, and determine the head coordinates corresponding to the candidate line at the head position, the tail coordinates corresponding to the candidate line at the tail position, and the center coordinates corresponding to the line center based on the line center and the scanning direction matched by the candidate line set.
3. The barcode recognition and positioning method according to claim 2, characterized in that: Determining the locator candidate frame that matches each candidate line set based on the image features of each candidate line set includes performing the following steps for each candidate line set: Based on the head coordinates and the tail coordinates corresponding to the candidate line set and the image features of the candidate line set, determine the edge angle of the candidate line set and a first extension direction matched by the edge angle; wherein the first extension direction is matched with a second extension direction perpendicular thereto; Based on the center coordinates and the second extension direction corresponding to the candidate line set, and the image features of the candidate line set, the boundary points corresponding to the candidate lines at the specified position are determined, and based on the boundary points, the head coordinates and the tail coordinates, and the first extension direction and the second extension direction, the locator candidate box matching the candidate line set is obtained.
4. The barcode recognition and positioning method according to claim 2, characterized in that: The locator on the barcode corresponds to a first position type and a second position type, the locator of the first position type and the locator of the second position type are matched with respective line features, the line features correspond to the line distribution ratio of the locator, and at least some of the candidate lines in the candidate line set satisfy some proportion values in the line distribution ratio.
5. The barcode recognition and positioning method according to claim 4, characterized in that: The locator candidate box of the first position type and the candidate box of the second position type are combined to obtain a combination to be confirmed; The step of determining a candidate frame combination that matches each other among all the locator candidate frames, and obtaining a barcode initial frame corresponding to the barcode based on the position of the locator candidate frame in the candidate frame combination, comprises: Acquire the frame features corresponding to the locator candidate frame, and determine the combination score corresponding to the combination to be confirmed based on the frame features of the locator candidate frame in the combination to be confirmed; wherein the combination to be confirmed that meets the scoring rule is used as the candidate frame combination; Based on the position of the locator candidate frame in the candidate frame combination, the corner points of the locator candidate frame in the candidate frame combination are connected to obtain the barcode initial frame.
6. The barcode recognition and positioning method according to claim 5, characterized in that: The acquiring the frame feature corresponding to the locator candidate frame, and determining the combination score corresponding to the combination to be confirmed based on the frame feature of the locator candidate frame in the combination to be confirmed, includes: Determining a frame feature corresponding to the locator candidate frame based on the area and extension direction of the locator candidate frame; Based on the border features corresponding to the locator candidate frames in the combination to be confirmed, the area deviation score and the extension direction deviation score between the two locator candidate frames in the combination to be confirmed are determined; based on the area deviation score and the extension direction deviation score, the combination score corresponding to the combination to be confirmed is determined.
7. The barcode recognition and positioning method according to claim 2, characterized in that: The step of obtaining the frame points on the initial frame of the barcode and determining the barcode target frame corresponding to the barcode based on the frame points and image features within a preset range thereof includes: Based on the center coordinates and the first side length direction and the second side length direction of the initial barcode frame, determine the frame points in the first side length direction and the second side length direction; wherein the first side length direction corresponds to other areas except the locator, the second side length direction corresponds to only the locator, and the frame points in the first side length direction include the intersection of the positioning reference line passing through the center coordinates and the first side length direction; Based on all the frame points on the initial frame of the barcode and image features within a preset range thereof, edge points to be fitted corresponding to the barcode are determined, and the edge points to be fitted are fitted to obtain the target frame of the barcode.
8. The barcode recognition and positioning method according to claim 7, characterized in that: The determining of the border points in the first side length direction and the second side length direction based on the center coordinates and the first side length direction and the second side length direction of the initial border of the barcode includes: Determining a positioning reference line passing through the center coordinates based on a rotation angle corresponding to the center coordinates and an extension direction of the locator candidate box; Obtaining an intersection point between the positioning reference line and the first side length direction, determining a plurality of extension points obtained by extending the intersection point by a preset number of pixels in the first side length direction, and using the intersection point and the extension points as the frame points in the first side length direction; A plurality of points in the direction of the second side length are obtained as border points in the direction of the second side length.
9. An electronic device, characterized in that: include: A memory and a processor coupled to each other, wherein the memory stores program data, and the processor calls the program data to execute the method according to any one of claims 1 to 8.
10. A computer-readable storage medium having program data stored thereon, characterized in that: When the program data is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Two-dimensional code positioning method, two-dimensional code positioning device and computer storage medium
CN120633688A
Two-dimensional code positioning method, two-dimensional code positioning device and computer storage medium
CN120633688B