CN116842977A - Bar code identification method - Google Patents

Bar code identification method Download PDF

Info

Publication number
CN116842977A
CN116842977A CN202311110523.7A CN202311110523A CN116842977A CN 116842977 A CN116842977 A CN 116842977A CN 202311110523 A CN202311110523 A CN 202311110523A CN 116842977 A CN116842977 A CN 116842977A
Authority
CN
China
Prior art keywords
character
boundary
sequence
nth
length
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.)
Granted
Application number
CN202311110523.7A
Other languages
Chinese (zh)
Other versions
CN116842977B (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.)
Zhongke Weizhi Technology Co ltd
Original Assignee
Zhongke Weizhi Technology 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 Zhongke Weizhi Technology Co ltd filed Critical Zhongke Weizhi Technology Co ltd
Priority to CN202311110523.7A priority Critical patent/CN116842977B/en
Publication of CN116842977A publication Critical patent/CN116842977A/en
Application granted granted Critical
Publication of CN116842977B publication Critical patent/CN116842977B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • G06F16/90344Query processing by using string matching techniques
    • 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/1408Methods for optical code recognition the method being specifically adapted for the type of code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition
    • G06V30/14Image acquisition
    • G06V30/148Segmentation of character regions
    • G06V30/153Segmentation of character regions using recognition of characters or words
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition
    • G06V30/18Extraction of features or characteristics of the image
    • G06V30/1801Detecting partial patterns, e.g. edges or contours, or configurations, e.g. loops, corners, strokes or intersections
    • G06V30/18019Detecting partial patterns, e.g. edges or contours, or configurations, e.g. loops, corners, strokes or intersections by matching or filtering
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition
    • G06V30/19Recognition using electronic means
    • G06V30/19007Matching; Proximity measures
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/30Computing systems specially adapted for manufacturing

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Multimedia (AREA)
  • Toxicology (AREA)
  • Artificial Intelligence (AREA)
  • General Health & Medical Sciences (AREA)
  • Electromagnetism (AREA)
  • Health & Medical Sciences (AREA)
  • Databases & Information Systems (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • Character Discrimination (AREA)
  • Character Input (AREA)

Abstract

The application discloses a bar code identification method, which relates to the technical field of image identification, and comprises the following steps: extracting information of the bar code to be identified to obtain bar space boundary information of the bar code to be identified; based on the space boundary information and the preset m space numbers, extracting N character sequence sets, wherein the space numbers adopted in the process of extracting each character sequence are the same or different, and m and N are positive integers; matching an nth character sequence set in the N character sequence sets with character sequence templates contained in a character sequence template library to obtain an nth character matching result, wherein the character sequence template library contains character sequence templates corresponding to different characters, N is a positive integer, and N is E N; and determining each character contained in the bar code to be identified based on the nth character matching result in the case that the nth character matching result passes verification. The method provided by the embodiment of the application effectively improves the identification capability of the bar code under the low resolution of the sub-pixel level.

Description

Bar code identification method
Technical Field
The application relates to the technical field of image recognition, in particular to a bar code recognition method.
Background
The bar code has the characteristics of large information storage quantity, strong reliability, flexible use and the like, so that the working efficiency of automatic management is greatly improved, and the bar code plays an increasingly important role in the current Internet age. The application of the method is gradually permeated into different industries such as business, transportation, book management, logistics distribution and engineering projects.
The bar code identification technology is a key link of the bar code using process and directly relates to the working efficiency and quality of the whole system. The existing bar code recognition technology is mostly used for reading bar code information with normal resolution, and for bar codes with lower definition, such as bar codes with sub-pixel level low resolution, the blank edge positions of bar codes can be confused, and the edge positions cannot be extracted accurately, so that the recognition rate and recognition accuracy are lower.
Disclosure of Invention
The inventor provides a bar code identification method aiming at the problems and the technical requirements, and the technical scheme of the application is as follows:
in one aspect, a method for identifying a bar code is provided, comprising the steps of:
extracting information of a bar code to be identified to obtain bar space boundary information of the bar code to be identified, wherein the bar space boundary information comprises boundary position information of bars and spaces in the bar code to be identified;
extracting N character sequence sets based on the bar space boundary information and preset m bar space numbers, wherein the bar space numbers are the bar space numbers and the space numbers contained in single characters, the bar space numbers adopted in the process of extracting each character sequence are the same or different, and m and N are positive integers;
Matching an nth character sequence set in the N character sequence sets with character sequence templates contained in a character sequence template library to obtain an nth character matching result, wherein the character sequence template library contains character sequence templates corresponding to different characters, N is a positive integer, and N epsilon N;
and determining each character contained in the bar code to be identified based on the nth character matching result under the condition that the nth character matching result passes verification.
Wherein, further scheme is:
the m kinds of bar space numbers are preset according to a target coding rule corresponding to the bar code to be identified, and the m kinds of bar space numbers comprise bar space numbers specified by the target coding rule;
based on the empty boundary information and the preset m empty numbers, extracting N character sequence sets, wherein the N character sequence sets comprise:
extracting N initial termination boundaries based on the bar space boundary information and m bar space numbers, wherein the initial termination boundaries comprise initial boundaries of initial characters and termination boundaries of termination characters in the bar code to be identified;
determining an nth reference character length interval based on an nth starting and ending boundary, and determining an nth intermediate boundary set based on the nth reference character length interval and m kinds of the stripe numbers, wherein the intermediate boundary set contains character boundaries of each intermediate character, the intermediate characters are characters between the starting character and the ending character, and the reference character length interval is a length range to be followed by character lengths of all the intermediate characters;
Extracting an nth character sequence set based on the nth starting and ending boundary and the nth middle boundary set;
the obtaining the nth character matching result comprises the following steps:
and matching the character sequences contained in the nth character sequence set with the character sequence templates to obtain the nth character matching result.
The extracting to obtain N kinds of initial termination boundaries based on the empty boundary information and m kinds of empty numbers includes:
determining an ith group of initial boundaries of the initial character based on the strip-blank boundary information and the ith blank quantity, and determining a kth group of termination boundaries of the termination character based on the strip-blank boundary information and the kth blank quantity, wherein i and k are positive integers, i is the same as or different from k, and i is less than or equal to m and k is less than or equal to m;
the determining the nth reference character length interval based on the nth start-stop boundary includes:
and determining the nth reference character length interval based on the s character length of the starting character indicated by the s-th starting boundary in the i-th group starting boundary and/or the t character length of the ending character indicated by the t-th ending boundary in the k-th group ending boundary, wherein s and k are positive integers.
The determining the i-th group start boundary of the start character based on the bar space boundary information and the i-th bar space number comprises the following steps:
Searching in a start character searching interval based on the bar space boundary information and the ith bar space quantity to obtain a candidate boundary of the start character, wherein the start character searching interval is set according to the total length of the sequence of the bar code to be identified;
extracting a candidate character sequence based on various candidate boundaries, and matching various candidate character sequences with the character sequence templates to obtain candidate characters;
and adding the boundary corresponding to the character belonging to the initial character type in the candidate characters into the initial boundary of the ith group.
The determining the nth reference character length interval includes:
and determining the nth reference character length interval under the condition that the character sequence length between the s-th starting boundary and the t-th ending boundary is within a preset length range, wherein the preset length range is set according to the target coding rule.
The determining an nth intermediate boundary set based on the nth reference character length interval and m kinds of the stripe space numbers comprises the following steps:
traversing m kinds of the bar space numbers, and determining the character boundary of the p+1st character based on the bar space numbers and the character boundary of the p-th intermediate character in the traversing process, wherein p is a positive integer;
Determining a p+1th character reference length based on the i-th character length, and/or the k-th character length, and/or the p-th character length;
determining character lengths of the p+1th character indicated by m character boundaries, and determining a length difference between the m character lengths and the p+1th character reference length;
and determining the character boundary corresponding to the minimum length difference as the n-th middle character boundary of the p+1-th character under the condition that the character length indicated by the character boundary corresponding to the minimum length difference is in the n-th reference character length interval.
The method further comprises the steps of:
based on coding rules, generating ideal bar-space gray scale sequences corresponding to all characters, wherein bar-space combination modes corresponding to the characters indicated by different coding rules are different;
performing image preprocessing on the ideal blank gray sequence to obtain a character sequence template corresponding to each character, wherein the image preprocessing is used for enabling the ideal blank gray sequence to be close to a gray sequence obtained by shooting under the actual shooting condition;
adding the character sequence templates corresponding to the characters into a template library to obtain a character sequence template library corresponding to the coding rule;
the matching the nth character sequence set of the N character sequence sets with the character sequence templates contained in the character sequence template library comprises the following steps:
And matching the nth character sequence set with the character sequence templates contained in a character sequence template library corresponding to a target coding rule, wherein the target coding rule is a coding rule corresponding to the bar code to be identified.
The method further comprises the steps of:
extracting features of character sequence templates in the character sequence template library to obtain curve gray feature templates corresponding to the character sequence templates, and forming a curve gray feature template library;
the matching the nth character sequence set with the character sequence templates contained in the character sequence template library corresponding to the target coding rule comprises the following steps:
extracting the characteristics of the character sequences in the nth character sequence set to obtain curve gray scale characteristics;
and matching the curve gray scale characteristic with the curve gray scale characteristic template.
The obtaining the nth character matching result comprises the following steps:
and determining an nth character matching result based on the characteristic similarity between the curve gray feature and each curve gray feature template, wherein the characteristic similarity of the characters in the nth character matching result is higher than that of other characters.
The feature extraction of the character sequences in the nth character sequence set is performed to obtain a curve gray feature, and the feature extraction comprises the following steps:
Scaling the character sequence based on a scaling ratio, the scaling ratio being determined according to a ratio between a sequence length of the character sequence and a sequence length of the character sequence template;
and extracting the characteristics of the scaled character sequence to obtain the gray scale characteristics of the curve.
The method further comprises the steps of:
dividing the bar code to be identified in the horizontal direction to obtain a sub bar code set, wherein the sub bar code set comprises a plurality of sub bar codes;
performing bar code identification on the sub bar codes to obtain identification results of a plurality of sub bar codes;
and under the condition that the identification results of the plurality of sub-barcodes are the same for times and larger than a preset threshold value, determining each character in the barcode to be identified based on the same identification results.
The beneficial technical effects of the application are as follows:
in the embodiment of the application, a plurality of bar space numbers are preset, character sequence extraction is carried out based on bar space boundary information of the bar code to be identified and the preset bar space numbers in the process of identifying the bar code, then, the character sequence can be matched with a character sequence template of each character in a template library, and the characters in the bar code are determined according to the matching result. In the process, a plurality of character sequence sets can be extracted according to the bar space boundaries and the number of the bar spaces, so that a multi-round matching process is performed, the influence of the inaccuracy of the bar space boundaries on the bar code identification can be reduced through the multi-round matching process, the accuracy of the bar code identification can be improved, and the capability of the bar code identification under the low resolution of the sub-pixel level is effectively improved.
Drawings
FIG. 1 is a flow chart of a bar code identification method provided by an exemplary embodiment of the present application;
FIG. 2 is a schematic diagram of a code128 bar code provided by an exemplary embodiment of the present application;
FIG. 3 is a diagram of a low resolution bar code versus a normal resolution bar code provided by an exemplary embodiment of the present application;
FIG. 4 is a flowchart of an initiate-terminate character matching process provided by an exemplary embodiment of the present application;
FIG. 5 is a flowchart of an intermediate character matching process provided by an exemplary embodiment of the present application;
FIG. 6 is a schematic diagram of a character sequence template and a curved gray scale feature template provided in accordance with an exemplary embodiment of the present application;
FIG. 7 is a schematic diagram of a feature matching process provided by an exemplary embodiment of the present application;
fig. 8 is a flowchart of a bar code recognition method according to another exemplary embodiment of the present application.
Detailed Description
The following describes the embodiments of the present application further with reference to the drawings.
Referring to fig. 1, a flowchart of a bar code recognition method according to an exemplary embodiment of the present application is shown, and the method is described with an example of execution of a computer device. The method comprises the following steps:
And step 101, extracting information of the bar code to be identified to obtain the bar space boundary information of the bar code to be identified.
The barcode to be identified may be a barcode obtained by shooting, may be obtained by shooting in real time, or may be a barcode uploaded after shooting in advance. Alternatively, the barcode to be identified may be a barcode generated by simulation of a computer device, which is not limited in this embodiment.
The bar code to be identified can be a sub-pixel low-resolution bar code obtained through shooting, and can also be a normal-resolution bar code.
The bar space boundary information comprises boundary position information between bars and spaces in the bar code to be identified.
The bar code is a symbol formed by combining black lines and blank bars according to a certain coding rule, wherein the coding rule comprises various regulations on coding types, character compositions, character densities, character lengths and the like. In the embodiment of the application, the mentioned 'bar' is a black bar in the bar code, and the 'blank' is a blank bar in the bar code.
Illustratively, the Code128 type bar Code corresponds to the coding rules specified in: except for the termination character, the single character is composed of 3 bars and 3 spaces (i.e., the number of bars and spaces contained in the single character is 6), each bar or space is composed of 1-4 unit modules, i.e., the width of each bar or space is 1-4 times the corresponding width of the unit module, and the total character length of each character is 11 unit modules, the termination character is composed of 4 bars and 3 spaces, and the character length is 13 (i.e., the termination character is composed of 13 unit modules and the number of contained bars and spaces is 7). As shown in fig. 2, which shows a Code128 type bar Code, comprising a start character 201 consisting of 3 bars and 3 spaces; a data character 202 comprising three characters, each consisting of 3 bars and 3 spaces, respectively; check character 203, consisting of 3 spaces and termination character 204, consisting of 4 3 spaces.
In one possible manner, after receiving the bar code to be identified, the bar-space boundary information in the bar code to be identified may be first extracted, including the bar-space boundary position coordinates between each "bar" and each "space", and the bar-space attribute (i.e., the attribute indicating that the position is "bar" or "space").
Step 102, extracting N character sequence sets based on the space boundary information and the preset m space numbers, wherein the character sequence sets comprise character sequences of all the characters.
Wherein the number of bar spaces is the total number of bars and spaces contained by a single character. In the bar code identification process, there may be bar space adhesion in the bar code, so that the bar space boundary cannot be effectively divided, at this time, since the number of the bar spaces corresponding to the character templates extracted by the bar space boundary is different from that of the character templates corresponding to the ideal situation, if the division of the character boundary is performed according to the number of the bar spaces specified in the bar code corresponding coding rule, the situation of inaccurate division of the character boundary is caused, so that the identification of the characters in the subsequent bar code is affected. As shown in fig. 3, the bar code 301 at low resolution has a bar space stuck, and the boundary is not clear, and cannot be recognized based on the standard number of bar spaces, compared with the bar code 302 at normal resolution.
Therefore, in the embodiment of the application, the character boundaries are extracted according to the number of m kinds of bar spaces respectively by presetting the number of m kinds of bar spaces, and the character sequences are extracted based on the character boundaries to identify the bar codes, so that the influence of the division of the bar space boundaries on the identification of the bar codes is reduced through a multi-round matching process, and m is a positive integer.
In one possible implementation manner, the character boundaries of each character may be determined according to the space boundary information and the preset space number, and then the character sequences corresponding to each character may be extracted based on the character boundaries of each character. In the process of determining the character boundary according to the bar space boundary information and the preset bar space quantity, the bar space count can be started from the ending boundary of the last character, and when the number of the bar space counts reaches the bar space quantity, the ending boundary of the last bar or space is determined to be the character boundary of the current character. Illustratively, when the number of the bar spaces is 4, the boundary of the start character is the start boundary of the 1 st bar space and the end boundary of the 4 th bar space.
The number of preset spaces used in the process of extracting the character boundaries of each character may be the same or different, that is, the number of spaces used in the process of extracting each character sequence may be the same or different, so that N kinds of character sequence sets may be extracted according to m kinds of space numbers, in one kind of character sequence set, each character sequence may be extracted based on the same or different preset space numbers, and N is a positive integer.
After the character boundaries of each character are obtained, the area surrounded by the two boundaries corresponding to the single character can be extracted to obtain the character sequence corresponding to the character. And extracting the character sequences corresponding to the characters to obtain a character sequence set.
Step 103, matching the nth character sequence set in the N character sequence sets with the character sequence templates contained in the character sequence template library to obtain an nth character matching result.
The character sequence template library comprises character sequence templates corresponding to different characters.
In the embodiment of the application, a character sequence template library is constructed in advance. The character sequence template library comprises character sequence templates corresponding to various characters, and character sequences (composed of bar spaces) corresponding to different characters under different coding rules are different, so that different types of character sequence template libraries can be pre-constructed, and the different types of template libraries respectively correspond to different coding rules.
In the identification process of the bar code to be identified, a corresponding target template library can be determined according to the coding rule of the bar code to be identified. And then, matching the character sequences in the character sequence set with character sequence templates in the target template library. Illustratively, when the barcode to be identified is a Code128 Code, a character sequence template library generated based on the Code128 coding rule may be determined as the target template library. The target template library can be set as a plurality of template libraries of different bar code types, the matching sequence of the template libraries is preset, and when the recognition of the template library of the previous category fails, the template library of the next category is called in sequence for recognition, and the embodiment is not limited to the recognition.
According to m preset bar space numbers, extracting N character sequence sets, and for the N character sequence sets, matching each character sequence set with a character sequence template library to obtain a character matching result of each character sequence set. In one possible implementation manner, the nth character sequence set is an nth character sequence set in the N character sequence sets, and the character sequence of each character in the nth character sequence set can be matched with each character sequence template in the character sequence template library to obtain a character matching result corresponding to each character sequence, so as to form an nth character matching result, wherein N is a positive integer, and N epsilon N.
And 104, determining each character contained in the bar code to be identified based on the nth character matching result in the case that the nth character matching result passes verification.
After the nth character matching result is obtained, the characters indicated in the nth character matching result need to be checked, and if the checking is passed, each character contained in the bar code to be identified can be confirmed according to the nth character matching result.
In the process of checking the n character matching result, each character in the n character matching result can be calculated based on a checking mode indicated by a coding rule, the calculated result is matched with the checking character indicated in the n character matching result, if the calculated result is the same as the checking character indicated in the n character matching result, the checking is confirmed to pass, and if the calculated result is different from the checking character indicated in the n character matching result, the checking is confirmed to fail.
If the N-th character matching result fails to be checked, the n+1-th character sequence set in the N-th character sequence set can be matched with the character sequence template to obtain an n+1-th character matching result, and then the n+1-th character matching result is checked until the matching result is checked successfully. Therefore, in the embodiment of the application, the accuracy of bar code identification can be improved by presetting the number of the bar spaces of different types and performing the process of multi-round matching verification.
In the embodiment of the application, a plurality of bar space numbers are preset, character sequence extraction is carried out based on bar space boundary information of the bar code to be identified and the preset bar space numbers in the process of identifying the bar code, then, the character sequence can be matched with a character sequence template of each character in a template library, and the characters in the bar code are determined according to the matching result. In the process, a plurality of character sequence sets can be extracted according to the bar space boundaries and the number of the bar spaces, so that a multi-round matching process is performed, the influence of the inaccuracy of the bar space boundaries on the bar code identification can be reduced through the multi-round matching process, the accuracy of the bar code identification can be improved, and the capability of the bar code identification under the low resolution of the sub-pixel level is effectively improved.
The identification of the bar code in the embodiment of the application is based on a character sequence template library. The following describes the way to construct the character sequence template library, comprising the following steps:
based on coding rules, generating ideal bar-space gray scale sequences corresponding to all characters, wherein bar-space combination modes corresponding to the characters indicated by different coding rules are different.
The bar codes of different types have different coding rules, the coding rules indicate the bar-space combination modes corresponding to the characters, and an ideal bar-space gray sequence is generated according to the bar-space combination modes and the preset character gray sequence length. The preset character gray sequence length is set according to the standard character sequence length in the coding rule. Since the width of the bar or space correspondence in the actually photographed bar code may not be the standard width under the coding rule, the length of the composed character sequence is not the standard length. Therefore, when the template is constructed, the character sequence template is generated by using the preset character gray sequence length, so that the condition that the recognition errors are caused by comparison by using the standard length is avoided. In one possible implementation, the length of the preset character gray sequence may be an integer multiple of the length of the standard character sequence in the coding rule, and the higher the multiple is, the higher the accuracy of bar code identification is, and the selection may be made according to actual requirements. In the process of generating the ideal bar blank gray level sequence, the preset character gray level sequence length can be used for determining the width of the unit module.
Illustratively, for Code128, the standard character sequence length of the other characters except the termination character is 11, and thus the preset gray sequence length may be 22, 33 or 44, etc.
The ideal bar blank gray scale sequence consists of black bars with gray scale value of 0 and blank bars with gray scale value of 255. For each character, generating a corresponding ideal bar-space gray scale sequence according to the unit module width indicated by the preset gray scale sequence length and the bar-space combination mode corresponding to the character.
And secondly, carrying out image preprocessing on the ideal blank gray sequence to obtain a character sequence template corresponding to each character, wherein the image preprocessing is used for enabling the ideal blank gray sequence to be close to a gray sequence obtained by shooting under the actual shooting condition.
Because the ideal bar blank gray sequence has larger difference with the gray sequence of the bar code to be identified, which is obtained by shooting under the actual environment, in order to enable the characteristics of the ideal bar blank gray sequence to be close to the characteristics of the bar code to be identified, after the ideal bar blank gray sequence is obtained, the image preprocessing can be carried out on the ideal bar blank gray sequence, so that the ideal bar blank gray sequence can be close to the gray sequence obtained by shooting under the actual shooting condition, and the accuracy of characteristic matching is improved.
The image preprocessing process includes, but is not limited to, blurring processing, interpolation scaling, corrosion expansion and the like. And (3) performing image preprocessing on the ideal blank gray sequence to obtain a character gray sequence template corresponding to the character. The manner of blurring processing, interpolation scaling and erosion expansion can be implemented by technical means commonly used by those skilled in the art, and this embodiment will not be described herein.
And after the image preprocessing is carried out on the ideal bar space gray level sequence corresponding to the character, a character sequence template corresponding to the character can be obtained. As shown in fig. 6, the ideal bar-space gray scale sequence 601 is subjected to image preprocessing, and a character sequence template 602 is obtained.
And thirdly, adding the character sequence templates corresponding to the characters into a template library to obtain a character sequence template library corresponding to the target coding rule.
In one possible implementation manner, the ideal bar space gray level sequence of each character generated based on the coding rule is obtained through image preprocessing, and then the character sequence templates are obtained, namely the character sequence template library corresponding to the coding rule is formed.
For any coding rule, the corresponding character sequence template library can be generated in the mode. In the process of identifying the bar code to be identified, a corresponding target template library can be selected for matching according to the target coding rule of the bar code to be identified. In the process of matching the nth character sequence set, matching the nth character sequence set with a character sequence template contained in a character sequence template library corresponding to the target coding rule.
And when the character sequence of the bar code to be identified is matched with the character sequence template, matching is carried out by utilizing the curve gray scale characteristics corresponding to the character sequence, and a matching result is determined according to the characteristic similarity of the curve gray scale characteristics.
In order to improve the matching efficiency, after a character sequence template library is generated, character sequence templates in the character sequence template library can be subjected to feature extraction to obtain curve gray feature templates corresponding to the character sequence templates, the curve gray feature templates are formed, and the curve gray feature templates can be directly called to obtain the curve gray feature templates in the curve gray feature template library for matching in the process of identifying the bar codes in real time.
After the template library is generated, each template library (comprising a character sequence template library and a curve gray feature template library) can be stored locally, and the template library is directly called from the local when matched, so that the performance of identifying the bar code in real time can be improved.
In one possible implementation manner, when extracting the character sequences according to the m kinds of space numbers, a set of character sequences of the start character and the stop character may be extracted first, and then the character sequences of the intermediate characters are extracted with the character sequences of the start character and the stop character as references, so as to further improve the accuracy of character sequence extraction. The following will illustrate an example row embodiment. The method comprises the following steps:
and step s1, extracting information of the bar code to be identified to obtain the bar space boundary information of the bar code to be identified.
For the bar code to be identified, the gray value of one column in the bar code to be identified is uneven, in fact, the bar code is a two-dimensional gray array, the gray value of one column in the character sequence template is even, the bar code to be identified is one-dimensional gray array, for matching the two, the bar code to be identified can be processed, the average gray value of the bar code column to be identified is calculated, and therefore the bar code to be identified is simplified into the one-dimensional gray array, and the influence of data fluctuation caused by noise and the like on bar code identification can be reduced through column average calculation. The process of calculating the average gray value of the bar code column to be identified can be regarded as projection of the pixel value in the bar code column direction to be identified, namely gray projection, then gradient amplitude values and gradient directions of the gray projection can be calculated, and the bar space boundary information can be determined based on the gradient amplitude values and the gradient directions, and optionally, the bar space attribute can be determined according to the gradient directions. Illustratively, for black bars in a bar code, the left boundary is a blank bar to black bar jump, the gradient direction is negative, the right boundary is a black bar to white bar jump, and the gradient direction is positive. And the boundary position coordinates can be determined according to the gradient amplitude, and optionally, at least one of gradient operators such as a Sobel operator, a Roberts crossing operator or a Laplacian operator can be adopted to determine the boundary coordinates; alternatively, edge detection algorithms such as Marr-Hildreth, canny may be used to determine the boundary coordinates, which is not limited in this embodiment.
By the method, the bar space boundary position coordinates among the bar spaces in the bar code to be identified and the bar space attribute of each area can be obtained. And then, matching the bar space quantity according to the bar space boundary information of the bar code to be identified.
Step s2, extracting N initial and termination boundaries based on the bar space boundary information and m bar space numbers, wherein the initial and termination boundaries comprise the initial boundaries of initial characters and the termination boundaries of termination characters in the bar code to be identified.
The m kinds of bar space numbers are preset according to target coding rules corresponding to the bar codes to be identified, and the m kinds of bar space numbers comprise standard bar space numbers specified by the target coding rules. Illustratively, for Code128 codes, wherein for other characters than the termination character. The standard number of the bar spaces is 6, and the preset number of the bar spaces can be 2,4,6 or 8, etc., wherein the standard number of the bar spaces is included.
In one possible implementation, the character boundaries of the start character and the end character may be extracted first, and the character sequences of the start character and the end character may be extracted. For the extraction of the initial character, there are m kinds of blank numbers, each of which can be extracted to obtain a set of initial boundaries (a set of initial boundaries may include multiple boundaries), m kinds of blank numbers can be extracted to obtain m1 kinds of initial boundaries, and similarly, m2 kinds of termination boundaries of the termination character can be extracted, each initial boundary and each termination boundary can be combined to form a set of initial termination boundaries, and m1 kinds of initial boundaries and m2 kinds of termination boundaries can be combined to form N kinds of initial termination boundaries.
Optionally, when extracting the nth starting and ending boundary (i.e., the nth starting and ending boundary), determining the ith starting boundary of the starting character based on the bar space boundary information and the ith space quantity, and determining the kth ending boundary of the ending character based on the bar space boundary information and the kth space quantity, wherein i and k are positive integers, i is the same as or different from k, and i is less than or equal to m and k is less than or equal to m. The s-th initial boundary and the t-th final boundary in the i-th initial boundary and the k-th final boundary can form the n-th initial final boundary according to different or same number of the strip spaces after the i-th initial boundary and the k-th final boundary are obtained through extraction, wherein s is less than or equal to m1, and t is less than or equal to m2.
The initial character is present in a region where the bar code is initiated, and in one possible implementation, an initial character search interval may be preset, and in the initial character search interval, a preset number of bar spaces is used for searching. The initial character search interval may be set according to the total length of the sequence of the bar code to be identified. Illustratively, the interval length of the start character search interval may be 1/2, 1/3, or 1/4 of the total length of the sequence.
Optionally, the searching for the ith group of starting boundaries in the starting character search interval based on the ith empty amount may include the following steps:
Step s21, searching in the initial character searching interval based on the bar space boundary information and the ith bar space quantity to obtain a candidate boundary of the initial character.
Searching in the initial character searching interval by utilizing the ith empty quantity, so that candidate boundaries of a plurality of initial characters can be obtained, and the empty quantity corresponding to the candidate boundaries is the ith empty quantity. Illustratively, when the i-th number of spaces is 2, searching can be performed in the initial character search interval based on the i-th number of spaces 2, so as to obtain a plurality of candidate boundaries.
And step s22, extracting candidate character sequences based on various candidate boundaries, and matching the various candidate character sequences with a character sequence template to obtain candidate characters.
For a candidate boundary, a corresponding candidate character sequence can be extracted, and the candidate character sequence is matched with a character sequence template in a character sequence template library to obtain a corresponding candidate character.
And in the process of matching the candidate character sequence with the character sequence template, determining the character corresponding to the template with the feature similarity larger than the preset threshold value as the candidate character. The preset threshold may be set according to a feature distribution rule and a value range of each feature, which is not limited in this embodiment. The value range of the feature similarity can be limited through setting of a preset threshold value, and the matching result with a large similarity difference is deleted, so that the matching accuracy is improved.
Step s23, adding the boundary corresponding to the character belonging to the initial character type in the candidate characters to the initial boundary of the ith group.
To improve the matching efficiency, it is first determined whether the candidate character belongs to the start character. For one type of bar code, the starting characters are fixed ones. In one possible implementation manner, a fixed initial character corresponding to a bar code type corresponding to a bar code to be identified can be obtained, whether the candidate character belongs to the fixed initial character is detected, if so, the candidate character is determined to be successfully matched, the corresponding boundary can be determined to be the boundary of an initial character, and the initial character is added to the initial boundary of the ith group.
Similarly, a termination character search boundary may be preset, and a kth group of termination boundaries may be searched in the termination character boundaries based on the number of kth spaces, and the manner may refer to the above process of extracting the ith group of start boundaries, which is not described herein again.
Any one of the ith set of start boundaries may be combined with any one of the kth set of end boundaries to obtain an nth start end boundary, which may include an ith start boundary of the ith set of start boundaries and a kth end boundary of the kth set of end boundaries.
Step s3, determining an nth reference character length interval based on the nth starting and ending boundary, and determining an nth intermediate boundary set based on the nth reference character length interval and m kinds of bar space numbers, wherein the intermediate boundary set contains character boundaries of all intermediate characters, and the reference character length interval is a length range to be followed by the character lengths of all the intermediate characters.
In this embodiment, the extraction of the intermediate character sequence is performed with reference to the character length of the start character and/or the end character and/or the preceding character of the current intermediate character. The intermediate characters are characters between the start character and the end character, and optionally, the intermediate characters include data characters and check characters.
There may be a non-matching Start-stop character sequence among the N Start-stop character sequences indicated by the Start-stop boundaries, which will result in an intermediate character extraction error based on the non-matching Start-stop character sequence as a reference. Therefore, when extracting the intermediate character with a group of initial and final characters as reference, the initial and final characters need to be paired first, and if pairing is successful, the initial and final characters are again used as reference.
Optionally, when the initial termination characters indicated by the nth initial termination boundary are paired, determining an nth reference character length interval when the character sequence length between the mth initial boundary and the mth termination boundary is within a preset length range, wherein the preset length range is set according to the target coding rule.
In the pairing process, the character sequence lengths of all intermediate characters indicated by the s-th starting boundary and the t-th ending boundary are used as references for pairing, in a possible implementation manner, the character sequence lengths between the boundaries (namely, the character sequence lengths of all characters) can be calculated based on the coordinates of the s-th starting boundary and the t-th ending boundary, the successful pairing is determined under the condition that the character sequence lengths belong to a preset length range, and the n-th reference character length interval can be determined based on the s-th starting boundary and/or the t-th ending boundary. Alternatively, the preset length range may be a standard intermediate character length of a preset ratio, where the standard intermediate character length is a character length obtained by combining all intermediate character sequences specified in the target coding rule, that is, a product of the number of intermediate characters and the single character length. Illustratively, the predetermined length range may be an interval formed by the product of the minimum number of characters, the maximum number of characters and the length of a single character. Illustratively, the minimum number of characters is 4, i.e., the bar code contains 1 initiator, 1 data character, 1 check character, 1 terminator (i.e., contains 2 intermediate characters), and the maximum number of characters is set to constant values of 100, 200, etc. Of course, the preset length range may be set in other manners, which is not limited in this embodiment.
After the n-th start termination boundary pairing is successful, an n-th reference character length interval may be determined based on the s-th character length of the start character indicated by the s-th start boundary and/or the t-th character length of the termination character indicated by the t-th termination boundary.
In this process, a first reference length may be determined according to the s-th character length, and a second reference length may be determined based on the t-th character length. Illustratively, when the target encoding rule indicates that the ratio of the character length of the intermediate character to the character length of the start character is a first ratio and the ratio of the character length of the end character is a second ratio, a product of the first ratio and the length of the s-th character may be calculated to obtain a first reference length, and a product of the second ratio and the length of the t-th character may be calculated to obtain a second reference length.
Alternatively, a section surrounded by the first reference length and the second reference length may be determined as an nth reference character length section. In this process, the nth reference character length interval is determined by combining the first reference length, the second reference length, the small end proportion a and the large end proportion b, wherein the product of the small end proportion and the small end proportion in the first reference length and the second reference length is the head end of the interval, the product of the large end proportion and the large end proportion in the first reference length and the second reference length is the tail end of the interval, the small end proportion a is smaller than 1, the large end proportion b is larger than 1, for example, a is 0.9, and b is 1.1.
The nth reference character length interval corresponds to the length range of all intermediate characters, i.e., the character lengths of all intermediate characters should be within the nth reference character length interval. An nth intermediate boundary set may be extracted based on the nth reference character length interval. In order to improve the accuracy of boundary extraction, in a possible implementation manner, for each intermediate character, boundary division may be performed by taking the character length of the last character as a reference. The method can comprise the following steps:
step s31, traversing m kinds of space numbers, and determining the character boundary of the (p+1) th character based on the space numbers and the character ending boundary of the (p) th intermediate character in the traversing process, wherein p is a positive integer.
For each of the intermediate characters, m number of bar spaces may be combined to obtain m character boundaries, which in one possible implementation are selected among the m character boundaries in combination with the reference character length.
First, the character boundary of the current character may be determined based on a number of slots and the ending boundary of the previous character. That is, for the p+1-th character, the bar space count may be performed with the character end boundary of the p-th intermediate character as the starting point, and when the bar space count reaches the bar space number, the end boundary is determined as the character boundary of the p+1-th character.
Step s32, determining the p+1st character reference length based on the s-th character length, and/or the t-th character length, and/or the p-th character length.
For the p+1th character, m character boundaries can be obtained by combining m kinds of bar space numbers, and in one possible implementation, the p+1th character reference length can be combined, and the character boundary of the p+1th character can be selected from the m character boundaries.
Optionally, the length of the s-th character corresponding to the initial character may be used as a reference, the length of the t-th character corresponding to the final character may be used as a reference, or the length of the character of the last character (p-th character) may be used as a reference; alternatively, the p+1-th character reference length may be determined by combining a plurality of the three as references.
In connection with the above embodiment, when the s-th character length is taken as a reference, the first reference length may be determined as the p+1-th character reference length; when the t-th character length is taken as a reference, the second reference length may be determined as the p+1-th character reference length.
When the p-th character length is taken as a reference, since the character lengths of all the intermediate characters are the same, the p-th character length can be directly taken as the p+1-th character reference length for the extraction of the p+1-th character boundary.
When a plurality of the three items are combined (for example, two by two or combined together), the p+1th character reference length is determined, a weighted average value can be obtained by calculating a certain weight proportion of the combined items, and the weighted average value is determined as the p+1th character reference length. For example, when the s-th character length, the t-th character length and the p-th character length are used as references, a weighted average of the first reference length, the second reference length and the third reference length can be calculated by a certain weight proportion, so as to obtain the p+1-th character reference length. The third reference length is the p-th character length of the p-th character. Illustratively, the weight ratio of the three may be 1:1:2. in this way, when p=0, the 1 st character reference length can be calculated with the first reference length and the second reference length.
Step s33, determining the character length of the p+1th character indicated by the m character boundaries, and determining the length difference between the m character length and the p+1th character reference length.
For the p+1th character, m character boundaries can be obtained by combining m kinds of bar space numbers, m character lengths corresponding to the m character boundaries can be calculated respectively, and a length difference value between the m character lengths and the p+1th character reference length is calculated respectively. When the character length is calculated according to one character boundary, the character length can be calculated according to the coordinates of the character boundary.
Illustratively, for a first intermediate character, a first character boundary is extracted according to the number of spaces 2, a second character boundary is obtained according to the number of spaces 4, a third character boundary is obtained according to the number of spaces 6, a fourth character boundary is obtained according to the number of spaces 8, and the length difference between the four character lengths and the p+1th character reference length is calculated.
Step s34, determining the character boundary corresponding to the minimum length difference as the n-th middle character boundary of the p+1-th character, in the case that the character length indicated by the character boundary corresponding to the minimum length difference is within the n-th reference character length section.
The method comprises the steps of firstly determining the minimum length difference value in m length difference values, then calculating whether the minimum length difference value is in an nth reference character length interval in which all intermediate characters are required to be located, and if the character length is in the nth reference character length interval, determining a character boundary corresponding to the minimum length difference value as an nth intermediate character boundary of a p+1th character.
By the method, all the intermediate character boundaries can be searched one by one in the intermediate character search interval between the s-th starting boundary and the t-th ending boundary until the end of the intermediate character search interval is searched, and after the searching is finished, all the n-th intermediate character boundaries are obtained through recording search to form an n-th intermediate boundary set.
And step s4, extracting an nth character sequence set based on the nth starting and ending boundary and the nth middle boundary set.
The nth starting and ending boundary comprises an nth starting boundary and an nth ending boundary, an nth starting character sequence of a starting character can be extracted according to the nth starting boundary, and an nth ending character sequence of an ending character can be extracted according to the nth ending boundary. And according to the nth intermediate character sequence of each intermediate character in the nth intermediate boundary set. The nth start character sequence, the nth end character sequence, and the nth intermediate character sequence form an nth character sequence set.
And step s5, matching the character sequences contained in the nth character sequence set with each character sequence template to obtain an nth character matching result.
Matching the nth initial character sequence with a character sequence template to obtain a matching result of the nth initial character; matching the nth termination character sequence with the character sequence template to obtain a matching result of the nth termination character; and matching each nth intermediate character sequence with the character sequence template to obtain an nth intermediate character matching result of each intermediate character.
In combination with the above embodiment, the matching process of the start and stop characters is shown in fig. 4, and includes the following steps:
step 401, extracting bar space boundary information of a bar code to be identified.
Step 402, determining a start-stop character search interval.
The initial and final character search interval can be determined according to the total length of the sequence of the bar code to be identified.
Step 403, determining whether all boundary searches are completed based on the start and stop character search interval, if yes, executing step 408, and if not, executing step 404.
The method comprises the steps of taking an initial and terminal character search interval as a limit, combining m kinds of strip space numbers to determine N kinds of initial and terminal boundaries, searching the initial and terminal boundaries one by one based on the strip space numbers from small to large, and stopping the matching process of the initial and terminal character boundaries when the initial and terminal boundaries obtained based on the preset strip space numbers are not in the initial and terminal character search interval.
Step 404, determining a set of start and stop character boundaries based on the preset number of slots.
And step 405, extracting an initial and terminal character sequence based on the initial and terminal character boundary, and performing character sequence matching to obtain a matching result.
Step 406, determining whether the matching result is the start-stop character, if yes, executing step 407, otherwise, executing step 403.
The judgment of the matching result is based on the starting character and the ending character in the template library. When the initial character is matched as the initial character in the template library and the termination character is matched as the termination character in the template library, the matching is successful.
It should be noted that, the process of matching the initial character and the final character in the matching result with the template library is performed independently. For example, when it is determined that the start character is the start character in the template library and the end character is not the end character in the template library, a further end character boundary may be selected again, and the matching process may be performed again. When both the initial character and the termination character are matched, combining the initial character and the termination character which are successfully matched as a group of initial character and termination character, and after the initial character and the termination character are successfully matched, using the initial character and the termination character in the matching process of the subsequent intermediate character.
In step 407, the start and stop characters are recorded.
And after the matching of the start character and the stop character is successful and recorded, the next pair of the start character and the stop character is searched continuously, and the step 403 is executed continuously.
Step 408, the boundary search process ends.
Step 409, pairing is performed based on the start and end character boundaries.
Step 410, record the pairing result.
The matching process of the intermediate characters is shown in fig. 5, and comprises the following steps:
step 501, a set of paired start and stop character boundaries is obtained.
Step 502, a middle character search interval is determined.
The middle character search interval is determined according to the start and stop character boundaries obtained in the step 501.
Step 503, determining whether the end of the middle character search section is reached, if not, executing step 504, and if so, executing step 506.
Step 504, combining the blank boundary information and the reference length of the p+1th character, and determining the character boundary of the p+1th intermediate character by taking the character end boundary of the p-th character as a starting point.
The p+1st character reference length is determined according to the initial and terminal character length corresponding to the paired initial and terminal character boundaries and the matched p character length.
And 505, recording the character boundary of the p+1st intermediate character, updating the reference length of the p+2nd character, and carrying out the next character search.
After recording the character boundary of the p+1 intermediate character, the p+1 character length can be calculated, the p+2 character reference length is updated, and the p+2 character is searched.
In one possible implementation, for the first intermediate character, the character length of the start and stop character may be determined, and for the subsequent intermediate character, the reference character length may be updated in combination with the character length of the last character, so as to improve the accuracy of boundary extraction.
Step 506, extracting an intermediate character sequence according to the character boundary of each intermediate character, and matching based on the intermediate character sequence.
Step 507, determining whether the matching result is successfully checked, if so, executing step 508, and if not, executing step 509.
And obtaining an intermediate character based on the intermediate character sequence matching, and in the verification process, combining the matched initial and final characters with the intermediate character to verify with the verification character in the intermediate character, and determining that the verification of the matching result is successful under the condition of successful verification.
Step 508, record the matching result.
Step 509, determining whether there is an unprocessed start-stop character pairing, if so, executing step 501, and if not, ending.
In the embodiment of the application, when the character sequence is matched with the character sequence template, the matching is performed based on the corresponding curve gray scale characteristics. Comprises the following steps:
And step 1, extracting the characteristics of the character sequences in the nth character sequence set to obtain the curve gray scale characteristics.
The length of the character sequence of each character in the character sequence template library is a fixed length, namely the length of the preset character gray sequence, and before the character sequence is matched with the characteristics of the character sequence template, the proportion of the character sequence and the character sequence template is required to be kept consistent because the length of the extracted character sequence is uncertain. In one possible implementation, the scaling may be performed according to a ratio between a predetermined character gray sequence length and a character sequence length, and then the feature extraction may be performed, including the following steps:
and a step a, scaling the character sequence based on a scaling ratio, wherein the scaling ratio is determined according to the ratio between the sequence length of the character sequence and the sequence length of the character sequence template.
Firstly, determining a scaling ratio according to the ratio between the sequence length of the character sequence and the sequence length of the character sequence template (namely the length of the preset character gray sequence), and scaling the character sequence based on the scaling ratio. Illustratively, the sequence length of the character sequence is 20, and the preset character gray sequence length is 22, and the scaling ratio is 11/10.
The scaling may be performed using an interpolation algorithm, and optionally, one of nearest neighbor interpolation, linear interpolation, bilinear interpolation, and bicubic interpolation may be used, which is not limited in this embodiment.
And b, extracting the characteristics of the scaled character sequence to obtain the gray scale characteristics of the curve.
The curve gray scale characteristics can comprise gray scale extreme point amplitude values, gray scale extreme point positions, relative distances between the gray scale extreme points amplitude values, gradient change directions of the gray scale sequences and the like.
And step 2, matching the curve gray scale characteristics with the curve gray scale characteristic templates.
The curve gray feature template is obtained by extracting features from character sequence templates in a character feature template library. By combining the embodiments, when matching, the curve gray feature template can be directly obtained from the curve gray feature template library, so that the real-time matching performance is improved. The characteristic type contained in the curve gray characteristic template is the same as the characteristic type in the curve gray characteristic, and the characteristic template corresponding to the character sequence template of one character also contains characteristic templates corresponding to the characteristics such as gray extreme point amplitude, gray extreme point position, amplitude relative distance between gray extreme points, gradient change direction of each part of the gray sequence and the like. Illustratively, as shown in fig. 6, the character sequence template 602 is subjected to feature extraction, so as to obtain a curved gray feature template 603 (including templates corresponding to the character 19, the character 42 and the character 90).
And matching each characteristic contained in the curve gray scale characteristic with a corresponding characteristic template respectively.
And 3, determining an nth character matching result based on the feature similarity between the curve gray feature and each curve gray feature template, wherein the feature similarity of the characters in the nth character matching result is higher than that of other characters.
After each feature contained in the curve gray level features is matched with the corresponding feature template, feature similarity corresponding to each feature can be obtained, then the feature similarity corresponding to each feature is accumulated to obtain total feature similarity, and an nth character matching result is determined according to the total feature similarity. The overall feature similarity is calculated as follows:
wherein,,Srepresenting the overall feature similarity;wfor the weighting coefficients of the different features,xas a value of the feature template,yas the characteristic value of the bar code to be identified,rfor the number of feature types,qfeature points for each feature.iWhich represents a feature of the i-th class,ijjth bit representing ith class of featuresThe symptom points.
The weight coefficients of the different features are preset parameters, and can be set according to empirical values, which is not limited in this embodiment.
As shown in fig. 7, the curve gray feature (light color) corresponding to the character sequence is matched with the curve gray feature templates (dark color) corresponding to the character sequence templates (51, 95 and 48), wherein the template matching corresponding to the character 51 is successful, the template matching corresponding to the characters 95 and 48 is failed, and the character sequence can be determined as the sequence corresponding to the character 51.
Through the method, the feature similarity between the character sequence of the single character and each character sequence template can be calculated, the feature similarity is sequenced from top to bottom in sequence, and optionally, the character corresponding to the character sequence template with the feature similarity larger than the preset threshold and sequenced at the first position can be determined as a matching result of the character. And obtaining character matching results of the characters to form an nth character matching result. And then checking the nth character matching result, and if the nth character matching result passes the check, determining the nth character matching result as the identification result of the bar code to be identified. If the verification is not passed, the next round of matching process is entered. In the next round of matching, firstly extracting to obtain an n+1th initial termination boundary (consisting of an n+1th combination in N initial termination boundary combination sequences, wherein the n+1th combination is different from an N (consisting of an s initial boundary and a t termination boundary) initial boundary and/or a termination boundary), then determining an n+1th reference character length based on the n+1th initial termination boundary, extracting an n+1th intermediate boundary set based on the n+1th reference character length and m kinds of empty numbers, and then extracting to obtain an n+1th character sequence set based on the n+1th initial termination boundary and the n+1th intermediate boundary set respectively, and carrying out n+1th round of matching.
In another possible implementation manner, the nth character matching result includes a plurality of candidate character sets, where the candidate character sets are character sets formed by characters with feature similarities arranged in the first t bits, and illustratively, t is 3. Checking each candidate character group, and determining the candidate character groups as the recognition result of the bar code to be recognized under the condition that one group of checked characters passes; if all the candidate character sets are not checked, the n+1st round of matching process is entered.
In this embodiment, the initial and final boundaries are extracted first, and then the reference character length intervals of all intermediate characters are determined based on the character lengths of the initial character and the final character indicated by the boundaries, so that the intermediate characters are extracted according to the number of spaces and the reference character length intervals, and in the process of extracting each intermediate character, the character length of the last character can be used as a reference, so that the accuracy of extracting the character sequence can be improved, and the extraction efficiency of the intermediate character sequence can be improved.
In this embodiment, when the initial and terminal boundaries are extracted, the extraction is performed in combination with the preset length range, so that the initial and terminal characters with the excessive difference from the standard initial and terminal character length are avoided, and based on the process, the pre-screening can be realized, and the recognition efficiency of the bar code is further improved.
In the embodiment, in the process of feature matching, the character sequence of the bar code to be identified is scaled first, so that the proportion of the character sequence to be identified to the template is kept consistent, and the matching accuracy is ensured.
In the above manner, the identification is performed based on the whole barcode to be identified, and since the barcode to be identified may have a problem of unclear partial area, in order to improve the identification accuracy, in one possible implementation manner, the barcode to be identified may be divided to obtain sub barcode images, so that multiple identifications are performed based on multiple sub barcode images, and characters contained in the barcode to be identified are determined according to multiple identification results. The method comprises the following steps:
the method comprises the steps of firstly, carrying out horizontal segmentation on a bar code to be identified to obtain a sub bar code set, wherein the sub bar code set comprises a plurality of sub bar codes.
In one possible implementation, the entire image of the barcode to be identified may be divided in the horizontal direction to obtain a sub-barcode set containing n sub-barcodes, and the heights of the sub-barcodes in the sub-barcode set may be the same or different. Illustratively, the sub-image height may be determined in combination with the overall image height and the estimated processable sub-image number range, and the sub-image heights may be 8, 12, 16, 20, and 32 equivalents.
And secondly, carrying out bar code identification on the sub bar codes to obtain identification results of a plurality of sub bar codes.
The bar code identification is performed on each sub bar code, wherein the method for bar code identification can refer to the identification mode of the whole bar code to be identified in the above embodiment, and this embodiment is not described herein again.
The identification results of the plurality of sub-barcodes can be obtained by carrying out barcode identification on the plurality of sub-barcodes.
And step three, under the condition that the same times of the identification results of the plurality of sub-barcodes are larger than a preset threshold value, determining each character in the barcode to be identified based on the same identification results.
And in the plurality of identification results, if the same times of the identification results are larger than a preset threshold value, the successful identification can be determined, and the same identification result is the final identification result of the bar code to be identified.
The preset threshold value can be determined according to the number (z) of the sub-barcodes obtained through dividing and a preset proportion. Illustratively, when the preset ratio is 80% and z is 5, the preset threshold is 4.
Through the division of the bar codes, the bar codes in different areas can be used for multiple times of recognition, so that the influence of unclear recognition of the bar codes in a certain area is avoided, and the recognition accuracy is improved.
In combination with the above embodiment, in one possible implementation manner, the method for identifying a barcode includes the following steps:
step 801, initializing a character sequence template library.
Step 802, performing horizontal segmentation on the bar code to be identified to obtain a plurality of sub bar codes.
Step 803, sub bar code bar space boundary information is obtained.
Step 804, performing initial character matching and termination character matching based on the bar space boundary information of the sub bar codes.
Step 805, performing intermediate character matching based on the start and end characters of the pairing.
Step 806, determining whether the start character, the stop character and the intermediate character are successfully verified, if so, executing step 807, and if not, executing step 803.
In step 807, the sub bar code is successfully identified, and the identification result is recorded.
Step 808, determining whether the same number of times of the recognition result reaches the number threshold, if so, executing step 809, and if not, executing step 803.
Step 809, record the same recognition result.
The implementation of steps 801-809 may refer to the above-mentioned examples, and will not be described here again.
The above is only a preferred embodiment of the present application, and the present application is not limited to the above examples. It is to be understood that other modifications and variations which may be directly derived or contemplated by those skilled in the art without departing from the spirit and concepts of the present application are deemed to be included within the scope of the present application.

Claims (9)

1. A method of bar code identification, the method comprising:
extracting information of a bar code to be identified to obtain bar space boundary information of the bar code to be identified, wherein the bar space boundary information comprises boundary position information of bars and spaces in the bar code to be identified;
extracting N initial termination boundaries based on the bar space boundary information and the preset m bar space numbers, wherein the bar space numbers are the numbers of bars and spaces contained in single characters, the initial termination boundaries contain the initial boundaries of initial characters and the termination boundaries of termination characters in the bar codes to be identified, and m and N are positive integers;
determining an nth reference character length interval based on an nth starting and ending boundary of the N starting and ending boundaries, and determining an nth intermediate boundary set based on the nth reference character length interval and m kinds of the bar space numbers, wherein the intermediate boundary set comprises character boundaries of each intermediate character, the intermediate characters are characters between the starting character and the ending character, the reference character length interval is a length range to be followed by character lengths of all the intermediate characters, N is a positive integer, and N is E N;
Extracting an nth character sequence set based on the nth starting and ending boundary and the nth middle boundary set;
matching the character sequences contained in the nth character sequence set with character sequence templates contained in a character sequence template library to obtain an nth character matching result, wherein the character sequence template library contains character sequence templates corresponding to different characters;
and determining each character contained in the bar code to be identified based on the nth character matching result under the condition that the nth character matching result passes verification.
2. The method of claim 1, wherein the extracting N kinds of start and stop boundaries based on the slice boundary information and the preset m kinds of slice numbers includes:
determining an ith group of initial boundaries of the initial character based on the strip-blank boundary information and the ith blank quantity, and determining a kth group of termination boundaries of the termination character based on the strip-blank boundary information and the kth blank quantity, wherein i and k are positive integers, i is the same as or different from k, and i is less than or equal to m and k is less than or equal to m;
the determining an nth reference character length interval based on an nth start-stop boundary of the N start-stop boundaries includes:
And determining the nth reference character length interval based on the s character length of the starting character indicated by the s-th starting boundary in the i-th group starting boundary and/or the t character length of the ending character indicated by the t-th ending boundary in the k-th group ending boundary, wherein s and k are positive integers.
3. The method of claim 2, wherein the determining the i-th set of starting boundaries for the starting character based on the bar space boundary information and the i-th number of bars spaces comprises:
searching in a start character searching interval based on the bar space boundary information and the ith bar space quantity to obtain a candidate boundary of the start character, wherein the start character searching interval is set according to the total length of the sequence of the bar code to be identified;
extracting a candidate character sequence based on various candidate boundaries, and matching various candidate character sequences with the character sequence templates to obtain candidate characters;
and adding the boundary corresponding to the character belonging to the initial character type in the candidate characters into the initial boundary of the ith group.
4. The method of claim 2, wherein the determining the nth reference character length interval comprises:
And determining the nth reference character length interval under the condition that the character sequence length between the s-th starting boundary and the t-th ending boundary is within a preset length range, wherein the preset length range is set according to the target coding rule.
5. The method of claim 2, wherein the determining an nth intermediate boundary set based on the nth reference character length interval and the m number of slots comprises:
traversing m kinds of the strip-space numbers, and determining the character boundary of the p+1st character based on the strip-space numbers and the character ending boundary of the p-th intermediate character in the traversing process, wherein p is a positive integer;
determining a p+1st character reference length based on the s-th character length, and/or the t-th character length, and/or the p-th character length;
determining the character length of the p+1th character indicated by m character boundaries, and determining a length difference between the m character lengths and the p+1th character reference length;
and determining the character boundary corresponding to the minimum length difference as the n-th middle character boundary of the p+1-th character under the condition that the character length indicated by the character boundary corresponding to the minimum length difference is in the n-th reference character length interval.
6. The method according to any one of claims 1 to 5, further comprising:
based on coding rules, generating ideal bar-space gray scale sequences corresponding to all characters, wherein bar-space combination modes corresponding to the characters indicated by different coding rules are different;
performing image preprocessing on the ideal blank gray sequence to obtain a character sequence template corresponding to each character, wherein the image preprocessing is used for enabling the ideal blank gray sequence to be close to a gray sequence obtained by shooting under the actual shooting condition;
adding the character sequence templates corresponding to the characters into a template library to obtain a character sequence template library corresponding to the coding rule;
the matching the nth character sequence set of the N character sequence sets with the character sequence templates contained in the character sequence template library comprises the following steps:
and matching the nth character sequence set with the character sequence templates contained in a character sequence template library corresponding to a target coding rule, wherein the target coding rule is a coding rule corresponding to the bar code to be identified.
7. The method of claim 6, wherein the method further comprises:
extracting features of character sequence templates in the character sequence template library to obtain curve gray feature templates corresponding to the character sequence templates, and forming a curve gray feature template library;
The matching the nth character sequence set with the character sequence templates contained in the character sequence template library corresponding to the target coding rule comprises the following steps:
extracting the characteristics of the character sequences in the nth character sequence set to obtain curve gray scale characteristics;
matching the curve gray scale characteristics with the curve gray scale characteristic template;
the obtaining the nth character matching result comprises the following steps:
and determining an nth character matching result based on the characteristic similarity between the curve gray feature and each curve gray feature template, wherein the characteristic similarity of the characters in the nth character matching result is higher than that of other characters.
8. The method of claim 7, wherein the feature extraction of the character sequences in the nth character sequence set to obtain a curved gray scale feature comprises:
scaling the character sequence based on a scaling ratio, the scaling ratio being determined according to a ratio between a sequence length of the character sequence and a sequence length of the character sequence template;
and extracting the characteristics of the scaled character sequence to obtain the gray scale characteristics of the curve.
9. The method according to any one of claims 1 to 5, further comprising:
dividing the bar code to be identified in the horizontal direction to obtain a sub bar code set, wherein the sub bar code set comprises a plurality of sub bar codes;
performing bar code identification on the sub bar codes to obtain identification results of a plurality of sub bar codes;
and under the condition that the identification results of the plurality of sub-barcodes are the same for times and larger than a preset threshold value, determining each character in the barcode to be identified based on the same identification results.
CN202311110523.7A 2023-08-31 2023-08-31 Bar code identification method Active CN116842977B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311110523.7A CN116842977B (en) 2023-08-31 2023-08-31 Bar code identification method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311110523.7A CN116842977B (en) 2023-08-31 2023-08-31 Bar code identification method

Publications (2)

Publication Number Publication Date
CN116842977A true CN116842977A (en) 2023-10-03
CN116842977B CN116842977B (en) 2023-11-17

Family

ID=88174679

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311110523.7A Active CN116842977B (en) 2023-08-31 2023-08-31 Bar code identification method

Country Status (1)

Country Link
CN (1) CN116842977B (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101833641A (en) * 2010-06-01 2010-09-15 福建新大陆电脑股份有限公司 Bar code decoding chip
CN103034831A (en) * 2011-09-30 2013-04-10 无锡爱丁阁信息科技有限公司 Method and system for identifying linear bar code
CN106991348A (en) * 2017-03-21 2017-07-28 浙江华睿科技有限公司 A kind of bar code decoding method and device
CN109299628A (en) * 2017-07-24 2019-02-01 杭州海康威视数字技术股份有限公司 A kind of interpretation method and device of bar code
CN109670364A (en) * 2018-12-24 2019-04-23 艾体威尔电子技术(北京)有限公司 A kind of template identification information proofreading method
CN111027343A (en) * 2019-12-12 2020-04-17 中科微至智能制造科技江苏有限公司 Bar code area positioning method and device
CN112241641A (en) * 2019-07-19 2021-01-19 杭州海康威视数字技术股份有限公司 Decoding method for bar code, terminal device and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101833641A (en) * 2010-06-01 2010-09-15 福建新大陆电脑股份有限公司 Bar code decoding chip
CN103034831A (en) * 2011-09-30 2013-04-10 无锡爱丁阁信息科技有限公司 Method and system for identifying linear bar code
CN106991348A (en) * 2017-03-21 2017-07-28 浙江华睿科技有限公司 A kind of bar code decoding method and device
CN109299628A (en) * 2017-07-24 2019-02-01 杭州海康威视数字技术股份有限公司 A kind of interpretation method and device of bar code
CN109670364A (en) * 2018-12-24 2019-04-23 艾体威尔电子技术(北京)有限公司 A kind of template identification information proofreading method
CN112241641A (en) * 2019-07-19 2021-01-19 杭州海康威视数字技术股份有限公司 Decoding method for bar code, terminal device and storage medium
CN111027343A (en) * 2019-12-12 2020-04-17 中科微至智能制造科技江苏有限公司 Bar code area positioning method and device

Also Published As

Publication number Publication date
CN116842977B (en) 2023-11-17

Similar Documents

Publication Publication Date Title
US8326037B1 (en) Methods and apparatus for locating an object in an image
JP5334042B2 (en) Character string recognition method and character string recognition apparatus
US5754695A (en) Degraded gray-scale document recognition using pseudo two-dimensional hidden Markov models and N-best hypotheses
CN111339797B (en) Decoding method and terminal capable of accurately identifying damaged one-dimensional bar code
CN102870399A (en) Segmentation of a word bitmap into individual characters or glyphs during an OCR process
US20010033694A1 (en) Handwriting recognition by word separation into sillouette bar codes and other feature extraction
CN109657515B (en) Decoding method and device for one-dimensional bar code
CN109508571B (en) Strip-space positioning method and device, electronic equipment and storage medium
CN117195928B (en) Bar code positioning detection method based on deep learning
EP0877335B1 (en) Character recognition method, character recognition apparatus
CN116842977B (en) Bar code identification method
CN105844200A (en) Method of determining bar code type
CN112597868A (en) Test paper identification and correction method based on no positioning point
CN112329495A (en) Bar code identification method, device and system
CN114298078B (en) Decoding method of stained one-dimensional bar code
CN113837119A (en) Method and equipment for recognizing confusable characters based on gray level images
CN115438682A (en) Method and device for determining decoding direction and decoding equipment
Lin et al. Multi-symbology and multiple 1d/2d barcodes extraction framework
CN111368576B (en) Global optimization-based Code128 bar Code automatic reading method
CN113158704A (en) Method and system for rapidly positioning Dotcode code
Tseng et al. Retrospective tracking for barcode reading
CN112632313A (en) Bud thread lace retrieval method based on deep learning
CN114943241B (en) Method for repairing bar code image, electronic equipment and storage medium
JP2832928B2 (en) Character recognition method
CN118097676B (en) Downhole tool tag monitoring system based on image processing

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