Barcode image recognition method, device and equipment and storage medium
By identifying the position and status of line segment endpoints in the barcode image, the problem of low recognition accuracy under high-speed barcode marking is solved, and fast decoding and high-precision recognition are achieved.
Patent Information
- Application Number
- CN202411800920.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-12-09
AI Technical Summary
The high-speed product marking scheme causes the barcode identification algorithm to face problems such as inaccurate spatial spacing, easy to blur and serious diffusion, which affects the recognition accuracy.
By obtaining the barcode image to be identified, the first endpoint position of each line segment is identified, and the target classification line of the first endpoint is determined according to the setting rules, and the status of each first endpoint is determined, and finally decoded based on the line segment state is realized to achieve rapid decoding.
It realizes rapid decoding of barcodes, improves recognition accuracy, and can efficiently determine the status of each line segment in the barcode.
Smart Images

Figure CN119647501A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a barcode image recognition method, device, equipment and storage medium. Background Art
[0002] Currently, barcodes are widely used in logistics companies or postal companies. They are developed to store information including sender, delivery address and postal code. Barcodes are usually printed on a flat paper surface. They can be dark on a light background or light on a dark background, as long as there is enough contrast to ensure readability. Barcodes are usually marked using high-speed inkjet printing and other marking technologies.
[0003] However, high-speed product marking solutions are accompanied by problems such as inaccurate spatial spacing, easy blurring, and severe diffusion, which pose challenges to recognition algorithms. Summary of the invention
[0004] In order to solve the above technical problems, the present application provides a barcode image recognition method, device, equipment and storage medium, which efficiently determine the state of each line segment in the barcode, thereby realizing fast decoding of the barcode with good recognition accuracy.
[0005] In a first aspect, the present application provides a method for recognizing a barcode image, the method comprising: obtaining a barcode image to be recognized, the barcode image to be recognized comprising a plurality of parallel line segments; identifying the position of the first endpoint of each line segment; determining a target classification line of the first endpoint according to a set rule; determining a state of each first endpoint based on a positional relationship between the position of each first endpoint and the target classification line of the first endpoint; determining a state of each line segment based on the state of the first endpoint of each line segment; and decoding based on the state of each line segment to obtain a recognition result of the barcode image to be recognized.
[0006] In a second aspect, the present application provides a barcode image recognition device, which includes: an image acquisition module, used to acquire a barcode image to be recognized, wherein the barcode image to be recognized includes multiple parallel line segments; an endpoint position recognition module, used to identify the position of the first endpoint of each line segment; a classification line determination module, used to determine the target classification line of the first endpoint according to a set rule; an endpoint state determination module, used to determine the state of each first endpoint based on the positional relationship between the position of each first endpoint and the target classification line of the first endpoint; a line segment state determination module, used to determine the state of each line segment based on the state of the first endpoint of each line segment; and a state decoding module, used to decode based on the state of each line segment to obtain a recognition result of the barcode image to be recognized.
[0007] In a third aspect, the present application provides a barcode image recognition device, the device comprising: one or more processors; a storage device for storing one or more programs; when the one or more programs are executed by one or more processors, the one or more processors implement the barcode image recognition method as described in the first aspect above.
[0008] In a fourth aspect, the present application provides a storage medium, which may be a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the barcode image recognition method as in the first aspect described above is implemented.
[0009] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program or instructions, and when the computer program or instructions are executed by a processor, implements a barcode image recognition method as described in any one of the first aspects above.
[0010] The embodiment of the present application provides a method, device, equipment and storage medium for identifying a barcode image, the method comprising: obtaining a barcode image to be identified, the barcode image to be identified includes a plurality of parallel line segments; identifying the position of the first endpoint of each line segment; determining the target classification line of the first endpoint according to a set rule; determining the state of each first endpoint based on the positional relationship between the position of each first endpoint and the target classification line of the first endpoint; determining the state of each line segment based on the state of the first endpoint of each line segment; decoding based on the state of each line segment to obtain the identification result of the barcode image to be identified. The characteristic that the endpoints on one side of the barcode are simultaneously located on a straight line is utilized to efficiently determine the state of each line segment in the barcode, thereby realizing rapid decoding of the barcode with good recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0012] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0013] Figure 1 A schematic diagram of a process for identifying a barcode image provided in an embodiment of the present application;
[0014] Figure 2 A schematic diagram of a binary barcode provided in an embodiment of the present application;
[0015] Figure 3A schematic diagram of a flow chart of a method for determining a classification line of an endpoint provided in an embodiment of the present application;
[0016] Figure 4 A schematic diagram of the process flow of the optimized barcode image recognition method provided in the embodiment of the present application;
[0017] Figure 5 A schematic diagram of the state of a quaternary barcode provided in an embodiment of the present application;
[0018] Figure 6 A schematic diagram of the initial dividing line of a quaternary barcode provided in an embodiment of the present application;
[0019] Figure 7a A schematic diagram of a state line of a first endpoint of a quaternary barcode provided in an embodiment of the present application;
[0020] Figure 7b A schematic diagram of a state line of a second endpoint of a quaternary barcode provided in an embodiment of the present application;
[0021] Figure 8 A schematic diagram of the structure of a barcode image recognition device provided in an embodiment of the present application;
[0022] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the scheme of the present application will be further described below. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.
[0024] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only part of the embodiments of the present application, rather than all of the embodiments.
[0025] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0026] It should be noted that the concepts such as "first" and "second" mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0027] It should be noted that the modifications of "one" and "plurality" mentioned in the present application are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0028] The barcode image recognition method provided by the present application is described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0029] Figure 1 This is a flow chart of a barcode image recognition method in an embodiment of the present application. This embodiment is applicable to the case of identifying and interpreting a multi-state barcode image. The method can be executed by a barcode image recognition device. The barcode image recognition device can be implemented in software and / or hardware. The barcode image recognition device can be configured in an electronic device. The electronic device can include a barcode scanning and reading device such as a scanner or a scanning box.
[0030] like Figure 1 As shown, the barcode image recognition method provided in the embodiment of the present application mainly includes steps S101-S106.
[0031] The barcode image recognition method provided in the present application can recognize binary (2-state) barcode images, and can also recognize quaternary (4-state) barcode images. First, the process of recognizing binary barcode images is introduced.
[0032] S101, obtaining a barcode image to be identified, wherein the barcode image to be identified includes a plurality of parallel line segments.
[0033] Barcode is a technology used for automatic identification and data collection, which represents data through a set of black and white stripes and spaces. The stripes and spaces are arranged according to certain rules to form a coded form that can be read by a machine. Barcodes are usually used in scenarios such as product identification, inventory management, logistics tracking, and ticket management to improve the speed and accuracy of data entry. In the embodiments of this application, the barcode is a binary barcode as an example for explanation.
[0034] The binary barcode provided in the embodiment of the present application refers to a barcode encoding method in which the barcode (line segment) width is the same but the barcode length is different. Figure 2 As shown, the binary barcode consists of line segments of only two lengths, and the line segments are combined in parallel. The lengths of the first line segment 21, the third line segment 23, the fourth line segment 24, and the sixth line segment 26 are the first length, and the lengths of the second line segment 22, the fifth line segment 25, and the seventh line segment 27 are the second length, and the first length is greater than the second length.
[0035] The barcode image refers to an image obtained by photographing the binary barcode area. The barcode image to be identified can be understood as a barcode image captured by an electronic device through a camera, the information contained in which needs to be identified.
[0036] Furthermore, the barcode can be placed horizontally in the barcode image to be identified (e.g. Figure 2 The placement direction shown in the figure) can also be placed vertically (such as Figure 2 The direction may be any other placement direction, for example, a direction having a certain angle with the horizontal direction or a direction having a certain angle with the vertical direction.
[0037] S102: Identify the position of the first endpoint of each line segment.
[0038] Depend on Figure 2 It can be seen that the barcode image to be identified includes multiple parallel line segments, and the lengths of the line segments are different. In a binary barcode, the first endpoint of a line segment refers to the endpoint of the line segment that is not aligned. For example: Figure 2 The upper endpoints of the first line segment 21, the second line segment 22, the third line segment 23, the fourth line segment 24, the fifth line segment 25, the sixth line segment 26, and the seventh line segment 27 are the first endpoints.
[0039] The position of the first endpoint refers to the position parameter of the first endpoint in the barcode image to be identified, and the position parameter can be marked by coordinates. Further, the position of the first endpoint can be represented by the coordinates of the pixel point of the first endpoint in the barcode image to be identified.
[0040] Identifying the position of the first endpoint of a line segment mainly includes the following steps:
[0041] 1) Image preprocessing: Convert the color barcode image to be identified into a grayscale image, use Gaussian filtering or other smoothing techniques to reduce the noise in the image and improve the accuracy of edge detection.
[0042] 2) Edge detection. Use methods such as the Canny edge detector or the Sobel operator to detect edges in grayscale images. The above algorithms can highlight the boundary information in the image to find possible line segments.
[0043] 3) Line segment detection. Use the Hough Transform algorithm or the Probabilistic Hough Transform algorithm to detect straight lines from the above edge image. By parameterizing the straight line and accumulating votes in the parameter space, the straight line in the image can be effectively detected.
[0044] 4) Endpoint positioning. If a line segment is detected in the barcode image to be identified, the endpoints of the line segment can be determined by calculating the positions of the pixels at both ends of the line segment. A line segment is composed of a series of continuous edge points, so the endpoints of the line segment are usually the first and last two points on the line segment. Furthermore, for more accurate endpoint positioning, the area near the line segment can be refined by analyzing it, such as applying sub-pixel edge detection, or fitting a more accurate model (such as least squares linear regression) to obtain the true position of the line segment.
[0045] 5) Post-processing: Further processing is performed to remove incorrectly detected line segments (e.g., line segments that are too short, line segments that do not match the expected direction, etc.), and to merge line segment endpoints that are too close.
[0046] In the embodiment of the present application, only a brief introduction is given to the method for identifying the position of the first endpoint of a line segment. Other methods for identifying the endpoints of line segments may also be used to determine the first endpoint of each line segment in the barcode image to be identified, which is not specifically limited in the embodiment of the present application.
[0047] S103: Determine the target classification line of the first endpoint according to the set rule.
[0048] The target classification line of the first endpoint is a straight line located in the specified area and is approximately parallel to or parallel to the set straight line. The target classification line of the first endpoint is mainly used to identify the state of the first endpoint. The set straight line may refer to a straight line formed by connecting the first endpoints of a line segment of the first length, such as Figure 2 The dashed line 27 shown in FIG. 1 may also refer to a straight line formed by connecting the first endpoints of a line segment having a line segment length of the second length, such as Figure 2 The designated area is the area between the dotted line 27 and the dotted line 28.
[0049] The following is an introduction to the setting rules. Figure 3 As shown, the method for determining the classification line of the endpoint of a line segment provided in the embodiment of the present application mainly includes steps S201-S214. The method for determining the classification line of the endpoint of a line segment provided in the embodiment of the present application can be used to determine the target classification line of the first endpoint in a binary barcode, and can also be used to determine the target classification line of the first endpoint in a quaternary barcode and determine the target classification line of the second endpoint in a quaternary barcode. In the embodiment of the present application, the determination of the target classification line of the first endpoint in a binary barcode is used as an example for explanation.
[0050] S201: Determine an initial classification line of a current endpoint, where the current endpoint includes a first endpoint or a second endpoint.
[0051] First, an initial classification line of the first endpoint is obtained, wherein the initial classification line of the first endpoint is a straight line within a specified area and having no intersection with the dotted line 28 and the dotted line 29 in the barcode image to be identified.
[0052] Furthermore, the initial classification line of the first endpoint is obtained by connecting the first endpoint of the first line segment and the first endpoint of the last line segment among the multiple parallel line segments.
[0053] The first line segment is the first line segment in the barcode image, such as Figure 2 The first line segment 21 in the barcode image, and the last line segment is the last line segment at the end of the barcode image, such as Figure 2 The seventh line segment 27 in .
[0054] The first endpoint of the first line segment 21 is connected to the first endpoint of the seventh line segment 27 to obtain an initial classification line 210 of the first endpoint.
[0055] S202: Calculate the distance between each current endpoint and the initial classification line.
[0056] The distance between each first endpoint and the initial classification line of the first endpoint is calculated. The distance between the first endpoint and the initial classification line of the first endpoint may be a perpendicular distance from the first endpoint to the initial classification line.
[0057] Based on the coordinate value of the first endpoint of the first line segment and the coordinate value of the first endpoint of the last line segment, the straight line expression of the initial classification line 210 of the first endpoint is determined. Based on the coordinate value of each first endpoint, the straight line expression of the initial classification line 210 of the first endpoint and the point-to-line distance formula, the distance between each first endpoint and the initial classification line of the first endpoint is calculated.
[0058] S203 . Grouping the current endpoints based on the distances between the current endpoints and the initial classification line to obtain a first endpoint group, a second endpoint group, and a third endpoint group.
[0059] Among them, the first endpoint group includes: the current endpoint whose distance from the initial classification line is greater than or equal to the first set threshold, the second endpoint group includes: the current endpoint whose distance from the initial classification line is less than the second set threshold, and the third endpoint group includes: the current endpoint whose distance from the initial classification line is less than the first set threshold and greater than the second set threshold.
[0060] The second threshold value is the opposite of the first threshold value. For example, if the first threshold value is th, then the second threshold value is -th.
[0061] The first set threshold is proportional to the distance between adjacent line segments. Figure 2As shown in , the distance between adjacent line segments refers to the width of the blank area between adjacent line segments, such as Figure 2 As shown, the distance d1 of the adjacent line segments. The first set threshold is in direct proportion to the distance d1 of the adjacent line segments. The first set threshold is less than or equal to the distance d1 of the adjacent line segments, and the first set threshold is greater than or equal to one half of the distance d1 of the adjacent line segments.
[0062] Furthermore, the first set threshold th is the product of the constant c1 and the distance d1 between adjacent line segments, that is, th=c1×d1. The selection range of the constant c1 is [0.5, 1].
[0063] After calculating the distance between each first endpoint and the initial classification line of the first endpoint in S202, the distance between each first endpoint and the initial classification line of the first endpoint is compared with the first set threshold, and the first endpoint whose distance is greater than or equal to the first set threshold is divided into the first endpoint group, the first endpoint whose distance is less than or equal to the second set threshold is divided into the second endpoint group, and the first endpoint whose distance is less than the first set threshold and greater than the second set threshold is divided into the third endpoint group.
[0064] In other words, the distance between the first endpoint included in the first endpoint group and the initial classification line of the first endpoint is greater than or equal to the first set threshold, the distance between the first endpoint included in the second endpoint group and the initial classification line of the first endpoint is less than or equal to the second set threshold, and the distance between the first endpoint included in the third endpoint group and the initial classification line of the first endpoint is less than the first set threshold and greater than the second set threshold.
[0065] S204: Count the number of endpoints included in the first endpoint group, the number of endpoints included in the second endpoint group, and the number of endpoints included in the third endpoint group respectively.
[0066] After grouping in S203, a first endpoint group, a second endpoint group and a third endpoint group are obtained, each endpoint group includes a plurality of first endpoints, and then the number of endpoints included in each group is counted.
[0067] The counter is used to traverse the first endpoint included in the first endpoint group. After the traversal is completed, the counter value is used as the number of endpoints n1 included in the first endpoint group. The counter is used to traverse the first endpoint included in the second endpoint group. After the traversal is completed, the counter value is used as the number of endpoints n2 included in the second endpoint group. The counter is used to traverse the first endpoint included in the third endpoint group. After the traversal is completed, the counter value is used as the number of endpoints n3 included in the third endpoint group.
[0068] S205: The endpoint group with the largest number of endpoints is used as the target endpoint group.
[0069] The number of endpoints in each group is compared, and the endpoint group with the largest number of endpoints is selected. Specifically, the number of endpoints n1 included in the first endpoint group, the number of endpoints n2 included in the second endpoint group, and the number of endpoints n3 included in the third endpoint group are compared, and the endpoint group with the largest number of endpoints is selected as the target endpoint group.
[0070] For example: if the number of endpoints n3 included in the third endpoint group is greater than the number of endpoints n1 included in the first endpoint group, and greater than the number of endpoints n2 included in the second endpoint group, then the third endpoint group is the endpoint group with the largest number of endpoints, and the third endpoint group is used as the target endpoint group.
[0071] S206: Fit each current endpoint in the target endpoint group to obtain a first straight line.
[0072] After the target endpoint group is determined in S205, the target endpoint group includes a plurality of first endpoints whose coordinates are known, and the coordinates of each first endpoint in the target endpoint group are fitted to obtain the expression of the first straight line. For example, the least squares method can be used to implement the fitting process.
[0073] Specifically, the coordinates of each first endpoint in the target endpoint group are (xi, yi) where i = 1, 2, ..., n; we hope to find a straight line y = ax + b so that this line can best fit these points. Define an error function E(a, b) as the sum of the squares of the vertical distances from all first endpoints to the straight line y = ax + b, and find a and b so that E(a, b) is minimized. To this end, take the partial derivative of E(a, b) with respect to a and b and set it equal to zero. The above condition that the partial derivative is zero can be rewritten as a system of linear equations. The linear equations are sorted and solved to obtain the slope a and intercept b of the first straight line. That is, the expression of the first straight line L1 is obtained.
[0074] S207: Classify the current endpoint whose distance to the first straight line is less than the first set threshold into the fourth endpoint group.
[0075] The distance between the first endpoint of each line segment and the first straight line L1 is calculated. The distance between the first endpoint and the first straight line L1 may be a perpendicular distance from the first endpoint to the first straight line L1.
[0076] Based on the coordinate values of the first endpoints of each line segment, the straight line expression of the first straight line L1, and the point-to-line distance formula, the distance between the first endpoints of each line segment and the first straight line L1 is calculated.
[0077] The distance between each first endpoint and the first straight line L1 is compared with the first set threshold value, and the first endpoints whose distance is greater than or equal to the first set threshold value are classified into the fourth endpoint group. In other words, the distance between the first endpoints included in the fourth endpoint group and the first straight line L1 is greater than or equal to the first set threshold value.
[0078] S208. Count the number of endpoints included in the fourth endpoint group.
[0079] The counter is used to traverse the first endpoints included in the fourth endpoint group. After the traversal is completed, the counter value is used as the number n4 of endpoints included in the fourth endpoint group.
[0080] S209: Fit the current endpoints included in the fourth endpoint group to obtain a second straight line.
[0081] The fourth endpoint group includes a plurality of first endpoints, the coordinates of which are known. The coordinates of each first endpoint in the fourth endpoint group are fitted to obtain an expression of the second straight line L2. For example, the least squares method can be used to implement the fitting process. For the specific process, refer to the fitting process of the first straight line, which will not be described in detail in the embodiments of the present application.
[0082] S210, classify the current endpoint whose distance to the second straight line is less than a first set threshold into the fifth endpoint group.
[0083] The distance between the first endpoint of each line segment and the second straight line L2 is calculated. The distance between the first endpoint and the second straight line L2 may be a perpendicular distance from the first endpoint to the second straight line L2.
[0084] Based on the coordinate values of the first endpoints of each line segment, the straight line expression of the second straight line L2, and the point-to-line distance formula, the distance between each first endpoint and the second straight line L2 is calculated.
[0085] The distance between each first endpoint and the second straight line L2 is compared with the first set threshold value, and the first endpoints whose distance is greater than or equal to the first set threshold value are classified into the fifth endpoint group. In other words, the distance between the first endpoints included in the fifth endpoint group and the second straight line L2 is greater than or equal to the first set threshold value.
[0086] S211. Count the number of endpoints included in the fifth endpoint group.
[0087] The counter is used to traverse the first endpoints included in the fifth endpoint group. After the traversal is completed, the counter value is used as the number n5 of endpoints included in the fourth endpoint group.
[0088] S212: Determine whether the difference between the number of endpoints included in the fourth endpoint group and the number of endpoints included in the fifth endpoint group is greater than a set value. If so, execute S213; if not, execute S214.
[0089] The set value is mainly used to indicate the difference between the number of endpoints n4 included in the fourth endpoint group and the number of endpoints n5 included in the fifth endpoint group. The set value can be set according to actual conditions, for example, the set value can be 1 or 2.
[0090] The number of endpoints n4 included in the fourth endpoint group is subtracted from the number of endpoints n5 included in the fifth endpoint group to obtain a difference between the two. If the difference between the two is less than or equal to the set value, it indicates that the number of endpoints n4 included in the fourth endpoint group and the number of endpoints n5 included in the fifth endpoint group are relatively close and the difference is not large. If the difference between the two is greater than the set value, it indicates that the number of endpoints n4 included in the fourth endpoint group and the number of endpoints n5 included in the fifth endpoint group are greatly different.
[0091] S213, taking the second straight line as the first straight line and the fifth endpoint group as the fourth endpoint group, and returning to execute S209.
[0092] If the difference between the two is less than or equal to the set value, it indicates that the number of endpoints n4 included in the fourth endpoint group is greatly different from the number of endpoints n5 included in the fifth endpoint group, indicating that the second straight line is not a straight line within the set area, and the second straight line L2 is not suitable as the target classification line of the first endpoint. Therefore, it is necessary to use the second straight line as a new first straight line, the fifth endpoint group as a new fourth endpoint group, fit the first endpoints included in the new fourth endpoint group, obtain a new second straight line, and perform subsequent steps.
[0093] Until the difference between the number of endpoints included in the fourth endpoint group and the number of endpoints included in the fifth endpoint group is less than or equal to the set value, the appropriate target classification line of the first endpoint is determined.
[0094] S214. Use the second straight line as the target classification line of the current endpoint.
[0095] If the difference between the two is less than or equal to the set value, it indicates that the number of endpoints n4 included in the fourth endpoint group is relatively close to the number of endpoints n5 included in the fifth endpoint group, and the difference is not large, which indicates that the second straight line is a straight line within the set area, and the second straight line L2 can be used as the target classification line of the first endpoint.
[0096] In an embodiment of the present application, a method for determining a target classification line of a first endpoint is provided, which can efficiently and quickly determine the classification line of the endpoint, so as to quickly determine the length of the line segment.
[0097] S104: Determine the state of each first endpoint based on the positional relationship between the position of each first endpoint and the target classification line of the first endpoint.
[0098] In one possible implementation, the state of each first endpoint is determined based on the positional relationship between each first endpoint and the target classification line of the first endpoint, including: for the first endpoint of each line segment, if the first endpoint is on the first side of the target classification line of the first endpoint, the first endpoint is determined to be in the first state, and the first side of the target classification line of the first endpoint refers to the side of the target classification line of the first endpoint away from the second endpoint; if the first endpoint is on the second side of the target classification line of the first endpoint, the first endpoint is determined to be in the second state; the second side of the target classification line of the first endpoint refers to the side of the target classification line of the first endpoint close to the second endpoint.
[0099] The first side of the target classification line of the first endpoint and the second side of the target classification line of the first endpoint refer to both sides of the target classification line of the first endpoint, such as Figure 2 As shown, the first side of the target classification line of the first endpoint is the upper side of the target classification line of the first endpoint, and the second side of the target classification line of the first endpoint is the lower side of the target classification line of the first endpoint. Alternatively, the first side of the target classification line of the first endpoint is the lower side of the target classification line of the first endpoint, and the second side of the target classification line of the first endpoint is the upper side of the target classification line of the first endpoint. The two sides of the classification line can be divided and determined according to actual conditions, and are not specifically limited in the embodiments of the present application.
[0100] The first state and the second state can be understood as two different states of the first endpoint. For example, in the embodiment of the present application, the first state is 0 in binary and the second state is 1 in binary for example.
[0101] For example, if the first endpoint of each line segment is above the target classification line of the first endpoint, the state of the first endpoint is recorded as 0; if the first endpoint of each line segment is below the target classification line of the first endpoint, the state of the first endpoint is recorded as 1. Figure 2 As shown, the state of the first endpoint of the first line segment 21 is 0, the state of the first endpoint of the second line segment 22 is 1, the state of the first endpoint of the third line segment 23 is 0, the state of the first endpoint of the fourth line segment 24 is 0, the state of the first endpoint of the fifth line segment 25 is 1, the state of the first endpoint of the sixth line segment 26 is 0, and the state of the first endpoint of the seventh line segment 27 is 1.
[0102] S105. Determine the state of each line segment based on the state of the first endpoint of each line segment.
[0103] In one possible implementation, the state of each line segment is determined by the state of the first endpoint of each line segment, including: when the barcode is a binary barcode, for each line segment, if the first endpoint of the line segment is in the first state, then the state of the line segment is determined to be the first state; if the first endpoint of the line segment is in the second state, then the state of the line segment is determined to be the second state.
[0104] When the barcode in the barcode image to be identified is a binary barcode, since the second endpoints of the binary barcode are on the same straight line and represent the same state, the state of the first endpoint of each line segment is directly used as the state of each line segment. For example: for each line segment, if the first endpoint is above the target classification line of the first endpoint, the state of the first endpoint is recorded as 1, and accordingly, the state of the line segment is 1. If the first endpoint is below the target classification line of the first endpoint, the state of the first endpoint is recorded as 0, and accordingly, the state of the line segment is 0.
[0105] like Figure 2 As shown, the state of the first line segment 21 is 0, the state of the second line segment 22 is 1, the state of the third line segment 23 is 0, the state of the fourth line segment 24 is 0, the state of the fifth line segment 25 is 1, the state of the sixth line segment 26 is 0, and the state of the seventh line segment 27 is 1.
[0106] S106: Decode based on the status of each line segment to obtain a recognition result of the barcode image to be recognized.
[0107] After determining the status of each line segment, the status of each line segment is combined according to the arrangement order of the line segments in the barcode to obtain the status of the barcode to be identified, for example: Figure 2 The status of the barcode shown is 0100101.
[0108] After determining the status of the barcode to be identified, you can decode it according to the preset barcode rules. For example: the first digit is the identification digit, and the following digits are grouped into three and translated according to the binary rule. Figure 2 The decoding result after the barcode is shown is: 45. It should be noted that, in the embodiment of the present application, only the decoding is described. The specific barcode rules can be set according to the actual situation.
[0109] The embodiment of the present application provides a method, device, equipment and storage medium for identifying a barcode image, the method comprising: obtaining a barcode image to be identified, the barcode image to be identified includes a plurality of parallel line segments; identifying the position of the first endpoint of each line segment; determining the target classification line of the first endpoint according to a set rule; determining the state of each first endpoint based on the positional relationship between the position of each first endpoint and the target classification line of the first endpoint; determining the state of each line segment based on the state of the first endpoint of each line segment; decoding based on the state of each line segment to obtain the identification result of the barcode image to be identified. The characteristic that the endpoints on one side of the barcode are simultaneously located on one or two straight lines is utilized to efficiently determine the state of each line segment of the barcode, thereby realizing rapid decoding of the barcode with good recognition accuracy.
[0110] On the basis of the above embodiments, the barcode image recognition method is further optimized in the embodiments of the present application. Figure 4 As shown, the optimized barcode image recognition method mainly includes steps S301-S309.
[0111] In the embodiment of the present application, a process for recognizing a quaternary barcode image is introduced.
[0112] S301, obtaining a barcode image to be identified, wherein the barcode image to be identified includes a plurality of parallel line segments.
[0113] The quaternary barcode provided in the embodiments of the present application refers to a barcode encoding method in which the barcode (line segment) width is the same but the barcode length is different. The quaternary barcode is composed of line segments of 3 lengths, and the line segments are combined in parallel. Based on the position of the line segments, the quaternary barcode can be divided into 4 states. The line segment with the longest length is recorded as state 0; the line segment with the shortest length is recorded as state 3; the line segment protruding upward is composed of an upper endpoint on the upper side and a lower endpoint on the upper side, recorded as state 1; the line segment protruding downward is composed of an upper endpoint on the lower side and a lower endpoint on the lower side, recorded as state 2. Figure 5 As shown, the first line segment 51 is recorded as state 1, the second line segment 52 is recorded as state 2, the third line segment 53 is recorded as state 3, and the fourth line segment 54 is recorded as state 0.
[0114] S302: Identify the position of the first endpoint of each line segment.
[0115] The barcode image to be identified includes multiple line segments arranged in parallel, and the lengths of the line segments are different. In a quaternary barcode, the first endpoint of a line segment can be an endpoint on any specified side. For example: when the quaternary barcode is placed horizontally, the first endpoint of the line segment can refer to the upper endpoint of the line segment, and when the quaternary barcode is placed vertically, the first endpoint of the line segment can refer to the left endpoint of the line segment.
[0116] S302 provided in the embodiment of the present application is the same as the S102 process in the above embodiment. For details, please refer to the description in the above embodiment, which will not be repeated in the embodiment of the present application.
[0117] S303: Identify the position of the second endpoint of each line segment.
[0118] Depend on Figure 5 It can be seen that the barcode image to be identified includes multiple parallel line segments, and the lengths of the line segments are different. In the quaternary barcode, the second endpoint of the line segment refers to the endpoint opposite to the first endpoint of the line segment. In other words, the second endpoint of the line segment refers to the endpoint other than the first endpoint of the line segment. For example: Figure 5 The upper endpoints of the first line segment 51, the second line segment 52, the third line segment 53, and the fourth line segment 54 are the first endpoints. The lower endpoints of the first line segment 51, the second line segment 52, the third line segment 53, and the fourth line segment 54 are the second endpoints.
[0119] The position of the second endpoint refers to the position parameter of the second endpoint in the barcode image to be identified, and the position parameter can be marked by coordinates. Further, the position of the second endpoint can be represented by the coordinates of the pixel point of the second endpoint in the barcode image to be identified.
[0120] The method for identifying the position of the second endpoint of a line segment is consistent with the method for identifying the position of the first endpoint of a line segment. For details, please refer to the description in the above embodiment, and will not be repeated in the embodiments of the present application.
[0121] S304: Determine the target classification line of the first endpoint according to the set rule.
[0122] S304 provided in the embodiment of the present application is the same as the S103 process in the above embodiment. For details, please refer to the description in the above embodiment, which will not be repeated in the embodiment of the present application.
[0123] S305: Determine the target classification line of the second endpoint according to the set rule.
[0124] First, an initial classification line of the second endpoint is obtained. The initial classification line of the second endpoint is obtained by connecting the second endpoint of the first line segment and the second endpoint of the last line segment in a plurality of parallel line segments.
[0125] The first line segment is the first line segment in the barcode image, such as Figure 6 The first line segment 61 in the barcode image, and the last line segment is the last line segment at the end of the barcode image, such as Figure 6 The second endpoint of the first line segment 61 is connected to the second endpoint of the last line segment 62 to obtain an initial classification line 63 of the second endpoint.
[0126] The distance between each second endpoint and the initial classification line 63 of the second endpoint is calculated. The distance between the second endpoint and the initial classification line 63 of the second endpoint may be a perpendicular distance from the second endpoint to the initial classification line. Based on the coordinate value of the second endpoint of the first line segment and the coordinate value of the second endpoint of the last line segment, the straight line expression of the initial classification line 63 of the second endpoint is determined. Based on the coordinate value of each second endpoint, the straight line expression of the initial classification line 63 of the second endpoint, and the point-to-line distance formula, the distance between each second endpoint and the initial classification line 63 of the second endpoint is calculated.
[0127] After calculating the distance between each second endpoint and the initial classification line 63 with the second endpoint, the distance between each second endpoint and the initial classification line 63 with the second endpoint is compared with the first set threshold, and the second endpoint whose distance is greater than or equal to the first set threshold is classified into the first endpoint group. The second endpoint whose distance is less than or equal to the second set threshold is classified into the second endpoint group. The second endpoint whose distance is less than the first set threshold and greater than the second set threshold is classified into the third endpoint group.
[0128] In other words, the distance between the second endpoint included in the second endpoint group and the initial classification line is greater than or equal to the first set threshold, the distance between the second endpoint included in the second endpoint group and the initial classification line is less than or equal to the second set threshold, and the distance between the second endpoint included in the third endpoint group and the initial classification line is less than the first set threshold and greater than the second set threshold.
[0129] The counter is used to traverse the second endpoints included in the second endpoint group. After the traversal is completed, the counter value is used as the number of endpoints n1 included in the second endpoint group. The counter is used to traverse the second endpoints included in the second endpoint group. After the traversal is completed, the counter value is used as the number of endpoints n2 included in the second endpoint group. The counter is used to traverse the second endpoints included in the third endpoint group. After the traversal is completed, the counter value is used as the number of endpoints n3 included in the third endpoint group.
[0130] The number of endpoints in each group is compared, and the endpoint group with the largest number of endpoints is selected as the target endpoint group.
[0131] The target endpoint group includes multiple second endpoints, and the coordinates of the second endpoints are known. The coordinates of the second endpoints in the target endpoint group are fitted to obtain the expression of the first straight line L1. For example, the least squares method can be used to implement the fitting process.
[0132] Calculate the distance between each second endpoint and the first straight line L1. The distance between the second endpoint and the first straight line L1 can be the perpendicular distance from the second endpoint to the first straight line L1. Calculate the distance between each second endpoint and the first straight line L1 based on the coordinate values of each second endpoint, the straight line expression of the first straight line L1, and the point-to-line distance formula. Compare the distance between each second endpoint and the first straight line L1 with the first set threshold value, and classify the second endpoints whose distance is greater than or equal to the first set threshold value into the fourth endpoint group. In other words, the distance between the second endpoints included in the fourth endpoint group and the first straight line L1 is greater than or equal to the first set threshold value.
[0133] The counter is used to traverse the second endpoints included in the fourth endpoint group. After the traversal is completed, the counter value is used as the number n4 of endpoints included in the fourth endpoint group.
[0134] The fourth endpoint group includes a plurality of second endpoints, the coordinates of which are known, and the coordinates of each second endpoint in the fourth endpoint group are fitted to obtain an expression of the second straight line L2. For example, the least squares method can be used to implement the fitting process.
[0135] The distance between each second endpoint and the second straight line L2 is calculated. The distance between the second endpoint and the second straight line L2 may be a perpendicular distance from the second endpoint to the second straight line L2. The distance between each second endpoint and the second straight line L2 is calculated based on the coordinate values of each second endpoint, the straight line expression of the second straight line L2, and the point-to-line distance formula.
[0136] The distance between each second endpoint and the second straight line L2 is compared with the first set threshold, and the second endpoints whose distance is greater than or equal to the first set threshold are classified into the fifth endpoint group.
[0137] The counter is used to traverse the second endpoints included in the fifth endpoint group. After the traversal is completed, the counter value is used as the number n5 of endpoints included in the fourth endpoint group.
[0138] Determine whether the difference between the number of endpoints included in the fourth endpoint group and the number of endpoints included in the fifth endpoint group is greater than the set value. If so, take the second straight line as the first straight line, the fifth endpoint group as the fourth endpoint group, and return to execute fitting the current endpoint included in the fourth endpoint group to obtain the second straight line. If not, take the second straight line as the classification line of the current endpoint.
[0139] The number of endpoints n4 included in the fourth endpoint group is subtracted from the number of endpoints n5 included in the fifth endpoint group to obtain the difference between the two. If the difference between the two is less than or equal to the set value, it indicates that the number of endpoints n4 included in the fourth endpoint group is greatly different from the number of endpoints n5 included in the fifth endpoint group, which indicates that the second straight line is not a straight line within the set area, and the second straight line L2 is not suitable as the target classification line of the second endpoint. Therefore, it is necessary to use the second straight line as a new first straight line, the fifth endpoint group as a new fourth endpoint group, fit the second endpoint included in the new fourth endpoint group, obtain a new second straight line, and perform subsequent steps. Until the difference between the number of endpoints included in the fourth endpoint group and the number of endpoints included in the fifth endpoint group is less than or equal to the set value, the target classification line of the appropriate second endpoint is determined.
[0140] If the difference between the two is less than or equal to the set value, it indicates that the number of endpoints n4 included in the fourth endpoint group is relatively close to the number of endpoints n5 included in the fifth endpoint group, and the difference is not large, which indicates that the second straight line is a straight line within the set area, and the second straight line L2 can be used as the target classification line of the second endpoint.
[0141] In an embodiment of the present application, a method for determining a target classification line of a second endpoint is provided, which can efficiently and quickly determine the classification line of the endpoint, so as to quickly determine the length of the line segment.
[0142] S306: Determine the state of each first endpoint based on the positional relationship between the position of each first endpoint and the target classification line of the first endpoint.
[0143] S306 provided in the embodiment of the present application is the same as the S104 process in the above embodiment. For details, please refer to the description in the above embodiment, which will not be repeated in the embodiment of the present application.
[0144] S307: Determine the state of each second endpoint based on the positional relationship between the position of each second endpoint and the target classification line of the second endpoint.
[0145] In one possible implementation, the state of each second endpoint is determined based on the positional relationship between each second endpoint and the target classification line of the second endpoint, including: for the second endpoint of each line segment, if the second endpoint is on the first side of the target classification line of the second endpoint, the second endpoint is determined to be in the second state; the first side of the target classification line of the second endpoint refers to the side of the target classification line of the second endpoint away from the first endpoint; if the second endpoint is on the second side of the target classification line of the second endpoint, the second endpoint is determined to be in the first state; the second side of the target classification line of the second endpoint refers to the side of the target classification line of the second endpoint close to the first endpoint.
[0146] The first state and the second state can be understood as two different states of the second endpoint. For example, in the embodiment of the present application, the first state is 0 in binary and the second state is 1 in binary for example.
[0147] For example: for the second endpoint of each line segment, if the second endpoint is above the target classification line of the second endpoint, the state of the first endpoint is recorded as 1; for the second endpoint of each line segment, if the second endpoint is below the target classification line of the second endpoint, the state of the first endpoint is recorded as 0.
[0148] Further, such as Figure 7a As shown, the first endpoint on the upper side of the target classification line of the first endpoint is connected to obtain the state 0 line 71 of the first endpoint, and the states of all the first endpoints on the state 0 line 71 of the first endpoint are state 0. The first endpoint on the lower side of the target classification line of the first endpoint is connected to obtain the state 1 line 72 of the first endpoint, and the states of all the first endpoints on the state 1 line 72 of the first endpoint are state 1.
[0149] like Figure 7b As shown, the second endpoint on the upper side of the target classification line of the second endpoint is connected to obtain the state 0 line 73 of the second endpoint, and the states of all second endpoints on the state 0 line 73 of the second endpoint are state 0. The second endpoint on the lower side of the target classification line of the second endpoint is connected to obtain the state 1 line 74 of the second endpoint, and the states of all second endpoints on the state 1 line 74 of the second endpoint are state 1.
[0150] S308. Merge the state of the first endpoint and the state of the second endpoint of each line segment to obtain the state of the line segment.
[0151] In the embodiments of the present application, Figure 5 As shown, there are 4 states of the line segment, the first line segment 51 is recorded as state 1, the second line segment 52 is recorded as state 2, the third line segment 53 is recorded as state 3, and the fourth line segment 54 is recorded as state 0. State 0 represents the longest line segment, state 3 represents the shortest line segment, state 1 represents a line segment of medium length and protruding upward, and state 2 represents a line segment of medium length and protruding downward.
[0152] The state of the first endpoint and the state of the second endpoint of each line segment are combined to obtain the state of each line segment, including: when the barcode is a quaternary barcode, for each line segment, if the first endpoint of the line segment is in the first state and the second endpoint is in the first state, then the state of the line segment is determined to be the first state; if the first endpoint of the line segment is in the first state and the second endpoint is in the second state, then the state of the line segment is determined to be the second state; if the first endpoint of the line segment is in the second state and the second endpoint is in the first state, then the state of the line segment is determined to be the third state; if the first endpoint of the line segment is in the second state and the second endpoint is in the second state, then the state of the line segment is determined to be the fourth state.
[0153] The first state can be Figure 5 The state 0 shown in FIG. 1 and the second state can be Figure 5 The third state can be Figure 5 The fourth state can be Figure 5 The state shown in 3.
[0154] Specifically, if the state of the first endpoint of the line segment is 0 and the state of the second endpoint is 0, then the state of the line segment is determined to be 0; if the state of the first endpoint of the line segment is 0 and the state of the second endpoint is 1, then the state of the line segment is determined to be 1; if the state of the first endpoint of the line segment is 1 and the state of the second endpoint is 1, then the state of the line segment is determined to be 3; if the state of the first endpoint of the line segment is 1 and the state of the second endpoint is 0, then the state of the line segment is determined to be 2.
[0155] Furthermore, the state of the line segment can also be calculated according to the following formula.
[0156] V=2×V1+V2.
[0157] Among them, V represents the state of the line segment, V1 represents the state of the first endpoint of the line segment, and V2 represents the state of the second endpoint of the line segment.
[0158] It should be noted that in the embodiments of the present application, only the first state, the second state, the third state and the fourth state are exemplarily described. In practical applications, other practical meanings can be given to the above states according to actual conditions.
[0159] S309: Decode based on the status of each line segment to obtain a recognition result of the barcode image to be recognized.
[0160] After determining the status of each line segment, the status of each line segment is combined according to the arrangement order of the line segments in the barcode to obtain the status of the barcode to be identified, for example: Figure 6 The status of the barcode shown is 1301011030302.
[0161] After determining the state of the barcode to be identified, decoding can be performed according to the preset barcode rules. In the embodiment of the present application, only decoding is described. The specific barcode rules can be set according to the actual situation.
[0162] The embodiment of the present application provides a method, device, equipment and storage medium for identifying a barcode image, the method comprising: obtaining a barcode image to be identified, the barcode image to be identified includes a plurality of parallel line segments; identifying the position of the first endpoint of each line segment; identifying the position of the second endpoint of each line segment, determining the target classification line of the first endpoint according to a set rule; determining the target classification line of the second endpoint according to the set rule, determining the state of each first endpoint based on the positional relationship between the position of each first endpoint and the target classification line of the first endpoint; determining the state of each second endpoint based on the positional relationship between the position of each second endpoint and the target classification line of the second endpoint; merging the state of the first endpoint of each line segment with the state of the second endpoint to obtain the state of the line segment; decoding based on the state of each line segment to obtain the recognition result of the barcode image to be identified. The characteristic that the single-side endpoint of the barcode is located on one or two straight lines at the same time is utilized to efficiently determine the state of each line segment of the barcode, thereby realizing fast decoding of the barcode with good recognition accuracy.
[0163] Figure 8 FIG. 1 is a schematic diagram of a barcode image recognition device in an embodiment of the present application. Figure 8 As shown, the barcode image recognition device 80 provided in the embodiment of the present application mainly includes: an image acquisition module 81, an endpoint position recognition module 82, a classification line determination module 83, an endpoint state determination module 84, a line segment state determination module 85 and a state decoding module 86.
[0164] Among them, the image acquisition module 81 is used to acquire the barcode image to be identified, which includes multiple parallel line segments; the endpoint position identification module 82 is used to identify the position of the first endpoint of each line segment; the classification line determination module 83 is used to determine the target classification line of the first endpoint according to the set rules; the endpoint state determination module 84 is used to determine the state of each first endpoint based on the positional relationship between the position of each first endpoint and the target classification line of the first endpoint; the line segment state determination module 85 is used to determine the state of each line segment based on the state of the first endpoint of each line segment; the state decoding module 86 is used to decode based on the state of each line segment to obtain the recognition result of the barcode image to be identified.
[0165] The embodiment of the present application provides a barcode image recognition device, which is mainly used to execute the following process: obtain a barcode image to be recognized, which includes multiple parallel line segments; recognize the position of the first endpoint of each line segment; determine the target classification line of the first endpoint according to the set rules; determine the state of each first endpoint based on the positional relationship between the position of each first endpoint and the target classification line of the first endpoint; determine the state of each line segment based on the state of the first endpoint of each line segment; decode based on the state of each line segment to obtain the recognition result of the barcode image to be recognized. The characteristic that the single-side endpoint of the barcode is located on one or two straight lines at the same time is utilized to efficiently determine the state of each line segment of the barcode, thereby realizing fast decoding of the barcode with good recognition accuracy.
[0166] In a possible implementation, the endpoint position identification module 82 is also used to identify the position of the second endpoint of each line segment; the classification line determination module 83 is also used to determine the target classification line of the second endpoint according to the set rules; the endpoint state determination module 84 is also used to determine the state of each second endpoint based on the positional relationship between the position of each second endpoint and the target classification line of the second endpoint; the line segment state determination module 85 is specifically used to merge the state of the first endpoint of each line segment with the state of the second endpoint to obtain the state of the line segment.
[0167] In a possible implementation, the classification line determination module 83 is specifically used to determine the initial classification line of the current endpoint, the current endpoint includes the first endpoint or the second endpoint; calculate the distance between each current endpoint and the initial classification line; based on the distance between each current endpoint and the initial classification line, group the current endpoint to obtain a first endpoint group, a second endpoint group and a third endpoint group, wherein the first endpoint group includes: the current endpoint whose distance from the initial classification line is greater than or equal to a first set threshold, the second endpoint group includes: the current endpoint whose distance from the initial classification line is less than or equal to a second set threshold, and the third endpoint group includes: the current endpoint whose distance from the initial classification line is less than the first set threshold and greater than the second set threshold; respectively count the number of endpoints included in the first endpoint group, the number of endpoints included in the second endpoint group, and the number of endpoints included in the third endpoint group; and take the endpoint group with the largest number of endpoints as the target endpoint group ; Fit each current endpoint in the target endpoint group to obtain a first straight line; classify the current endpoint whose distance to the first straight line is less than a first set threshold into the fourth endpoint group; count the number of endpoints included in the fourth endpoint group; fit the current endpoint included in the fourth endpoint group to obtain a second straight line; classify the current endpoint whose distance to the second straight line is less than a first set threshold into the fifth endpoint group; count the number of endpoints included in the fifth endpoint group; if the difference between the number of endpoints included in the fourth endpoint group and the number of endpoints included in the fifth endpoint group is greater than a set value, then take the second straight line as the first straight line, the fifth endpoint group as the fourth endpoint group, and return to execute the step of fitting the current endpoint included in the fourth endpoint group to obtain a second straight line; until the difference between the number of endpoints included in the fourth endpoint group and the number of endpoints included in the fifth endpoint group is less than or equal to the set value, then take the second straight line as the classification line of the current endpoint.
[0168] In one possible implementation, when the current endpoint includes the first endpoint, the initial classification line of the first endpoint is obtained by connecting the first endpoint of the first line segment among multiple parallel line segments and the first endpoint of the last line segment; when the current endpoint includes the second endpoint, the initial classification line of the second endpoint is obtained by connecting the second endpoint of the first line segment among multiple parallel line segments and the second endpoint of the last line segment.
[0169] In a possible implementation, the second set threshold is the inverse of the first set threshold, and the first set threshold is in direct proportion to the distance between adjacent line segments.
[0170] In one possible implementation, the endpoint state determination module 84 is specifically used to determine, for the first endpoint of each line segment, that the first endpoint is in the first state if the first endpoint is on the first side of the target classification line of the first endpoint, and the first side of the target classification line of the first endpoint refers to the side of the target classification line of the first endpoint away from the second endpoint; if the first endpoint is on the second side of the target classification line of the first endpoint, then the first endpoint is determined to be in the second state; the second side of the target classification line of the first endpoint refers to the side of the target classification line of the first endpoint close to the second endpoint.
[0171] In one possible implementation, the endpoint state determination module 84 is specifically used to determine, for the second endpoint of each line segment, that the second endpoint is in the second state if the second endpoint is on the first side of the target classification line of the second endpoint; the first side of the target classification line of the second endpoint refers to the side of the target classification line of the second endpoint away from the first endpoint; if the second endpoint is on the second side of the target classification line of the second endpoint, the second endpoint is determined to be in the first state; the second side of the target classification line of the second endpoint refers to the side of the target classification line of the second endpoint close to the first endpoint.
[0172] In a possible implementation, the line segment state determination module 85 is specifically configured to, when the barcode is a binary barcode, for each line segment, if the first endpoint of the line segment is in the first state, determine that the state of the line segment is the first state;
[0173] If the first endpoint of the line segment is in the second state, it is determined that the state of the line segment is the second state.
[0174] In one possible implementation, the line segment state determination module 85 is specifically used to, when the barcode is a quaternary barcode, for each line segment, if the first endpoint of the line segment is in the first state and the second endpoint is in the first state, determine that the state of the line segment is the first state; if the first endpoint of the line segment is in the first state and the second endpoint is in the second state, determine that the state of the line segment is the second state; if the first endpoint of the line segment is in the second state and the second endpoint is in the first state, determine that the state of the line segment is the third state; if the first endpoint of the line segment is in the second state and the second endpoint is in the second state, determine that the state of the line segment is the fourth state.
[0175] The barcode image recognition device provided in the embodiment of the present application can execute the barcode image recognition method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0176] Fig. 9 is a schematic diagram of the structure of an electronic device provided in this embodiment. The electronic device may include a barcode image recognition device, such as Fig. 9As shown, the electronic device 900 includes a processor 910, a memory 920, an input device 930, and an output device 940; the number of the processor 910 in the electronic device can be one or more. Fig. 9 A processor 910 is taken as an example; the processor 910, the memory 920, the input device 930 and the output device 940 in the electronic device can be connected via a bus or other means. Fig. 9 The example of connecting through bus is taken in the following.
[0177] The memory 920 is a computer-readable storage medium that can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the barcode image recognition method in the embodiment of the present invention. The processor 910 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 920, that is, implements the barcode image recognition method provided in the embodiment of the present invention.
[0178] The memory 920 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 920 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 920 may further include a memory remotely arranged relative to the processor 910, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0179] The input device 930 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the electronic device, and may include a keyboard, a mouse, etc. The output device 940 may include a display device such as a display screen.
[0180] This embodiment further provides a storage medium containing computer executable instructions, and when the computer executable instructions are executed by a computer processor, they are used to implement the barcode image recognition method provided by the embodiment of the present invention.
[0181] Of course, the computer executable instructions of a storage medium including computer executable instructions provided by an embodiment of the present invention are not limited to the operations of the method described above, and can also execute related operations in the barcode image recognition method provided by any embodiment of the present invention.
[0182] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0183] It is worth noting that in the embodiment of the above-mentioned barcode image recognition device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0184] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0185] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A barcode image recognition method, characterized in that: The method comprises: Acquire a barcode image to be identified, wherein the barcode image to be identified includes a plurality of parallel line segments; identifying the position of the first endpoint of each of the line segments; Determine a target classification line of the first endpoint according to a set rule; determining the state of each of the first endpoints based on a positional relationship between the position of each of the first endpoints and a target classification line of the first endpoint; Determining the state of each of the line segments based on the state of the first endpoint of each of the line segments; Decoding is performed based on the states of the line segments to obtain a recognition result of the barcode image to be recognized.
2. The method according to claim 1, characterized in that Before determining the state of each of the line segments based on the state of the first endpoint of each of the line segments, the method further includes: identifying the position of the second endpoint of each of the line segments; Determine the target classification line of the second endpoint according to the set rule; determining the state of each of the second endpoints based on a positional relationship between the position of each of the second endpoints and a target classification line of the second endpoint; Determining the state of each of the line segments based on the state of the first endpoint of each of the line segments includes: The state of the first endpoint of each of the line segments is combined with the state of the second endpoint to obtain the state of the line segment.
3. The method according to claim 1 or 2, characterized in that: The setting rules include: determining an initial classification line of a current endpoint, the current endpoint comprising a first endpoint or a second endpoint; Calculating the distance between each of the current endpoints and the initial classification line; Based on the distance between each of the current endpoints and the initial classification line, the current endpoints are grouped to obtain a first endpoint group, a second endpoint group and a third endpoint group, wherein the first endpoint group includes: current endpoints whose distance from the initial classification line is greater than or equal to a first set threshold, the second endpoint group includes: current endpoints whose distance from the initial classification line is less than or equal to a second set threshold, and the third endpoint group includes: current endpoints whose distance from the initial classification line is less than the first set threshold and greater than the second set threshold; Respectively counting the number of endpoints included in the first endpoint group, the number of endpoints included in the second endpoint group, and the number of endpoints included in the third endpoint group; The endpoint group with the largest number of endpoints is used as the target endpoint group; Fitting each current endpoint in the target endpoint group to obtain a first straight line; Classify the current endpoint whose distance to the first straight line is less than the first set threshold into the fourth endpoint group; Counting the number of endpoints included in the fourth endpoint group; Fitting the current endpoints included in the fourth endpoint group to obtain a second straight line; Classify the current endpoint whose distance to the second straight line is less than the first set threshold into the fifth endpoint group; Counting the number of endpoints included in the fifth endpoint group; If the difference between the number of endpoints included in the fourth endpoint group and the number of endpoints included in the fifth endpoint group is greater than a set value, the second straight line is used as the first straight line, the fifth endpoint group is used as the fourth endpoint group, and the step of fitting the current endpoints included in the fourth endpoint group to obtain the second straight line is returned; Until the difference between the number of endpoints included in the fourth endpoint group and the number of endpoints included in the fifth endpoint group is less than or equal to the set value, the second straight line is used as the target classification line of the current endpoint.
4. The method according to claim 3, characterized in that When the current endpoint includes the first endpoint, the initial classification line of the first endpoint is obtained by connecting the first endpoint of the first line segment and the first endpoint of the last line segment among the multiple parallel line segments; When the current endpoint includes the second endpoint, the initial classification line of the second endpoint is obtained by connecting the second endpoint of the first line segment and the second endpoint of the last line segment among the multiple parallel line segments.
5. The method according to claim 3, characterized in that: The second set threshold is the inverse of the first set threshold, and the first set threshold is in direct proportion to the distance between adjacent line segments.
6. The method according to claim 2, characterized in that Determining the state of each of the first endpoints based on a positional relationship between each of the first endpoints and a target classification line of the first endpoint includes: For the first endpoint of each of the line segments, if the first endpoint is on a first side of a target classification line of the first endpoint, determining that the first endpoint is in a first state, wherein the first side of the target classification line of the first endpoint refers to a side of the target classification line of the first endpoint that is away from the second endpoint; If the first endpoint is on the second side of the target classification line with the first endpoint, the first endpoint is determined to be in the second state; the second side of the target classification line of the first endpoint refers to a side of the target classification line of the first endpoint close to the second endpoint; Accordingly, determining the state of each second endpoint based on the positional relationship between each second endpoint and the target classification line of the second endpoint includes: For the second endpoint of each line segment, if the second endpoint is on the first side of the target classification line of the second endpoint, the second endpoint is determined to be in the second state; the first side of the target classification line of the second endpoint refers to a side of the target classification line of the second endpoint that is far away from the first endpoint; If the second endpoint is on the second side of the target classification line of the second endpoint, the second endpoint is determined to be in the first state; the second side of the target classification line of the second endpoint refers to a side of the target classification line of the second endpoint close to the first endpoint.
7. The method according to claim 6, characterized in that The state of the first endpoint and the state of the second endpoint of each line segment are combined to obtain the state of each line segment, including: When the barcode is a quaternary barcode, for each line segment, if the first endpoint of the line segment is in the first state and the second endpoint is in the first state, determining that the state of the line segment is the first state; If the first endpoint of the line segment is in the first state and the second endpoint is in the second state, determining that the state of the line segment is the second state; If the first endpoint of the line segment is in the second state and the second endpoint is in the first state, determining that the state of the line segment is a third state; If the first endpoint of the line segment is in the second state and the second endpoint is in the second state, it is determined that the state of the line segment is a fourth state.
8. A barcode image recognition device, characterized in that: The device comprises: An image acquisition module, used for acquiring a barcode image to be identified, wherein the barcode image to be identified includes a plurality of parallel line segments; An endpoint position identification module, used to identify the position of the first endpoint of each of the line segments; A classification line determination module, used to determine a target classification line of the first endpoint according to a set rule; An endpoint state determination module, configured to determine the state of each of the first endpoints based on a positional relationship between the position of each of the first endpoints and a target classification line of the first endpoint; A line segment state determination module, used to determine the state of each line segment according to the state of the first endpoint of each line segment; The state decoding module is used to perform decoding based on the state of each of the line segments to obtain a recognition result of the barcode image to be recognized.
9. An electronic device, characterized in that: The device comprises: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the barcode image recognition method according to any one of claims 1 to 7.
10. A storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the barcode image recognition method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
To-be-recognized image correction method and device
CN112686959A
Method and device for determining decoding direction and decoding equipment
CN115438682A
Equal-interval-based binary stripe coding projection method and system
CN117252913A
Bar code recognition method and recognition device
JP2004246795A
Print controller
JP2013167967A