CN117540762A - Bar code identification method, device, equipment and readable storage medium - Google Patents
Bar code identification method, device, equipment and readable storage medium Download PDFInfo
- Publication number
- CN117540762A CN117540762A CN202311602742.7A CN202311602742A CN117540762A CN 117540762 A CN117540762 A CN 117540762A CN 202311602742 A CN202311602742 A CN 202311602742A CN 117540762 A CN117540762 A CN 117540762A
- Authority
- CN
- China
- Prior art keywords
- bar code
- image
- candidate
- target area
- gradient direction
- 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.)
- Withdrawn
Links
- 238000000034 method Methods 0.000 title claims abstract description 73
- 238000012545 processing Methods 0.000 claims description 20
- 230000000903 blocking effect Effects 0.000 claims description 13
- 230000008569 process Effects 0.000 claims description 7
- 230000008859 change Effects 0.000 description 7
- 238000004891 communication Methods 0.000 description 6
- 238000010586 diagram Methods 0.000 description 6
- 238000012216 screening Methods 0.000 description 3
- 230000001133 acceleration Effects 0.000 description 2
- 238000013459 approach Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000000605 extraction Methods 0.000 description 1
- 238000001914 filtration Methods 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 230000005484 gravity Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000011218 segmentation Effects 0.000 description 1
- 230000009466 transformation Effects 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06K—GRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
- G06K7/00—Methods or arrangements for sensing record carriers, e.g. for reading patterns
- G06K7/10—Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
- G06K7/14—Methods 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/1404—Methods for optical code recognition
- G06K7/1439—Methods for optical code recognition including a method step for retrieval of the optical code
- G06K7/1443—Methods for optical code recognition including a method step for retrieval of the optical code locating of the code in an image
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06K—GRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
- G06K7/00—Methods or arrangements for sensing record carriers, e.g. for reading patterns
- G06K7/10—Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
- G06K7/14—Methods 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/1404—Methods for optical code recognition
- G06K7/1439—Methods for optical code recognition including a method step for retrieval of the optical code
- G06K7/1452—Methods for optical code recognition including a method step for retrieval of the optical code detecting bar code edges
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06K—GRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
- G06K7/00—Methods or arrangements for sensing record carriers, e.g. for reading patterns
- G06K7/10—Methods or arrangements for sensing record carriers, e.g. for reading patterns by electromagnetic radiation, e.g. optical sensing; by corpuscular radiation
- G06K7/14—Methods 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/1404—Methods for optical code recognition
- G06K7/146—Methods for optical code recognition the method including quality enhancement steps
- G06K7/1486—Setting the threshold-width for bar codes to be decoded
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- Health & Medical Sciences (AREA)
- Electromagnetism (AREA)
- General Health & Medical Sciences (AREA)
- Toxicology (AREA)
- Artificial Intelligence (AREA)
- Computer Vision & Pattern Recognition (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Quality & Reliability (AREA)
- Image Analysis (AREA)
Abstract
The application discloses a method, a device and equipment for identifying a bar code and a readable storage medium, and relates to the technical field of image identification. The method comprises the steps that the images to be identified are segmented to obtain a local image set, clustering is conducted based on gradient direction trends of candidate images in the local image set, and because gradient features of areas where the bar codes are located have the characteristics of similarity and dense distribution, areas which are formed by candidate images belonging to the same class in a clustering result based on the gradient direction trends are target areas of the bar codes, so that accurate positioning of the bar codes is achieved, after the target areas where the bar codes are located are determined, the bar codes in the target areas can be decoded, and therefore recognition of the bar codes is completed. Because the embodiment of the application realizes the accurate positioning of the bar codes through clustering, the stability of bar code identification is ensured, the probability of success of bar code decoding is improved, namely the robustness of the bar code identification scheme is improved.
Description
Technical Field
The present disclosure relates to the field of image recognition technologies, and in particular, to a method, an apparatus, a device, and a readable storage medium for recognizing a barcode.
Background
In the conventional scheme of barcode identification based on image processing, a potential barcode area needs to be identified and the barcode in the barcode area needs to be decoded. However, when aiming at a complex recognition scene, the conventional recognition scheme is easy to be influenced by the background of a non-bar code part in the process of positioning the bar code, so that positioning failure is caused, further, the accurate bar code cannot be acquired by a subsequent decoding part, and finally decoding failure is caused.
Disclosure of Invention
The main purpose of the application is to provide a bar code identification method, which aims to solve the technical problem of high decoding failure probability of the traditional image-based bar code decoding scheme.
In order to achieve the above object, the present application provides a method for identifying a barcode, the method for identifying a barcode comprising:
performing blocking processing on the image to be identified to obtain a local image set;
clustering each local image based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold;
and determining a target area in the image to be identified based on the clustering result, and decoding the bar code of the target area to obtain the identification result of the bar code.
Optionally, after the step of performing the blocking processing on the image to be identified to obtain the local image set, the method further includes:
for any one local image in the local image set, determining the number of edge points in the local image, wherein the edge points are points with gradient amplitude larger than a preset gradient amplitude threshold value in the local image;
and if the number of the edge points in the local image is larger than a preset number threshold, taking the local image as a candidate image.
Optionally, the step of using the local image as a candidate image includes:
determining a main gradient direction section with the maximum number of edge points in each gradient direction section of the local image;
and if the duty ratio of the edge points of the main gradient direction interval in the edge points of the local image is larger than a preset duty ratio threshold, taking the local image as the candidate image, wherein the gradient direction trend of the candidate image is the direction corresponding to the main gradient direction interval.
Optionally, before the step of clustering each of the partial images based on the gradient direction trend of each of the candidate images in the partial image set to obtain a clustering result, the method further includes:
And for any candidate image, if no other candidate image exists in the adjacent area of the candidate image, eliminating the candidate image from the clustered objects of the clusters.
Optionally, the step of determining the target region in the image to be identified based on the clustering result includes:
and for any candidate image group formed by candidate images of the same type in the clustering result, splicing the candidate images in the candidate image group based on the relative positions of the candidate images in the candidate image group in the image to be identified, so as to obtain the target area.
Optionally, before the step of decoding the barcode of the target area, the method further comprises:
performing binarization processing on the target area to determine the geometric characteristics of the target area;
and if the geometric characteristics of the target area are not consistent with the geometric characteristics of the preset bar code area, discarding the target area.
Optionally, the recognition result of the barcode is a set of target character sequences, and the step of decoding the barcode in the target area to obtain the recognition result of the barcode includes:
Scanning at different scanning positions in the target area based on a preset scanning direction to obtain a plurality of width information groups, wherein the width information groups consist of the width information of each bar code in the target area;
decoding width information in any width information group to obtain a group of candidate character sequences;
and taking the candidate character sequence with the highest occurrence frequency in the candidate character sequences as a recognition result of the bar code.
Optionally, the step of scanning at different scanning positions in the target area based on a preset scanning direction to obtain a plurality of width information sets includes:
scanning the target area based on the scanning position and a preset scanning direction for any scanning position in the target area to obtain edge information of the scanning position in the preset scanning direction;
determining the sub-pixel position of the edge position in the gradient direction in the edge information;
generating width information of each bar code according to the distance between two adjacent sub-pixel positions, wherein each width information forms one width information group.
To achieve the above object, the present application further provides a bar code identification device, including:
The acquisition module is used for carrying out blocking processing on the image to be identified to obtain a local image set;
the clustering module is used for clustering the local images based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between the candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold;
and the identification module is used for determining a target area in the image to be identified based on the clustering result, and decoding the bar code of the target area to obtain an identification result of the bar code.
To achieve the above object, the present application further provides an identification apparatus for a bar code, the identification apparatus for a bar code including: the method comprises the steps of a memory, a processor and a bar code identification program stored in the memory and capable of running on the processor, wherein the bar code identification program is executed by the processor to realize the bar code identification method.
In order to achieve the above object, the present application further provides a readable storage medium, which is a computer readable storage medium, and the readable storage medium stores a barcode identification program thereon, where the barcode identification program is executed by a processor to implement the steps of the barcode identification method described above.
The embodiment of the application provides a method, a device, equipment and a readable storage medium for identifying a bar code. In the embodiment, the image to be identified is subjected to block processing to obtain a local image set; clustering each local image based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold; and determining a target area in the image to be identified based on the clustering result, and decoding the bar code of the target area to obtain the identification result of the bar code. The method comprises the steps that the image to be identified is segmented to obtain a local image set, clustering is conducted on the basis of gradient direction trends of candidate images in the local image set, and the gradient features of the areas where the bar codes are located are similar and densely distributed, so that the areas formed by candidate images belonging to the same class in a clustering result based on the gradient direction trends are target areas of the bar codes, accurate positioning of the bar codes is achieved, after the target areas where the bar codes are located are determined, the bar codes in the target areas can be decoded, and identification of the bar codes is completed. Because the embodiment of the application realizes the accurate positioning of the bar codes through clustering, the stability of bar code identification is ensured, the probability of success of bar code decoding is improved, namely the robustness of the bar code identification scheme is improved.
Drawings
FIG. 1 is a schematic diagram of a device architecture of a hardware operating environment according to an embodiment of the present application;
FIG. 2 is a flow chart of a first embodiment of a method for identifying a bar code according to the present application;
FIG. 3 is a flow chart of a second embodiment of a method for identifying a bar code according to the present application;
FIG. 4 is a schematic diagram of the division of gradient direction intervals in the identification method of the bar code of the present application;
FIG. 5 is a schematic diagram of the gradient direction of a bar code in the method of identifying a bar code of the present application;
FIG. 6 is a flow chart of a third embodiment of a method for identifying a bar code according to the present application;
fig. 7 is a schematic structural diagram of a bar code recognition device in the bar code recognition method of the present application.
The realization, functional characteristics and advantages of the present application will be further described with reference to the embodiments, referring to the attached drawings.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
As shown in fig. 1, fig. 1 is a schematic device structure diagram of a hardware running environment according to an embodiment of the present application.
The device of the embodiment of the application can be electronic terminal devices such as a PC, a smart phone, a tablet personal computer, a portable computer and the like.
As shown in fig. 1, the apparatus may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display, an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may further include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
Optionally, the device may also include a camera, RF (Radio Frequency) circuitry, sensors, audio circuitry, wiFi modules, and the like. Among other sensors, such as light sensors, motion sensors, and other sensors. Specifically, the light sensor may include an ambient light sensor that may adjust the brightness of the display screen according to the brightness of ambient light, and a proximity sensor that may turn off the display screen and/or the backlight when the mobile terminal moves to the ear. As one type of motion sensor, a gravitational acceleration sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary, vibration recognition related functions (such as pedometer, knocking) and the like; of course, the mobile terminal may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, and the like, which are not described herein.
It will be appreciated by those skilled in the art that the device structure shown in fig. 1 is not limiting of the device and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
As shown in fig. 1, an operating system, a network communication module, a user interface module, and a bar code identification program may be included in a memory 1005 as one type of computer storage medium.
In the device shown in fig. 1, the network interface 1004 is mainly used for connecting to a background server, and performing data communication with the background server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and the processor 1001 may be configured to call an identification program of the bar code stored in the memory 1005 and perform the following operations:
performing blocking processing on the image to be identified to obtain a local image set;
clustering each local image based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold;
and determining a target area in the image to be identified based on the clustering result, and decoding the bar code of the target area to obtain the identification result of the bar code.
Further, the processor 1001 may call the identification program of the barcode stored in the memory 1005, and also perform the following operations:
after the step of performing the blocking processing on the image to be identified to obtain the local image set, the method further comprises the following steps:
for any one local image in the local image set, determining the number of edge points in the local image, wherein the edge points are points with gradient amplitude larger than a preset gradient amplitude threshold value in the local image;
and if the number of the edge points in the local image is larger than a preset number threshold, taking the local image as a candidate image.
Further, the processor 1001 may call the identification program of the barcode stored in the memory 1005, and also perform the following operations:
the step of using the local image as a candidate image comprises the following steps:
determining a main gradient direction section with the maximum number of edge points in each gradient direction section of the local image;
and if the duty ratio of the edge points of the main gradient direction interval in the edge points of the local image is larger than a preset duty ratio threshold, taking the local image as the candidate image, wherein the gradient direction trend of the candidate image is the direction corresponding to the main gradient direction interval.
Further, the processor 1001 may call the identification program of the barcode stored in the memory 1005, and also perform the following operations:
before the step of clustering each of the partial images based on the gradient direction trend of each of the candidate images in the partial image set to obtain a clustering result, the method further includes:
and for any candidate image, if no other candidate image exists in the adjacent area of the candidate image, eliminating the candidate image from the clustered objects of the clusters.
Further, the processor 1001 may call the identification program of the barcode stored in the memory 1005, and also perform the following operations:
the step of determining the target area in the image to be identified based on the clustering result comprises the following steps:
and for any candidate image group formed by candidate images of the same type in the clustering result, splicing the candidate images in the candidate image group based on the relative positions of the candidate images in the candidate image group in the image to be identified, so as to obtain the target area.
Further, the processor 1001 may call the identification program of the barcode stored in the memory 1005, and also perform the following operations:
Before the step of decoding the bar code of the target area, the method further comprises:
performing binarization processing on the target area to determine the geometric characteristics of the target area;
and if the geometric characteristics of the target area are not consistent with the geometric characteristics of the preset bar code area, discarding the target area.
Further, the processor 1001 may call the identification program of the barcode stored in the memory 1005, and also perform the following operations:
the step of decoding the bar code of the target area to obtain the identification result of the bar code comprises the following steps:
scanning at different scanning positions in the target area based on a preset scanning direction to obtain a plurality of width information groups, wherein the width information groups consist of the width information of each bar code in the target area;
decoding width information in any width information group to obtain a group of candidate character sequences;
and taking the candidate character sequence with the highest occurrence frequency in the candidate character sequences as a recognition result of the bar code.
Further, the processor 1001 may call the identification program of the barcode stored in the memory 1005, and also perform the following operations:
The step of scanning at different scanning positions in the target area based on a preset scanning direction to obtain a plurality of width information sets comprises the following steps:
scanning the target area based on the scanning position and a preset scanning direction for any scanning position in the target area to obtain edge information of the scanning position in the preset scanning direction;
determining the sub-pixel position of the edge position in the gradient direction in the edge information;
generating width information of each bar code according to the distance between two adjacent sub-pixel positions, wherein each width information forms one width information group.
Referring to fig. 2, a first embodiment of a method for identifying a barcode according to the present application includes:
s10, performing blocking processing on an image to be identified to obtain a local image set;
the image to be identified is generally an image of the outer package of the article with a bar code. At present, two modes exist for identifying the bar code on the outer package of the article, one is to use a bar code scanner, and the method needs manual operation to decode and record the scanning port of the scanner aligned with the bar code. Another is an automatic decoding technique using digital processing techniques, which first needs to be able to locate accurately the bar codes that may be present in the picture against a complex image background, and then send the located candidate regions to a decoder for decoding. However, in practical applications, the image to be decoded usually has a relatively complex background pattern, which affects the decoding process of the bar code, so that the probability of decoding failure is relatively high. Therefore, the application provides a bar code identification method for improving the success rate of decoding codes of bar codes.
The image to be identified may be obtained by a visual sensor, for example, a camera, and the area where the barcode is located on the product or the area where the barcode is located on the package is photographed by the camera, so as to obtain the image to be identified. After the image to be identified is obtained, the image to be identified can be subjected to blocking processing (or segmentation processing) to obtain local image combination. It should be noted that, each local image in the local image set is an image with uniform shape and size, and the size of the local image can be set by a technician according to actual requirements, and in general, the local image is set to be smaller than the size of the area where the whole barcode is located, that is, when the whole area to be identified is segmented, the area where the barcode is located is segmented into a plurality of local images.
Step S20, clustering each local image based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold;
it should be noted that the bar code is composed of vertical bars with alternating black and white, so the image of the area where the bar code is located has a large gradient change. The bar code is located based on features that can be based on gradient information in the image, such as gradient direction. Therefore, for the obtained image to be identified (or each partial image obtained after the image to be identified is segmented), the gradient amplitude and the direction of the image are calculated after the image to be identified is subjected to filtering treatment, wherein the gradient amplitude refers to the gradient change degree, the gradient direction refers to the gradient transformation direction, and in the bar code, for example, a larger gradient change exists at the edge between the black bar and the white bar in the bar code, and the gradient change direction is generally perpendicular to the edge line of the black bar and the white bar. It will be appreciated that, since the image of the region where the bar code is located has a larger gradient change, the partial image with more edge points distributed (points with larger gradient change, such as gradient amplitude greater than a preset threshold value) can be regarded as a candidate image.
Exemplary, clustering is performed on each local image based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result. The gradient direction trend of any candidate image refers to a direction in which a gradient change of the candidate image approaches, for example, a plurality of edge points are distributed on the candidate image, wherein each edge point has a specific gradient direction, so that the gradient direction trend of the candidate image can be determined by counting the gradient directions of the edge points, for example, if the number of edge points in the same gradient direction is the largest, the gradient direction is taken as the gradient direction trend of the candidate image. And clustering the candidate images based on the gradient direction trend, wherein in the clustering result, the candidate images classified into the candidate images of the same type have gradient direction trend difference smaller than a preset difference threshold, for example, the candidate images with gradient direction trend difference smaller than 10 degrees can be considered as the candidate images of the same type. In addition, if the accuracy of the clustering result is ensured, the gradient direction trend of the candidate images of the same type in the clustering result can be set to be the same.
And step S30, determining a target area in the image to be identified based on the clustering result, and decoding the bar code of the target area to obtain the identification result of the bar code.
For example, since the barcodes have a certain density, and the partial images obtained by dividing the barcodes have the same gradient characteristics (such as consistent gradient directions), the region where the candidate images belonging to the same class in the clustering result are located can be considered as the target region where the barcodes are located in the images to be identified. And decoding the bar code of the target area to obtain the recognition result of the bar code. For example, the width of each bar code in the bar code is scanned, and decoding is performed based on the width of each bar code to obtain information carried by the bar code, namely the recognition result of the bar code.
In the embodiment, the image to be identified is subjected to blocking processing to obtain a local image set; clustering each local image based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold; and determining a target area in the image to be identified based on the clustering result, and decoding the bar code of the target area to obtain the identification result of the bar code. The method comprises the steps that the image to be identified is segmented to obtain a local image set, clustering is conducted on the basis of gradient direction trends of candidate images in the local image set, and the gradient features of the areas where the bar codes are located are similar and densely distributed, so that the areas formed by candidate images belonging to the same class in a clustering result based on the gradient direction trends are target areas of the bar codes, accurate positioning of the bar codes is achieved, after the target areas where the bar codes are located are determined, the bar codes in the target areas can be decoded, and identification of the bar codes is completed. Because the embodiment of the application realizes the accurate positioning of the bar codes through clustering, the stability of bar code identification is ensured, the probability of success of bar code decoding is improved, namely the robustness of the bar code identification scheme is improved.
In a possible implementation manner, after the step of performing the blocking processing on the image to be identified to obtain the local image set, the method further includes:
step S110, for any one local image in the local image set, determining the number of edge points in the local image, wherein the edge points are points with gradient amplitude larger than a preset gradient amplitude threshold value in the local image;
and step S120, if the number of edge points in the local image is greater than a preset number threshold, taking the local image as a candidate image.
For example, for any one local image in the local image set, determining the number of edge points in the local image, where the edge points refer to points in the local image with gradient amplitude greater than a preset gradient amplitude threshold, where the preset gradient amplitude threshold is an empirical value, and a technician can set the gradient amplitude threshold according to practical situations. Further, if the number of edge points in the local image is greater than a preset number threshold, the local image may be used as a candidate image. Similarly, the preset number threshold may be an empirical value, and the technician may set the threshold according to the actual situation.
In a possible embodiment, the step of determining the target area in the image to be identified based on the clustering result includes:
And step S300, for any candidate image group formed by candidate images of the same type in the clustering result, splicing the candidate images in the candidate image group based on the relative positions of the candidate images in the candidate image group in the image to be identified, so as to obtain the target area.
It can be understood that, since the gradient features of the region where the bar code is located have similar and densely distributed characteristics, for any candidate image group composed of candidate images of the same type in the clustering result, the region where each candidate image in the candidate image group is located can be considered as the target region where the bar code is located. And therefore, according to the original relative position of each candidate image in the candidate image group in the image to be identified, each candidate image in the candidate image group is spliced and combined to obtain the target area.
Referring to fig. 3, a second embodiment of the identification method of the bar code of the present application is presented based on the first embodiment of the identification method of the bar code of the present application. In this embodiment, the same or similar parts as those of the above embodiment may be referred to the above, and will not be described here again.
In a possible embodiment, the step of using the local image as a candidate image includes:
Step S121, determining a main gradient direction section with the maximum number of edge points in each gradient direction section divided in advance in the partial image;
and step S122, if the duty ratio of the edge point of the main gradient direction interval in the edge point of the local image is greater than a preset duty ratio threshold, taking the local image as the candidate image, wherein the gradient direction trend of the candidate image is the direction corresponding to the main gradient direction interval.
In practical application, in order to determine the gradient direction trend of the local image and further screen out candidate images, gradient direction intervals are divided in the local image in advance, and then the number of edge points of which the gradient direction belongs to each interval is counted, so that the concentration degree of the gradient direction of each edge point in the local image and the gradient direction trend of the local image are determined. For example, referring to fig. 4, a schematic division diagram of gradient direction intervals in the present application is shown, and considering that the gradient directions of the bar code have symmetry (as shown in fig. 5, the gradient directions of the bar code in the present application are opposite but symmetrically distributed on the same straight line), for convenience, the present embodiment will divide intervals in a range of 0 ° to 180 °, as shown in fig. 4, to obtain 8 intervals, where there is a gradient direction of one edge point belonging to a range of 0 ° to 22.5 °, and in some special cases, for example, an edge point is close to or belongs to a boundary line between two gradient direction intervals, for example, a range of 0 ° to 22.5 ° and a range of 22.5 ° to 45 ° are provided, if there is one. The gradient direction of the edge point is 22.5 °, and in practical applications, the edge point can be recorded in statistics of the interval of 0 ° to 22.5 ° and the interval of 22.5 ° to 45 °. In practical applications, the number of gradient direction intervals and the magnitude of the gradient direction can be set by a technician according to requirements, so the method is not limited herein. Counting the number of edge points belonging to each gradient direction interval, and taking the gradient direction interval with the largest number of edge points as a main gradient direction interval. Further, the duty ratio of the edge point of the main gradient direction interval in the edge point of the local image is calculated, and if the duty ratio is larger than a preset duty ratio threshold value, the local image can be used as a candidate image. It will be appreciated that, according to the distribution characteristics of the gradient directions of the bar code, that is, the gradient directions of the bar code should be perpendicular to the black-white boundary, if the bar code exists in the partial image, the gradient directions of the edge points in the partial image should be concentrated in a direction interval, and the ratio of the edge points in the main gradient direction interval of the partial image to the edge points of the partial image can represent the concentration degree of the gradient directions of the edge points in the partial image, if the concentration degree is higher, the probability of the bar code exists in the partial image is higher, so if the ratio is greater than the preset ratio threshold, the partial image can be used as a candidate image. The gradient direction trend of the candidate image is a direction corresponding to the main gradient direction section, and for example, a direction included in the main gradient direction section may be directly used as the gradient direction trend of the candidate image, or an intermediate direction (for example, an intermediate direction of a section of 0 ° to 22.5 ° is 11.25 °) of the main gradient direction section may be used as the gradient direction trend of the candidate image.
In a possible implementation manner, before the step of clustering each of the local images based on the gradient direction trend of each of the candidate images in the local image set to obtain a clustering result, the method further includes:
step S201, for any one of the candidate images, if no other candidate image exists in the adjacent area of the candidate image, eliminating the candidate image from the clustered object of the cluster.
For example, due to the continuity of the bar code, for a partial image with a bar code, there should also be other partial images with bar codes in adjacent areas of the partial image. Therefore, for any candidate image (namely, a local image with a bar code with a high probability), if other candidate images do not exist in the adjacent area of the candidate image, the isolated candidate image is characterized as having a high probability of not having a bar code, so that the candidate image can be removed from the clustering objects of the subsequent clustering step and does not participate in clustering. Therefore, each type of candidate image group in the clustering result can be spliced and combined to form a target area, and the accuracy of the bar code positioning result is improved.
In a possible embodiment, before the step of decoding the barcode of the target area, the method further includes:
step S301, binarizing the target area to determine the geometric characteristics of the target area;
step S302, if the geometric features of the target area are not consistent with the geometric features of the preset bar code area, discarding the target area.
Illustratively, the target region is binarized such that the target region forms a region of continuous or uniform pixels, thereby facilitating extraction of geometric features of the target region. The geometric feature may be the area of the target area, may be the side length of the target area, or the ratio of length to width, etc. And comparing the determined geometric features of the target area with the geometric features of the preset barcode area (wherein the geometric features of the preset barcode area can be set according to the geometric features of the common barcode), and if the geometric features of the target area are not matched with the geometric features of the preset barcode area, representing that the target area does not have the barcode, so that the target area is discarded, namely the target area does not participate in subsequent barcode decoding.
Referring to fig. 6, a third embodiment of the present application is presented based on the first and second embodiments of the identification method of the bar code of the present application. In this embodiment, the same or similar parts as those of the above embodiment may be referred to the above, and will not be described here again. The step of decoding the bar code of the target area to obtain the identification result of the bar code comprises the following steps:
Step S310, scanning is carried out at different scanning positions in the target area based on a preset scanning direction, so as to obtain a plurality of width information groups, wherein the width information groups consist of the width information of each bar code in the target area;
step S320, for any one width information group, decoding the width information in the width information group to obtain a group of candidate character sequences;
and step S330, taking the candidate character sequence with the highest occurrence frequency in the candidate character sequences as the recognition result of the bar code.
Illustratively, the recognition result is actually a set of target character sequences, e.g., a character sequence consisting of a string of digits. When scanning the target area, scanning may be performed at different scanning positions in the target area based on a preset scanning direction, where the preset scanning direction may be set according to characteristics of the barcode, for example, the preset scanning direction may be set to be a direction perpendicular to the barcode in the barcode, or set based on a gradient direction trend of a candidate image group used for determining the target area, for example, set to be parallel to the gradient direction trend. In practical application, since there may be interference information before and after the bar code, and the scanning result may be interfered, in this embodiment, scanning is performed at different scanning positions in the target area, so as to obtain multiple width information sets, where the width information sets are composed of width information of each bar code in the target area, for example, the width information sets are composed of widths of black bars and white bars in the target area. For any one width information set, decoding is performed based on the width information in the width information set to obtain a set of candidate character sequences, and the step of decoding based on the width information can refer to the existing decoding mode, which is not described herein. And decoding the plurality of width information groups to obtain a plurality of candidate character sequences. And counting the occurrence frequency of each candidate character sequence, and taking the highest candidate character sequence as the recognition result of the bar code.
It can be understood that, in this embodiment, for a barcode in a target area, the application scans multiple times, and uses the scanning result with the highest occurrence frequency as the recognition result of the final barcode, so as to avoid the condition that the barcode is interfered, and thus ensure the accuracy of the recognition result of the barcode.
In a possible implementation manner, the step of scanning at different scanning positions in the target area based on a preset scanning direction to obtain a plurality of width information sets includes:
step S311, for any scanning position in the target area, scanning the target area based on the scanning position and a preset scanning direction to obtain edge information of the scanning position in the preset scanning direction;
step S312, determining the sub-pixel position of the edge position in the gradient direction in the edge information;
step S313, generating width information of each bar code according to the distance between two adjacent sub-pixel positions, wherein each width information forms one width information group.
For example, for any scanning position in the target area, scanning is performed on the target area based on the scanning position and a preset scanning direction to obtain edge information of the scanning position in the preset scanning direction, for example, information of a certain line in the target area is scanned to obtain edge information of a pixel level of a bar code in the target area. The edge information includes each edge position (corresponding to an edge point), and the sub-pixel position of the edge position in the gradient direction is calculated based on the edge position and the pixels around the edge position, for example, if the coordinates of the edge position are set to (1, 0), the coordinates of the pixel point adjacent to the edge position in the gradient direction of the edge position are set to (2, 0), and the calculated sub-pixel position coordinates are set to (1.5, 0). In the method, the width information of each bar code is generated according to the distance between two adjacent sub-pixel positions, for example, the distance between two adjacent sub-pixel positions is used as the width of a certain bar code, and in practical application, after the sub-pixel positions are determined, the width information of each bar code in a row of pixels can be obtained by performing convolution calculation on a row of adjacent pixels including the sub-pixel positions. And each width information can form a width information group.
In addition, referring to fig. 7, an embodiment of the present application further proposes a barcode identification apparatus 100, where the barcode identification apparatus 100 includes:
the acquisition module 10 is used for carrying out blocking processing on the image to be identified to obtain a local image set;
the clustering module 20 clusters each local image based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold;
and the identification module 30 determines a target area in the image to be identified based on the clustering result, decodes the bar code of the target area, and obtains the identification result of the bar code.
Optionally, the identification device 100 for bar codes further includes a screening module 40, where the screening module 40 is configured to:
for any one local image in the local image set, determining the number of edge points in the local image, wherein the edge points are points with gradient amplitude larger than a preset gradient amplitude threshold value in the local image;
and if the number of the edge points in the local image is larger than a preset number threshold, taking the local image as a candidate image.
Optionally, the screening module 40 is further configured to:
determining a main gradient direction section with the maximum number of edge points in each gradient direction section of the local image;
and if the duty ratio of the edge points of the main gradient direction interval in the edge points of the local image is larger than a preset duty ratio threshold, taking the local image as the candidate image, wherein the gradient direction trend of the candidate image is the direction corresponding to the main gradient direction interval.
Optionally, the bar code identification device 100 further includes a rejection module 40, where the rejection module 40 is configured to:
and for any candidate image, if no other candidate image exists in the adjacent area of the candidate image, eliminating the candidate image from the clustered objects of the clusters.
Optionally, the identification module 30 is further configured to:
and for any candidate image group formed by candidate images of the same type in the clustering result, splicing the candidate images in the candidate image group based on the relative positions of the candidate images in the candidate image group in the image to be identified, so as to obtain the target area.
Optionally, the identification device 100 of the barcode further comprises a discarding module 50, and the discarding module 50 is configured to:
Performing binarization processing on the target area to determine the geometric characteristics of the target area;
and if the geometric characteristics of the target area are not consistent with the geometric characteristics of the preset bar code area, discarding the target area.
Optionally, the identification module 30 is further configured to:
scanning the target area based on the scanning position and a preset scanning direction for any scanning position in the target area to obtain edge information of the scanning position in the preset scanning direction;
determining the sub-pixel position of the edge position in the gradient direction in the edge information;
generating width information of each bar code according to the distance between two adjacent sub-pixel positions, wherein each width information forms one width information group.
The bar code identification device provided by the application adopts the bar code identification method in the embodiment, and aims to solve the technical problem of high decoding failure probability of the traditional image-based bar code decoding scheme. Compared with the prior art, the beneficial effects of the bar code identification device provided in the embodiment of the present application are the same as those of the bar code identification method provided in the first embodiment, and other technical features of the bar code identification device are the same as those disclosed in the method of the first embodiment, which are not described in detail herein.
In addition, the embodiment of the application also provides a bar code identification device, which comprises: the method comprises the steps of a memory, a processor and a bar code identification program stored in the memory and capable of running on the processor, wherein the bar code identification program is executed by the processor to realize the bar code identification method.
The specific implementation manner of the bar code identification device in the present application is basically the same as the above-mentioned examples of the bar code identification method, and will not be described herein again.
In addition, the embodiment of the application also provides a readable storage medium, which is a computer readable storage medium, wherein the readable storage medium stores a bar code identification program, and the bar code identification program realizes the steps of the bar code identification method when being executed by a processor.
The specific embodiments of the medium in the present application are basically the same as the embodiments of the identification method of the barcode, and are not repeated here.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present application are merely for describing, and do not represent advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above, including several instructions for causing a terminal device (which may be a computer, a server, or a network device, etc.) to perform the method described in the embodiments of the present application.
The foregoing description is only of the preferred embodiments of the present application, and is not intended to limit the scope of the claims, and all equivalent structures or equivalent processes using the descriptions and drawings of the present application, or direct or indirect application in other related technical fields are included in the scope of the claims of the present application.
Claims (11)
1. A method of identifying a bar code, the method comprising:
performing blocking processing on the image to be identified to obtain a local image set;
clustering each local image based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold;
and determining a target area in the image to be identified based on the clustering result, and decoding the bar code of the target area to obtain the identification result of the bar code.
2. The method for identifying a bar code according to claim 1, wherein after the step of performing a blocking process on the image to be identified to obtain a local image set, the method further comprises:
for any one local image in the local image set, determining the number of edge points in the local image, wherein the edge points are points with gradient amplitude larger than a preset gradient amplitude threshold value in the local image;
and if the number of the edge points in the local image is larger than a preset number threshold, taking the local image as a candidate image.
3. The method of identifying a bar code of claim 2, wherein the step of using the partial image as a candidate image comprises:
determining a main gradient direction section with the maximum number of edge points in each gradient direction section of the local image;
and if the duty ratio of the edge points of the main gradient direction interval in the edge points of the local image is larger than a preset duty ratio threshold, taking the local image as the candidate image, wherein the gradient direction trend of the candidate image is the direction corresponding to the main gradient direction interval.
4. The method of identifying a bar code of claim 1, wherein prior to the step of clustering each of the partial images based on a gradient direction trend of each of the candidate images in the set of partial images to obtain a clustered result, the method further comprises:
and for any candidate image, if no other candidate image exists in the adjacent area of the candidate image, eliminating the candidate image from the clustered objects of the clusters.
5. The method of identifying a bar code of claim 1, wherein the step of determining a target region in the image to be identified based on the clustering result comprises:
And for any candidate image group formed by candidate images of the same type in the clustering result, splicing the candidate images in the candidate image group based on the relative positions of the candidate images in the candidate image group in the image to be identified, so as to obtain the target area.
6. The method of identifying a bar code of claim 1, wherein prior to the step of decoding the bar code of the target area, the method further comprises:
performing binarization processing on the target area to determine the geometric characteristics of the target area;
and if the geometric characteristics of the target area are not consistent with the geometric characteristics of the preset bar code area, discarding the target area.
7. The method of claim 1, wherein the step of decoding the bar code of the target area to obtain the recognition result of the bar code comprises:
scanning at different scanning positions in the target area based on a preset scanning direction to obtain a plurality of width information groups, wherein the width information groups consist of the width information of each bar code in the target area;
decoding width information in any width information group to obtain a group of candidate character sequences;
And taking the candidate character sequence with the highest occurrence frequency in the candidate character sequences as a recognition result of the bar code.
8. The method of claim 7, wherein the step of scanning at different scanning positions in the target area based on a preset scanning direction to obtain a plurality of width information sets comprises:
scanning the target area based on the scanning position and a preset scanning direction for any scanning position in the target area to obtain edge information of the scanning position in the preset scanning direction;
determining the sub-pixel position of the edge position in the gradient direction in the edge information;
generating width information of each bar code according to the distance between two adjacent sub-pixel positions, wherein each width information forms one width information group.
9. A bar code identification device, characterized in that the bar code identification device comprises:
the acquisition module is used for carrying out blocking processing on the image to be identified to obtain a local image set;
the clustering module is used for clustering the local images based on the gradient direction trend of each candidate image in the local image set to obtain a clustering result, wherein the gradient direction trend difference between the candidate images of the same type in the clustering result is smaller than or equal to a preset difference threshold;
And the identification module is used for determining a target area in the image to be identified based on the clustering result, and decoding the bar code of the target area to obtain an identification result of the bar code.
10. A bar code identification device, characterized in that the bar code identification device comprises: memory, a processor and a bar code identification program stored on the memory and executable on the processor, which when executed by the processor, implements the steps of the bar code identification method according to any one of claims 1 to 8.
11. A readable storage medium, characterized in that the readable storage medium is a computer readable storage medium, on which a bar code identification program is stored, which bar code identification program, when being executed by a processor, implements the steps of the bar code identification method according to any one of claims 1 to 8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311602742.7A CN117540762A (en) | 2023-11-27 | 2023-11-27 | Bar code identification method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311602742.7A CN117540762A (en) | 2023-11-27 | 2023-11-27 | Bar code identification method, device, equipment and readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117540762A true CN117540762A (en) | 2024-02-09 |
Family
ID=89785832
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311602742.7A Withdrawn CN117540762A (en) | 2023-11-27 | 2023-11-27 | Bar code identification method, device, equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117540762A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118396009A (en) * | 2024-06-24 | 2024-07-26 | 深圳盈达信息科技有限公司 | Automatic bar code identification method, system, storage medium and electronic equipment |
-
2023
- 2023-11-27 CN CN202311602742.7A patent/CN117540762A/en not_active Withdrawn
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118396009A (en) * | 2024-06-24 | 2024-07-26 | 深圳盈达信息科技有限公司 | Automatic bar code identification method, system, storage medium and electronic equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110046529B (en) | Two-dimensional code identification method, device and equipment | |
CN103714327B (en) | Method and system for correcting image direction | |
US9076056B2 (en) | Text detection in natural images | |
US9147095B2 (en) | Optical code scanner optimized for reading 2D optical codes | |
EP2974261A2 (en) | Systems and methods for classifying objects in digital images captured using mobile devices | |
US10169629B2 (en) | Decoding visual codes | |
WO2013044875A1 (en) | Linear barcode identification method and system | |
CN102667810A (en) | Face recognition in digital images | |
CN117540762A (en) | Bar code identification method, device, equipment and readable storage medium | |
CN111899270A (en) | Card frame detection method, device and equipment and readable storage medium | |
US20200302135A1 (en) | Method and apparatus for localization of one-dimensional barcodes | |
CN112163443A (en) | Code scanning method, code scanning device and mobile terminal | |
WO2020156553A1 (en) | Qr code positioning box identification method and apparatus, and electronic device and storage medium | |
CN117496560B (en) | Fingerprint line identification method and device based on multidimensional vector | |
CN108108646B (en) | Bar code information identification method, terminal and computer readable storage medium | |
WO2024164581A1 (en) | Multi-code decoding method and system based on gradient algorithm | |
KR100404306B1 (en) | Coded pattern and method for the extraction of code from the same | |
CN112163655B (en) | Dynamic implicit two-dimensional code and generation and detection method and device thereof | |
CN112749769B (en) | Graphic code detection method, graphic code detection device, computer equipment and storage medium | |
JP4163406B2 (en) | Bar code recognition device | |
CN116306731A (en) | Method and device for identifying bar codes, electronic equipment and storage medium | |
CN115880362A (en) | Code region positioning method and device, computer equipment and computer readable storage medium | |
JP2023061880A (en) | Collation device and program | |
CN105469015B (en) | A kind of fast positioning claps the method and system of code distance | |
CN114611540A (en) | One-dimensional code image area identification method based on digital image processing and electronic equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
WW01 | Invention patent application withdrawn after publication |
Application publication date: 20240209 |
|
WW01 | Invention patent application withdrawn after publication |