CN114943241B - Method for repairing bar code image, electronic equipment and storage medium - Google Patents

Method for repairing bar code image, electronic equipment and storage medium Download PDF

Info

Publication number
CN114943241B
CN114943241B CN202210882340.6A CN202210882340A CN114943241B CN 114943241 B CN114943241 B CN 114943241B CN 202210882340 A CN202210882340 A CN 202210882340A CN 114943241 B CN114943241 B CN 114943241B
Authority
CN
China
Prior art keywords
repair
bar
code
repaired
sequence
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210882340.6A
Other languages
Chinese (zh)
Other versions
CN114943241A (en
Inventor
续素芬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Unigroup Tsingteng Microsystems Co Ltd
Original Assignee
Beijing Unigroup Tsingteng Microsystems Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Unigroup Tsingteng Microsystems Co Ltd filed Critical Beijing Unigroup Tsingteng Microsystems Co Ltd
Priority to CN202210882340.6A priority Critical patent/CN114943241B/en
Publication of CN114943241A publication Critical patent/CN114943241A/en
Application granted granted Critical
Publication of CN114943241B publication Critical patent/CN114943241B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K7/00Methods or arrangements for sensing record carriers, e.g. for reading patterns
    • G06K7/10Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
    • G06K7/14Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation using light without selection of wavelength, e.g. sensing reflected white light
    • G06K7/1404Methods for optical code recognition
    • G06K7/146Methods for optical code recognition the method including quality enhancement steps

Abstract

The application relates to the technical field of bar code repair, and discloses a method for repairing a bar code image, which comprises the following steps: identifying the bar code image to be repaired to obtain the original code system category of the bar code image; repairing the bar code graph according to the type of the original code system to obtain a repaired code graph; acquiring a first repair bar space proportion sequence corresponding to a repair code map; and repairing the first repairing strip empty proportion sequence. Therefore, the bar code graph is repaired according to the original code system category of the bar code graph to obtain a repaired bar code graph, then the first repaired bar space proportion sequence corresponding to the repaired bar code graph is repaired, and through two times of repair, the probability of distortion of the repaired bar space proportion sequence is reduced, so that the bar space accuracy of the repaired bar code graph is improved. The application also discloses an electronic device and a storage medium.

Description

Method for repairing bar code image, electronic equipment and storage medium
Technical Field
The present application relates to the field of barcode repair technology, and for example, to a method, an electronic device, and a storage medium for repairing a barcode diagram.
Background
At present, with the rapid expansion and development of retail industry and consumer market, the application field of bar codes is more and more extensive. For example, in the fields of logistics industry, cargo classification in logistics, distribution of warehouse locations, inquiry of warehouse locations, information of entering and leaving a warehouse, checking of entering and leaving a warehouse, product inquiry and the like, the figure of a bar code can be seen. People acquire the bar code through the acquisition device to obtain a bar code image. However, due to the fact that the barcode itself is damaged or the hardware of the acquisition device is limited, the accuracy of the acquired image is not high, the identification is difficult, and the acquired image needs to be repaired to prepare for subsequent decoding. For example, chinese patent publication No. CN113449536A discloses a barcode image repairing method, which includes: correcting the barcode image collected by the terminal equipment to obtain a corrected barcode image which is a barcode image to be identified; identifying the color of each pixel in the barcode image to be identified line by line, and generating a color matrix corresponding to the barcode image to be identified according to a color identification result; determining color marks corresponding to all columns of the color matrix according to the number of black elements in all columns of the color matrix; and generating a target bar code image corresponding to the color matrix according to the color identification. Chinese patent publication No. CN109214229B discloses a barcode scanning method, comprising: obtaining a target image containing a bar code; the bar code is a one-dimensional bar code; determining light spot pixel points in a light spot area in the target image according to the gray value of each pixel point in the target image; adopting the gray value of a non-light spot pixel point in each target pixel column to repair the gray value of the light spot pixel point in the target pixel column, wherein the target pixel column is as follows: a pixel column where a light spot pixel point is located in each pixel column of an area where a bar code is located in a target image; the gray value of each pixel point is the same on the same pixel column of the one-dimensional bar code, and the pixel column of the target image is parallel to the column direction of the one-dimensional bar code; performing strip-space scanning on the repaired target image to obtain strip-space information; and decoding the bar space information to obtain the character information of the bar code identifier contained in the target image.
In the process of implementing the embodiments of the present disclosure, it is found that at least the following problems exist in the related art: in the prior art, under the condition that the accuracy of a bar code image reaches sub-pixel accuracy, the color boundary of the bar code image is not obvious, and the pixel color cannot be effectively read, so that the bar code image cannot be effectively repaired, and errors may exist in bar spaces of the repaired bar code image.
Disclosure of Invention
The following presents a simplified summary in order to provide a basic understanding of some aspects of the disclosed embodiments. This summary is not an extensive overview nor is intended to identify key/critical elements or to delineate the scope of such embodiments but rather as a prelude to the more detailed description that is presented later.
The embodiment of the disclosure provides a method, an electronic device and a storage medium for repairing a bar code image, so as to improve the accuracy of bar space of the repaired bar code image.
In some embodiments, the method for repairing a barcode diagram comprises: identifying a bar code image to be repaired to obtain an original code system category of the bar code image; repairing the bar code image according to the original code system category to obtain a repaired code image; acquiring a first repair bar space proportion sequence corresponding to the repair code map; and repairing the first repairing strip empty proportion sequence.
In some embodiments, the electronic device includes a processor and a memory storing program instructions, and the processor is configured to execute the method for repairing a barcode pattern described above when executing the program instructions.
In some embodiments, the storage medium stores program instructions that, when executed, perform the above-described method for repairing a barcode pattern.
The method, the electronic device and the storage medium for repairing the barcode diagram provided by the embodiment of the disclosure can achieve the following technical effects: the method comprises the steps of identifying a bar code image to be repaired to obtain an original code system type of the bar code image, repairing the bar code image according to the original code system type to obtain a repaired code image, obtaining a first repaired bar space proportion sequence corresponding to the repaired code image, and repairing the first repaired bar space proportion sequence. In this way, the bar code image is repaired according to the original code system category of the bar code image to obtain a repaired code image, then the first repaired bar-space proportion sequence corresponding to the repaired code image is repaired, and through two times of repairs, the probability of distortion of the repaired bar-space proportion sequence is reduced, so that the bar-space accuracy of the repaired bar code image is improved.
The foregoing general description and the following description are exemplary and explanatory only and are not restrictive of the application.
Drawings
One or more embodiments are illustrated by way of example in the accompanying drawings, which correspond to the accompanying drawings and not in limitation thereof, in which elements having the same reference numeral designations are shown as like elements and not in limitation thereof, and wherein:
FIG. 1 is a schematic diagram of a method for repairing a barcode diagram according to an embodiment of the present disclosure;
FIG. 2 is a schematic diagram of a repair template provided by an embodiment of the present disclosure;
fig. 3 is a schematic diagram of a gray value of each pixel point in a barcode code image to be repaired according to the embodiment of the present disclosure;
fig. 4 is a schematic diagram of a gray value after enhancement of each pixel point in a barcode code image to be repaired according to the embodiment of the present disclosure;
fig. 5 is a schematic diagram of a method for obtaining a repair code pattern according to an embodiment of the present disclosure;
FIG. 6 is a diagram of a repair code graph according to an embodiment of the present disclosure;
FIG. 7 is a schematic diagram of a method for repairing a second repair bar null-ratio sequence according to an embodiment of the present disclosure;
fig. 8 is a schematic diagram of a barcode diagram corresponding to a repaired second repair bar empty scale sequence according to an embodiment of the present disclosure;
FIG. 9 is a schematic diagram of a method for decoding provided by an embodiment of the present disclosure;
FIG. 10 is a schematic diagram of an apparatus for repairing a barcode diagram according to an embodiment of the present disclosure;
fig. 11 is a schematic diagram of an electronic device provided by an embodiment of the disclosure.
Detailed Description
So that the manner in which the features and advantages of the embodiments of the present disclosure can be understood in detail, a more particular description of the embodiments of the disclosure, briefly summarized above, may be had by reference to the appended drawings, which are included to illustrate, but are not intended to limit the embodiments of the disclosure. In the following description of the technology, for purposes of explanation, numerous details are set forth in order to provide a thorough understanding of the disclosed embodiments. However, one or more embodiments may be practiced without these details. In other instances, well-known structures and devices may be shown in simplified form in order to simplify the drawing.
The terms "first," "second," and the like in the description and claims of the embodiments of the disclosure and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It should be understood that the data so used may be interchanged under appropriate circumstances such that embodiments of the present disclosure described herein may be made. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion.
The term "plurality" means two or more unless otherwise specified.
In the embodiment of the present disclosure, the character "/" indicates that the preceding and following objects are in an or relationship. For example, A/B represents: a or B.
The term "and/or" is an associative relationship that describes objects, meaning that three relationships may exist. For example, a and/or B, represents: a or B, or A and B.
The term "correspond" may refer to an association or binding relationship, and a corresponds to B refers to an association or binding relationship between a and B.
The method for repairing the barcode drawing provided by the embodiment of the disclosure is applied to electronic equipment. The electronic equipment identifies the bar code image to be repaired to obtain the original code system type of the bar code image, and repairs the bar code image according to the original code system type to obtain the repaired bar code image. And then the electronic equipment acquires a first repair bar space ratio sequence corresponding to the repair code map. And repairing the first repairing strip empty proportion sequence. Therefore, through two times of repairing, the probability of the repaired bar space proportion sequence distortion is reduced, and the bar space accuracy of the repaired bar code image is improved.
With reference to fig. 1, an embodiment of the present disclosure provides a method for repairing a barcode diagram, including:
step S101, the electronic equipment identifies the bar code image to be repaired to obtain the original code system category of the bar code image. Wherein, the bar code image to be repaired is the code image of the bar code. The barcode includes a one-dimensional barcode or a two-dimensional barcode.
And S102, the electronic equipment repairs the bar code image according to the type of the original code system to obtain a repaired code image.
Step S103, the electronic device obtains a first repair bar space ratio sequence corresponding to the repair code map.
And step S104, the electronic equipment repairs the first repair bar space ratio sequence.
By adopting the method for repairing the barcode diagram provided by the embodiment of the disclosure, the original code system category of the barcode diagram is obtained by identifying the barcode diagram to be repaired, the barcode diagram is repaired according to the original code system category to obtain the repaired barcode diagram, the first repaired barcode blank proportion sequence corresponding to the repaired barcode diagram is obtained, and the first repaired barcode blank proportion sequence is repaired. In this way, the bar code image is repaired according to the original code system category of the bar code image to obtain a repaired code image, then the first repaired bar-space proportion sequence corresponding to the repaired code image is repaired, and through two times of repairs, the probability of distortion of the repaired bar-space proportion sequence is reduced, so that the bar-space accuracy of the repaired bar code image is improved.
Further, before the electronic device identifies the barcode diagram to be repaired, the method further includes: the electronic equipment acquires an image including a bar code pattern to be repaired. And the electronic equipment positions the bar code image to be repaired in the image to obtain the bar code image to be repaired. Therefore, the bar code can be repaired aiming at the area where the bar code image to be repaired is located, so that the repair is more targeted, and the efficiency of repairing the bar code image is improved.
Further, the electronic device obtains an image including a barcode diagram to be repaired, including: the electronic equipment shoots the bar code to be repaired through the camera device to obtain an image comprising a bar code pattern to be repaired.
In some embodiments, in the case that the barcode is small or the shooting distance is long, the barcode code image in the image shot by the camera device is blurred, and the accuracy of the barcode code image is low and is sub-pixel accuracy. The width of a pixel occupied by a bar space in a bar code image with sub-pixel precision is less than 1 pixel, and the problem of difficult discrimination of the bar space exists. The electronic equipment identifies the sub-pixel precision bar code image to obtain the original code system category of the sub-pixel precision bar code image. And then, restoring the bar code image with the sub-pixel precision according to the original code system category to obtain a restored code image. And acquiring a first repair bar space ratio sequence corresponding to the repair code map, and repairing the first repair bar space ratio sequence. Therefore, the probability of the distortion of the repaired bar space proportional sequence of the bar code image with sub-pixel precision is reduced, and the accuracy of the bar space of the repaired bar code image is improved.
Further, the electronic device locates the barcode pattern to be repaired in the image to obtain the barcode pattern to be repaired, and the method includes the following steps: the electronic device constructs a first gradient direction histogram corresponding to the image. The electronic device identifies a Region where the peak value in the first gradient direction histogram is located, and obtains a barcode diagram to be repaired. Therefore, the ROI identification is carried out on the region where the peak value in the first gradient direction histogram is located, the region where the bar code image is located can be accurately positioned, and the accuracy of the bar space of the bar code image is improved aiming at the region. Meanwhile, images in other areas are abandoned, so that the time of repairing the bar code image can be shortened, and the efficiency of repairing the bar code image is improved.
Further, the electronic device constructs a second histogram of gradient directions corresponding to the image by the following method: the electronic device constructs a cartesian coordinate system on the image, wherein coordinate axes of the cartesian coordinate system are an axis a and an axis b, respectively. The electronic equipment obtains the gray value of each pixel point in the image. The electronic equipment respectively acquires the gradient value of each pixel point in the image in the a-axis direction and the gradient value of each pixel point in the image in the b-axis direction according to the gray value of each pixel point. And obtaining the gradient field of the image according to the gradient value of each pixel point in the a-axis direction and the gradient value in the b-axis direction. The electronics acquire a directional field corresponding to the gradient field of the image. The electronic equipment counts the direction field of the image to obtain a first gradient direction histogram.
Optionally, the electronic device identifies the barcode diagram to be repaired, and obtains an original code system category of the barcode diagram, including: the electronic equipment acquires the original initial character in the bar code image. The electronic equipment utilizes a preset first code system category database to perform table look-up operation on the original initial symbol to obtain the code system category corresponding to the original initial symbol. The first code system type database stores the corresponding relation between the original initial character and the code system type. And the electronic equipment determines the code system type corresponding to the original initial symbol as the original code system type of the bar code image. Wherein, the original start symbol is positioned at the start position of the bar code image to be repaired. Therefore, the original code system category of the bar code image can be obtained through the original starter, so that the code image can be repaired by utilizing the obtained original code system category, the accuracy of distinguishing bar spaces in the code image is improved, a first repair bar space proportion sequence can be obtained and repaired, and the accuracy of the bar spaces of the repaired bar code image is improved.
Optionally, the electronic device repairs the barcode code image to be repaired according to the type of the original code system to obtain a repaired code image, including: the electronic device obtains an original codeword length for the original start symbol. And the electronic equipment acquires the original unit module width of the bar code image according to the original code word length and the original code system type. The electronic equipment acquires the code pattern direction of the bar code pattern. And under the condition that the width of the original unit module is less than or equal to a set first threshold value, the electronic equipment constructs a repair template according to the width of the original unit module and the direction of the code graph. And the electronic equipment utilizes the repair template to carry out image enhancement on the bar code image. And the electronic equipment determines the bar code image after the image enhancement as a repair code image. Further, the original codeword length is the pixel length of the original start symbol. Therefore, the original unit module width of the bar code image is obtained through the original code word length of the original initial character, and a repair template is constructed according to the code image direction of the bar code image and the original unit module width. And carrying out image enhancement on the bar code image by using the repair template, and determining the bar code image after the image enhancement as a repair code image. The method and the device realize the restoration of the bar code graph, and preliminarily improve the accuracy of distinguishing the bar spaces in the code graph so as to carry out restoration by utilizing the first restoration bar space proportion sequence corresponding to the restoration code graph. The probability of the repaired bar space ratio sequence distortion is reduced, and therefore the bar space accuracy of the repaired bar code image is improved.
Further, the electronic device obtains the original unit module width of the bar code pattern to be repaired according to the original code word length and the original code system category, and the method comprises the following steps: the electronic equipment utilizes the preset number of the initial symbol modules to match the database, and performs table look-up operation on the original code system category to obtain the number of the initial symbol modules corresponding to the original code system category. The initial symbol module number matching database stores the corresponding relation between the original code system category and the initial symbol module number. And the electronic equipment determines the number of modules of the initial character corresponding to the original code system type as the number of original modules. And the electronic equipment determines the quotient of the length of the original code word and the number of the original modules as the width of the original unit module of the bar code image.
Further, the electronic device obtains the code pattern direction of the barcode code pattern to be repaired, including: and the electronic equipment constructs a second gradient direction histogram corresponding to the bar code image. The electronic device obtains a direction corresponding to a peak in the second gradient direction histogram. And the electronic equipment determines the direction corresponding to the peak value in the second gradient direction histogram as the code pattern direction of the barcode code pattern.
Further, the electronic device constructs a second gradient direction histogram corresponding to the barcode diagram to be repaired by the following method: the electronic equipment constructs a Cartesian coordinate system on a bar code image to be repaired, wherein coordinate axes of the Cartesian coordinate system are an x axis and a y axis respectively. The electronic equipment obtains the gray value of each pixel point in the bar code image. And the electronic equipment respectively acquires the gradient value of each pixel point in the bar code image in the x-axis direction and the gradient value of each pixel point in the y-axis direction according to the gray value of each pixel point. And the electronic equipment obtains the gradient field of the bar code image according to the gradient value of each pixel point in the x-axis direction and the gradient value in the y-axis direction. The electronic device acquires a directional field corresponding to each gradient field. And the electronic equipment counts the directional fields to obtain a second gradient direction histogram.
Further, the electronic device respectively obtains the gradient value of each pixel point in the x-axis direction and the gradient value of the pixel point in the y-axis direction in the barcode code image to be repaired according to the gray value of each pixel point, and the method comprises the following steps: electronic device passing through computing G x (I, j) = I (I +1, j) -I (I, j), and obtaining the gradient value of a pixel point with the coordinate (I, j) in the bar code image to be repaired in the x-axis direction. Wherein G is x And (i, j) is the gradient value of the pixel point with the coordinate (i, j) in the bar code image to be repaired in the x-axis direction. And I (I +1, j) is the gray value of a pixel point with the coordinate (I +1, j) in the bar code image to be repaired. And I (I, j) is the gray value of a pixel point with the coordinate (I, j) in the bar code image to be repaired. Electronic device through calculating G y (I, j) = I (I, j + 1) -I (I, j), and obtaining the gradient value of a pixel point with the coordinate of (I, j) in the bar code pattern to be repaired in the y-axis direction. Wherein G is y (i, j) is the y-axis of the pixel point with the coordinate (i, j) in the bar code image to be repairedA gradient value in direction. And I (I, j + 1) is the gray value of a pixel point with the coordinate (I, j + 1) in the bar code image to be repaired. Further, i, j are positive integers. Further, i is more than or equal to 1 and less than or equal to m-1, and j is more than or equal to 1 and less than or equal to n-1. Wherein m is the maximum value of each pixel point in the bar code image to be repaired in the x direction, and n is the maximum value of each pixel point in the bar code image to be repaired in the y direction.
Further, the electronic device obtains a gradient field of the barcode pattern to be repaired according to the gradient value of each pixel point in the x-axis direction and the gradient value in the y-axis direction, and the method comprises the following steps: the electronic equipment calculates G (x, y) = G x (i,j)+G y (i, j) obtaining the gradient comparison value of each pixel point in the bar code image. And G (x, y) is a gradient comparison value of each pixel point in the bar code image to be repaired. And the electronic equipment determines the pixel points corresponding to the gradient comparison value as gradient pixel points under the condition that the gradient comparison value is greater than or equal to a preset comparison threshold value. Electronic device passing through computing G xx =∑∑G x (i,j)×G x (i, j) obtaining a gradient field of the bar code pattern to be repaired in the x-axis direction. Wherein G is xx The gradient field of the bar code image to be repaired in the direction of the x axis. Electronic device passing through computing G yy =∑∑G y (i,j)×G y And (i, j) obtaining a gradient field of the bar code image to be repaired in the y-axis direction. Wherein, G yy The gradient field of the bar code pattern to be repaired in the y-axis direction. Electronic device through calculating G xy =∑∑G x (i,j)×G y And (i, j) obtaining gradient fields of the bar code image to be repaired in the directions of the x axis and the y axis. Wherein, G xy The gradient fields of the bar code pattern to be repaired in the directions of the x axis and the y axis are obtained.
Further, the electronic device obtains a direction corresponding to a peak value in the second histogram of gradient directions, including: the electronic device calculates θ = (1/2) × tan -1 (2G xy /G xx -G yy ) And obtaining the angle corresponding to the peak value in the second gradient direction histogram. Where θ is an angle corresponding to a peak in the second histogram of gradient directions. The electronic equipment acquires the direction corresponding to the angle and determines the direction corresponding to the angle as a second gradient direction histogramThe direction corresponding to the peak in (b).
In some embodiments, θ is 0 degrees, the direction corresponding to the angle 0 is horizontal to the right, and the direction corresponding to the peak in the second histogram of gradient directions is horizontal to the right. θ is 45 degrees, and the direction corresponding to this angle 45 is diagonally right up, then the direction corresponding to the peak in the second histogram of gradient directions is diagonally right up. θ is 90 degrees, the direction corresponding to the angle 90 is vertically upward, and the direction corresponding to the peak in the second histogram of gradient directions is vertically upward. θ is 135 degrees, and the direction corresponding to the angle 135 is inclined to the left and up, then the direction corresponding to the peak in the second histogram of gradient directions is inclined to the left and up. θ is 180 degrees, the direction corresponding to the angle 180 is horizontal to the left, and the direction corresponding to the peak in the second histogram of gradient directions is horizontal to the left.
Further, the electronic device constructs a repair template according to the original unit module width and the code pattern direction, including: the electronic equipment utilizes a preset restoration template database to perform table look-up operation on the original unit module width and the code pattern direction, and obtains the size of the restoration template and the direction of the restoration template corresponding to the original unit module width and the code pattern direction. The repair template database stores the corresponding relationship among the unit module width, the code pattern direction, the template size and the template direction. And the electronic equipment constructs an alternative repair template according to the size of the repair template and the direction of the repair template. And the electronic equipment fills data in the alternative repairing template according to a preset rule to obtain the repairing template.
In some embodiments, the original unit block width is 3 and the code pattern direction is horizontal to the right. The electronic equipment matches the size of the repair template corresponding to the width of the original unit module and the code pattern direction in a preset repair template database, wherein the size is 3 multiplied by 3. The direction of the electronic equipment matching the repair template corresponding to the width of the original unit module and the direction of the code pattern in a preset repair template database is horizontal to the right. The electronic equipment constructs an alternative repair template with the size of 3 multiplied by 3 and the direction of the repair template is horizontal and right. The electronic device fills data in the candidate repair template according to the horizontal sharpening and vertical smoothing rules to obtain the repair template shown in fig. 2, where fig. 2 is a schematic diagram of a repair template provided in the embodiment of the present disclosure.
Further, the electronic device performs image enhancement on the barcode diagram to be repaired by using the repair template, including: the electronic equipment convolutes the gray value of each pixel point in the bar code image to be repaired by using the enhancement template to obtain the enhanced gray value of each pixel point so as to enhance the image of the bar code image. Therefore, the barcode code image after image enhancement is formed by the pixels after gray value enhancement, the difference between the pixels in the barcode code image is amplified, and the code image is repaired. And the second repair bar space ratio sequence extracted each time is repaired in the first repair bar space ratio sequence corresponding to the repaired repair code map. The probability of the repaired bar space proportion sequence distortion is reduced, and therefore the bar space accuracy of the repaired bar code image is improved.
With reference to fig. 2 and fig. 3, fig. 3 is a schematic diagram of gray values of each pixel point in a barcode code image to be repaired according to the embodiment of the present disclosure. The size of the bar code pattern is 6 multiplied by 6, and the direction of the bar code pattern is horizontal to the right. Fig. 2 is a schematic diagram of a repair template according to an embodiment of the present disclosure. The repairing template is constructed according to the original unit module width and the code pattern direction of the bar code pattern to be repaired. The repair template has a size of 3 x 3 and a direction of horizontal to the right. A Cartesian coordinate system is established on a to-be-repaired bar code image, the origin of the Cartesian coordinate system is the first pixel point at the upper left corner of the bar code image, the x-axis direction is horizontal to the right, and the y-axis direction is vertical to the downward. And establishing a Cartesian coordinate system on the repairing template, wherein the origin of the Cartesian coordinate system is the first data of the upper left corner of the repairing template, the x-axis direction is horizontal to the right, and the y-axis direction is vertical to the lower. The electronic device convolves the gray scale value of each pixel point in the barcode diagram by calculating I' (I, j) = C (0, 0) × I (I-1, j-1) + C (0, 2) × I (I-1, j + 1) + C (1, 0) × I (I, j-1) + C (1, 1) × I (I, j) + C (1, 2) × I (I, j + 1) + C (2, 0) × I (I +1, j-1) + C (2, 1) × I (I +1, j) + C (2, 2) × I (I +1, j 1) to obtain the gray scale value after the pixel point with coordinates (I, j) is enhanced by calculating the gray scale value of each pixel point in the barcode diagram. Wherein, I' (I, j) is the gray value of the pixel point with the coordinate (I, j) after being enhanced. C (0, 0) is the value at the coordinates (0, 0) in the repair template, i.e., 0.C (0, 1) is the value at the coordinate (0, 1) in the repair template, i.e., 2.C (0, 2) is the value at the coordinates (0, 2) in the repair template, i.e., 0.C (1, 0) is the value at the coordinates (1, 0) in the repair template, i.e., -1.C (1, 1) is the value at coordinate (1, 1) in the repair template, i.e., 4.C (1, 2) is the value at coordinate (1, 2) in the repair template, i.e., -1.C (2, 0) is the value at coordinate (2, 0) in the repair template, i.e., 0.C (2, 1) is the value at coordinate (2, 1) in the repair template, i.e., 2.C (2, 2) is the value at coordinate (2, 2) in the repair template, i.e., 0.I (I-1, j-1) is the gray value of the pixel point with the coordinate of (I-1, j-1). And I (I-1, j) is the gray value of the pixel point with the coordinate of (I-1, j). I (I-1, j + 1) is the gray value of the pixel point with the coordinate of (I-1, j + 1). And I (I, j-1) is the gray value of the pixel point with the coordinate of (I, j-1). And I (I, j) is the gray value of the pixel point with the coordinate (I, j). I (I, j + 1) is the gray value of the pixel point with the coordinate (I, j + 1). I (I +1, j-1) is the gray value of the pixel point with the coordinate of (I +1, j-1). I (I +1, j) is the gray value of the pixel point with the coordinate of (I +1, j). I (I +1, j + 1) is the gray value of the pixel point with the coordinate of (I +1, j + 1). When i =0, j =5, or j =5, the gradation value of the pixel point cannot be convolved by the above formula, and the gradation value of the pixel point cannot be enhanced. After the gray value of each pixel point in the barcode code image to be repaired is convolved, the obtained enhanced gray value of each pixel point is shown in fig. 4. Fig. 4 is a schematic diagram of a gray value of each pixel point in a barcode code image to be repaired after enhancement according to the embodiment of the present disclosure. As shown in fig. 3 and 4, before enhancement, the maximum difference between the grayscale values of the pixel points at the edge portion of the image is 10, i.e., 10-0=10. After enhancement, the maximum difference between the gray values of the pixel points in the edge portion of the image is 80, i.e., 70- (-10) =80. Therefore, the difference between the pixel points in the bar code image is amplified, and the bar code image is repaired. The second repair bar-space proportion sequence extracted each time is repaired in the first repair bar-space proportion sequence corresponding to the repaired repair code map, the probability of distortion of the repaired repair bar-space proportion sequence is reduced, and therefore the accuracy of bar space of the repaired bar code map is improved.
With reference to fig. 5, an embodiment of the present disclosure provides a method for obtaining a repair code map, including:
step S501, the electronic equipment acquires the original code word length of the original initial character of the bar code pattern to be repaired.
Step S502, the electronic equipment acquires the original unit module width of the bar code image according to the original code word length and the original code system type.
In step S503, the electronic device constructs a second gradient direction histogram corresponding to the barcode diagram.
In step S504, the electronic device obtains a direction corresponding to a peak value in the second histogram of gradient directions.
In step S505, the electronic device determines a direction corresponding to a peak value in the second gradient direction histogram as a code pattern direction of the barcode code pattern to be repaired.
In step S506, the electronic device constructs a repair template according to the original unit module width and the code pattern direction when the original unit module width is less than or equal to the set first threshold.
In step S507, the electronic device performs image enhancement on the barcode image by using the repair template.
Step S508, the electronic device determines the barcode image with enhanced image as a repair code image.
By adopting the method for obtaining the repaired code image provided by the embodiment of the disclosure, the original unit module width of the bar code image is obtained through the original code word length of the original start symbol, and the code image direction of the bar code image is accurately obtained according to the second gradient direction histogram corresponding to the bar code image. And then, constructing a repairing template by utilizing the direction of the code pattern and the width of the original unit module, so that the repairing template is more accordant with the code pattern of the bar code. The method improves the effect of image enhancement on the bar code image by using the repairing template, preliminarily improves the accuracy of distinguishing the bar spaces in the bar code image, is convenient for repairing by using the first repairing bar space proportion sequence corresponding to the repairing code image, reduces the probability of distortion of the repaired repairing bar space proportion sequence, and improves the accuracy of the bar spaces of the repaired bar code image.
Further, the electronic device obtains a first repair bar space ratio sequence corresponding to the repair code map, including: the electronic equipment acquires the repair code word direction of the repair code pattern. And the direction of the repaired code word of the repaired code image is the same as the direction of the code image of the bar code image to be repaired. And the electronic equipment binarizes the repair code image to obtain a binarized repair code image. And the electronic equipment constructs a scanning line on the binary repair code image. And the electronic equipment scans the binary repair code map by using the scanning line according to the repair code word direction to obtain a first repair bar space ratio sequence. Further, the scanning direction of the scanning line is the same as the direction of the repair code word. And the data in the first repair bar space proportion sequence is used for reflecting the pixel length corresponding to the bar or space in the repair code image. Furthermore, the bars in the repair code map are black bars in the one-dimensional code. The spaces in the repair code map are white bars in the one-dimensional code.
Further, the electronic device binarizes the repair code image to obtain a binarized repair code image, including: and under the condition that the gray value of each pixel point in the restoration code image is greater than or equal to a set third threshold value, determining the data of the pixel point in the binary restoration code image as 1. And under the condition that the gray value of each pixel point in the restoration code image is smaller than a set third threshold value, determining the data of the pixel point in the binary restoration code image as 0. And the number of the data in the binary repair code image is the same as the number of the pixel points in the repair code image.
In some embodiments, with reference to fig. 6, fig. 6 is a schematic diagram of a repair code pattern provided in the embodiments of the present disclosure. As shown in fig. 6, the length of the pixel corresponding to the first bar L1 in the repair code map is 2. The first empty L2 corresponds to a pixel length of 2. The second bar L3 corresponds to a pixel length of 0.5. The second empty L4 corresponds to a pixel length of 1. The third bar L5 corresponds to a pixel length of 0.5. The third space L6 corresponds to a pixel length of 6. The fourth bar L7 corresponds to a pixel length of 4. The fourth space L8 corresponds to a pixel length of 6. The repair codeword direction of the repair code pattern is horizontal to the right. And the electronic equipment binarizes the repair code image to obtain a binarized repair code image. And the electronic equipment constructs a scanning line on the binary restoration code image, wherein the direction of the scanning line is horizontal to the right. The binary repair code image is scanned by using a scanning line according to the direction of the repair code word, and the obtained first repair bar space ratio sequence is { 2. Then, the electronic device repairs the first repair bar empty scale sequence.
Optionally, the electronic device repairs the first repair bar empty scale sequence, including: and the electronic equipment sequentially extracts a plurality of sections of second repair bar empty proportion sequences from the first repair bar empty proportion sequence, wherein the second repair bar empty proportion sequences extracted each time are repaired. Therefore, the multiple sections of second repairing bar empty proportion sequences are extracted from the first repairing bar empty proportion sequence in sequence, and the extracted second repairing bar empty proportion sequences are repaired, so that the first repairing bar empty proportion sequence is repaired, the probability of distortion of the repaired repairing bar empty proportion sequences is reduced, and the bar empty accuracy of the repaired bar code graph is improved.
Optionally, the extracting, by the electronic device, the second repair bar space ratio sequence from the first repair bar space ratio sequence includes: the electronics determine a bar space ratio sequence extraction length. And the electronic equipment extracts a second repairing strip space proportion sequence from the first repairing strip space proportion sequence according to the strip space proportion sequence extraction length. And the length of the extracted second repair strip space proportion sequence is the same as the extraction length of the strip space proportion sequence. Therefore, the electronic equipment can extract the second repairing bar space proportion sequence with the bar space proportion sequence extraction length from the first repairing bar space proportion sequence so as to repair the second repairing bar space proportion sequence, reduce the probability of distortion of the repaired repairing bar space proportion sequence and improve the bar space accuracy of the repaired bar code diagram.
Optionally, the electronic device determines a strip-space ratio sequence extraction length, including: the electronic device determines a repair start symbol in the repair code map. And the electronic equipment performs table look-up operation on the repair start symbol by using a preset second code system category database to obtain the code system category corresponding to the repair start symbol. The second code system type database stores the corresponding relation between the repair start symbol and the code system type. And the electronic equipment determines the extraction length of the bar space ratio sequence according to the code system type corresponding to the repair start symbol. Wherein, the repair start symbol is located at the start position of the repair code map. Or, the electronic device obtains the first codeword length. And the length of the first code word is the length of the code word corresponding to the repaired second repair strip space ratio sequence. The repaired second repair strip space proportion sequence is a strip space proportion sequence obtained after a section of second repair strip space proportion sequence is extracted from the first repair strip space proportion sequence by utilizing the extraction length of the first alternative strip space proportion sequence for repairing. The first alternative stripe space ratio sequence extraction length is the stripe space ratio sequence extraction length determined according to the repair start symbol in the repair code map. And acquiring the strip space ratio sequence extraction length according to the first code word length. Wherein, the strip-space ratio sequence extraction length is the pixel length of the repair start character. Or, a second codeword length is obtained. The second code word length is the length of the code word corresponding to the repaired second repair strip space ratio sequence. The repaired second repair bar-space ratio sequence is a bar-space ratio sequence obtained after a section of second repair bar-space ratio sequence is extracted from the first repair bar-space ratio sequence for the nth time and is repaired. n is a positive integer. And acquiring the strip space ratio sequence extraction length according to the second code word length. Therefore, the electronic equipment can determine the extraction length of the bar space ratio sequence according to the code system type corresponding to the repair start symbol in the repair code image or the number of times of extracting the second repair bar space ratio sequence, so that the second repair bar space ratio sequence with the extraction length of the bar space ratio sequence is extracted from the first repair bar space ratio sequence, the second repair bar space ratio sequence is repaired conveniently, the probability of distortion of the repaired repair bar space ratio sequence is reduced, and the accuracy of the bar space of the repaired bar code image is improved.
Further, the electronic device determines the extraction length of the bar space ratio sequence according to the code system type corresponding to the repair start symbol, and the method includes: and the electronic equipment obtains the third code word length corresponding to the code system type according to the code system type corresponding to the repair start symbol. The electronic equipment calculates D = D 1 X (1 + e), obtaining the strip space ratio sequence extraction length. Wherein D is the extraction length of the strip-space ratio sequence. d 1 Is the third codeword length. e is a set fourth threshold. Furthermore, e is more than or equal to 0 and less than or equal to 1.
Further, the electronic device obtains the strip space ratio sequence extraction length according to the first codeword length, including: the electronic equipment calculates D = D 2 X (1 + e), obtaining the strip space ratio sequence extraction length. Wherein D is the extraction length of the strip-space ratio sequence. d 2 Is the first codeword length. Therefore, the extraction length of the bar space ratio sequence is longer than that of the first code word, so that the second repair bar space ratio sequence extracted according to the extraction length of the bar space ratio sequence comprises one code word, the second repair bar space ratio sequence is repaired conveniently, the probability of distortion of the repaired repair bar space ratio sequence is reduced, and the accuracy of the bar space of the repaired bar code diagram is improved.
Further, the electronic device obtains the strip space ratio sequence extraction length according to the second codeword length, including: the electronic equipment calculates D = D 3 X (1 + e), obtaining the strip space ratio sequence extraction length. Wherein D is the extraction length of the strip-space ratio sequence. d 3 Is the second codeword length. Therefore, the strip space ratio sequence extraction length is longer than the length of the second code word, so that the second repair strip space ratio sequence extracted according to the strip space ratio sequence extraction length comprises one code word, the second repair strip space ratio sequence is repaired conveniently, the probability of distortion of the repaired repair strip space ratio sequence is reduced, and the strip space accuracy of the repaired bar code image is improved.
In some embodiments, when the n +1 th time extracts a second repair strip space ratio sequence, the electronic device obtains the length of the codeword corresponding to the strip space ratio sequence obtained after the nth time extracts a second repair strip space ratio sequence from the first repair strip space ratio sequence for repair. The electronic device determines the codeword length as a second codeword length. And the electronic equipment acquires the extraction length of the bar space ratio sequence according to the length of the second code word, namely the extraction length of the bar space ratio sequence acquired at the (n + 1) th time. Then, under the condition that a segment of the second repair bar null proportion sequence is extracted at the (n + 1) th time, the electronic device re-extracts the second repair bar null proportion sequence from the first repair bar null proportion sequence by taking the end point of the second repair bar null proportion sequence extracted at the nth time as a starting point. The length of the second repair strip space proportion sequence which is re-extracted is the extraction length of the strip space proportion sequence which is obtained at the (n + 1) th time. And after the electronic equipment repairs the second repaired blank proportion sequence extracted again, the length of the code word corresponding to the repaired second repaired blank proportion sequence extracted again is obtained. The code word is the length of the code word corresponding to the repaired second repair strip space ratio sequence. Therefore, the strip-space ratio sequence extraction length of the second repair strip-space ratio sequence extracted at the last time is determined according to the length of the code word corresponding to the second repair strip-space ratio sequence repaired at the last time, so that the extracted second repair strip-space ratio sequence certainly comprises one code word, the second repair strip-space ratio sequence is repaired conveniently, the probability of distortion of the repaired repair strip-space ratio sequence is reduced, and the accuracy of the strip space of the repaired bar code diagram is improved.
Optionally, the electronic device repairs the second repair bar empty proportion sequence by the following method: the electronic equipment acquires the repair code system type and repair unit module width of the repair code image. And the electronic equipment acquires the number of units corresponding to the code word according to the repair code system category of the repair code map. The electronic device determines a product of the repair unit module width and a set second threshold as a correction threshold. And the electronic equipment repairs the second repair strip empty proportion sequence according to the correction threshold and the number of the units. Alternatively, 0 ≦ p ≦ 1. Wherein p is a set second threshold. In this way, the number of units corresponding to the code word is obtained through the type of the repair code system, the repair threshold is obtained according to the width of the repair unit module, and then the second repair bar space ratio sequence is repaired according to the repair threshold and the number of the units, so that the probability of distortion of the repaired repair bar space ratio sequence is reduced, and the accuracy of the bar space of the repaired bar code image is improved.
Further, the electronic device obtains the repair code system type and repair unit module width of the repair code map, including: and the electronic equipment identifies the repair code image and obtains the repair code system category of the repair code image. The electronic device obtains a repair codeword length for the repair initiator. Wherein, the length of the repair code word is the pixel length of the repair start symbol. The electronic equipment utilizes the preset number of the initial symbol modules to match the database, and carries out table look-up operation on the repair code system category to obtain the number of the initial symbol modules corresponding to the repair code system category. The preset initial symbol module number matching database stores the corresponding relation between the repair code system type and the initial symbol module number. And the electronic equipment determines the number of modules of the initial character corresponding to the repair code system type as the number of repair modules. And the electronic equipment determines the quotient of the length of the repair code word and the number of the repair modules as the width of the repair unit module.
Further, the electronic device obtains the number of units corresponding to the code word according to the type of the repair code system of the repair code map, including: and the electronic equipment performs table look-up operation on the repair code system category by using a preset database of the number of the code system category units to obtain the number of the units of the code words corresponding to the repair code system category. The preset database of the number of the code system units stores the corresponding relationship between the repair code system types and the number of the code word units.
Further, the electronic device repairs the second repair stripe space ratio sequence according to the correction threshold and the number of the units, and the method includes: and the electronic equipment extracts a third repairing strip empty proportion sequence from the second repairing strip empty proportion sequence according to the number of the units. And the number of the third repair strip null ratio sequence data is the same as the number of the units corresponding to the code words. And the electronic equipment determines the data smaller than the correction threshold value in the third repair bar space proportion sequence as the data to be corrected. The electronic equipment adds the data to be corrected and two adjacent data thereof to obtain the corrected data. And under the condition that the corrected data is equal to the set fifth threshold, the electronic equipment replaces the data to be corrected and two adjacent data thereof with the corrected data in the third repair bar space ratio sequence to obtain a fourth repair bar space ratio sequence. And the electronic equipment replaces the third repairing bar space proportion sequence with the fourth repairing bar space proportion sequence in the second repairing bar space proportion sequence to obtain a fifth repairing bar space proportion sequence. And the electronic equipment extracts a sixth repair bar empty proportion sequence from the fifth repair bar empty proportion sequence. And the number of the sixth repair strip null ratio sequence data is the same as the number of the units corresponding to the code words. And the electronic equipment determines the sixth repair bar empty proportion sequence as the second repaired repair bar empty proportion sequence. Therefore, the electronic equipment can repair the second repair bar space ratio sequence in the first repair bar space ratio sequence, the probability of distortion of the repaired repair bar space ratio sequence is reduced, and the bar space accuracy of the repaired bar code image is improved.
With reference to fig. 7, an embodiment of the present disclosure provides a method for repairing a second repair bar null ratio sequence, including:
in step S701, the electronic device obtains a repair code system type, a repair unit module width, and a second repair bar empty ratio sequence to be repaired of the repair code map.
Step S702, the electronic device obtains the number of units corresponding to the code word according to the type of the repair code system.
In step S703, the electronic device determines a product of the repair unit module width and the set second threshold as a correction threshold.
Step S704, the electronic device extracts a third repair bar null proportion sequence in the second repair bar null proportion sequence according to the number of the units. And the number of the third repair strip null proportion sequence data is the same as the number of units corresponding to the code word.
In step S705, the electronic device determines the data smaller than the correction threshold in the third repair bar space ratio sequence as the data to be corrected.
Step S706, the electronic device adds the data to be corrected and two adjacent data to obtain the corrected data.
In step S707, when the corrected data is equal to the set fifth threshold, the electronic device replaces two adjacent data of the data to be corrected with the corrected data in the third repair bar space ratio sequence, and obtains a fourth repair bar space ratio sequence.
In step S708, the electronic device replaces the third repair bar air proportion sequence with the fourth repair bar air proportion sequence in the second repair bar air proportion sequence to obtain a fifth repair bar air proportion sequence.
In step S709, the electronic device extracts a sixth repair bar empty proportion sequence from the fifth repair bar empty proportion sequence. And the number of the sixth repair strip null ratio sequence data is the same as the number of the units corresponding to the code words.
In step S710, the electronic device determines the sixth repair bar empty proportion sequence as the repaired second repair bar empty proportion sequence.
By adopting the method for repairing the second repair bar space ratio sequence provided by the embodiment of the disclosure, the electronic device obtains the number of units corresponding to the code word according to the repair code system type of the repair code map, and obtains the correction threshold according to the repair unit module width. And then correcting the second repaired bar-space proportion sequence according to the number of units corresponding to the code word and the correction threshold value, so that a correct bar-space proportion sequence can be obtained, and the probability of distortion of the repaired bar-space proportion sequence is reduced, thereby improving the bar-space accuracy of the repaired bar code image.
In some embodiments, the second repair bar null ratio sequence is { 2. The length of the pixel corresponding to the first bar L1 is 2. The first empty L2 corresponds to a pixel length of 2. The second bar L3 corresponds to a pixel length of 0.5. The second empty L4 corresponds to a pixel length of 1. The third bar L5 corresponds to a pixel length of 0.5. The third space L6 corresponds to a pixel length of 6. The fourth bar L7 corresponds to a pixel length of 4. The fourth space L8 corresponds to a pixel length of 6. If the repair Code system class is Code128, the number of units of the codeword corresponding to the repair Code system class Code128 is 6. The repair unit block width is 2. If the set second threshold is 0.75, the correction threshold is 1.5, which is the product of the repair unit module width 2 and the set second threshold of 0.75. The set fifth threshold includes 1,2, 3, or 4. The electronic device extracts data of which the number is 6 in the second repair bar null proportion sequence, and obtains a third repair bar null proportion sequence { 2. And in the case of data smaller than the correction threshold in the third repair bar-space proportion sequence, the electronic equipment determines that the bar or space corresponding to the data needs to be corrected. The electronic device determines the data in the third repair bar space proportion sequence that is smaller than the correction threshold, i.e., 0.5 and 1, as the data to be corrected. Then L3, L4 and L5 are nulls for the bars to be corrected. The electronic equipment adds the data to be corrected and two adjacent data thereof to obtain the corrected data. The bar space to be corrected is merged with two adjacent bar spaces to obtain the corrected bar space. That is, the sum of the pixel lengths of the space L2, the bar L3, and the space L4 is determined as the pixel length of the corrected space P3, and the pixel length of the space P3 is 3.5. The sum of the pixel lengths of the bar L3, the space L4, and the bar L5 is determined as the pixel length of the corrected bar P4, and the pixel length of the bar P4 is 2. The sum of the pixel lengths of the space L4, the bar L5, and the space L6 is determined as the pixel length of the corrected space P5, and the pixel length of the space P5 is 7.5. The corrected data 3.5 and 7.5 are not equal to the set fifth threshold, and the electronic device discards the corrected null P3 and the corrected null P5, that is, discards the pixel lengths of the two, that is, the pixel lengths of the two are 3.5 and 7.5, respectively. The corrected data 2 is equal to the set fifth threshold, the electronic device retains the corrected bar P4, and replaces the data to be corrected and two adjacent data thereof with the corrected data in the third repair bar space ratio sequence, so as to obtain a fourth repair bar space ratio sequence { 2. In the second repair bar null ratio sequence, the electronic device replaces the third repair bar null ratio sequence with the fourth repair bar null ratio sequence to obtain a fifth repair bar null ratio sequence { 2. The electronic device extracts data whose number is 6 units from the fifth repair strip null ratio sequence, and obtains a sixth repair strip null ratio sequence { 2. The electronic device determines the sixth repair bar null proportion sequence { 1. The barcode code image corresponding to the repaired second repair bar empty scale sequence is shown in fig. 8, and fig. 8 is a schematic diagram of the barcode code image corresponding to the repaired second repair bar empty scale sequence.
Optionally, after repairing the second repair bar empty proportion sequence extracted each time, the electronic device further includes: and the electronic equipment decodes the repaired second repair strip space ratio sequence to obtain a code word corresponding to the second repair strip space ratio sequence. Therefore, the decoding rate of the algorithm is improved by decoding the bar code pattern with the bar space accuracy improved, so that accurate code words can be obtained, and the decoding accuracy is improved.
Further, the electronic device decodes the repaired second repair stripe space ratio sequence by the following method: and the electronic equipment performs table look-up operation on the repaired second repair bar-space ratio sequence by using a preset decoded character database to obtain characters corresponding to the repaired second repair bar-space ratio sequence. And the preset decoding character database stores the corresponding relation between the repaired second repair bar space ratio sequence and the characters. Therefore, the repaired second repair strip empty proportion sequence is matched in the decoded character database, and the clothes corresponding to the repaired second repair strip empty proportion sequence can be accurately obtained, so that the repaired second repair strip empty proportion sequence can be decoded, and the decoding accuracy is improved.
In some embodiments, the repair Code system class is Code128, and the second repair bar after repair has a null ratio sequence of { 1. The electronic device obtains a database of decoded characters corresponding to the Code 128. And then, performing table look-up operation on the repaired second repair bar space ratio sequence by using the decoded character database to obtain a character 'A' corresponding to the repaired second repair bar space ratio sequence. And decoding the second repair strip space ratio sequence of the second repair strip space ratio sequence is realized.
As shown in fig. 9, an embodiment of the present disclosure provides a method for decoding, including:
step S901, the electronic device acquires an image including a barcode diagram.
Step S902, the electronic device locates the barcode diagram in the image to obtain the barcode diagram.
Step S903, the electronic equipment acquires an original initial character in the bar code image.
In step S904, the electronic device performs a table lookup operation on the original start symbol by using a preset first code system category database to obtain a code system category corresponding to the original start symbol. The first code system type database stores the corresponding relation between the original initial symbol and the code system type.
Step S905, the electronic device determines the code system type corresponding to the original start symbol as the original code system type of the barcode code image.
In step S906, the electronic device obtains an original codeword length of the original start symbol.
In step S907, the electronic device obtains the original unit module width of the barcode diagram according to the original codeword length and the original code system type.
Step S908, the electronic device obtains a code pattern direction of the barcode code pattern.
In step S909, the electronic device constructs a repair template according to the original unit module width and the code pattern direction when the original unit module width is less than or equal to the set first threshold.
In step S910, the electronic device performs image enhancement on the barcode diagram by using the repair template.
And step S911, the electronic equipment determines the bar code image after image enhancement as a repair code image.
In step S912, the electronic device obtains a first repair bar empty ratio sequence corresponding to the repair code map.
Step S913, the electronic device sequentially extracts a plurality of segments of second repair bar space ratio sequences from the first repair bar space ratio sequence, wherein the second repair bar space ratio sequence extracted each time is decoded after being repaired, and a codeword corresponding to each segment of the second repair bar space ratio sequence is obtained.
By adopting the method for decoding provided by the embodiment of the disclosure, the barcode code image to be decoded is positioned in the image to obtain the barcode code image, and the repair template is obtained according to the original initial character in the barcode code image. And the bar code image is repaired by utilizing the repair template. And acquiring a first repair bar space ratio sequence corresponding to the repaired repair code map. And then, sequentially extracting a plurality of sections of second repairing strip empty proportion sequences from the first repairing strip empty proportion sequence, repairing the second repairing strip empty proportion sequence extracted each time, and then decoding to obtain code words corresponding to each section of second repairing strip empty proportion sequence. Therefore, the accuracy of distinguishing bar spaces in the bar code image is preliminarily improved by firstly repairing the bar code image, and in a first repairing bar space proportion sequence corresponding to the repaired repairing code image, a second repairing bar space proportion sequence extracted each time is repaired and then decoded. The probability of the repaired bar space ratio sequence distortion is reduced, the bar space accuracy of the repaired bar code image is improved, and the decoding accuracy is improved.
Referring to fig. 10, an apparatus for repairing a barcode diagram provided in the embodiment of the present disclosure includes a code system type identification module 1, a code diagram repair module 2, a proportional sequence acquisition module 3, and a proportional sequence repair module 4. The code system type identification module 1 is configured to identify a barcode code image to be repaired, and obtain an original code system type of the barcode code image. The code pattern repairing module 2 is configured to repair the code pattern according to the original code system category to obtain a repaired code pattern. The proportional sequence obtaining module 3 is configured to obtain a first repair bar empty proportional sequence corresponding to the repair code pattern. The proportional sequence repair module 4 is configured to repair the first repair bar null proportional sequence.
By adopting the device for repairing the barcode diagram provided by the embodiment of the disclosure, by adopting the electronic equipment provided by the embodiment of the disclosure, the original code system category of the barcode diagram is obtained by identifying the barcode diagram to be repaired, the barcode diagram is repaired according to the original code system category to obtain the repaired barcode diagram, the first repaired barcode blank proportion sequence corresponding to the repaired barcode diagram is obtained, and the first repaired barcode blank proportion sequence is repaired. Therefore, the bar code graph is repaired according to the original code system category of the bar code graph to obtain a repaired bar code graph, then the first repaired bar space proportion sequence corresponding to the repaired bar code graph is repaired, and through two times of repair, the probability of distortion of the repaired bar space proportion sequence is reduced, so that the bar space accuracy of the repaired bar code graph is improved.
Further, the code system type identification module is configured to identify the barcode code image to be repaired by the following method to obtain the original code system type of the barcode code image: and acquiring an original initial character in the bar code image. And performing table look-up operation on the original initial symbol by utilizing a preset first code system category database to obtain the code system category corresponding to the original initial symbol. The first code system type database stores the corresponding relation between the original initial symbol and the code system type. And determining the code system type corresponding to the original initial character as the original code system type of the bar code image.
Further, the code pattern repairing module is configured to repair the barcode pattern according to the original code system category by the following method to obtain a repaired code pattern: the original codeword length of the original start symbol is obtained. And acquiring the original unit module width of the bar code image according to the original code word length and the original code system category. And acquiring the code image direction of the bar code image. And under the condition that the width of the original unit module is less than or equal to a set first threshold value, constructing a repair template according to the width of the original unit module and the direction of the code graph. And carrying out image enhancement on the bar code image by using the repairing template. And determining the bar code image after the image enhancement as a repair code image.
Further, the scaled sequence repair module is configured to repair the first repair bar empty scaled sequence by: and sequentially extracting a plurality of sections of second repair strip empty proportion sequences from the first repair strip empty proportion sequence, wherein the second repair strip empty proportion sequence extracted each time is repaired.
Further, the scaled sequence restoration module is configured to extract a second restoration bar null scaled sequence in the first restoration bar null scaled sequence by: and determining the extraction length of the strip-space ratio sequence. And extracting a second repairing strip space proportion sequence from the first repairing strip space proportion sequence according to the strip space proportion sequence extraction length.
Further, the scaled sequence repair module is configured to determine the strip-space scaled sequence extraction length by: a repair start in the repair code map is determined. And performing table look-up operation on the repair initial symbol by using a preset second code system category database to obtain the code system category corresponding to the repair initial symbol. The second code system type database stores the corresponding relation between the repair start symbol and the code system type. And determining the extraction length of the strip-space ratio sequence according to the code system type corresponding to the repair start symbol. Or, obtaining the first codeword length. And the length of the first code word is the length of the code word corresponding to the repaired second repair strip space ratio sequence. The repaired second repair strip space proportion sequence is a strip space proportion sequence obtained after a section of second repair strip space proportion sequence is extracted from the first repair strip space proportion sequence by utilizing the extraction length of the first alternative strip space proportion sequence for repairing. The extraction length of the first alternative strip space ratio sequence is determined according to a repair start symbol in the repair code image; and acquiring the strip space ratio sequence extraction length according to the first code word length. Or, a second codeword length is obtained. And the length of the second code word is the length of the code word corresponding to the repaired second repair strip space ratio sequence. The repaired second repair strip-space proportion sequence is obtained after extracting a section of second repair strip-space proportion sequence from the first repair strip-space proportion sequence for repairing at the nth time, wherein n is a positive integer. And acquiring the strip space ratio sequence extraction length according to the second code word length.
Further, the scaled sequence repair module is configured to repair the second repair bar empty scaled sequence by: and acquiring the repair code system type and repair unit module width of the repair code image. And acquiring the number of units corresponding to the code word according to the repair code system category. And determining the product of the width of the repair unit module and the set second threshold value as a correction threshold value. And repairing the second repairing strip empty proportion sequence according to the correction threshold and the number of the units.
Further, the device for repairing the barcode diagram also comprises a decoding module. The decoding module is configured to decode the repaired second repair strip space ratio sequence after repairing the second repair strip space ratio sequence extracted each time, so as to obtain a codeword corresponding to the second repair strip space ratio sequence.
As shown in fig. 11, an embodiment of the present disclosure provides an electronic device including a processor (processor) 100 and a memory (memory) 101. Optionally, the apparatus may also include a Communication Interface (Communication Interface) 102 and a bus 103. The processor 100, the communication interface 102, and the memory 101 may communicate with each other via a bus 103. The communication interface 102 may be used for information transfer. The processor 100 may invoke logic instructions in the memory 101 to perform the method for repairing a barcode pattern of the above-described embodiments.
In addition, the logic instructions in the memory 101 may be implemented in the form of software functional units and stored in a computer readable storage medium when the logic instructions are sold or used as independent products.
The memory 101 is a storage medium and can be used for storing software programs, computer executable programs, such as program instructions/modules corresponding to the methods in the embodiments of the present disclosure. The processor 100 executes functional applications and data processing by executing program instructions/modules stored in the memory 101, namely, implements the method for repairing barcode patterns in the above embodiments.
The memory 101 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to the use of the terminal device, and the like. In addition, the memory 101 may include a high-speed random access memory, and may also include a nonvolatile memory.
By adopting the electronic equipment provided by the embodiment of the disclosure, the original code system type of the bar code image is obtained by identifying the bar code image to be repaired, the bar code image is repaired according to the original code system type to obtain the repair code image, the first repair bar space proportion sequence corresponding to the repair code image is obtained, and the first repair bar space proportion sequence is repaired. In this way, the bar code image is repaired according to the original code system category of the bar code image to obtain a repaired code image, then the first repaired bar-space proportion sequence corresponding to the repaired code image is repaired, and through two times of repairs, the probability of distortion of the repaired bar-space proportion sequence is reduced, so that the bar-space accuracy of the repaired bar code image is improved.
Optionally, the electronic device includes a user terminal, a scanning device, and the like.
The embodiment of the disclosure provides a storage medium, which stores computer-executable instructions configured to execute the method for repairing a barcode diagram.
The storage medium described above may be a transitory computer-readable storage medium or a non-transitory computer-readable storage medium. A non-transitory storage medium comprising: a U-disk, a portable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other media capable of storing program codes, and may also be a transient storage medium.
The above description and drawings sufficiently illustrate embodiments of the disclosure to enable those skilled in the art to practice them. Other embodiments may incorporate structural, logical, electrical, process, and other changes. The examples merely typify possible variations. Individual components and functions are optional unless explicitly required, and the sequence of operations may vary. Portions and features of some embodiments may be included in or substituted for those of others. Furthermore, the words used in the specification are words of description only and are not intended to limit the claims. As used in the description of the embodiments and the claims, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. Similarly, the term "and/or" as used in this application is meant to encompass any and all possible combinations of one or more of the associated listed. Furthermore, the terms "comprises" and/or "comprising," when used in this application, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof. Without further limitation, an element defined by the phrase "comprising a" \8230; "does not exclude the presence of additional like elements in a process, method or apparatus comprising the element. In this document, each embodiment may be described with emphasis on differences from other embodiments, and the same and similar parts between the respective embodiments may be referred to each other. For methods, products, etc. of the embodiment disclosures, reference may be made to the description of the method section for relevance if it corresponds to the method section of the embodiment disclosure.
Those of skill in the art would appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software may depend upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the disclosed embodiments. It can be clearly understood by the skilled person that, for convenience and simplicity of description, the specific working processes of the above-described systems, apparatuses, and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. In the description corresponding to the flowcharts and block diagrams in the figures, operations or steps corresponding to different blocks may also occur in different orders than disclosed in the description, and sometimes there is no specific order between the different operations or steps. For example, two sequential operations or steps may in fact be executed substantially concurrently, or they may sometimes be executed in the reverse order, depending upon the functionality involved. Each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.

Claims (8)

1. A method for repairing a barcode diagram, comprising:
identifying a bar code image to be repaired to obtain an original code system category of the bar code image;
repairing the bar code image according to the original code system category to obtain a repaired code image;
acquiring a first repair bar space proportion sequence corresponding to the repair code map;
repairing the first repairing strip empty proportion sequence;
the method for identifying the bar code image to be repaired to obtain the original code system category of the bar code image comprises the following steps: acquiring an original initial character in the bar code image; performing table look-up operation on the original initial symbol by using a preset first code system category database to obtain a code system category corresponding to the original initial symbol; the first code system type database stores the corresponding relation between the original initial symbol and the code system type; determining the code system type corresponding to the original initial symbol as the original code system type of the bar code image;
the repairing the bar code image according to the original code system category to obtain a repaired code image comprises the following steps: acquiring the original code word length of the original initial symbol; acquiring the original unit module width of the bar code graph according to the original code word length and the original code system category; acquiring the code pattern direction of the bar code pattern; under the condition that the width of the original unit module is smaller than or equal to a set first threshold value, constructing a repair template according to the width of the original unit module and the direction of the code graph; carrying out image enhancement on the bar code image by using the repair template; and determining the bar code image after the image enhancement as a repair code image.
2. The method of claim 1, wherein repairing the first repair bar null ratio sequence comprises:
and sequentially extracting a plurality of sections of second repairing strip empty proportion sequences from the first repairing strip empty proportion sequence, wherein the second repairing strip empty proportion sequences extracted each time are repaired.
3. The method according to claim 2, wherein extracting a second repair bar null ratio sequence in the first repair bar null ratio sequence comprises:
determining the extraction length of the strip-space ratio sequence;
and extracting a second repairing strip space proportion sequence from the first repairing strip space proportion sequence according to the strip space proportion sequence extraction length.
4. The method of claim 3, wherein determining the strip-space ratio sequence extraction length comprises:
determining a repair start symbol in a repair code map; performing table look-up operation on the repair initial symbol by using a preset second code system category database to obtain a code system category corresponding to the repair initial symbol; the second code system type database stores the corresponding relation between the repair initial symbol and the code system type; determining the extraction length of the bar space ratio sequence according to the code system type corresponding to the repair start symbol; or the like, or a combination thereof,
acquiring a first code word length; the length of the first code word is the length of the code word corresponding to the repaired second repair strip space ratio sequence; the repaired second repairing strip space proportion sequence is a strip space proportion sequence obtained by extracting a section of second repairing strip space proportion sequence from the first repairing strip space proportion sequence by utilizing the extraction length of the first alternative strip space proportion sequence for repairing; the first alternative strip space ratio sequence extraction length is the strip space ratio sequence extraction length determined according to a repair start symbol in a repair code map; obtaining a strip space ratio sequence extraction length according to the first code word length; or the like, or, alternatively,
acquiring a second codeword length; the length of the second code word is the length of the code word corresponding to the repaired second repair bar space ratio sequence; the repaired second repair strip empty proportion sequence is an n-th strip empty proportion sequence obtained after a section of second repair strip empty proportion sequence is extracted from the first repair strip empty proportion sequence and repaired; n is a positive integer; and acquiring the strip space ratio sequence extraction length according to the second code word length.
5. The method according to any one of claims 2 to 4, wherein the second repair bar null ratio sequence is repaired by:
acquiring the repair code system category and repair unit module width of a repair code map;
acquiring the number of units corresponding to the code word according to the repair code system type;
determining the product of the width of the repair unit module and a set second threshold as a correction threshold;
and repairing the second repairing strip empty proportion sequence according to the correction threshold and the number of the units.
6. The method according to claim 2 or 4, wherein after repairing the second repair bar empty proportion sequence extracted each time, the method further comprises:
and decoding the repaired second repair strip space ratio sequence to obtain a code word corresponding to the second repair strip space ratio sequence.
7. An electronic device comprising a processor and a memory storing program instructions, wherein the processor is configured to perform the method for repairing a barcode pattern of any one of claims 1 to 6 when executing the program instructions.
8. A storage medium storing program instructions which, when executed, perform a method for repairing a barcode pattern according to any one of claims 1 to 6.
CN202210882340.6A 2022-07-26 2022-07-26 Method for repairing bar code image, electronic equipment and storage medium Active CN114943241B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210882340.6A CN114943241B (en) 2022-07-26 2022-07-26 Method for repairing bar code image, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210882340.6A CN114943241B (en) 2022-07-26 2022-07-26 Method for repairing bar code image, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN114943241A CN114943241A (en) 2022-08-26
CN114943241B true CN114943241B (en) 2022-10-25

Family

ID=82910789

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210882340.6A Active CN114943241B (en) 2022-07-26 2022-07-26 Method for repairing bar code image, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114943241B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109214229A (en) * 2017-06-30 2019-01-15 杭州海康威视数字技术股份有限公司 A kind of bar code scanning method, device and electronic equipment
CN111539238A (en) * 2020-04-27 2020-08-14 广州致远电子有限公司 Two-dimensional code image restoration method and device, computer equipment and storage medium
CN113449536A (en) * 2021-07-16 2021-09-28 深圳思谋信息科技有限公司 Bar code image repairing method and device, computer equipment and storage medium
CN114581336A (en) * 2022-03-21 2022-06-03 北京有竹居网络技术有限公司 Image restoration method, device, equipment, medium and product

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8439260B2 (en) * 2010-10-18 2013-05-14 Jiazheng Shi Real-time barcode recognition using general cameras

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109214229A (en) * 2017-06-30 2019-01-15 杭州海康威视数字技术股份有限公司 A kind of bar code scanning method, device and electronic equipment
CN111539238A (en) * 2020-04-27 2020-08-14 广州致远电子有限公司 Two-dimensional code image restoration method and device, computer equipment and storage medium
CN113449536A (en) * 2021-07-16 2021-09-28 深圳思谋信息科技有限公司 Bar code image repairing method and device, computer equipment and storage medium
CN114581336A (en) * 2022-03-21 2022-06-03 北京有竹居网络技术有限公司 Image restoration method, device, equipment, medium and product

Also Published As

Publication number Publication date
CN114943241A (en) 2022-08-26

Similar Documents

Publication Publication Date Title
EP1374148B1 (en) Method and device for recognition of a handwritten pattern
CN111783495B (en) Bar code identification method and device, electronic equipment and storage medium
RU2621601C1 (en) Document image curvature eliminating
CN110647795A (en) Form recognition method
CN113673655B (en) Method and device for determining decoding direction of two-dimensional code, electronic equipment and medium
CN109214229B (en) Bar code scanning method and device and electronic equipment
US20090317003A1 (en) Correcting segmentation errors in ocr
CN111476050B (en) Bar code identification method and device, electronic equipment and storage medium
CN108830275B (en) Method and device for identifying dot matrix characters and dot matrix numbers
EP3561729B1 (en) Method for detecting and recognising long-range high-density visual markers
CN111311497B (en) Bar code image angle correction method and device
US7406201B2 (en) Correcting segmentation errors in OCR
CN112733568B (en) One-dimensional bar code recognition method, device, equipment and storage medium
CN115511031A (en) Capacity-expansion two-dimensional code and three-dimensional code decoding method, system, equipment and medium
CN111275049A (en) Method and device for acquiring character image skeleton feature descriptors
CN110147785B (en) Image recognition method, related device and equipment
CN114943241B (en) Method for repairing bar code image, electronic equipment and storage medium
CN113420580A (en) Method and device for positioning auxiliary locator for two-dimensional code, two-dimensional code scanning equipment and storage medium
CN115410191B (en) Text image recognition method, device, equipment and storage medium
CN107016317B (en) Bar code decoding method and device
CN116469090A (en) Method and device for detecting code spraying pattern, electronic equipment and storage medium
CN115147847A (en) Text recognition result determining method and device, storage medium and computer equipment
CN110895849A (en) Method and device for cutting and positioning crown word number, computer equipment and storage medium
CN109871910B (en) Handwritten character recognition method and device
CN113822092A (en) Method and apparatus for positioning position detection pattern, electronic device, and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant