A color bar code, a method for decoding a bar code image, and an electronic device
By introducing colored areas into traditional barcodes and using the location and color of the colored areas for encoding, the problem of small information capacity of traditional barcodes is solved, and significant expansion of information capacity and efficient decoding are achieved.
Patent Information
- Application Number
- CN202510373750.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-27
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2045-03-27
AI Technical Summary
Traditional barcodes only use black and white, resulting in a small capacity of encoded information and the inability to effectively expand information storage and transmission capabilities.
Using color bar identification code, N rectangular color blocks are arranged at intervals along the width direction of the color block on the carrier, and each color block is evenly divided into 4 areas along the length direction, of which 3 areas are black and 1 area is a colored area. The first T color blocks are used as verification color blocks, and the last (N-T) color blocks are used as coded color blocks. The color of the color area is selected from the standard color set and encoded by the position and color of the color area.
The encoding information capacity has been significantly expanded, and efficient information encoding and decoding is achieved through different colors and locations of the colored areas, solving the problem of small information capacity of traditional barcodes.
Smart Images

Figure CN119887812B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an identification code, an identification code decoding method and device, and particularly to a color bar code, a bar code image decoding method and device. Background Art
[0002] As a mature bar code technology, its essence is to arrange multiple black bars and white bars with unequal widths according to a certain coding rule to store corresponding information. When it is necessary to interpret the bar code, the bar code is decoded according to the corresponding coding rule. It is widely used because of its characteristics such as easy production, simple scanning operation, and fast information processing speed.
[0003] However, the color reference positions for storing information in traditional bar codes are only black and white, which greatly limits the information capacity of bar codes. Summary of the Invention
[0004] Object of the Invention: Aiming at the above-mentioned existing technology, a color bar identification code, an identification code image decoding method and an electronic device are proposed to solve the problem that the traditional bar code technology only uses black and white colors, resulting in a relatively small coding information capacity.
[0005] Technical Solution: A color bar identification code includes N rectangular color blocks arranged at intervals along the width direction of the color blocks on a carrier, with white gaps between adjacent color blocks; each color block is evenly divided into 4 regions along the length direction, which are sequentially denoted as regions A, B, C, and D from top to bottom, and 3 of the 4 regions are black, and the remaining 1 region is a color other than black and white; among them, the first T color blocks are defined as verification color blocks, and in each verification color block, the color of the color region is selected from o standard colors; the latter (N - T) color blocks are defined as coding color blocks, and in each coding color block, the color of the color region is selected from j standard colors, and there is no color overlap between the j standard colors and the o standard colors.
[0006] Further, the width of each verification color block is fixed at 2L, and in the color blocks with odd sequences, the color region is fixed in region B, and in the color blocks with even sequences, the color region is fixed in region C, and the width of the white gap between adjacent verification color blocks is fixed at L; according to the y-channel value of the color of the color region, the width of each coding color block is set to L or 2L, and the width of the white gap between the color block with a width of L and the next adjacent color block is 2L, and the width of the white gap between the color block with a width of 2L and the next adjacent color block is L.
[0007] Further, in the encoding color blocks, when the y-channel value of the color in the colored area is in the range of [0, 0.3], the width of the color block is L; when the y-channel value of the color in the colored area is in the range of [0.70, 1.0], the width of the color block is 2L; in the verification color blocks, the y-channel value of the color in the colored area of the odd-sequence color blocks is in the range of [0.35, 0.40], and the y-channel value of the color in the colored area of the even-sequence color blocks is in the range of [0.60, 0.65]; the y-channel value of the black area in each color block is in the range of [0.45, 0.50], and the y-channel value of the white area between adjacent color blocks is in the range of [0.53, 0.58].
[0008] Further, the length of each color block is denoted as W, N ∈ [20, 30], T ∈ [8, 12], W:L = 8:1, and the value of W is not less than 3 mm.
[0009] The image decoding method of the color bar identification code includes:
[0010] Step 1: Preprocess the image containing the color bar identification code collected by the image sensor;
[0011] Step 2: Process the preprocessed image to identify the color block areas of the color bar identification code;
[0012] Step 3: Determine the characteristic conditions of the color bar identification code, and extract the encoding area after passing the judgment;
[0013] Step 4: Decode the encoding area of the color bar identification code.
[0014] Further, the specific content of Step 2 includes: converting the image preprocessed in Step 1 into a grayscale image, and then using the Canny operator to detect to obtain a binary image containing the edges of each color block area.
[0015] Further, the specific content of Step 3 includes: First, apply the Hough transform to the binary image obtained in Step 2 to detect the straight lines of the edges of each color block, and calculate the inclination angle between the straight line and the origin of the image. Determine whether each color block satisfies the rectangle rule as the first characteristic condition of the bar identification code by the inclination angle, and complete the first angle correction by rotating the inclination angle of the color image located by the binary image;
[0016] Next, calculate the y value of the internal pixel points of the color image after angle correction in the HSV space, respectively count the number of pixels in all black areas and colored areas, and judge whether the color bar identification code meets the second characteristic condition by the ratio of the number of pixels in the black area and the colored area; then count the y values of the colored areas of each color block to judge whether the verification color block is on the left or right side of the image, and perform the second angle correction;
[0017] Finally, determine whether the positions of the colored areas of the verification color blocks match the y value, and determine whether the y value of the colored area of the coding color block matches the width of the coding color block; if the verification area of the color bar identification code contains a predefined verification code string, it is considered that the color bar identification code meets the third feature condition, and thus the coding area is extracted from the image.
[0018] Further, in step 3, after passing the judgment of the second feature condition, calculate the average value of the widths of the upper and lower sides of all coding color blocks as the value of L, which is used to judge whether the y value of the colored area of the coding color block matches the width of the coding color block.
[0019] Further, for each coding color block, calculate the HSV average value of the pixel points in the colored area of the coding color block respectively to form the decoded color vector of the colored area of the block, perform variance operations on the decoded color vector and the vectors of the j standard colors respectively, and take the standard color with the smallest variance as the identification color of the colored area of the block, and the coding value corresponding to the standard color is the decoded value of the colored area of the block; the decoded values of the colored areas of each coding color block and the decoded values of the positions of each colored area in each coding color block together form the decoded value of the color bar identification code.
[0020] An electronic device includes a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the image decoding method of the color bar identification code when executing the program.
[0021] Beneficial effects: The present invention provides a color bar identification code, an identification code image decoding method, and an electronic device. The color bar identification code adds a strip-shaped colored area on a black color block, and encodes through the different positions of the strip-shaped colored area on the black color block and the different colors of the colored area, greatly expanding the coding information capacity compared with traditional barcodes.
[0022] During decoding, the contour of the barcode is recognized through an image algorithm to perform color block segmentation, and a preliminary judgment is made by testing whether the sides of each color block satisfy the law of a rectangle; then, by recognizing the relevant characteristics of the y-channel values of the segmented color blocks, through steps such as angle correction and verification decoding, the complete coding information of the color bar identification code is accurately extracted from the color image to achieve accurate decoding of the color bar identification code. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a schematic diagram of the recognition and decoding process of the color bar identification code designed by the present invention;
[0024] Figure 2 It is a schematic diagram of contour detection related to the present invention. Detailed implementation mode
[0025] The following further explains the present invention in conjunction with the attached drawings.
[0026] A color bar code is made on a carrier by means of spraying, printing, digital display, etc. The carrier includes the article itself, article packaging, various display screens, etc.
[0027] The color bar code is composed of N rectangular color blocks arranged at intervals in the width direction of the color blocks. The length of each color block is denoted as W, and there is a white gap between adjacent color blocks. Each color block is evenly divided into 4 regions along the length direction, denoted as regions A, B, C, and D from top to bottom in sequence. And 3 of the 4 regions are black, and the remaining 1 region is a color other than black and white.
[0028] The first T color blocks of the color bar code are defined as verification color blocks. The width of each verification color block is fixed at 2L, and the color region in the odd-numbered sequence of color blocks is fixed in region B, and the color region in the even-numbered sequence of color blocks is fixed in region C. The width of the white gap between adjacent verification color blocks is fixed at L. In each verification color block, the color of the color region is selected from o standard colors. In the verification region of the color bar code composed of T verification color blocks, a verification code string is formed through the position of the color region in the color block and the color of the color region, which is used for region positioning and verification when decoding the color bar code image later.
[0029] The last (N - T) color blocks of the color bar code are defined as coding color blocks. In each coding color block, the color of the color region is selected from j standard colors, and there is no color overlap between the j standard colors and the o standard colors. According to the different y-channel values of the colors of the color regions, the widths of each coding color block are respectively set to L or 2L, and the width of the white gap between the color block with width L and the next adjacent color block is 2L, and the width of the white gap between the color block with width 2L and the next adjacent color block is L, so as to ensure that the distance between the left boundaries of two adjacent coding color blocks is 3L. The coding region of the color bar code composed of (N - T) coding color blocks forms a total coding capacity of 4 * j for the coding region through the position of the color region in each color block and the color of the color region. (N-T) 。
[0030] After a large number of experimental demonstrations, when N ∈ [20, 30], T ∈ [8, 12], W:L = 8:1, and the value of W is not less than 3 mm, it has a good color bar code segmentation and recognition effect. When detecting the outline of the color blocks, the white gaps between adjacent color blocks can separate each color block, which is convenient for separately judging different color blocks when making a straight-line judgment in the process of color bar code recognition, and avoiding interference between color blocks.
[0031] In the HSV (Hue, Saturation, Value) color space, the hue H, saturation S, and value V are independent of each other. The maximum value of the hue H is 180 degrees, and the minimum value is 0 degrees, representing the position of the color on the color wheel; the maximum value of the saturation S is 255, and the minimum value is 0, representing the purity and gray level of the color; the maximum value of the value V is 255, and the minimum value is 0, representing the brightness of the color. Since the hue H, saturation S, and value V in the HSV color space are independent of each other, when selecting and comparing colors, one or two of these properties can be adjusted individually without affecting the others. Compared with the RGB color space, it is more suitable for color comparison and selection. Moreover, due to the independence of the hue in the HSV color space, the operation of color judgment is simpler and more accurate. Also, the HSV color space is less sensitive to ambient light than RGB in some cases because the value V component in the HSV color space is relatively independent of the lighting conditions. The value represents the brightness of the color, and in the HSV model, the value is a separate channel and is not directly affected by ambient light like RGB. According to the different ranges of HSV values, colors can be well segmented. Table 1 below gives the HSV value ranges of common colors.
[0032] Table 1 HSV value ranges of common colors
[0033]
[0034] The o standard colors of the verification color patches and the j standard colors of the coded color patches together form the standard color set CS, and the total number of elements Z in the set CS is Z = o + j. Through experiments, it is measured that Z is preferably in the range of [10, 20]. In the HSV color space, each element in the set CS is a three-dimensional vector.
[0035] When decoding a color bar code image through image technology, the image can be converted from the RGB color space to the HSV color space, and the image can be segmented by selecting appropriate thresholds. For j standard color components, their respective y components are extracted, and the y components are normalized. Since the value range of hue H is [0, 179], which is different from the value ranges of saturation S and brightness V, which are [0, 255], in order to make the influence of H, S, and V values on the y component consistent, the value of hue H is enlarged by 255 / 179 times. For an 8-bit image, the calculation formula for its y component is y = (0.297H + 0.209S + 0.578V) / 255. The value range of y is [0, 1]. For the black area of the color block, by adjusting its HSV value, ensure that the y value range of the black area is [0.45, 0.50], and for the white area between adjacent color blocks, the y value range is [0.53, 0.58]. For the color area of the verification color block, ensure that the y value range of its odd sequence (the color area is located in area B) is [0.35, 0.40]; the y value range of its even sequence (the color area is located in area C) is [0.60, 0.65]. For the encoded color block with a y value range between [0, 0.3], its width is L; for the encoded color block with a y value range between [0.70, 1.0], its width is 2L, as shown in Table 2 specifically.
[0036] Table 2 Value ranges of y components of different colors and corresponding positions
[0037] y-value range corresponding position 0-0.3 color area of the encoded color block with width L 0.35-0.40 color area of the verification color block of the odd sequence 0.45-0.50 black area of the color block 0.53-0.58 white area between adjacent color blocks 0.60-0.65 color area of the verification color block of the even sequence 0.70-1.0 color area of the encoded color block with width 2L
[0038] As Figure 1 shown, the method for decoding a color bar code image of the present invention is specifically as follows:
[0039] Step 1: Preprocess the original image containing the color bar code collected by the image sensor.
[0040] Step 1.1: Obtain a color image containing the color bar code from the imaging device, and the image size is Q*A pixels.
[0041] Step 1.2: Perform low-intensity Gaussian filtering on all three RGB channels of the color image to reduce the interference of image noise on graphic segmentation and positioning. Among them, the purpose of low intensity is to avoid edge blurring caused by smoothing filtering. A 5*5 Gaussian filter kernel with a small standard deviation used in this embodiment is:
[0042]
[0043] In this way, a single pixel noise becomes almost insignificant on the Gaussian-smoothed image.
[0044] Step 1.3: Perform histogram equalization on the numerical values of each channel of the Gaussian-filtered color image to reduce the interference of image shadows or highlights on graphic segmentation and positioning.
[0045] Step 2: Process the preprocessed image to identify the color block regions of the color bar identification code.
[0046] First, convert the image processed in Step 1 into a grayscale image, and then use the Canny operator to detect a binary image containing the edges of each color block region. The experimental results are as Figure 2 shown. Figure 2 In (a) of [], it is the input image in this step. As an example, this image only includes two color blocks; Figure 2 In (b) of [], it is the grayscale image converted from (a); Figure 2 In (c) of [], it is the binary image obtained after edge detection of (b).
[0047] Step 3: Determine the characteristic conditions of the color bar identification code, and extract the coding region after passing the determination.
[0048] Step 3.1: Due to the imperfection of the color image collected by the image sensor or the imperfection of the edge detection in Step 2, some pixels of the bar identification code are missing or there is noise, resulting in the deviation of the region boundary of the bar identification code from the actual boundary. Therefore, after Step 2, it is necessary to further judge the region boundary of each color block of the bar identification code. By performing line detection on the edges of each color block in the image processed in Step 2, the situations where irregular objects appear in the image or there are large boundary errors are excluded.
[0049] Specifically, apply the Hough transform to the binary image obtained in Step 2 to perform line detection on the edges of each color block. The Hough transform generates a parameter space. For each edge point in the image space, the angle θ is used to represent the inclination degree of the line compared to the image coordinate axes. Calculate all its possible line parameters and increase the count in the corresponding parameter space. Set a threshold. When the count of a certain cell in the parameter space exceeds this threshold, it is considered that an edge is found. In the parameter space, find the regions with high concentration. These regions correspond to the lines in the image, which are the potential color block edges, and exclude the influence of irregular graphics. Then, test the potential color block edges. Determine whether each color block meets the rule of a rectangle as the first characteristic condition of the bar identification code by judging the inclination angle θ, that is, detect whether the absolute value of the difference in θ between opposite sides of each potential color block is within 3°, and whether the absolute value of the difference in θ between adjacent sides is within the range of [87°, 93°]. If each color block meets the conditions, it is considered that the bar identification code passes the judgment of the first characteristic condition.
[0050] Next, rotate the color image located by the binary image with the arithmetic mean value of θ of the two long sides of all color blocks to achieve the first angle correction of the image.
[0051] Step 3.2: Calculate the y value of the internal pixel points of the color image after angle correction in the HSV space, and judge whether the color bar identification code meets the second characteristic condition according to the proportion of the y value in different intervals.
[0052] Specifically, according to Table 2, the y value of the black area of the color block is between 0.45 and 0.50, and it is verified that the y value distribution of the color areas of the verification color block and the coded color block is between 0 and 0.30, 0.35 and 0.40, 0.60 and 0.65, and 0.70 and 1. Perform color verification on the color bar identification code judged by the first characteristic condition, that is, convert the format of the color image after the first angle correction from RGB to HSV, calculate the y value of the pixels within the area boundary of all color blocks, and count the number of pixels in all black areas and color areas respectively. If the ratio of the number of pixels in the black area and the color area is between 3.9 and 4.1:1, it is considered that the bar identification code passes the judgment of the second characteristic condition.
[0053] Step 3.3: Judge the distribution of the verification area and the coding area, and extract the coding area.
[0054] Because the y value of the color area of the verification color block is between 0.35 and 0.40 and between 0.60 and 0.65, judge whether the verification color block is on the left or right side of the image after the first angle correction through the y value. If the verification color blocks are distributed on the right side of the image, the image needs to be rotated 180° to complete the second angle correction. Then, judge whether the color area of the odd sequence of the verification color block is in the B area of the color block and the y value is between 0.35 and 0.40, and whether the color area of the even sequence is in the C area of the color block and the y value is between 0.60 and 0.65.
[0055] Calculate the average value of the widths of the upper and lower sides of all coded color blocks as the value of L, and compare the y value and width of each coded color block, that is, whether the width is L when the y value of the coded color block is between 0 and 0.3, or whether the width is 2L when the y value of the coded color block is between 0.7 and 1. If the verification area contains a complete defined verification coding string, and the y value and color block width of the coding area color block match, it is considered that the bar identification code passes the judgment of the third characteristic condition.
[0056] Since the y-value range of the black area is between 0.45 and 0.50, and the y-value range of the colored color blocks is between 0 and 0.4, 0.6 and 1.0. Count the number of pixel points with y-values in different ranges in the four different areas of the color block. Assume that the number of pixel points with y-values between 0.45 and 0.5 in an area is a, and the number of pixel points with y-values in the ranges of 0 to 0.4, 0.6 to 1.0 is b. When a / (a + b) < 10%, it can be determined that the area is a colored area; when b / (a + b) < 10%, it can be determined that the area is a black area.
[0057] Step 4: Decode the encoding area of the bar code identifier.
[0058] For each encoded color block, calculate the HSV average value of the pixel points in the colored area of the encoded color block respectively, form the decoded color vector of the colored area of the color block, and calculate the variance between the decoded color vector and j color vectors related to the encoded color block in the standard color set CS respectively. The calculation formula is:
[0059]
[0060] Among them, c ( dblock i ) = H ( dblock i ), S ( dblock i ), V ( dblock i ) represents the decoded color vector of the colored area of the i th color block, CSJ l = { H ( CSJ l ), S ( CSJ l ), V ( CSJ l )} represents the l th standard color vector, Var ( block i ) represents the variance between the decoded color vector of the colored area of the i th color block and the l th standard color vector. Take the standard color with the smallest variance as the recognized color of the colored area of the color block, and the encoding value corresponding to the standard color is the decoded value of the colored area of the color block. The decoded values of the colored areas of each encoded color block and the decoded values of the positions of each colored area in each encoded color block together form the decoded value of this color bar code identifier.
[0061] The above are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and modifications can be made, and these improvements and modifications should also be regarded as the protection scope of the present invention.
Claims
1. A method for generating a color barcode, characterized in that: It includes N rectangular color blocks which are made on a carrier by spraying, printing or digital display, and are arranged at intervals along the width direction of the color block, with white gaps between adjacent color blocks; each color block is evenly divided into 4 areas along the length direction, which are recorded as A, B, C, and D areas from top to bottom, and 3 of the 4 areas are black, and the remaining 1 area is a color other than black and white; wherein the first T color blocks are defined as verification color blocks, and the color of the color area in each verification color block is selected from o standard colors; the last (NT) color blocks are defined as coding color blocks, and the color of the color area in each coding color block is selected from j standard colors, and there is no color overlap between the j standard colors and the o standard colors; The width of each verification color block is fixed to 2L, and the color area in the color blocks of the odd sequence is fixed in area B, the color area in the color blocks of the even sequence is fixed in area C, and the width of the white gap between adjacent verification color blocks is fixed to L; the width of each encoding color block is set to L or 2L according to the y channel value of the color of the color area, and the width of the white gap between the color block with a width of L and the next adjacent color block is 2L, and the width of the white gap between the color block with a width of 2L and the next adjacent color block is L.
2. The method for generating a color barcode according to claim 1, characterized in that: In the coding color block, when the y channel value of the color area is in the interval [0,0.3], the width of the color block is L, and when the y channel value of the color area is in the interval [0.70,1.0], the width of the color block is 2L; in the verification color block, the y channel value of the color area of the odd sequence color block is in the interval [0.35,0.40], and the y channel value of the color area of the even sequence color block is in the interval [0.60,0.65]; the y channel value of the black area in each color block is in the interval [0.45,0.50], and the y channel value of the white area between adjacent color blocks is in the interval [0.53,0.58].
3. The method for generating a color barcode according to claim 1, characterized in that: The length of each color block is denoted as W, N∈[20,30], T∈[8,12], W:L=8:1, and the W value is not less than 3mm.
4. The image decoding method of the color barcode generated by any one of the methods described in claims 1 to 3, characterized in that: include: Step 1: pre-processing the image containing the color barcode collected by the image sensor; Step 2: Process the preprocessed image to identify the color block areas of the color bar code; Step 3: Determine the characteristic conditions of the color bar code and extract the coding area after the determination; Step 4: Decode the encoded area of the color barcode.
5. The image decoding method of the color bar code according to claim 4, characterized in that: The step 2 specifically includes: converting the image preprocessed in step 1 into a grayscale image, and then using the Canny operator to detect to obtain a binary image containing the edges of each color block area.
6. The image decoding method of the color bar code according to claim 5, characterized in that: The step 3 specifically includes: first, applying Hough transform to the binary image obtained in step 2 to perform straight line detection on the edge of each color block, and calculating the inclination angle between the straight line and the image origin, judging whether each color block meets the rectangular rule as the first characteristic condition of the bar code by the inclination angle, and completing the first angle correction by rotating the color image located by the binary image by the inclination angle; Next, the y value of the pixel point inside the color image after angle correction in the HSV space is calculated, and the number of pixels in all black areas and color areas is counted respectively. The ratio of the number of pixels in the black area to the color area is used to determine whether the color barcode meets the second characteristic condition; then the y value of the color area of each color block is counted to determine whether the verification color block is on the left or right side of the image, and the second angle correction is performed; Finally, determine whether the position of the color area of each verification color block matches the y value, and determine whether the y value of the color area of the coding color block matches the width of the coding color block; if the verification area of the color bar identification code contains the defined verification code string, the color bar identification code is considered to meet the third feature condition, so that the coding area is extracted from the image.
7. The image decoding method of the color bar code according to claim 6, characterized in that: In step 3, after passing the judgment of the second characteristic condition, the average value of the widths of the upper and lower sides of all the coded color blocks is calculated as the value of L, which is used to judge whether the y value of the color area of the coded color block matches the width of the coded color block.
8. The image decoding method of a color barcode according to any one of claims 5 to 7, characterized in that: For each coded color block, the HSV average value of the pixel points in the color area of the coded color block is calculated respectively to form a decoded color vector of the color area of the color block, and the variance operation is performed on the decoded color vector and the vectors of the j standard colors respectively, and the standard color with the smallest variance is taken as the identification color of the color area of the color block, and the encoding value corresponding to the standard color is the decoding value of the color area of the color block; the decoding values of the color areas of each coded color block and the decoding values of each color area located at the position of each coded color block together constitute the decoding value of the color bar identification code.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the image decoding method of the color bar identification code described in any one of claims 4-8 is implemented.
Citation Information
Patent Citations
Matrix type colorful two-dimensional bar code encoding and decoding method
CN101149813A
Colorful lattice point code picture and three-dimensional bar code coding method thereof
CN102999773A