A multi-code decoding method and system based on gradient algorithm
By using a gradient algorithm-based multi-code decoding method, the position and orientation of multiple barcodes can be accurately located and decoded, solving the problem of multi-code decoding failure and achieving efficient, one-time decoding of multiple barcodes.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-07
- Publication Date
- 2026-03-31
AI Technical Summary
Existing technologies cannot effectively decode multiple closely spaced barcodes, leading to mis-decoding and missed decoding. Furthermore, traditional methods require manual scanning of each barcode, which is cumbersome.
A multi-code decoding method based on gradient algorithm is adopted. By grayscale conversion, gradient calculation, rectangular box positioning and maximum gradient sampling line decoding, the position and orientation of the barcode are accurately located, and multi-code decoding is achieved at one time.
It can accurately locate the position and orientation of multiple barcodes, improve decoding efficiency, solve the problem of multi-code decoding failure, and reduce operation steps.
Smart Images

Figure CN116152834B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition technology, and in particular to a multi-code decoding method and system based on gradient algorithm. Background Technology
[0002] Barcode technology is an emerging technology developed on the basis of computer and information technology, integrating encoding, printing, identification, data collection, and processing. Due to its advantages such as fast, accurate, reliable, and low-cost identification, barcode technology is widely used in commerce, library management, warehousing, postal services, transportation, and industrial control, and is poised to play a significant role in the emerging "Internet of Things" applications.
[0003] One-dimensional barcodes, also known as linear barcodes, consist of multiple parallel "bars" and "spaces." Barcode information is expressed through the varying widths and positions of the bars and spaces. One-dimensional barcodes only express information in one direction (usually horizontally), and do not express any information in the vertical direction.
[0004] A typical one-dimensional barcode is captured by photographic equipment to obtain a barcode image. The barcode image typically undergoes processing such as denoising, grayscale extraction, binarization, codeword extraction, and decoding. However, this process is only suitable for decoding a single one-dimensional barcode and cannot decode multiple barcodes. Furthermore, during grayscale extraction and binarization, multiple barcodes are often mistakenly identified as a single barcode, leading to problems such as unsuccessful decoding, misdecoding, and missed decoding.
[0005] like Figure 1 As shown, a complete one-dimensional barcode consists of two static areas, a start symbol, data characters, a check symbol, and a stop symbol. It arranges multiple black bars and spaces of varying widths according to certain encoding rules to represent a set of information. Figure 2-3 As shown, multiple barcodes are multiple one-dimensional barcodes arranged side by side or multiple items with barcodes arranged in sequence, resulting in very small intervals between the barcodes. This makes it difficult to decode multiple barcodes successfully.
[0006] Commonly used barcode scanning devices typically consist of components such as a light source (e.g., laser), an optical lens, a photosensitive device (e.g., CCD, CMOS), a decoding logic circuit, and an I / O interface. The light source projects light onto the barcode, and the light reflected from the barcode passes through the optical lens and enters the surface of the photosensitive device. After a series of processes such as photoelectric conversion and analog-to-digital conversion, a digital image of the barcode is formed. Then, the decoding logic circuit analyzes and decodes the captured image.
[0007] The existing one-dimensional barcode codeword decoding method is as follows: 1. Preprocess the acquired barcode image (grayscale conversion, contrast enhancement); 2. Barcode image edge detection; 3. Barcode image smoothing; 4. Barcode image morphological processing; 5. Barcode localization based on region description; 6. Identify the barcodes in X regions respectively; Among them, step 5 is specifically: (1) Starting from the first pixel of the image, set the current label to 1; (2) If the pixel is a foreground pixel and it does not have a label yet, then give it the current label and add it as the first element in the set, and then proceed to step (3). If it is the background pixel, then... If an element has already been labeled, then proceed to step (2) for the next element in the image; (3) pop an element from the sequence and check its neighboring elements. If the neighboring element is a foreground element and has not yet been labeled, then give it the current label and add it to the queue. Repeat step (2) until there are no more elements in the set; (4) go to step (2), the next element in the image, and increment the current label by 1; (5) calculate the area of each region, i.e. the number of pixels; (6) set a threshold, clear the regions below the threshold, and obtain the regions of X barcodes, denoted as {X1,X2,...}.
[0008] Existing methods begin with edge detection in step 2. This step can detect the edge lines of the barcode and the edge lines of the internal bar and space units, but it cannot locate the barcode region. Further image processing operations are required, such as image smoothing and morphological processing. These two operations can remove most of the edge lines of the internal bar and space units while retaining the barcode edge lines. The final step is to locate the barcode region using a region-based method. However, existing methods cannot locate the barcode edge lines of multiple consecutive barcodes because image smoothing and morphological processing merge multiple consecutive barcodes together and recognize them as a single barcode. This will lead to decoding failures, misinterpretations, or omissions of multiple consecutive barcodes, thus affecting the barcode decoding performance.
[0009] Within the device's field of view, N barcodes can be captured, with the barcodes closely spaced and typically arranged perpendicular to the barcode direction, or in an irregular distribution, without overlapping. However, current barcode decoding methods decode each barcode individually, making it difficult to decode multiple barcodes at once. Each barcode needs to be scanned manually, which is cumbersome for scenarios like libraries, pharmacies, and stores.
[0010] To address the problems in existing technologies, this invention provides a multi-code decoding method and system based on gradient algorithms. Summary of the Invention
[0011] The purpose of this invention is to address the shortcomings of existing technologies by providing a multi-code decoding method and system based on gradient algorithms.
[0012] To achieve the above objectives, the present invention adopts the following technical solution:
[0013] A multi-code decoding method based on gradient algorithm includes:
[0014] S1. Acquire images corresponding to multiple barcodes, perform grayscale conversion and contrast enhancement processing on the acquired images to obtain grayscale images of multiple barcodes;
[0015] S2. Calculate the gradient of the grayscale image in the preset direction to obtain several gradient images corresponding to multiple barcodes. Calculate the number of non-black pixels in each gradient image and obtain the gradient image with the largest number of non-black pixels.
[0016] S3. Binarize the gradient image with the largest number of non-black pixels to obtain the white area as the location of the barcode. Expand the white area into a rectangle to obtain the barcode area location box.
[0017] S4. Traverse the pixels in the barcode area location box. The white pixels in the barcode area location box are the barcode. Start sampling from the middle part of each barcode to obtain multiple sampling lines in different directions for each barcode. Calculate the gradient of each sampling line and obtain the sampling line with the largest gradient.
[0018] S5. Decode the barcode pixels in the sampling line with the largest gradient to obtain the decoding result.
[0019] Furthermore, the preset directions in step S2 include 45°, 90°, 135°, and 180°.
[0020] Furthermore, step S2 also includes using the gradient map with the largest number of non-black pixels as the base direction.
[0021] Furthermore, step S2 also includes determining whether the barcode orientation is the same as the base orientation; if not, the base orientation is tilted.
[0022] Furthermore, step S3 specifically includes:
[0023] S31. Calculate the average value of the pixels in the gradient map with the largest number of non-black pixels, and use the calculated average value as the brightness threshold of the gradient map;
[0024] S32. Based on the brightness threshold of the gradient map, the gradient map is binarized, and the resulting white area is the location of the barcode;
[0025] S33. Expand the white area into a rectangle and calculate the coordinates of the four vertices of the rectangle to obtain the barcode area location frame.
[0026] Furthermore, in step S4, the pixels in the barcode area location box are traversed from the top left starting point of the barcode area location box, searching from left to right and from top to bottom. The white pixels found are the barcode pixels.
[0027] Furthermore, in step S4, the gradient of each sampling line is calculated to obtain the sampling line with the largest gradient, specifically as follows:
[0028] Calculate the distance of each sampling line as it passes through the barcode, and select the sampling line with the shortest distance as the optimal sampling line.
[0029] Furthermore, the calculation of the distance each sampling line travels through the barcode is expressed as:
[0030]
[0031] f(L)=MAX(f(l0),f(l1),...,f(l z ))(z≥0)
[0032] Where f(l) represents the gradient value of the sampling line; f(L) represents the gradient value of the optimal sampling line; l represents the sampling line; L represents the optimal sampling line; x represents the pixel value of the white pixel; m, n represent the positions of the white pixels; x n Represents the pixel value at position n; x n-1 represents the pixel value at position n-1; z represents the number of sampling lines.
[0033] Furthermore, step S5, which involves decoding, specifically involves: acquiring barcode pixels along the sampling line direction, decoding the acquired pixels, and iterating through each barcode until all barcodes have been decoded.
[0034] Correspondingly, a multi-code decoding system based on a gradient algorithm is also provided, including:
[0035] The acquisition module is used to acquire images corresponding to multiple barcodes, perform grayscale conversion and contrast enhancement processing on the acquired images, and obtain grayscale images of multiple barcodes.
[0036] The calculation module is used to calculate the gradient of the grayscale image in the preset direction, obtain several gradient maps corresponding to multiple barcodes, calculate the number of non-black pixels in each gradient map, and obtain the gradient map with the largest number of non-black pixels.
[0037] The processing module is used to binarize the gradient image with the largest number of non-black pixels, and the resulting white area is the location of the barcode. The white area is then expanded into a rectangle to obtain the barcode area location box.
[0038] The traversal module is used to traverse the pixels in the barcode area location box. The white pixels within the barcode area location box are the barcodes. Sampling starts from the middle part of each barcode to obtain multiple sampling lines in different directions for each barcode. The gradient of each sampling line is calculated, and the sampling line with the largest gradient is obtained.
[0039] The decoding module is used to decode the barcode pixels in the sampling line with the largest gradient to obtain the decoding result.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] 1. This invention solves the problem of multiple barcodes being undecoded, can be applied to multi-code decoding in various scenarios, and can accurately locate the position and orientation of the barcode.
[0042] 2. Based on the principle of maximizing the gradient change in the barcode direction, this invention focuses on proposing a solution for finding the solution for each barcode direction, which can efficiently solve the problem of multi-code decoding and the problem that multiple barcodes cannot output multiple decoding results at the same time;
[0043] 3. This invention fully considers the distribution of multiple codes within the visible range of the device, and proposes a sampling and decoding method for closely connected barcodes based on directional consistency. This invention can greatly improve the decoding effect and adaptability of multiple barcode codes. Attached Figure Description
[0044] Figure 1 This is a schematic diagram of a one-dimensional barcode provided by the background technology.
[0045] Figure 2 These are several one-dimensional barcode illustrations provided by the background technology;
[0046] Figure 3 These are several one-dimensional barcode illustrations provided by the background technology;
[0047] Figure 4 This is a flowchart of a multi-code decoding method based on a gradient algorithm provided in Embodiment 1;
[0048] Figure 5 This is a schematic diagram of the multi-code gradient map provided in Implementation Example 1;
[0049] Figure 6 This is a schematic diagram of the multi-code gradient map provided in Implementation Example 1;
[0050] Figure 7 This is a schematic diagram of the barcode area location frame provided in Embodiment 1;
[0051] Figure 8 This is a schematic diagram of the barcode area location frame provided in Embodiment 1;
[0052] Figure 9This is a schematic diagram of the sampling line provided in Example 1;
[0053] Figure 10 This is a schematic diagram of the calculation of the optimal sampling line provided in Example 1;
[0054] Figure 11 This is a schematic diagram of the sampling lines and sampling direction of each barcode provided in Example 1;
[0055] Figure 12 This is a schematic diagram of the sampling lines and sampling direction for each barcode provided in Example 1. Detailed Implementation
[0056] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.
[0057] The purpose of this invention is to address the shortcomings of existing technologies by providing a multi-code decoding method and system based on gradient algorithms.
[0058] Example 1
[0059] This embodiment provides a multi-code decoding method based on a gradient algorithm, such as... Figure 4 As shown, it includes:
[0060] S1. Acquire images corresponding to multiple barcodes, perform grayscale conversion and contrast enhancement processing on the acquired images to obtain grayscale images of multiple barcodes;
[0061] S2. Calculate the gradient of the grayscale image in the preset direction to obtain several gradient images corresponding to multiple barcodes. Calculate the number of non-black pixels in each gradient image and obtain the gradient image with the largest number of non-black pixels.
[0062] S3. Binarize the gradient image with the largest number of non-black pixels to obtain the white area as the location of the barcode. Expand the white area into a rectangle to obtain the barcode area location box.
[0063] S4. Traverse the pixels in the barcode area location box. The white pixels in the barcode area location box are the barcode. Start sampling from the middle part of each barcode to obtain multiple sampling lines in different directions for each barcode. Calculate the gradient of each sampling line and obtain the sampling line with the largest gradient.
[0064] S5. Decode the barcode pixels in the sampling line with the largest gradient to obtain the decoding result.
[0065] In step S1, images corresponding to multiple barcodes are acquired, and the acquired images are subjected to grayscale conversion and contrast enhancement processing to obtain grayscale images of multiple barcodes.
[0066] Get Figure 2 The image contains multiple barcodes, which will be referred to as multiple codes. The process involves acquiring an image of the multiple codes and then performing grayscale conversion and contrast enhancement on the acquired image. The purpose of grayscale conversion is to process a color image into a grayscale image, and the purpose of contrast enhancement is to process a grayscale image into a black and white image.
[0067] It should be noted that the grayscale conversion and enhancement processing in this embodiment can be implemented using existing technologies.
[0068] In step S2, the gradient of the grayscale image in the preset direction is calculated to obtain several gradient maps corresponding to multiple barcodes. The number of non-black pixels in each gradient map is calculated to obtain the gradient map with the largest number of non-black pixels.
[0069] The gradient of the obtained multi-code grayscale image is used to determine the multi-code region; specifically:
[0070] The black and white pixels in the multi-code region are the most widely and densely distributed, and the pixel changes are the fastest. Therefore, calculating the gradient between pixels in a multi-code grayscale image can distinguish the barcode part from the background part. In this embodiment, four directions of 45°, 90°, 135° and 180° are preset, and the gradients in the four directions are calculated respectively. The calculation method is as follows: subtract the pixel value of the (n-1)th position from the pixel value of the nth position, take the absolute value of the pixel difference, and calculate the entire image in a loop. The larger the difference, the larger the gradient. At this time, a multi-code image can obtain four gradient maps. Then, the number of non-black pixels in each of the four gradient maps is calculated. The gradient map with the largest number of non-black pixels is the required gradient map, and the direction of the obtained gradient map is set as the base direction.
[0071] In this embodiment, in order to facilitate the subsequent decoding of each barcode in the multi-code image, if the sampling direction required for each barcode in the multi-code image is different from the base direction, the base direction is tilted to the left or right to obtain the correct barcode sampling direction.
[0072] like Figure 5 As shown Figure 2 The gradient plot, such as Figure 6 As shown Figure 3The gradient map is calculated so that the base direction of the gradient map is 90° (vertical). However, the direction of each barcode in the gradient map is not always 90°. Therefore, in subsequent calculations, the sampling direction needs to be tilted to the left or right on the basis of 90° so that it is the same as the actual barcode direction.
[0073] In step S3, the gradient map with the largest number of non-black pixels is binarized, and the resulting white area is the location of the barcode. The white area is then expanded into a rectangle to obtain the barcode area location box.
[0074] S31. Calculate the average value of the pixels in the gradient map with the largest number of non-black pixels, and use the calculated average value as the brightness threshold of the gradient map;
[0075] After the gradient map of the multi-code is calculated in step S2, the pixel values of the multi-code gradient map are calculated, the average value of the multi-code gradient map is calculated based on the pixel values of the gradient map, and the calculated average value is used as the brightness threshold of the gradient map.
[0076] S32. Based on the brightness threshold of the gradient map, the gradient map is binarized, and the resulting white area is the location of the barcode;
[0077] Using a brightness threshold as the condition for maximizing brightness, the multi-code gradient map is binarized. The resulting gradient map has distinct light and dark areas. The bright areas (white areas) in the processed gradient map represent the positions of each barcode in the multi-code gradient map.
[0078] S33. Expand the white area into a rectangle and calculate the coordinates of the four vertices of the rectangle to obtain the barcode area location frame.
[0079] In step S32, barcodes at multiple locations in the multi-code gradient map are obtained. The positions of white pixels within each of these multiple barcode locations are counted, and each white region is expanded into a rectangle. The coordinates of the four vertices of each rectangle are calculated and denoted as P{P1,P2,P3,P4}, thus obtaining the corresponding barcode region bounding box. Figure 7 , 8 The image shows the location box for the barcode area.
[0080] In this embodiment, multiple barcodes will have multiple barcode area location frames. However, if multiple barcodes are arranged consecutively without any gaps between them, they will be counted as one barcode area location frame, and interval sampling and decoding will be performed in an alternating row or column manner.
[0081] In step S4, traverse the pixels in the barcode area position box. The white pixels within the barcode area position box are the barcodes. Start sampling from the middle part of each barcode to obtain multiple sampling lines in different directions for each barcode, and calculate the gradient of each sampling line to obtain the sampling line with the maximum gradient.
[0082] After determining the multiple barcode area position boxes in the multi-code, start traversing and searching from the upper-left starting point of the barcode area position box from left to right and top to bottom. White pixels will be found. Combine all the white areas within the found box to find any one barcode in the multi-code gradient map. Start sampling from the middle part of the barcode, and calculate the gradient of the sampling line in each of the preset multiple sampling directions. The sampling line with the maximum gradient is the best sampling line; as Figure 9 shown is the sampling line.
[0083] In this embodiment, the specific method for calculating the best sampling line is:
[0084] As Figure 10 described, select two sampling lines L1 and L2 from any multiple sampling lines for detailed description. Calculate the gradients of the two sampling lines L1 and L2. Specifically, calculate the distance w1 that sampling line L1 passes through when passing through the Figure 10 black line in, and calculate the distance w2 that sampling line L2 passes through when passing through the Figure 10 black line in. If w1 < w2, then sampling line L1 is considered the best sampling line. The direction of the best sampling line coincides with the barcode direction, and thus the sampling direction of each barcode can be obtained.
[0085] In this embodiment, the best sampling line is calculated using the formula, that is, calculate the derivatives of the two directions of sampling line L1 and sampling line L2, and the sampling line with the maximum derivative is the best sampling line, which is expressed as:
[0086]
[0087] f(L) = MAX(f(l0), f(l1),..., f(l z )) (z ≥ 0)
[0088] where, f(l) represents the gradient value of the sampling line; f(L) represents the gradient value of the best sampling line; l represents the sampling line; L represents the best sampling line; x represents the pixel value of the white pixel; m, n represent the positions of the white pixel points; x n represents the pixel value at position n; x n-1 represents the pixel value at position n - 1; z represents the number of sampling lines.
[0089] In this embodiment, since the position and orientation of each barcode in the multi-barcode gradient graph are different in most scenarios, the sampling direction of each barcode needs to be calculated when decoding each barcode. For multiple consecutive barcodes, the same sampling direction can be calculated, meaning that the barcodes within the barcode frame have the same sampling direction. Sampling is performed at intervals, either by skipping rows or columns, and the decoding result is used to distinguish each different barcode. In this way, each barcode is sampled, and each barcode has multiple sampling lines in multiple directions. The gradient of each sampling line is calculated according to the above formula, and the maximum gradient value is taken as the optimal sampling line, thus obtaining the optimal sampling line for each barcode in the multi-barcode gradient graph.
[0090] In step S5, the barcode pixels in the sampling line with the largest gradient are decoded to obtain the decoding result.
[0091] After obtaining the sampling lines for each barcode, decode each barcode one by one along the direction of each sampling line. Compare the barcode's black-and-white bar / space ratio with the corresponding encoding rule table for decoding. Output only one decoded value for each barcode. Iterate through each barcode until all barcodes are successfully decoded. Figure 11 , 12 The sampling lines and sampling direction for each barcode are shown.
[0092] It should be noted that the method in this embodiment can also be applied to decoding a single one-dimensional barcode.
[0093] This embodiment preliminarily determines the barcode area by calculating the gradient of the image, accurately calculates the barcode direction, samples and decodes along the barcode direction, decodes each code in turn, and outputs the result uniformly. Multiple codes only need to be scanned once.
[0094] Example 2
[0095] This embodiment provides a multi-code decoding system based on a gradient algorithm, including:
[0096] The acquisition module is used to acquire images corresponding to multiple barcodes, perform grayscale conversion and contrast enhancement processing on the acquired images, and obtain grayscale images of multiple barcodes.
[0097] The calculation module is used to calculate the gradient of the grayscale image in the preset direction, obtain several gradient maps corresponding to multiple barcodes, calculate the number of non-black pixels in each gradient map, and obtain the gradient map with the largest number of non-black pixels.
[0098] The processing module is used to binarize the gradient image with the largest number of non-black pixels, and the resulting white area is the location of the barcode. The white area is then expanded into a rectangle to obtain the barcode area location box.
[0099] The traversal module is used to traverse the pixels in the barcode area location box. The white pixels within the barcode area location box are the barcodes. Sampling starts from the middle part of each barcode to obtain multiple sampling lines in different directions for each barcode. The gradient of each sampling line is calculated, and the sampling line with the largest gradient is obtained.
[0100] The decoding module is used to decode the barcode pixels in the sampling line with the largest gradient to obtain the decoding result.
[0101] The multi-code decoding system based on gradient algorithm provided in this embodiment is similar to that in Embodiment 1, and will not be described in detail here.
[0102] This embodiment preliminarily determines the barcode area by calculating the gradient of the image, accurately calculates the barcode direction, samples and decodes along the barcode direction, decodes each code in turn, and outputs the result uniformly. Multiple codes only need to be scanned once.
[0103] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.
Claims
1. A multi-code decoding method based on a gradient algorithm, characterized in that, The method comprises the following steps: S1. Obtain images corresponding to a plurality of bar codes, perform grayscale and contrast enhancement processing on the obtained images, and obtain grayscale images of the plurality of bar codes; S2. Calculate the gradient of the grayscale image in a preset direction to obtain a plurality of gradient maps corresponding to the plurality of bar codes, calculate the number of non-black pixels of each gradient map, obtain the gradient map with the largest number of non-black pixels, and take the gradient map with the largest number of non-black pixels as the base direction; S3. Perform binarization processing on the gradient map with the largest number of non-black pixels, and take the white region obtained as the position of the bar code. The white region is expanded to a rectangle to obtain a bar code region position frame. There are a plurality of bar code region position frames for the plurality of bar codes. If the plurality of bar codes are arranged continuously and there is no interval between the bar codes, one bar code region position frame is counted, and interval sampling decoding is performed in the form of every other row or every other column; S4. Traverse the pixels in the bar code region position frame. The white pixels in the bar code region position frame are the bar codes. Sampling is started from the middle part of each bar code to obtain a plurality of sampling lines in different directions of each bar code. The gradient of each sampling line is calculated to obtain the sampling line with the largest gradient. For the case of a plurality of continuous bar codes, the same sampling direction is calculated, that is, the sampling direction of the bar codes in the bar code frame is the same, and interval sampling is performed in the form of every other row or every other column. The decoding result is used to distinguish each different bar code; S5. Decode the bar code pixels in the sampling line with the largest gradient to obtain a decoding result.
2. The multi-code decoding method based on gradient algorithm according to claim 1, characterized in that, The preset direction in step S2 comprises 45°, 90°, 135° and 180°.
3. The multi-code decoding method based on gradient algorithm according to claim 2, characterized in that, The step S2 further comprises judging whether the direction of the bar code is the same as the base direction. If not, the base direction is tilted.
4. The multi-code decoding method based on gradient algorithm according to claim 1, wherein, The step S3 specifically comprises: S31. Calculate the average value of the pixels in the gradient map with the largest number of non-black pixels, and take the calculated average value as the brightness threshold of the gradient map; S32. Based on the brightness threshold of the gradient map, perform binarization processing on the gradient map to obtain the position of the bar code in the white region; S33. Expand the white region to a rectangle, calculate the coordinates of the four vertices of the rectangle, and obtain a bar code region position frame.
5. The multi-code decoding method based on gradient algorithm according to claim 4, characterized in that, In step S4, the pixels in the bar code region position frame are searched from left to right and from top to bottom starting from the top left starting point of the bar code region position frame. The found white pixels are the bar codes.
6. The multi-code decoding method based on gradient algorithm according to claim 5, wherein, In step S4, the gradient of each sampling line is calculated to obtain the sampling line with the largest gradient. Specifically: Calculate the distance of each sampling line passing through the bar code. The sampling line with the shortest distance is the best sampling line.
7. The multi-code decoding method based on gradient algorithm according to claim 6, characterized in that, The distance of each sampling line passing through the bar code is represented as: ; wherein, f(l) represents a gradient value of a sampling line; f(L) represents a gradient value of an optimal sampling line; l represents a sampling line; L represents an optimal sampling line; x represents a pixel value of a white pixel; m,n represents a position of a white pixel pixel point; x n represents n a pixel value at a position; x n-1 represents n-1 a pixel value at a position; z represents a number of sampling lines.
8. The multi-code decoding method based on gradient algorithm according to claim 1, wherein, The decoding in step S5 is specifically: obtaining the bar code pixels in the sampling line direction, decoding the obtained pixels, and iteratively traversing each bar code until all bar codes obtain decoding results.
9. A system for multi-code decoding based on a gradient algorithm according to any one of claims 1 to 8, characterized in that, The method comprises the following steps: An acquisition module is configured to obtain images corresponding to a plurality of bar codes, perform grayscale and contrast enhancement processing on the obtained images, and obtain grayscale images of the plurality of bar codes; The computing module is configured to calculate the gradient of the gray-scale image in a preset direction to obtain a plurality of gradient images corresponding to the plurality of bar codes, and calculate the number of non-black pixels of each gradient image to obtain a gradient image with the maximum number of non-black pixels; The processing module is configured to perform binary processing on the gradient image with the maximum number of non-black pixels to obtain the position of the bar code as a white region, and to expand the white region to a rectangle to obtain a bar code region position frame; The traversal module is configured to traverse the pixels in the bar code region position frame, and to obtain the bar code as a white pixel in the bar code region position frame, to sample from the middle part of each bar code to obtain a plurality of sampling lines in different directions of each bar code, and to calculate the gradient of each sampling line to obtain a sampling line with the maximum gradient; The decoding module is configured to decode the bar code pixels in the sampling line with the maximum gradient to obtain a decoding result.
Citation Information
Patent Citations
Complex background bar code segmentation and reading method based on machine vision
CN107633192A
Bar code detection method and device, equipment and storage apparatus
CN112699704A