CN108920992B - Deep learning-based medicine label bar code positioning and identifying method - Google Patents

Deep learning-based medicine label bar code positioning and identifying method Download PDF

Info

Publication number
CN108920992B
CN108920992B CN201810894904.1A CN201810894904A CN108920992B CN 108920992 B CN108920992 B CN 108920992B CN 201810894904 A CN201810894904 A CN 201810894904A CN 108920992 B CN108920992 B CN 108920992B
Authority
CN
China
Prior art keywords
region
bar code
image
dimensional
regions
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810894904.1A
Other languages
Chinese (zh)
Other versions
CN108920992A (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.)
Changsha University of Science and Technology
Original Assignee
Changsha University of Science and Technology
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 Changsha University of Science and Technology filed Critical Changsha University of Science and Technology
Priority to CN201810894904.1A priority Critical patent/CN108920992B/en
Publication of CN108920992A publication Critical patent/CN108920992A/en
Application granted granted Critical
Publication of CN108920992B publication Critical patent/CN108920992B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

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

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • General Health & Medical Sciences (AREA)
  • Toxicology (AREA)
  • Electromagnetism (AREA)
  • Health & Medical Sciences (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Image Analysis (AREA)
  • Image Processing (AREA)

Abstract

The invention discloses a method for positioning and identifying a medicine label bar code based on deep learning, which solves the problem of difficult bar code positioning under complex conditions of uneven illumination, distortion and the like. On the basis, the problem of correcting the linear distortion two-dimensional bar Code is solved, the position of the bar Code under the complex condition can be effectively positioned, distortion correction and detail processing are carried out, a high-quality bar Code binary image is obtained, and accurate reading is realized.

Description

Deep learning-based medicine label bar code positioning and identifying method
Technical Field
The invention belongs to the field of automatic identification, and particularly relates to a method for positioning and identifying a medicine label bar code based on deep learning.
Background
The bar code technology is widely applied to the pharmaceutical industry, unique codes are given to medicines through laser coding, medicine serialization is realized, a global medicine tracing system is constructed, and the medicine health safety is greatly improved. For example, the electronic drug supervision code in China and the Data Matrix two-dimensional code in Europe and America and other countries both indirectly or directly provide information such as production date, batch number, serial number and the like of drugs. The bar code can only be found and read due to its own locating feature. Due to the wide use, the complexity of the application scenario is caused. The bar code may be distorted, stained, etc. In the case of losing part of the positioning feature or weakening the positioning feature, the bar code can be accurately positioned, and a universal method is lacked. Secondly, for the requirement of operability, no matter a mobile phone scans codes or a handheld code scanner, a camera needs to be aligned to the bar codes, and time and labor are consumed. Finally, the requirement on real-time performance and the speed determine the efficiency of the factory, and a real-time and efficient decoding process is a necessary condition. Therefore, an effective bar code identification method is urgently needed to be found in the production environment of the production line.
The noun explains:
rectangular expansion treatment: namely, dilation operation or dilation process, a term used in image processing, utilizes a custom-sized rectangle to expand a target region to the outside, and serves to fill in some holes in the target region and to eliminate small particle noise contained in the target region.
Disclosure of Invention
The invention discloses a method for positioning and identifying a medicine label bar code based on deep learning, which solves the problem of difficult bar code positioning under complex conditions of uneven illumination, distortion and the like. On the basis, the problem of correcting the linear distortion two-dimensional bar Code is solved, the position of the bar Code under the complex condition can be effectively positioned, distortion correction and detail processing are carried out, a high-quality bar Code binary image is obtained, and accurate reading is realized, wherein the identification objects comprise a Data Matrix two-dimensional Code, an EAN-13 Code and a Code-128 Code.
In order to achieve the purpose, the technical scheme of the invention is as follows:
a method for positioning and identifying a medicine label bar code based on deep learning comprises the following steps:
the method comprises the following steps: collecting a medicine box label bar code Image on a production line and recording the Image as Image 0;
step two: inputting the Image0 into a neural network for positioning to obtain an Image1 containing a barcode positioning frame;
step three: roughly cutting the barcode region by using the positioning frame to obtain an Image2, which specifically comprises the following steps:
step 3.1: converting the 3-channel Image1 into 3 single-channel images with the same domain of definition, namely Imagechannel1, Imagechannel2 and Imagechannel 3;
step 3.2: segmenting the positioning frame region from the Image1 to obtain Regions 1; setting MinGray1 as a set lower gray value limit, MaxGray1 as a set upper gray value limit, and Imagechannel1(x, y) as the gray value of the pixel at the (x, y) position in the image; x represents the X-axis coordinate of the pixel in the Image1, and Y represents the Y-axis coordinate of the pixel in the Image 1;
selecting a region, the selected region satisfying:
MinGray1<Imagechannel1(x,y)<MaxGray1;
step 3.3: filling the obtained Regions1 to obtain Regions _ fill 1; conducting connected domain searching operation on the region Regions1, and finding the largest connected domain region Regions 2;
step 3.4: carrying out region shape transformation on the region Regions2 to obtain a region Regions3 of the maximum internal connecting moment;
step 3.5: performing intersection processing on the Image Imagechannel1 and the Regions3 to obtain an Image3 only containing Regions of the Regions 3;
step four: accurately positioning the bar code area, removing all background information, and accurately extracting the bar code area; the method comprises the following steps:
step 4.1: filtering the Image3 by using a mean value filtering method to obtain an Image Imagemean 1; ImageMean1(x, y) is the gray value of the pixel at the (x, y) position after filtering, f (x, y) is the gray values of adjacent M pixels, then:
Figure BDA0001757879600000031
step 4.2: dividing the Image3 by using a local threshold value to obtain a region RegionDynThresh 1; wherein Image3(x, y) is the gray scale value of Image3 at the (x, y) pixel, and T1 is the selected offset value; the obtained regional gray value satisfies the formula:
Image3(x,y)≤ImageMean1(x,y)-T1;
step 4.3: performing rectangular expansion processing on the region RegionDynThresh1 to obtain a region RegionDilation;
step 4.4: filling the region registration division to obtain registers _ fill 2; and selects the largest connected domain Regions 4;
step 4.5: region transformation is performed on the Regions 4: filling in the region defect part and regularizing the edges of the region Regions4 to obtain convex hull Regions5 of the region Regions 4; intersection processing is carried out on the convex hull Regions5 and the Image3, and the accurate position Image4 of the bar code is obtained;
after the accurate position of the bar code is obtained, two situations can occur, namely, the two-dimensional code with linear distortion is corrected, and the bar code with a certain rotation angle inclination is subjected to rotation angle prediction to obtain a horizontal image;
performing the following steps on the linear distortion Data Matrix two-dimensional code to correct the image;
step five: extracting boundary information and angular point information of the two-dimensional code;
step 5.1: extracting closed boundary contour lines Contours of the Regions 5;
step 5.2: dividing the closed contour line Contours into 4 contour line segments;
step 5.3: numbering and sequencing the 4 line segments according to a clockwise sequence;
step 5.4: extracting a plurality of points from one contour line, fitting the points into a straight line by a weighted least square method, and obtaining the coordinates of the end points of the straight line segment; wherein N is the number of points on the collected contour line, (x)i,yi) I is more than or equal to 1 and less than or equal to N, and N is more than or equal to 3;
Figure BDA0001757879600000041
y′=ax′+b
x 'represents coordinates of pixels in the Image4 in the X-axis direction according to the straight line to which the contour lines are fitted, and Y' represents coordinates of pixels in the Image4 in the Y-axis direction according to the straight line to which the contour lines are fitted;
repeating the step 5.4, sequentially fitting the four contour lines to obtain the coordinates of the starting points of the line segments, arranging the coordinates according to the clockwise sequence to obtain the coordinate information of the corner points of the two-dimensional code, and expressing the coordinate information as Xhorns and Yhorns in an array form;
step six: calculating a homogeneous transformation Matrix applied to the linearly distorted two-dimensional code Image4 by affine transformation, wherein Px=Xcorners,Py=Ycorners,Pw=(1,1,1),QxAnd QyIs a transformed custom corner point coordinate, Qw=(1,1,1);
Figure BDA0001757879600000051
Step seven: affine transformation correction is applied to the linear distortion two-dimensional code Image4 to obtain a regular Image 5;
the steps of calculating the rotation angle alpha of the one-dimensional bar code and the two-dimensional bar code with nonlinear distortion are as follows:
step eight: converting the minimum external moment of the region Regions5 to obtain the angle of the minimum external rectangle, namely the rotation angle alpha of the bar code;
step nine: rotating the Image4 to obtain a regular Image 5;
step ten: filtering the Image5 by using a mean value filtering method to obtain an Image Imagemean 2; ImageMean2(x, y) is the gray value of the pixel at the (x, y) position after filtering, f (x, y) is the gray value of the adjacent M pixels;
Figure BDA0001757879600000052
step eleven: dividing the Image5 by using a local threshold value to obtain a region RegionDynThresh 2; wherein Image5(x, y) is the gray scale value of Image5 at the (x, y) pixel, and T2 is the selected offset value; the obtained regional gray value satisfies the formula:
Image5(x,y)≤ImageMean2(x,y)-T2
step twelve: carrying out corrosion operation on the region RegionDynThresh2 to eliminate a part of adhesion regions in the target and obtain a region RegionErosis;
step thirteen: performing rectangular expansion operation on the region RegionErosis to supplement a part of missing part to obtain a region RegionDilation;
fourteen, if the label bar code is a one-dimensional code, the one-dimensional code is accurately processed; if the label bar code is a two-dimensional code, performing accurate processing on the two-dimensional code; thereby obtaining a binary image BinImage with accurate one-dimensional bar code or two-dimensional bar code;
and step fifteen, decoding the binary image BinImage to obtain a processed medicine label bar code image.
In a further improvement, in the fourteenth step, the precision processing of the one-dimensional code includes the following steps:
14.1: calculating a connected component of a connecting domain of the region RegionDilation to enable black small blocks of the one-dimensional bar code to be independent from each other, so that the independent processing is facilitated; obtaining regions connected regions;
14.2: performing region deformation on the region connected regions, and filling each independent black bar region by using a minimum external moment mode to obtain a normalized and accurate one-dimensional bar code region RegionTrans;
14.3: converting the region RegionTran into a binary image to obtain a normalized one-dimensional bar code image BinImage;
Figure BDA0001757879600000061
in a further improvement, in the fourteenth step, the precision processing of the two-dimensional code includes the following steps: converting the region RegionDilation into a binary image to obtain a normalized two-dimensional bar code image BinImage;
Figure BDA0001757879600000071
in a further improvement, in the fifteenth step, the image BinImage is decoded by using HALCON software.
In a further improvement, in the second step, the collected Image0 is sent to a trained deep learning neural network, and the training of the neural network is obtained according to the following steps:
step 1) establishing a data set of a medicine label bar code: establishing a data set containing 400 medical label bar codes through object shooting, google and hundred-degree search;
step 2) calibrating the pictures in the data set: classifying and marking the targets in each picture by using a LabelImg tool, marking out target region information and category information, and correspondingly setting two categories: bar Code, Data matrix;
step 3) randomly dividing the data set into two parts, wherein 280 pictures are used for training, and 120 pictures are used for testing;
and 4) training a neural network, performing multi-target detection training by using the pre-trained SSD network, adjusting the relevant parameters, iterating 40000 times, stabilizing an error function within a range of 1 +/-0.3, and considering that the training is finished.
In a further improvement, in the step 1, a trigger type mode is adopted to collect the barcode image of the label of the medicine box.
Compared with the prior art, the invention has the advantages that:
(1) the invention solves the problem of difficult positioning of one-dimensional bar codes and two-dimensional bar codes under complex conditions by utilizing a deep learning method. The barcode area can be effectively and accurately positioned. In the subsequent processing process on the basis of positioning, the problem of linear distortion of the two-dimensional code can be solved, the rotation angle of the bar code can be predicted, an accurate binaryzation bar code picture is obtained, and the identification rate of the bar code is greatly improved. The whole algorithm is simple and effective, and the identification speed and the identification rate both meet the requirements of general industrial production.
(2) The identification object of the invention can be added conveniently on the existing basis without changing the main body of the algorithm too much, and the method has strong environmental adaptability and high universality.
(3) Compared with the traditional assembly line bar code detection technology, the positioning and processing method provided by the invention is lower in interference degree, and the image quality is different because the medicine box collection is influenced by the shooting angle, the environment, the illumination and the background. The requirements can not be met simultaneously under different production lines, medicine boxes and different environments; the method is hardly influenced by the factors and has better compatibility and stability.
(4) Compared with a handheld scanner or mobile phone scanning, the invention does not need to align the camera with the bar code. The image can be collected in a relatively large image range and angle, bar code information can be identified, and rapidity is better.
Drawings
FIG. 1 is a flow chart of the present invention;
FIG. 2-1 is a diagram of the effect of positioning a one-dimensional barcode under a complex situation by using a deep learning network, wherein 1(a) is a diagram of the effect of positioning a one-dimensional barcode under a complex background; 1(b) is a positioning effect diagram of the one-dimensional bar code under the condition of uneven illumination; 1(c) is a positioning effect diagram of the one-dimensional bar code under the condition of distortion and deformation; and 1(d) is a positioning effect diagram of the one-dimensional bar code under the condition of partial shielding.
2-2 is a diagram of the positioning effect of the two-dimensional bar code under the complex condition by using the deep learning network, wherein 2(a) is a diagram of the positioning effect of the two-dimensional bar code under the complex background; 2(b) is a positioning effect picture of the two-dimensional bar code under the condition of uneven illumination; 2(c) is a positioning effect graph of the two-dimensional bar code under the condition of distortion and deformation; and 2(d) is a positioning effect diagram of the two-dimensional bar code under the condition of partial shielding.
FIG. 3-1 is a diagram of a coarse positioning process of a one-dimensional barcode region, wherein 1(a) is an original image of the one-dimensional barcode; 1(b) positioning the bar code region by using a deep learning network; 1(c) is a diagram for converting three channels into a single channel; 1(d) extracting an effect graph of the positioning frame; 1(e) filling the positioning frame area effect graph; 1(f) is a roughly selected barcode region using the maximum inscribed moment; 1(g) roughly cutting a bar code area.
Fig. 3-2 is a diagram of a coarse positioning process of a one-dimensional barcode region, and fig. 2(a) is an original image of a two-dimensional barcode; 2(b) locating the bar code area by using a deep learning network; 2(c) is a diagram for converting three channels into a single channel; 2(d) extracting a positioning frame effect graph; 2(e) is a filling positioning frame area effect graph; 2(f) is a roughly selected barcode region using the maximum inscribed moment; 2(g) roughly cutting the bar code area.
FIG. 4-1 is a diagram of a process of accurately positioning a one-dimensional barcode region, wherein 1(a) is a diagram of an effect after one-dimensional barcode mean filtering; 1(b) is a one-dimensional bar code local threshold segmentation effect graph; 1(c) performing a zone expansion effect; 1(d) is connected domain filling effect; 1(e) selecting the maximum connected region effect; 1(f) carrying out convex surrounding deformation on the region to perfect the edge of the region; 1(g) cutting out a one-dimensional bar code image accurately.
FIG. 4-2 is a diagram of a process of accurately positioning a two-dimensional barcode region, wherein 2(a) is a diagram of an effect after two-dimensional barcode mean filtering; 2(b) is a two-dimensional bar code local threshold segmentation effect graph; 2(c) performing a zone expansion effect; 2(d) is connected domain filling effect; 2(e) selecting the maximum connected region effect; 2(f) carrying out convex surrounding deformation on the region to perfect the edge of the region; 2(g) accurately cutting out a two-dimensional bar code image;
fig. 5 is a linear distorted two-dimensional code calibration chart, and the coarse positioning and the precise positioning processes are the same as described above, and therefore are not repeated. Fig. (a) is a distorted two-dimensional code image extracted accurately; drawing (b) is two-dimensional code edge extraction and straight line fitting; the figure (c) is to obtain the coordinate effect of the two-dimension code corner point; fig. (d) is an image after affine transformation correction;
FIG. 6-1 shows a precise binarization process of a one-dimensional barcode, wherein 1(a) is an image obtained by performing preprocessing such as erosion-expansion on the one-dimensional barcode; 1(b) is a black stripe effect picture of the split one-dimensional bar code; 1(c) applying a minimum external moment to each individual stripe for defect handling; 1(d) is an effect diagram of the area binarization output.
FIG. 6-2 shows the precise binarization process of two bar codes, wherein 2(a) is an image obtained by performing pretreatment such as erosion-expansion on the two-dimensional bar code; and 2(b) is an effect diagram of the area binarization output.
Detailed Description
The invention is further described with reference to the following figures and specific examples. The Data Matrix two-dimensional Code, the Code-128 Code and the commodity bar Code (EAN-13 Code) on the medicine package are taken as examples for illustration, but the invention is not limited to the above.
In the embodiment, the camera adopts an area array gigabit network CCD camera with the resolution of 1080 x 960, the lens is a computer lens with a wide viewing angle of 6mm, and the light source is an annular LED light source with the radius of 10 cm;
as shown in fig. 1, a method for positioning and identifying a medical label barcode based on deep learning includes the following steps:
step 1: collecting the bar code Image of the medicine box label on the high-speed production line, and recording the Image as Image0, as shown in 1(a) and 2(a) in the figures 3-1 and 3-2;
step 2: inputting the Image0 into a neural network for positioning to obtain an Image1 containing a barcode positioning frame, as shown in 1(b) and 2(b) in the figures 3-1 and 3-2;
and step 3: roughly cutting the barcode region by using the positioning frame to obtain an Image2, as shown in 1(g) and 2(g) in fig. 3-1 and 3-2;
step 3.1: converting the 3-channel Image1 into 3 single-channel images having the same domain of definition, namely Imagechannel1, Imagechannel2 and Imagechannel3, as shown in FIGS. 3-1 and 3-2 at 1(c) and 2 (c);
[ yellow-green for contrast enhancement, the box color selection is located. Comparing the resulting 3 single channel images, image Imagechannel1 gave the best discrimination of the orientation box, showing a pure white color in the image. "C (B)
Step 3.2: the bounding box Regions are segmented from the image, resulting in Regions 1. MinGray1 is the set lower gray value limit, MaxGray1 is the set upper gray value limit, and Imagechannel1(x, y) is the gray value of the pixel at the (x, y) position in the image;
the selected region satisfies: MinGray1 < Imagechannel1(x, y) < MaxGray1, the effect is shown as 1(d) and 2(d) in FIG. 3-1 and FIG. 3-2;
according to the experimental results, when MinGray1 is 230 and maxgey 1 is 255, the obtained positioning frame area is the best. "C (B)
Step 3.3: and performing a filling operation on the obtained region Regions1 to obtain a region Regions _ fill 1. And performing a connected component search operation on the Regions to find the largest connected component Regions2, as shown in fig. 3-1 and 1(e) and 2(e) in fig. 3-2;
step 3.4: the region shape transformation is performed on the region Regions2 to obtain the maximum internal moment region Regions3, as shown in fig. 3-1 and 1(f) and 2(f) in fig. 3-2.
The upper part of the positioning frame contains information such as category, confidence coefficient and the like, and is useless information for the identification process. Therefore, to ensure that the barcode is disturbed by the background factors as little as possible, the region transformation method of the maximum internal contact moment is selected. Not only retains the content of the bar code, but also removes the redundant interference part
Step 3.5: intersection processing is carried out on the Image Imagechannel1 and the Regions3 to obtain an Image3 only containing Regions of the Regions3, as shown in 1(g) and 2(g) in FIGS. 3-1 and 3-2;
so far, under the complicated background condition, the bar code just can be pinpointed, and the subsequent process is proofreaied and correct the Data Matrix code that takes place linear distortion, rotates undistorted bar code. Thereby improving the decoding rate and the decoding speed. "C (B)
And 4, step 4: accurately positioning the bar code region, removing all background information, and accurately extracting the bar code region as shown in 1(g) and 2(g) in fig. 4-1 and 4-2;
step 4.1: the Image3 is filtered by using a mean filtering method, so as to obtain an Image ImageMean1, as shown in fig. 4-1 and 1(a) and 2(a) in fig. 4-2.
ImageMean1(x, y) is the gray value of the pixel at the (x, y) position after filtering, f (x, y) is the gray value of the adjacent M pixels;
Figure BDA0001757879600000121
step 4.2: the Image3 is segmented by using a local threshold to obtain a region RegionDynThresh1, as shown in FIGS. 4-1 and 4-2 (1 (b) and 2 (b)). Where Image3(x, y) is the grayscale value of Image3 at the (x, y) pixel, and T1 is the selected offset value. The obtained regional gray value satisfies the formula:
Image3(x,y)≤ImageMean1(x,y)-T1
step 4.1 and step 4.2 are adaptive threshold methods, which can extract the barcode region completely in different environments and under different illumination conditions, and are suitable for the requirements of the system in complex backgrounds. "C (B)
Step 4.3: subjecting the region RegionDynThresh to rectangular expansion to obtain a region RegionDilation as shown in FIGS. 4-1 and 4-2 (1 (c) and 2 (c);
the black small blocks are independent of each other for the two-dimensional code part, and the black small bars are not connected for the one-dimensional code. Therefore, partial information of the bar code is easy to be lost when the maximum connected domain is obtained. The respective portions in the barcode are connected to each other by the rectangular expansion process. "C (B)
Step 4.4: the region registration division is subjected to the padding process to obtain the registers _ fill2, as shown in fig. 4-1 and 1(d) and 2(d) in fig. 4-2. And selecting the largest connected domain Regions4, as shown in FIGS. 4-1 and 4-2 at 1(e), 2 (e);
step 4.5: region transformation is performed on the Regions 4: filling in the region defect part and regularizing the edges of the region Regions4 to obtain convex hull Regions5 of the region Regions 4; as shown in fig. 4-1 and 1(f) and 2(f) in fig. 4-2, and intersect with the Image3 to obtain an accurate position Image4 of the barcode, as shown in fig. 4-1 and 1(g) and 2(g) in fig. 4-2;
after the accurate position of the bar code is obtained, two situations can occur, namely, the two-dimensional code with linear distortion (situation A) is corrected, and the bar code with a certain rotation angle inclination (situation B) is subjected to rotation angle prediction to obtain a horizontal image;
[ case A ] the following steps are performed for a linearly distorted Data Matrix two-dimensional code, correcting an image;
and 5: extracting boundary information and angular point information of the two-dimensional code;
step 5.1: extracting a closed boundary contour line contiurs of the region Regions5, as shown in (b) of fig. 5;
step 5.2: dividing the closed contour line Contours into 4 contour line segments;
step 5.3: numbering and sequencing the 4 line segments according to a clockwise sequence;
step 5.4: extracting a plurality of points from the contour 1 and adding the points based on the contourAnd fitting the weight into a straight line by a least square method, and obtaining the coordinates of the end points of the straight line. N is the number of points on the contour line collected, (x)i,yi) Is the coordinates of the acquisition points, i is from 1 to N;
Figure BDA0001757879600000141
y=ax+b
[ contour lines Contours obtained from the region information are not formed by four straight line segments, but are curved and continuous curves formed along the region. In order to accurately obtain the angular point information, a least square method is used for linear operation, and the obtained intersection point coordinates of the four straight lines are required intersection point coordinates. "C (B)
Repeating the step 5.4, sequentially fitting the four line segments to obtain initial point coordinates of the line segments, arranging the initial point coordinates of the line segments in a clockwise sequence to obtain two-dimensional code corner point coordinate information, and expressing the two-dimensional code corner point coordinate information as Xcerners and Ycerners in an array form, as shown in (c) in fig. 5;
step 6: computing a homogeneous transformation Matrix applied over an affine transformation, where Px=Xcorners,Py=Ycorners,Pw=(1,1,1),QxAnd QyIs a transformed custom corner point coordinate, Qw=(1,1,1);
Figure BDA0001757879600000142
And 7: applying affine transformation correction to the linear distorted two-dimensional code Image4 to obtain a regular Image5, as shown in (d) of fig. 5;
[ case B ] calculating the rotation angle alpha of the one-dimensional barcode and the two-dimensional barcode which are not linearly distorted;
and 8: converting the minimum circumscribed moment of the region Regions5 to obtain the angle of the minimum circumscribed rectangle, namely the rotation angle alpha of the bar code;
and step 9: rotating the Image4 to obtain a regular Image5 as shown in 1(h) and 2(h) of FIG. 4-1 and FIG. 4-2;
to this end, both linearly distorted two-dimensional barcodes and arbitrary undistorted barcodes are extracted accurately and rotated to the horizontal. The contrast and characteristics of the barcode are not particularly apparent due to image acquisition equipment effects and image noise effects during transmission. In order to strengthen the characteristics and improve the decoding rate, the obtained Image5 is refined to obtain a bar code binary Image
Step 10: and filtering the Image5 by using a mean filtering method to obtain an Image Imagemean 2. ImageMean2(x, y) is the gray value of the pixel at the (x, y) position after filtering, f (x, y) is the gray value of the adjacent M pixels;
Figure BDA0001757879600000151
step 11: the Image5 is segmented using local thresholds to obtain region RegionDynThresh 2. Where Image5(x, y) is the grayscale value of Image5 at the (x, y) pixel, and T2 is the selected offset value. The obtained regional gray value satisfies the formula:
Image5(x,y)≤ImageMean2(x,y)-T2
step 10 and step 11 are adaptive threshold methods, which can extract the barcode region completely in different environments and under different illumination conditions, and are beneficial to the precise processing of the region in the future. "C (B)
Step 12: carrying out corrosion operation on the region RegionDynThresh2 to eliminate a part of adhesion regions in the target and obtain a region RegionErosis;
step 13: performing a rectangular expansion operation on the region regionerosis to supplement the partially missing part, and obtaining a region regionalization, as shown in fig. 6-1 and 1(a) and 2(a) of fig. 6-2;
after the area is preprocessed in the two steps, the one-dimensional bar code and the two-dimensional bar code are still different in structure, so that the two conditions are divided into two conditions. The method comprises the steps of firstly, accurately processing a one-dimensional code (case one), and secondly, accurately processing a two-dimensional code (case two);
[ case one ] precise binarization processing for a one-dimensional bar code;
step 14: and calculating a connected component of a connecting domain of the region RegionDilation to enable black small blocks of the one-dimensional bar code to be independent from each other, so that the single processing is facilitated. The region ConnectedRegions was obtained as shown in 1(b) in FIG. 6-1;
step 15: the region connectiededregions are subjected to region deformation, and each independent black bar region is filled in by means of minimum external connection moments. Obtaining a normalized and precise one-dimensional barcode region RegionTrans, as shown in 1(c) in FIG. 6-1;
step 16: converting the region RegionTran into a binary image to obtain a normalized one-dimensional barcode image BinImage, as shown in 1(d) in FIG. 6-1;
Figure BDA0001757879600000161
[ case two ] precise binarization processing for a two-dimensional bar code;
and step 17: converting the region RegionDilation into a binary image to obtain a normalized two-dimensional barcode image BinImage, as shown in 2(b) in FIG. 6-2;
Figure BDA0001757879600000162
so far, an accurate binary image of a one-dimensional bar code or a two-dimensional bar code is obtained and can be accurately and quickly identified
Step 18; decoding the binary image BinImage by using HALCON software;
the method can solve the problem of difficult bar code positioning under complex conditions and improve the bar code decoding rate. The method has high speed and good stability. Can reach the acquisition and identification speed of 125 ms/piece, and the identification rate can reach about 95%
And in the step 2, sending the acquired image into a trained deep learning neural network. The training of the neural network is obtained according to the following steps:
step 1) establishing a data set of the medical label bar code. A data set containing 400 medical label bar codes is established through real object shooting, google and hundred-degree search.
And 2) calibrating the pictures in the data set. And (4) classifying and marking the targets in each picture by using a LabelImg tool, and marking target region information and category information. The method sets two categories: bar Code, Data Matrix;
step 3) randomly dividing the data set into two parts, wherein 280 pictures are used for training, and 120 pictures are used for testing;
and 4) training a neural network, and performing multi-target detection training by using the pre-trained SSD network. After the relevant parameters are adjusted and the iteration is carried out for 40000 times, the error function is stabilized near 1, and the training is considered to be finished;
and in the step 1, the image acquisition mode is triggered acquisition.
Namely, when the medical packaging box is connected with the photoelectric switch, the photoelectric switch immediately triggers the industrial CCD camera to collect a frame of image.
The light source is a ring-shaped LED annular light source with the radius of 10 cm.
While the principles of the invention have been described in detail in connection with the preferred embodiments thereof, it will be understood by those skilled in the art that the foregoing embodiments are merely illustrative of exemplary implementations of the invention and are not limiting of the scope of the invention. The details of the embodiments are not to be interpreted as limiting the scope of the invention, and any obvious changes, such as equivalent alterations, simple substitutions and the like, based on the technical solution of the invention, can be interpreted without departing from the spirit and scope of the invention.

Claims (6)

1. A method for positioning and identifying a medicine label bar code based on deep learning is characterized by comprising the following steps:
the method comprises the following steps: collecting a medicine box label bar code Image on a production line and recording the Image as Image 0;
step two: inputting the Image0 into a neural network for positioning to obtain an Image1 containing a barcode positioning frame;
step three: roughly cutting the barcode region by using the positioning frame to obtain an Image2, which specifically comprises the following steps:
step 3.1: converting the 3-channel Image1 into 3 single-channel images with the same domain of definition, namely Imagechannel1, Imagechannel2 and Imagechannel 3;
step 3.2: segmenting the positioning frame region from the Image1 to obtain Regions 1; setting MinGray1 as a set lower gray value limit, MaxGray1 as a set upper gray value limit, and Imagechannel1(x, y) as the gray value of the pixel at the (x, y) position in the image; x represents the X-axis coordinate of the pixel in the Image1, and Y represents the Y-axis coordinate of the pixel in the Image 1;
selecting a region, the selected region satisfying:
MinGray1<Imagechannel1(x,y)<MaxGray1;
step 3.3: filling the obtained Regions1 to obtain Regions _ fill 1; conducting connected domain searching operation on the region Regions1, and finding the largest connected domain region Regions 2;
step 3.4: carrying out region shape transformation on the region Regions2 to obtain a region Regions3 of the maximum internal connecting moment;
step 3.5: performing intersection processing on the Image Imagechannel1 and the Regions3 to obtain an Image3 only containing Regions of the Regions 3;
step four: accurately positioning the bar code area, removing all background information, and accurately extracting the bar code area; the method comprises the following steps:
step 4.1: filtering the Image3 by using a mean value filtering method to obtain an Image Imagemean 1; ImageMean1(x, y) is the gray value of the pixel at the (x, y) position after filtering, f (x, y) is the gray values of adjacent M pixels, then:
Figure FDA0002781831910000021
step 4.2: dividing the Image3 by using a local threshold value to obtain a region RegionDynThresh 1; wherein Image3(x, y) is the gray scale value of Image3 at the (x, y) pixel, and T1 is the selected offset value; the obtained regional gray value satisfies the formula:
Image3(x,y)≤ImageMean1(x,y)-T1;
step 4.3: performing rectangular expansion processing on the region RegionDynThresh1 to obtain a region RegionDilation;
step 4.4: filling the region registration division to obtain registers _ fill 2; and selects the largest connected domain Regions 4;
step 4.5: region transformation is performed on the Regions 4: filling in the region defect part and regularizing the edges of the region Regions4 to obtain convex hull Regions5 of the region Regions 4; intersection processing is carried out on the convex hull Regions5 and the Image3, and the accurate position Image4 of the bar code is obtained;
after the accurate position of the bar code is obtained, two situations can occur, namely, the two-dimensional code with linear distortion is corrected, and the bar code with a certain rotation angle inclination is subjected to rotation angle prediction to obtain a horizontal image;
performing the following steps on the linear distortion DataMatrix two-dimensional code to correct the image;
step five: extracting boundary information and angular point information of the two-dimensional code;
step 5.1: extracting closed boundary contour lines Contours of the Regions 5;
step 5.2: dividing the closed contour line Contours into 4 contour line segments;
step 5.3: numbering and sequencing the 4 line segments according to a clockwise sequence;
step 5.4: extracting a plurality of points from one contour line, fitting the points into a straight line by a weighted least square method, and obtaining the coordinates of the end points of the straight line segment; wherein N is the number of points on the collected contour line, (x)i,yi) I is more than or equal to 1 and less than or equal to N, and N is more than or equal to 3;
Figure FDA0002781831910000031
y'=ax'+b
x 'represents coordinates of pixels in the Image4 in the X-axis direction according to the straight line to which the contour lines are fitted, and Y' represents coordinates of pixels in the Image4 in the Y-axis direction according to the straight line to which the contour lines are fitted;
repeating the step 5.4, sequentially fitting the four contour lines to obtain the coordinates of the starting points of the line segments, arranging the coordinates according to the clockwise sequence to obtain the coordinate information of the corner points of the two-dimensional code, and expressing the coordinate information as Xhorns and Yhorns in an array form;
step six: calculating a homogeneous transformation Matrix applied to the linearly distorted two-dimensional code Image4 by affine transformation, wherein Px=Xcorners,Py=Ycorners,Pw=(1,1,1),QxAnd QyIs a transformed custom corner point coordinate, Qw=(1,1,1);
Figure FDA0002781831910000032
Step seven: affine transformation correction is applied to the linear distortion two-dimensional code Image4 to obtain a regular Image 5;
the steps of calculating the rotation angle alpha of the one-dimensional bar code and the two-dimensional bar code with nonlinear distortion are as follows:
step eight: converting the minimum external moment of the region Regions5 to obtain the angle of the minimum external rectangle, namely the rotation angle alpha of the bar code;
step nine: rotating the Image4 to obtain a regular Image 5;
step ten: filtering the Image5 by using a mean value filtering method to obtain an Image Imagemean 2; ImageMean2(x, y) is the gray value of the pixel at the (x, y) position after filtering, f (x, y) is the gray value of the adjacent M pixels;
Figure FDA0002781831910000041
step eleven: dividing the Image5 by using a local threshold value to obtain a region RegionDynThresh 2; wherein Image5(x, y) is the gray scale value of Image5 at the (x, y) pixel, and T2 is the selected offset value; the obtained regional gray value satisfies the formula:
Image5(x,y)≤ImageMean2(x,y)-T2
step twelve: carrying out corrosion operation on the region RegionDynThresh2 to eliminate a part of adhesion regions in the target and obtain a region RegionErosis;
step thirteen: performing rectangular expansion operation on the region RegionErosis to supplement a part of missing part to obtain a region RegionDilation;
fourteen, if the label bar code is a one-dimensional code, the one-dimensional code is accurately processed; if the label bar code is a two-dimensional code, performing accurate processing on the two-dimensional code; thereby obtaining a binary image BinImage with accurate one-dimensional bar code or two-dimensional bar code;
and step fifteen, decoding the binary image BinImage to obtain a processed medicine label bar code image.
2. The method for locating and identifying medical label bar code based on deep learning of claim 1, wherein in the fourteenth step, the precision processing of the one-dimensional code comprises the following steps:
14.1: calculating a connected component of a connecting domain of the region RegionDilation to enable black small blocks of the one-dimensional bar code to be independent from each other, so that the independent processing is facilitated; obtaining regions connected regions;
14.2: performing region deformation on the region connected regions, and filling each independent black bar region by using a minimum external moment mode to obtain a normalized and accurate one-dimensional bar code region RegionTrans;
14.3: converting the region RegionTran into a binary image to obtain a normalized one-dimensional bar code image BinImage;
Figure FDA0002781831910000051
3. the method for locating and identifying a medical label bar code based on deep learning of claim 1, wherein in the fourteenth step, the precision processing of the two-dimensional code comprises the following steps: converting the region RegionDilation into a binary image to obtain a normalized two-dimensional bar code image BinImage;
Figure FDA0002781831910000052
4. the method for locating and identifying a medical label barcode based on deep learning of claim 1, wherein in the fifteenth step, HALCON software is used for binary image BinImage decoding.
5. The method for positioning and identifying medicine label bar codes based on deep learning of claim 1, wherein in the second step, the collected Image0 is sent to a trained deep learning neural network, and the training of the neural network is obtained according to the following steps:
step 1) establishing a data set of a medicine label bar code: establishing a data set containing 400 medical label bar codes through object shooting, google and hundred-degree search;
step 2) calibrating the pictures in the data set: classifying and marking the targets in each picture by using a LabelImg tool, marking out target region information and category information, and correspondingly setting two categories: bar Code, Data Matrix;
step 3) randomly dividing the data set into two parts, wherein 280 pictures are used for training, and 120 pictures are used for testing;
and 4) training a neural network, performing multi-target detection training by using the pre-trained SSD network, adjusting the relevant parameters, iterating 40000 times, stabilizing an error function within a range of 1 +/-0.3, and considering that the training is finished.
6. The method for locating and identifying a medicine label barcode based on deep learning of claim 1, wherein in the first step, a trigger-type manner is adopted to collect an image of the medicine box label barcode.
CN201810894904.1A 2018-08-08 2018-08-08 Deep learning-based medicine label bar code positioning and identifying method Active CN108920992B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810894904.1A CN108920992B (en) 2018-08-08 2018-08-08 Deep learning-based medicine label bar code positioning and identifying method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810894904.1A CN108920992B (en) 2018-08-08 2018-08-08 Deep learning-based medicine label bar code positioning and identifying method

Publications (2)

Publication Number Publication Date
CN108920992A CN108920992A (en) 2018-11-30
CN108920992B true CN108920992B (en) 2021-02-26

Family

ID=64397274

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810894904.1A Active CN108920992B (en) 2018-08-08 2018-08-08 Deep learning-based medicine label bar code positioning and identifying method

Country Status (1)

Country Link
CN (1) CN108920992B (en)

Families Citing this family (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111597846A (en) * 2019-02-20 2020-08-28 中科院微电子研究所昆山分所 Fold two-dimensional code recovery method, device and equipment and readable storage medium
CN109886060A (en) * 2019-02-21 2019-06-14 苏州天准科技股份有限公司 A kind of bar code area positioning method based on deep learning
CN110443118B (en) * 2019-06-24 2021-09-03 上海了物网络科技有限公司 Commodity identification method, system and medium based on artificial features
CN110245539A (en) * 2019-07-09 2019-09-17 江苏安方电力科技有限公司 A kind of automatic scan code system of Power Material
CN110532825B (en) * 2019-08-21 2022-09-30 厦门壹普智慧科技有限公司 Bar code identification device and method based on artificial intelligence target detection
CN110532826B (en) * 2019-08-21 2022-09-30 厦门壹普智慧科技有限公司 Bar code recognition device and method based on artificial intelligence semantic segmentation
CN110827247B (en) * 2019-10-28 2024-03-15 上海万物新生环保科技集团有限公司 Label identification method and device
CN111222355A (en) * 2019-12-30 2020-06-02 新大陆数字技术股份有限公司 Method and system for positioning bar code on PCB
CN111310509A (en) * 2020-03-12 2020-06-19 北京大学 Real-time bar code detection system and method based on logistics waybill
CN111767754B (en) * 2020-06-30 2024-05-07 创新奇智(北京)科技有限公司 Identification code identification method and device, electronic equipment and storage medium
WO2022036482A1 (en) * 2020-08-17 2022-02-24 江苏瑞科科技有限公司 Technique of locating and reading dpm code on complex background
CN112949471A (en) * 2021-02-27 2021-06-11 浪潮云信息技术股份公司 Domestic CPU-based electronic official document identification reproduction method and system
CN113313703B (en) * 2021-06-17 2024-05-24 上海红檀智能科技有限公司 Unmanned aerial vehicle power transmission line inspection method based on deep learning image recognition
CN113610362B (en) * 2021-07-20 2023-08-08 苏州超集信息科技有限公司 Deep learning assembly line-based product tracing method and system
CN113688649A (en) * 2021-08-16 2021-11-23 江苏博赛孚医疗科技有限公司 Quick QR code positioning method
CN113869475A (en) * 2021-09-24 2021-12-31 大连理工大学 Design method and system suitable for underwater communication two-dimensional code
CN115147389A (en) * 2022-07-19 2022-10-04 歌尔股份有限公司 Image processing method, apparatus, and computer-readable storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102346850A (en) * 2011-10-13 2012-02-08 西北工业大学 DataMatrix bar code area positioning method under complex metal background
CN107341523A (en) * 2017-07-13 2017-11-10 浙江捷尚视觉科技股份有限公司 Express delivery list information identifying method and system based on deep learning
CN107617573A (en) * 2017-09-30 2018-01-23 浙江瀚镪自动化设备股份有限公司 A kind of logistics code identification and method for sorting based on multitask deep learning

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102346850A (en) * 2011-10-13 2012-02-08 西北工业大学 DataMatrix bar code area positioning method under complex metal background
CN107341523A (en) * 2017-07-13 2017-11-10 浙江捷尚视觉科技股份有限公司 Express delivery list information identifying method and system based on deep learning
CN107617573A (en) * 2017-09-30 2018-01-23 浙江瀚镪自动化设备股份有限公司 A kind of logistics code identification and method for sorting based on multitask deep learning

Also Published As

Publication number Publication date
CN108920992A (en) 2018-11-30

Similar Documents

Publication Publication Date Title
CN108920992B (en) Deep learning-based medicine label bar code positioning and identifying method
US5796868A (en) Object edge point filtering system for machine vision
EP3309704B1 (en) Two-dimensional code partitioning and decoding method and system
CN109978839B (en) Method for detecting wafer low-texture defects
CN107633192B (en) Bar code segmentation and reading method based on machine vision under complex background
CN107301368B (en) Recognition method of DataMatrix two-dimensional code
CN109344820B (en) Digital ammeter reading identification method based on computer vision and deep learning
US9558403B2 (en) Chemical structure recognition tool
CN112085024A (en) Tank surface character recognition method
CN109190742B (en) Decoding method of coding feature points based on gray feature
CN108256375B (en) One-dimensional bar code scanning method
CN113724231A (en) Industrial defect detection method based on semantic segmentation and target detection fusion model
Tribak et al. QR code recognition based on principal components analysis method
Zhang et al. Detection and identification method of medical label barcode based on deep learning
CN113903024A (en) Handwritten bill numerical value information identification method, system, medium and device
CN116704516B (en) Visual inspection method for water-soluble fertilizer package
CN113228105A (en) Image processing method and device and electronic equipment
CN111027637A (en) Character detection method and computer readable storage medium
CN112686872B (en) Wood counting method based on deep learning
CN113658039A (en) Method for determining splicing sequence of label images of medicine bottles
CN104346596A (en) Identification method and identification device for QR (Quick Response) code
CN116994269A (en) Seal similarity comparison method and seal similarity comparison system in image document
Valiente et al. A process for text recognition of generic identification documents over cloud computing
CN115512381A (en) Text recognition method, text recognition device, text recognition equipment, storage medium and working machine
CN113537216B (en) Dot matrix font text line inclination correction method and device

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