1. Field of the Invention
The present invention relates to a barcode decoding method, and more particularly, to a barcode decoding method for effectively increasing decoding success rate.
2. Description of the Prior Art
A barcode is a figurate identification code composed of a plurality of parallel black stripes with different widths and arranged according to a specific encoding rule to present certain messages. Since a barcode can be used to identify a product's manufacturing country, manufacturer's name, product's name, manufacturing date, book category number and sender's and recipient's mailing addresses, etc., it is therefore widely applied in many fields.
When the barcode is read by the barcode reader, the minimum width of the stripe and the space in the barcode that can be decoded by the barcode reader is affected by the depth of field, the pixel resolution of the image sensor, the characteristics of the optical lens and so on. The width of the stripe and the space in the barcode read by the barcode reader decreases with the increase in distance between the barcode and the barcode reader. Under such circumstance, the barcode image captured by the barcode reader far away from the barcode would be vague. This causes decoding problems especially when the barcode reader is not incorporated with a zoom lens.
One of the purposes of the present invention is to provide a barcode decoding method for effectively increasing decoding success rate to solve the aforementioned problems.
According to one embodiment of the present invention, the barcode decoding method includes the steps of: capturing a target image of a target barcode by a barcode reader; setting a target scanning line on the target image; analyzing a relative relationship between at least two characteristic points of a gray level distribution of the target scanning line to obtain at least one reference characteristic parameter; determining a current distance between the barcode reader and the target barcode being a relatively long distance when the at least one reference characteristic parameter fits to at least one first predetermined characteristic parameter; dividing the gray level distribution of the target scanning line into at least one bar area and at least one space area according to a predetermined gray level when the current distance is the relatively long distance; setting a gray level region according to the predetermined gray level and locating at least one peak point and/or at least one valley point located within the gray level region from the gray level distribution of the target scanning line; interpolating a space corresponding to the peak point into the bar area when the peak point is located within the bar area; and interpolating a bar corresponding to the valley point into the space area when the valley point is located within the space area.
In sum, in the embodiments of the present invention when it is determined that the current distance between the barcode reader and the target barcode is the relatively long distance, the gray level distribution of the target scanning line is divided into at least one bar area and at least one space area. Thereafter, a space is interpolated into the bar area when the corresponding peak point within the gray level region is located within the bar area, and a bar is interpolated into the space area when the corresponding valley point within the gray level region is located within the space area, so as to recover the missing or vague bars or spaces in the target image of the target barcode. By such, the decoding success rate is increased when the current distance between the barcode reader and the target barcode is the relatively long distance.
The above-mentioned and other objectives of the present invention will no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiment that is illustrated in the various figures and drawings.
Please refer to
In the present invention an image of the template barcode 12 is captured by the barcode reader 10, and the relative distance between the barcode reader 10 and the template barcode 12 is estimated so as to provide the barcode reader 10 not having a zoom lens with the relation distance information required for decoding. The decoding success rate is thus increased. Before decoding a barcode, in the present invention a look-up table including correspondence between the characteristic parameters of a barcode image and the relative distances needs to be established first.
Step S10 is first executed to provide a template barcode 12. According to an embodiment of the present invention the template barcode 12 complies with a specific coding rule. As shown in
Thereafter, step S12 is executed to capture a plurality of template images of the template barcode 12 from a plurality of predetermined distances by the barcode reader 10. The plurality of predetermined distances include the relatively long distance, the relatively intermediate distance and the relatively short distance.
Thereafter, step S14 is executed to set a template scanning line 14 on each of the template images. The template scanning line 14 is a horizontal line on the template image as shown in
Thereafter, step S16 is executed to analyze a relative relationship between at least two characteristic points of a gray level distribution for each of the template scanning lines 14 to obtain at least one first predetermined characteristic parameter corresponding to the relatively long distance, at least one second predetermined characteristic parameter corresponding to the relative intermediate distance and at least one third predetermined characteristic parameter corresponding to the relatively short distance.
In the embodiment of the present invention,
In the embodiment as shown in
For example, the relatively intermediate distance is defined as 7 centimeters between the barcode reader 10 and the template barcode 12. The gray level distribution of the template scanning line 14 of the template image of the template barcode 12 shown in
After a plurality of template images of the template barcode 12 at a plurality of predetermined distances are captured by the barcode reader 10 and each of the gray level distribution of the template scanning line 14 for each template image is analyzed, a look-up table including correspondence between the characteristic parameters of the barcode image and the relative distances is established as shown in Table 1 below.
Please refer to
After the look-up table including correspondence between the characteristic parameters of the barcode image and the relative distances is established as shown in Table 1 above, the target barcode 32 shown in
Step S30 is executed to capture the target image of the target barcode 32 by the barcode reader 10. Step S32 is then executed to set a target scanning line 34 on the target image as shown in
The current distance between the barcode reader 10 and the target barcode 32 can be determined based on the characteristic parameters obtained in Step S34 and Table 1. When the at least reference characteristic parameter obtained in Step S34 fits to the at least one first predetermined characteristic parameter of Table 1, Step S36 is executed to determine that the current distance between the barcode reader 10 and the target barcode 32 is the relatively long distance.
When it is determined that the current distance between the barcode reader 10 and the target barcode 32 is the relatively long distance, Step S38 is executed to perform a binarization process on the gray level distribution of the target scanning line 34 according to a predetermined gray level PG so as to divide the gray level distribution of the target scanning line 34 into at least one bar area and at least one space area. As shown in
Step S40 is then executed to set a gray level region GTHmax-GTHmin according to the predetermined gray level and to locate the peak points P1-P5 and the valley points V1-V4 located within the gray level region GTHmax-GTHmin from the gray level distribution of the target scanning line 34. In the embodiment the upper bound and the lower bound of the gray level region GTHmax-GTHmin is determined by increasing and decreasing the predetermined gray level PG by a predetermined ratio, such as 25%, respectively. As shown in
Thereafter, whether the peak points P1-P5 are located within the bar area BA and whether the valley points V1-V4 are located within the space area SA are determined. Step S42 is then executed to interpolate a space corresponding to each of the peak points P1-P5 into the bar area BA when the peak point(s) P1-P5 is/are located within the bar area, and to interpolate a bar corresponding to each of the valley points V1-V4 into the space area SA when the valley point(s) is/are located within the space area.
In the embodiment of the present invention an interpolation point is interpolated between every two adjacent pixels for the gray level distribution of the target scanning line 34. The number of pixels for the gray level distribution of the target scanning line 34 is thus increased from 32 to 63 as shown in
x[n+0.5]=(x[n+1]−x[n])/2+x[n] Formula 1
When a peak point is located within the bar area BA, according to the embodiment of the present invention the width of the interpolated space is the width between the peak point and the interpolating point adjacent to the peak point. Similarly, when a valley point is located within the space area SA, the width of the interpolated bar is the width between the valley point and the interpolating point adjacent to the valley point.
As shown in
Once the spaces S1-S5 are interpolated into the bar area BA and the bar B1 is interpolated into the space area SA, the target barcode 32 is then decoded.
When the at least one reference characteristic parameter obtained in Step S34 fits to the at least one second predetermined characteristic parameter of Table 1, Step S44 is executed to determine that the current distance between the barcode reader 10 and the target barcode 32 is the relatively intermediate distance. When it is determined that the current distance between the barcode reader 10 and the target barcode 32 is the relatively intermediate distance, Step S46 is executed to perform a binarization process on the gray level distribution of the target scanning line 34 according to the predetermined gray level PG so as to decode the target barcode 32.
When the at least one reference characteristic parameter obtained in Step S34 fits to the at least one third predetermined characteristic parameter of Table 1, Step S48 is executed to determine that the current distance between the barcode reader 10 and the target barcode 32 is the relatively short distance. When it is determined that the current distance between the barcode reader 10 and the target barcode 32 is the relatively short distance, Step S50 is executed to filter and down-sample the target image. In the embodiment of the present invention down-sampling is performed by simply keeping one pixel between two or among more pixels so as to eliminate unnecessary pixels. For example, even-numbered pixels of the target scanning line 34 are eliminated, or only one pixel is kept among every four pixels to shorten the operation time of the barcode reader 10. Thereafter, moving average filter is used to filter the noise. Assuming that x[n] represents the gray level of the pixel of the target scanning line 34 and y[n] represents the gray level of the pixel after filtering, the moving average filtering is performed according to Formula 2 as shown below.
y[n]=(x[n−2]+x[n−1]+x[n]+x[n+1]+x[n+2])/5 Formula 2
Step S52 is then executed to perform a binarization process on the gray level distribution of the target scanning line 34 according to the predetermined gray level PG so as to decode the target barcode 32.
In the embodiment of the present invention in Table 1, three first predetermined characteristic parameters, three second predetermined characteristic parameters and three third predetermined characteristic parameters correspond to the relatively long distance, the relatively intermediate distance and the relatively short distance, respectively. Three reference characteristic parameters are therefore used to locate the corresponding relative distance from the Look-up Table. The number of the predetermined characteristic parameters and the number of the reference characteristic parameters in the present invention, however, are not so limited. Besides, when a plurality of the reference characteristic parameters, the first predetermined characteristic parameters, the second predetermined characteristic parameters and the third predetermined characteristic parameters are present, the plurality of reference characteristic parameters obtained in Step S34 may not fully fit to the plurality of the first predetermined characteristic parameters, the second predetermined characteristic parameters or the third predetermined characteristic parameters. According the embodiment of the present invention, when the reference characteristic parameters fit to N of the first predetermined characteristic parameters and M of the second predetermined characteristic parameters (wherein both N and M are positive integer), the current distance between the barcode reader 10 and the target barcode 32 is determined as follows. When N is greater than M, the current distance between the barcode reader 10 and the target barcode 32 is determined to be the relatively long distance. When N is smaller than or equal to M, the current distance between the barcode reader 10 and the target barcode 32 is determined to be the relatively intermediate distance. Similarly, when the reference characteristic parameters fits to N of the second predetermined characteristic parameters and M of the third predetermined characteristic parameters, the current distance between the barcode reader 10 and the target barcode 32 is determined to be the relatively intermediate distance or the relatively short distance upon comparison between N and M.
It is to be understood that in the present invention the control logic can be implemented by software design. The software can be executed in the barcode reader or other types of electronic devices with barcode reading function. Of course, each part or function of the aforementioned control logic can be implemented by software, hardware or the combination thereof. Moreover, the control logic of the barcode decoding method according to the present invention can be stored in the computer-readable storage medium, and the instruction data stored in the computer-readable storage medium can be executed by the barcode reader or other types of electronic devices with barcode reading function to generate control commands so as to perform the corresponding functions.
In sum, in the embodiments of the present invention when it is determined that the current distance between the barcode reader and the target barcode is the relatively long distance, the gray level distribution of the target scanning line is divided into at least one bar area and at least one space area. Thereafter, a space is interpolated into the bar area when the corresponding peak point within the gray level region is located within the bar area, and a bar is interpolated into the space area when the corresponding valley point within the gray level region is located within the space area, so as to recover the missing or vague bars or spaces in the target image of the target barcode. By such, the decoding success rate is increased when the current distance between the barcode reader and the target barcode is the relatively long distance. Besides, when the current distance between the barcode reader and the target barcode is determined to be the relatively intermediate distance, the binarization process is performed on the gray level distribution of the target scanning line according to the predetermined gray level PG so as to decode the target barcode. When the current distance between the barcode reader and the target barcode is determined to be the relatively short distance, filtering and down-sampling are performed on the target image, and the binarization process is performed on the gray level distribution of the target scanning line according to the predetermined gray level PG so as to decode the target barcode.
Those skilled in the art will readily observe that numerous modifications and alterations of the method may be made while retaining the teachings of the invention.
Number | Date | Country | Kind |
---|---|---|---|
105109126 | Mar 2016 | TW | national |