Barcode image binarization method and device, storage medium and computer device
By identifying the center point of the barcode image unit module and combining it with various binarization algorithms for scoring, the problem of binarization misjudgment caused by uneven illumination is solved, thus improving the accuracy and efficiency of barcode image recognition.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JIANGSU SEUIC TECH CO LTD
- Filing Date
- 2022-11-14
- Publication Date
- 2026-04-28
AI Technical Summary
Existing barcode image binarization methods are difficult to select a suitable threshold due to factors such as uneven illumination, sampling offset, and module dilation or erosion, resulting in poor binarization performance and affecting the accuracy and efficiency of barcode information recognition.
By identifying the center point of the unit module in the barcode image, at least two binarization algorithms are used to score each sampling point, calculate the black score and the white score, and combine the total binarization score of multiple algorithms to determine whether the sampling point is a black or white module, thus overcoming the problem of inappropriate threshold selection.
It improves the accuracy of barcode image binarization, effectively avoids misjudgment caused by improper threshold selection, and enhances recognition performance.
Smart Images

Figure CN115690431B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a method, apparatus, storage medium, and computer equipment for barcode image binarization. Background Technology
[0002] Barcodes are increasingly widely used in areas such as product and equipment labeling, and mobile payments. Barcodes mainly include one-dimensional (1D) and two-dimensional (2D) codes. Barcodes express information through a pattern of varying brightness and darkness, and can be read by specific devices, converting it into computer-compatible binary and decimal information. When parsing barcode images, binarization is usually performed for easier recognition.
[0003] Existing binarization methods are mainly divided into two categories: global thresholding and adaptive thresholding. However, during the acquisition of barcode images, uneven illumination, sampling offset, and the effects of surrounding module expansion or erosion make it difficult to select a suitable threshold for the barcode image, which can easily lead to poor binarization results and thus affect the accuracy and efficiency of barcode information recognition. Summary of the Invention
[0004] This application provides a method, apparatus, storage medium, and computer device for binarizing barcode images, which can improve the accuracy of binarization processing of barcode images.
[0005] In a first aspect, this application provides a method for binarizing barcode images, the method comprising:
[0006] Obtain the barcode image;
[0007] Identify the center point of each unit module in the barcode image and determine the sampling point for each unit module;
[0008] Each sampling point is binarized and scored according to at least two preset binarization algorithms, and the binarization score of each sampling point corresponding to each binarization algorithm is calculated; wherein, the binarization score includes a black score and a white score;
[0009] Calculate the total binarization score for each sampling point based on the binarization score corresponding to each binarization algorithm.
[0010] If the black score in the binarized total score of the sampling point is greater than the white score, then the unit module to which the sampling point belongs is determined as the black module;
[0011] If the black score in the total binary score of a sampling point is not greater than the white score, then the unit module to which the sampling point belongs is determined as a white module.
[0012] In one embodiment, the binarization scoring algorithm is a global threshold algorithm, a local threshold algorithm, or a neighborhood difference algorithm.
[0013] In one embodiment, when the binarization algorithm includes the neighborhood difference algorithm, performing the calculation of the binarization score for each sampling point corresponding to each binarization scoring algorithm includes:
[0014] Calculate the grayscale difference between each sampling point and each of its adjacent sampling points;
[0015] Calculate the sum of the grayscale differences between each sampling point and each adjacent sampling point;
[0016] The neighborhood score is determined based on the sum of the grayscale differences.
[0017] If the sum of grayscale differences is less than or equal to zero, then the black score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the white score is equal to zero.
[0018] If the sum of the grayscale differences is greater than zero, then the white score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the black score is equal to zero.
[0019] In one embodiment, when the binarization algorithm includes the global thresholding algorithm, performing the calculation of the binarization score for each sampling point corresponding to each binarization algorithm includes:
[0020] Calculate the global feature value of the barcode image as a global threshold; the global feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the barcode image;
[0021] The global score is determined based on the global feature values;
[0022] Determine whether the grayscale value of each sampling point is less than the global threshold;
[0023] If the value is less than the global threshold, then the black score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the white score is equal to zero.
[0024] If the value is not less than the global threshold, then the white score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the black score is equal to zero.
[0025] In one embodiment, when the binarization algorithm includes the local thresholding algorithm, performing the calculation of the binarization score for each sampling point corresponding to each binarization algorithm includes:
[0026] The barcode image is divided into multiple windows;
[0027] Calculate the local feature value of each window as the local threshold of that window; the local feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the window.
[0028] Local values are determined based on the local feature values of each window;
[0029] Determine whether the grayscale value of each sampling point in each window is less than the local threshold of its window;
[0030] If the value is less than the local threshold of its window, then the black score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the white score is equal to zero.
[0031] If the value is not less than the local threshold of its window, then the white score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the black score is equal to zero.
[0032] In one embodiment, calculating the total binarization score for each sampling point based on the binarization score corresponding to each binarization algorithm for each sampling point includes:
[0033] The binarization scores for each sampling point corresponding to each binarization algorithm are accumulated to obtain the total binarization score for each sampling point.
[0034] In one embodiment, calculating the total binarization score for each sampling point based on the binarization score corresponding to each binarization algorithm for each sampling point includes:
[0035] Based on the preset weights corresponding to each binarization algorithm, the binarization score of each sampling point corresponding to each binarization algorithm is multiplied by the preset weights to calculate a weighted score;
[0036] The weighted scores corresponding to each binarization algorithm are summed to obtain the total binarized score for each sampling point.
[0037] Secondly, this application provides a barcode image binarization device, comprising:
[0038] The image acquisition module is used to acquire barcode images;
[0039] The identification module is used to identify the center point of each unit module in the barcode image and determine the sampling point of each unit module respectively;
[0040] The scoring module is used to perform binarization scoring on each sampling point according to at least two preset binarization algorithms, and calculate the binarization score of each sampling point corresponding to each binarization algorithm; wherein, the binarization score includes a black score and a white score;
[0041] The total score calculation module is used to calculate the total binary score for each sampling point based on the binary score of each sampling point corresponding to each binary algorithm.
[0042] The first determining module is used to determine the unit module to which the sampling point belongs as a black module when the black score is greater than the white score in the binary total score of the sampling point.
[0043] The second determining module is used to determine the unit module to which the sampling point belongs as a white module when the black score in the binary total score of the sampling point is not greater than the white score.
[0044] Thirdly, this application provides a storage medium storing computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the barcode image binarization method as described in any of the above embodiments.
[0045] Fourthly, this application provides a computer device, including: one or more processors, and a memory;
[0046] The memory stores computer-readable instructions, and when the one or more processors execute the computer-readable instructions, they perform the steps of the barcode image binarization method as described in any of the above embodiments.
[0047] As can be seen from the above technical solutions, the embodiments of this application have the following advantages:
[0048] The barcode image binarization method, apparatus, storage medium, and computer equipment provided in this application identify unit modules of the acquired barcode image and identify the center point of each unit module. The center point of each unit module is determined as its sampling point. Each sampling point is binarized and scored according to at least two binarization algorithms. The black score and white score of each sampling point corresponding to each binarization algorithm are calculated. The total binarization score of each sampling point is calculated based on the binarization score (i.e., black score and white score) corresponding to each binarization algorithm. Finally, the sampling point is determined to be a black module or a white module based on the relationship between the black score and the white score in the total binarization score. This can overcome the problem of binarization misjudgment caused by improper threshold selection. It combines the preliminary recognition results of multiple binarization algorithms to make a joint decision, thereby improving the accuracy of binarization. Attached Figure Description
[0049] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0050] Figure 1 This is a flowchart illustrating a barcode image binarization method in one embodiment;
[0051] Figure 2 This is a flowchart illustrating the process of calculating the binarized score for each sampling point corresponding to each binarization scoring algorithm in one embodiment.
[0052] Figure 3 In another embodiment, a flowchart illustrating the process of calculating the binarized score for each sampling point corresponding to each binarization scoring algorithm is provided.
[0053] Figure 4 In another embodiment, a flowchart is shown to calculate the binarized score for each sampling point corresponding to each binarization scoring algorithm.
[0054] Figure 5 This is a structural block diagram of a barcode image binarization device in one embodiment;
[0055] Figure 6 This is a diagram of the internal structure of a computer device in one embodiment. Detailed Implementation
[0056] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0057] like Figure 1 As shown, this application embodiment provides a barcode image binarization method, the method including steps S101 to S107, wherein:
[0058] Step S101: Obtain the barcode image.
[0059] A barcode image is an image containing a barcode that needs to be identified; it can be obtained directly from an image acquisition device.
[0060] Step S102: Identify the center point of each unit module in the barcode image and determine the sampling point for each unit module.
[0061] In this context, a unit module refers to each black bar / dot or blank space arranged according to a certain pattern within the barcode area. If the barcode is a one-dimensional barcode, each black bar or blank bar constitutes a unit module; if the barcode is a two-dimensional barcode, each black dot or blank dot constitutes a unit module. The center point of a unit module is the pixel corresponding to its geometric center. Determining the center point as the sampling point for subsequent binarization processing, that is, characterizing the binarization of a unit module based on the binarization of the sampling point, can avoid color differences within the same unit module due to lighting or other reasons affecting the binarization effect.
[0062] Step S103: Perform binarization scoring on each sampling point according to at least two preset binarization algorithms, and calculate the binarization score of each sampling point corresponding to each binarization algorithm.
[0063] The binarization scoring includes black and white scores. Binarizing the sampling points using a binarization algorithm involves performing a preliminary binarization judgment on each sampling point. Each binarization algorithm yields a preliminary binarization result for each sampling point, which is then used as the basis for scoring. If the preliminary binarization result indicates that the sampling point is a dark area, then the black score for that sampling point is higher than the white score.
[0064] In one embodiment, the binarization scoring algorithm is a global thresholding algorithm, a local thresholding algorithm, or a neighborhood difference algorithm. Specifically, the global thresholding algorithm can be used as a binarization algorithm for scoring depending on the selected threshold; similarly, the local thresholding algorithm can also be used as a binarization algorithm for scoring depending on the selected threshold. The binarization algorithm to be used for scoring can be preset according to the environment or equipment conditions of the acquired image, and at least two binarization algorithms can be combined to overcome the influence of environmental and equipment factors on the binarization effect during image acquisition.
[0065] Step S104: Calculate the total binarization score for each sampling point based on the binarization score of each binarization algorithm corresponding to each sampling point.
[0066] The binarized total score includes the black and white scores of the binarized total score, calculated separately based on the black and white scores in each binarized score.
[0067] In one embodiment, the binarization scores corresponding to each sampling point for each binarization algorithm are accumulated to obtain the total binarization score for each sampling point.
[0068] In one embodiment, based on the preset weights corresponding to each binarization algorithm, the binarization score for each sampling point corresponding to each binarization algorithm is multiplied by the preset weights to calculate a weighted score; the weighted scores corresponding to each binarization algorithm are summed to obtain the total binarization score for each sampling point. By adjusting the preset weights, the influence of each binarization algorithm on the binarization result can be adjusted. The weights can be configured according to the acquisition environment and characteristics of the acquisition device for the barcode image, thereby improving the accuracy of the binarization result.
[0069] Step S105: Compare whether the black score in the binarized total score of each sampling point is greater than the white score.
[0070] Step S106: If the black score in the total binary score of the sampling point is greater than the white score, then the unit module to which the sampling point belongs is determined as the black module.
[0071] Step S107: If the black score in the binarized total score of the sampling point is not greater than the white score, then the unit module to which the sampling point belongs is determined as the white module.
[0072] Based on the total binarization score calculated using binarization scores obtained from at least two binarization algorithms, each sampling point is determined to be either a black or white pixel, thus identifying its corresponding unit module as either a black or white module. For each sampling point, if the black score in the total binarization score is greater than the white score, the corresponding sampling point is determined to be a black pixel, and its unit module is determined to be a black module; if the black score is not greater than the white score, the corresponding sampling point is determined to be a white pixel, and its unit module is determined to be a white module. This method does not rely on a single threshold for judgment but combines multiple binarization algorithms, effectively avoiding binarization errors caused by inappropriate threshold selection.
[0073] In this embodiment, the acquired barcode image is identified by recognizing unit modules and identifying the center point of each unit module. The center point of each unit module is determined as its sampling point. Each sampling point is binarized and scored according to at least two binarization algorithms. The black score and white score of each sampling point corresponding to each binarization algorithm are calculated. The total binarization score of each sampling point is calculated based on the binarization score (i.e., black score and white score) corresponding to each binarization algorithm. Finally, the sampling point is determined to be a black module or a white module based on the relationship between the black score and the white score in the total binarization score. This can overcome the problem of binarization misjudgment caused by improper threshold selection. The preliminary recognition results of multiple binarization algorithms are combined to make a joint decision, thereby improving the accuracy of binarization.
[0074] like Figure 2As shown, in one embodiment, when the binarization algorithm includes a neighborhood difference algorithm, the calculation of the binarization score for each sampling point corresponding to each binarization scoring algorithm includes:
[0075] Step S201: Calculate the grayscale difference between each sampling point and each of its adjacent sampling points;
[0076] Step S202: Calculate the sum of the grayscale differences between each sampling point and each adjacent sampling point;
[0077] Step S203: Determine the neighborhood score based on the sum of the grayscale differences;
[0078] Step S204: Compare whether the sum of the grayscale differences is greater than zero.
[0079] Step S205: If the sum of grayscale differences is less than or equal to zero, then the black score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the white score is equal to zero.
[0080] Step S206: If the sum of grayscale differences is greater than zero, then the white score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the black score is equal to zero.
[0081] In this context, adjacent sampling points can be adjacent in four or eight directions. Adjacent sampling points may or may not be adjacent pixels; they refer to the closest sampling point along a certain direction currently being identified. The neighborhood score can be a preset fixed score corresponding to the neighborhood difference algorithm, or it can be a preset weight corresponding to the neighborhood difference algorithm. The neighborhood score is calculated by multiplying the absolute value of the sum of grayscale differences by the preset weight.
[0082] For example, if the grayscale differences between a certain sampling point and its four adjacent sampling points in the four directions are d1, d2, d3, and d4 respectively, then the sum of the grayscale differences is calculated as D = d1 + d2 + d3 + d4. If D is less than or equal to zero, the neighborhood score is recorded as the black score and the white score is zero; if D is greater than zero, the neighborhood score is recorded as the white score and the black score is zero.
[0083] Barcode images may contain areas that cannot be binarized using thresholding, such as regions with uneven contrast. By using a neighborhood difference algorithm for binarization scoring, the grayscale difference of unit modules is used for judgment. The alternation of black and white in the barcode is used as prior information to calculate the grayscale difference between each sampling point and its neighboring sampling points. This can effectively solve the problem of inconsistent contrast changes caused by sampling offset, expansion or erosion of surrounding modules, and improve the accuracy of binarization.
[0084] like Figure 3As shown, in one embodiment, when the binarization algorithm includes the global thresholding algorithm, performing the calculation of the binarization score for each sampling point corresponding to each binarization algorithm includes:
[0085] Step S301: Calculate the global feature value of the barcode image as the global threshold.
[0086] The global feature values are the median gray value, the mean gray value, or the valley value of the image histogram of the barcode image.
[0087] Step S302: Determine the global score based on the global feature value.
[0088] The global score can be a preset score corresponding to the global feature value. Different preset scores can be set for different global feature values. In another embodiment, the same score can also be set.
[0089] Step S303: Determine whether the gray value of each sampling point is less than the global threshold.
[0090] Step S304: If the value is less than the global threshold, then the black score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the white score is equal to zero.
[0091] Step S305: If the value is not less than the global threshold, then the white score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the black score is equal to zero.
[0092] In this embodiment, global feature values are used as global thresholds for binarization scoring, which reduces computational complexity and compensates for binarization failures in monochrome regions. In some embodiments, the binarized score obtained by the global threshold algorithm can be used as an initial score, combined with binarized scores from other algorithms for final judgment. In some embodiments, different global feature values can be used as global thresholds for binarization scoring to overcome inaccurate binarization caused by improper threshold selection. In some embodiments, binarized scores obtained from one or more global feature values can be binarized together with binarized scores obtained from other types of algorithms.
[0093] like Figure 4 As shown, in one embodiment, when the binarization algorithm includes a local thresholding algorithm, performing the calculation of the binarization score for each sampling point corresponding to each binarization algorithm includes:
[0094] Step S401: Divide the barcode image into multiple windows.
[0095] Step S402: Calculate the local feature value of each window as the local threshold of that window.
[0096] Among them, the local feature values are the median gray value, the mean gray value, or the valley value of the image histogram for each window.
[0097] Step S403: Determine local partial values based on the local feature values of each window.
[0098] The local score can be a preset score corresponding to a local feature value. In one embodiment, different preset scores can be used for different local feature values. In another embodiment, the same score can also be set.
[0099] Step S404: Determine whether the gray value of each sampling point in each window is less than the local threshold of its window.
[0100] Step S405: If the value is less than the local threshold of its window, then the black score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the white score is equal to zero.
[0101] Step S406: If the value is not less than the local threshold of its window, then the white score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the black score is equal to zero.
[0102] During image acquisition, brightness differences may exist in different areas. By dividing the barcode image into multiple windows, and determining a local threshold for each window based on its own feature parameters for binarization, the negative impact of regional brightness differences on the binarization result can be reduced. In some embodiments, different local feature values can be used as local thresholds for binarization scoring, overcoming the problem of inaccurate binarization caused by improper threshold selection. In some embodiments, binarization scores obtained from one or more local feature values can be combined with binarization scores obtained from other types of algorithms for binarization processing.
[0103] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0104] The barcode image binarization apparatus provided in the embodiments of this application is described below. The barcode image binarization apparatus described below and the barcode image binarization method described above can be referred to in correspondence.
[0105] like Figure 5 As shown, this application embodiment provides a barcode image binarization device 500, including:
[0106] Image acquisition module 501 is used to acquire barcode images;
[0107] The identification module 502 is used to identify the center point of each unit module in the barcode image and determine the sampling point of each unit module respectively;
[0108] The scoring module 503 is used to perform binarization scoring on each sampling point according to at least two preset binarization algorithms, and to calculate the binarization score of each sampling point corresponding to each binarization algorithm; wherein, the binarization score includes a black score and a white score;
[0109] The total score calculation module 504 is used to calculate the total binary score of each sampling point based on the binary score of each sampling point corresponding to each binary algorithm.
[0110] The first determining module 505 is used to determine the unit module to which the sampling point belongs as a black module when the black score is greater than the white score in the binary total score of the sampling point.
[0111] The second determining module 506 is used to determine the unit module to which the sampling point belongs as a white module when the white score is greater than the black score in the binary total score of the sampling point.
[0112] In one embodiment, the scoring module is configured to perform the following steps:
[0113] Calculate the grayscale difference between each sampling point and each of its adjacent sampling points;
[0114] Calculate the sum of the grayscale differences between each sampling point and each adjacent sampling point;
[0115] The neighborhood score is determined based on the sum of the grayscale differences.
[0116] If the sum of grayscale differences is less than or equal to zero, then the black score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the white score is equal to zero.
[0117] If the sum of the grayscale differences is greater than zero, then the white score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the black score is equal to zero.
[0118] In one embodiment, the scoring module is also configured to perform the following steps:
[0119] Calculate the global feature value of the barcode image as a global threshold; the global feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the barcode image;
[0120] The global score is determined based on the global feature values;
[0121] Determine whether the grayscale value of each sampling point is less than the global threshold;
[0122] If the value is less than the global threshold, then the black score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the white score is equal to zero.
[0123] If the value is not less than the global threshold, then the white score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the black score is equal to zero.
[0124] In one embodiment, the scoring module is also configured to perform the following steps:
[0125] The barcode image is divided into multiple windows;
[0126] Calculate the local feature value of each window as the local threshold of that window; the local feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the window.
[0127] Local values are determined based on the local feature values of each window;
[0128] Determine whether the grayscale value of each sampling point in each window is less than the local threshold of its window;
[0129] If the value is less than the local threshold of its window, then the black score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the white score is equal to zero.
[0130] If the value is not less than the local threshold of its window, then the white score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the black score is equal to zero.
[0131] In one embodiment, the total score calculation module is configured to perform the following steps:
[0132] The binarization scores for each sampling point corresponding to each binarization algorithm are accumulated to obtain the total binarization score for each sampling point.
[0133] In one embodiment, the total score calculation module is configured to perform the following steps:
[0134] Based on the preset weights corresponding to each binarization algorithm, the binarization score of each sampling point corresponding to each binarization algorithm is multiplied by the preset weights to calculate a weighted score;
[0135] The weighted scores corresponding to each binarization algorithm are summed to obtain the total binarized score for each sampling point.
[0136] The division of modules in the above-described barcode image binarization device is merely illustrative. In other embodiments, the barcode image binarization device can be divided into different modules as needed to complete all or part of its functions. Each module in the above-described barcode image binarization device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0137] In one embodiment, this application also provides a storage medium storing computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the following steps:
[0138] Obtain the barcode image;
[0139] Identify the center point of each unit module in the barcode image and determine the sampling point for each unit module;
[0140] Each sampling point is binarized and scored according to at least two preset binarization algorithms, and the binarization score of each sampling point corresponding to each binarization algorithm is calculated; wherein, the binarization score includes a black score and a white score;
[0141] Calculate the total binarization score for each sampling point based on the binarization score corresponding to each binarization algorithm.
[0142] If the black score in the binarized total score of the sampling point is greater than the white score, then the unit module to which the sampling point belongs is determined as the black module;
[0143] If the white score is greater than the black score in the total binary score of the sampling point, then the unit module to which the sampling point belongs is determined to be a white module.
[0144] In one embodiment, the computer-readable instructions, when executed by the processor, further perform the following steps:
[0145] Calculate the grayscale difference between each sampling point and each of its adjacent sampling points;
[0146] Calculate the sum of the grayscale differences between each sampling point and each adjacent sampling point;
[0147] The neighborhood score is determined based on the sum of the grayscale differences.
[0148] If the sum of grayscale differences is less than or equal to zero, then the black score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the white score is equal to zero.
[0149] If the sum of the grayscale differences is greater than zero, then the white score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the black score is equal to zero.
[0150] In one embodiment, the computer-readable instructions, when executed by the processor, further perform the following steps:
[0151] Calculate the global feature value of the barcode image as a global threshold; the global feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the barcode image;
[0152] The global score is determined based on the global feature values;
[0153] Determine whether the grayscale value of each sampling point is less than the global threshold;
[0154] If the value is less than the global threshold, then the black score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the white score is equal to zero.
[0155] If the value is not less than the global threshold, then the white score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the black score is equal to zero.
[0156] In one embodiment, the computer-readable instructions, when executed by the processor, further perform the following steps:
[0157] The barcode image is divided into multiple windows;
[0158] Calculate the local feature value of each window as the local threshold of that window; the local feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the window.
[0159] Local values are determined based on the local feature values of each window;
[0160] Determine whether the grayscale value of each sampling point in each window is less than the local threshold of its window;
[0161] If the value is less than the local threshold of its window, then the black score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the white score is equal to zero.
[0162] If the value is not less than the local threshold of its window, then the white score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the black score is equal to zero.
[0163] In one embodiment, the computer-readable instructions, when executed by the processor, further perform the following steps:
[0164] The binarization scores for each sampling point corresponding to each binarization algorithm are accumulated to obtain the total binarization score for each sampling point.
[0165] In one embodiment, the computer-readable instructions, when executed by the processor, further perform the following steps:
[0166] Based on the preset weights corresponding to each binarization algorithm, the binarization score of each sampling point corresponding to each binarization algorithm is multiplied by the preset weights to calculate a weighted score;
[0167] The weighted scores corresponding to each binarization algorithm are summed to obtain the total binarized score for each sampling point.
[0168] In one embodiment, this application also provides a computer device storing computer-readable instructions, wherein when the one or more processors execute the computer-readable instructions, they perform the following steps:
[0169] Obtain the barcode image;
[0170] Identify the center point of each unit module in the barcode image and determine the sampling point for each unit module;
[0171] Each sampling point is binarized and scored according to at least two preset binarization algorithms, and the binarization score of each sampling point corresponding to each binarization algorithm is calculated; wherein, the binarization score includes a black score and a white score;
[0172] Calculate the total binarization score for each sampling point based on the binarization score corresponding to each binarization algorithm.
[0173] If the black score in the binarized total score of the sampling point is greater than the white score, then the unit module to which the sampling point belongs is determined as the black module;
[0174] If the white score is greater than the black score in the total binary score of the sampling point, then the unit module to which the sampling point belongs is determined to be a white module.
[0175] In one embodiment, the processor also performs the following steps when executing computer-readable instructions:
[0176] Calculate the grayscale difference between each sampling point and each of its adjacent sampling points;
[0177] Calculate the sum of the grayscale differences between each sampling point and each adjacent sampling point;
[0178] The neighborhood score is determined based on the sum of the grayscale differences.
[0179] If the sum of grayscale differences is less than or equal to zero, then the black score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the white score is equal to zero.
[0180] If the sum of the grayscale differences is greater than zero, then the white score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the black score is equal to zero.
[0181] In one embodiment, the processor also performs the following steps when executing computer-readable instructions:
[0182] Calculate the global feature value of the barcode image as a global threshold; the global feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the barcode image;
[0183] The global score is determined based on the global feature values;
[0184] Determine whether the grayscale value of each sampling point is less than the global threshold;
[0185] If the value is less than the global threshold, then the black score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the white score is equal to zero.
[0186] If the value is not less than the global threshold, then the white score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the black score is equal to zero.
[0187] In one embodiment, the processor also performs the following steps when executing computer-readable instructions:
[0188] The barcode image is divided into multiple windows;
[0189] Calculate the local feature value of each window as the local threshold of that window; the local feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the window.
[0190] Local values are determined based on the local feature values of each window;
[0191] Determine whether the grayscale value of each sampling point in each window is less than the local threshold of its window;
[0192] If the value is less than the local threshold of its window, then the black score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the white score is equal to zero.
[0193] If the value is not less than the local threshold of its window, then the white score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the black score is equal to zero.
[0194] In one embodiment, the processor also performs the following steps when executing computer-readable instructions:
[0195] The binarization scores for each sampling point corresponding to each binarization algorithm are accumulated to obtain the total binarization score for each sampling point.
[0196] In one embodiment, the processor also performs the following steps when executing computer-readable instructions:
[0197] Based on the preset weights corresponding to each binarization algorithm, the binarization score of each sampling point corresponding to each binarization algorithm is multiplied by the preset weights to calculate a weighted score;
[0198] The weighted scores corresponding to each binarization algorithm are summed to obtain the total binarized score for each sampling point.
[0199] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 6 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements a barcode image binarization method. The display screen can be an LCD screen or an e-ink display screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0200] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0201] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments described above. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0202] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0203] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0204] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.
[0205] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for binarizing barcode images, characterized in that, The method includes: Obtain the barcode image; Identify the center point of each unit module in the barcode image and determine the sampling point for each unit module; Each sampling point is binarized and scored according to at least two preset binarization algorithms, and the binarization score of each sampling point corresponding to each binarization algorithm is calculated; wherein, the binarization score includes a black score and a white score; Calculate the total binarization score for each sampling point based on the binarization score corresponding to each binarization algorithm. If the black score in the binarized total score of the sampling point is greater than the white score, then the unit module to which the sampling point belongs is determined as the black module; If the black score in the binarized total score of the sampling point is not greater than the white score, then the unit module to which the sampling point belongs is determined as a white module; When the binarization algorithm includes a neighborhood difference algorithm, the calculation of the binarization score for each sampling point corresponding to each binarization scoring algorithm includes: Calculate the grayscale difference between each sampling point and each of its adjacent sampling points; Calculate the sum of the grayscale differences between each sampling point and each adjacent sampling point; The neighborhood score is determined based on the sum of the grayscale differences. If the sum of grayscale differences is less than or equal to zero, then the black score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the white score is equal to zero. If the sum of the grayscale differences is greater than zero, then the white score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the black score is equal to zero.
2. The barcode image binarization method according to claim 1, characterized in that, The binarization scoring algorithm also includes a global threshold algorithm or a local threshold algorithm.
3. The barcode image binarization method according to claim 2, characterized in that, When the binarization algorithm includes the global thresholding algorithm, the calculation of the binarization score for each sampling point corresponding to each binarization algorithm is performed, including: Calculate the global feature value of the barcode image as a global threshold; the global feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the barcode image; The global score is determined based on the global feature values; Determine whether the grayscale value of each sampling point is less than the global threshold; If the value is less than the global threshold, then the black score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the white score is equal to zero. If the value is not less than the global threshold, then the white score of the sampling point corresponding to the global threshold algorithm is equal to the global score, and the black score is equal to zero.
4. The barcode image binarization method according to claim 2, characterized in that, When the binarization algorithm includes the local thresholding algorithm, the calculation of the binarization score for each sampling point corresponding to each binarization algorithm includes: The barcode image is divided into multiple windows; Calculate the local feature value of each window as the local threshold of that window; the local feature value is the median gray value, the mean gray value, or the valley value of the image histogram of the window. Local values are determined based on the local feature values of each window; Determine whether the grayscale value of each sampling point in each window is less than the local threshold of its window; If the value is less than the local threshold of its window, then the black score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the white score is equal to zero. If the value is not less than the local threshold of its window, then the white score of the sampling point corresponding to the local threshold algorithm is equal to the local score, and the black score is equal to zero.
5. The barcode image binarization method according to claim 1, characterized in that, The step of calculating the total binarization score for each sampling point based on the binarization score corresponding to each binarization algorithm includes: The binarization scores for each sampling point corresponding to each binarization algorithm are accumulated to obtain the total binarization score for each sampling point.
6. The barcode image binarization method according to claim 1, characterized in that, The step of calculating the total binarization score for each sampling point based on the binarization score corresponding to each binarization algorithm includes: Based on the preset weights corresponding to each binarization algorithm, the binarization score of each sampling point corresponding to each binarization algorithm is multiplied by the preset weights to calculate a weighted score; The weighted scores corresponding to each binarization algorithm are summed to obtain the total binarized score for each sampling point.
7. A barcode image binarization device, characterized in that, include: The image acquisition module is used to acquire barcode images; The identification module is used to identify the center point of each unit module in the barcode image and determine the sampling point of each unit module respectively; The scoring module is used to perform binarization scoring on each sampling point according to at least two preset binarization algorithms, and calculate the binarization score of each sampling point corresponding to each binarization algorithm; wherein, the binarization score includes a black score and a white score; The total score calculation module is used to calculate the total binary score for each sampling point based on the binary score of each sampling point corresponding to each binary algorithm. The first determining module is used to determine the unit module to which the sampling point belongs as a black module when the black score is greater than the white score in the binary total score of the sampling point. The second determining module is used to determine the unit module to which the sampling point belongs as a white module when the black score in the binary total score of the sampling point is not greater than the white score; When the binarization algorithm includes a neighborhood difference algorithm, the scoring module is specifically used to: calculate the grayscale difference between each sampling point and each of its neighboring sampling points; calculate the sum of the grayscale differences between each sampling point and each of its neighboring sampling points; determine the neighborhood score based on the sum of the grayscale differences; if the sum of the grayscale differences is less than or equal to zero, then the black score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the white score is equal to zero; if the sum of the grayscale differences is greater than zero, then the white score of the sampling point corresponding to the neighborhood difference algorithm is equal to the neighborhood score, and the black score is equal to zero.
8. A storage medium, characterized in that: The storage medium stores computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the barcode image binarization method as described in any one of claims 1 to 6.
9. A computer device, characterized in that, include: One or more processors, and memory; The memory stores computer-readable instructions, and when the one or more processors execute the computer-readable instructions, they perform the steps of the barcode image binarization method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Two-dimensional code image binarization processing method and device
CN111259680A
Efficient bar code binarization method and system
CN112364876A
Method and apparatus for recognizing code
US20050194445A1