CN107358138A - Bearing calibration, mobile terminal and the storage device of nonlinear distortion EAN bar codes - Google Patents
Bearing calibration, mobile terminal and the storage device of nonlinear distortion EAN bar codes Download PDFInfo
- Publication number
- CN107358138A CN107358138A CN201710424250.1A CN201710424250A CN107358138A CN 107358138 A CN107358138 A CN 107358138A CN 201710424250 A CN201710424250 A CN 201710424250A CN 107358138 A CN107358138 A CN 107358138A
- Authority
- CN
- China
- Prior art keywords
- area
- pixel
- ean
- line
- correction
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 claims abstract description 74
- 238000012937 correction Methods 0.000 claims abstract description 58
- 238000005070 sampling Methods 0.000 claims abstract description 28
- 238000012545 processing Methods 0.000 claims abstract description 15
- 238000005516 engineering process Methods 0.000 claims abstract description 10
- 238000000605 extraction Methods 0.000 claims abstract description 9
- 230000000717 retained effect Effects 0.000 claims abstract description 6
- 238000004590 computer program Methods 0.000 claims description 12
- 238000004891 communication Methods 0.000 claims description 8
- 238000012216 screening Methods 0.000 claims description 8
- 238000004422 calculation algorithm Methods 0.000 claims description 7
- 238000013507 mapping Methods 0.000 claims description 6
- 230000003044 adaptive effect Effects 0.000 claims description 3
- 238000000691 measurement method Methods 0.000 claims description 2
- 238000004364 calculation method Methods 0.000 abstract description 6
- 239000013256 coordination polymer Substances 0.000 description 13
- 238000010586 diagram Methods 0.000 description 9
- 230000009466 transformation Effects 0.000 description 8
- 230000000694 effects Effects 0.000 description 6
- 238000000844 transformation Methods 0.000 description 4
- PXFBZOLANLWPMH-UHFFFAOYSA-N 16-Epiaffinine Natural products C1C(C2=CC=CC=C2N2)=C2C(=O)CC2C(=CC)CN(C)C1C2CO PXFBZOLANLWPMH-UHFFFAOYSA-N 0.000 description 3
- 238000001514 detection method Methods 0.000 description 3
- 239000011159 matrix material Substances 0.000 description 2
- 238000003672 processing method Methods 0.000 description 2
- 230000001174 ascending effect Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000007812 deficiency Effects 0.000 description 1
- 238000001914 filtration Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000011426 transformation method Methods 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/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
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 Processing (AREA)
Abstract
本发明公开了一种非线性畸变EAN条码的校正方法、移动终端及存储装置。其中,校正方法包括:步骤S1、对非线性畸变EAN条码图像依次进行二值化处理和反色处理,得到包含背景区域和前景区域的反色图像;步骤S2、按照特定筛选规则对前景区域中的条纹进行筛选并提取,然后利用骨架提取技术对保留的条纹进行细化处理,得到单像素的细化线条集合;步骤S3、对相邻的单像素的细化线条按顺序两两进行平行校正,得到平行的细化线条集合;步骤S4、采用分块采样和双线性插值技术对平行的细化线条进行区域校正,得到相同尺寸的EAN条码校正图像。本发明的EAN条码校正方法采用分块采样和插值技术逐步校正,稳定性和精度高,计算量小。
The invention discloses a method for correcting nonlinearly distorted EAN barcodes, a mobile terminal and a storage device. Wherein, the correction method includes: step S1, sequentially performing binarization processing and inversion processing on the non-linearly distorted EAN barcode image to obtain an inverse image including the background area and the foreground area; Screen and extract the stripes, and then use the skeleton extraction technology to refine the retained stripes to obtain a set of single-pixel thinned lines; step S3, perform parallel correction on the adjacent single-pixel thinned lines in sequence , to obtain a set of parallel thinning lines; step S4 , perform area correction on the parallel thinning lines by using block sampling and bilinear interpolation technology, and obtain a corrected image of the EAN barcode with the same size. The EAN barcode correction method of the present invention adopts block sampling and interpolation technology to correct step by step, has high stability and precision, and small calculation amount.
Description
技术领域technical field
本发明涉及图形图像处理领域,尤其涉及一种非线性畸变EAN条码的校正方法、移动终端及存储装置。The invention relates to the field of graphics and image processing, in particular to a method for correcting nonlinearly distorted EAN barcodes, a mobile terminal and a storage device.
背景技术Background technique
EAN(European Article Number Bar Code)是国际物品编码协会制定的一种商品用条码,在商品流通、图书管理、交通运输、医疗卫生、金融银行等众多领域得到了广泛应用。在实际应用环境下,摄像头捕获的条码常常受到拍摄角度、条码附着表面形变等影响造成的条码图像质量下降,从而严重降低条码识别的准确性。EAN (European Article Number Bar Code) is a kind of barcode for commodities developed by the International Article Numbering Association, which has been widely used in many fields such as commodity circulation, book management, transportation, medical and health care, and finance and banking. In the actual application environment, the barcode captured by the camera is often affected by the shooting angle, the deformation of the barcode attachment surface, etc., which causes the quality of the barcode image to degrade, thereby seriously reducing the accuracy of barcode recognition.
所谓EAN条码畸变校正技术,是在分离出条码区域后,对其角度旋转、局部扭曲等非线性几何畸变进行校正的过程。The so-called EAN barcode distortion correction technology is a process of correcting nonlinear geometric distortions such as angle rotation and local distortion after separating the barcode area.
现有的条码畸变校正技术主要有两类:(1)基于直线检测的条码校正方法。借助于Hough变换等直线检测方法,利用条码黑白条纹的空间分布统计特性,对旋转变形或者仿射变形等线性畸变条码进行校正。(2)基于几何空间变换的条码校正方法。通过采集若干控制点对信息并求解方程组的解,然后利用空间变换矩阵对畸变条码进行校正。There are two main types of existing barcode distortion correction technologies: (1) barcode correction methods based on line detection. With the help of straight line detection methods such as Hough transform, the spatial distribution statistical characteristics of black and white stripes of barcodes are used to correct linear distortion barcodes such as rotation deformation or affine deformation. (2) Barcode correction method based on geometric space transformation. The distorted barcode is corrected by collecting the information of several control point pairs and solving the solution of the equation system, and then using the space transformation matrix.
现有的条码校正方法,存在以下缺点:(1)直线检测类方法只能够处理由于拍摄角度不同引入的刚体变换或者仿射变换等线性畸变,无法处理局部扭曲等非线性畸变,应用范围有限。(2)几何空间变换类方法利用矩阵运算方式求解方程组,求解计算量大且复杂。在某些特定环境下,方程组本身可能存在无解或者无穷多解的情况,导致其可靠性不高,实时性也较差。The existing barcode correction methods have the following disadvantages: (1) Line detection methods can only deal with linear distortions such as rigid body transformations or affine transformations introduced by different shooting angles, but cannot deal with nonlinear distortions such as local distortions, and their application range is limited. (2) The geometric space transformation method uses the matrix operation method to solve the equation system, and the calculation amount of the solution is large and complicated. In some specific environments, the equation system itself may have no solution or infinitely many solutions, resulting in low reliability and poor real-time performance.
因此,现有技术还有待于改进和发展。Therefore, the prior art still needs to be improved and developed.
发明内容Contents of the invention
鉴于上述现有技术的不足,本发明的目的在于提供一种非线性畸变EAN条码的校正方法、移动终端及存储设备,旨在解决现有技术无法处理局部扭曲等非线性畸变以及可靠性不高、实时性差的问题。In view of the above-mentioned deficiencies in the prior art, the purpose of the present invention is to provide a correction method for nonlinearly distorted EAN barcodes, a mobile terminal and a storage device, aiming at solving the problem that the prior art cannot handle nonlinear distortion such as local distortion and low reliability , The problem of poor real-time performance.
本发明的技术方案如下:Technical scheme of the present invention is as follows:
一种非线性畸变EAN条码的校正方法,包括:A method for correcting nonlinearly distorted EAN barcodes, comprising:
步骤S1、对非线性畸变EAN条码图像依次进行二值化处理和反色处理,得到包含背景区域和前景区域的反色图像;Step S1, sequentially performing binarization processing and inversion processing on the non-linearly distorted EAN barcode image to obtain an inversion image including a background area and a foreground area;
步骤S2、按照特定筛选规则对前景区域中的条纹进行筛选并提取,然后利用骨架提取技术对保留的条纹进行细化处理,得到单像素的细化线条集合;Step S2: Filter and extract the stripes in the foreground area according to specific screening rules, and then use the skeleton extraction technology to refine the retained stripes to obtain a single-pixel thinned line set;
步骤S3、对相邻的单像素的细化线条按顺序两两进行平行校正,得到平行的细化线条集合;Step S3. Parallel correction is performed on adjacent single-pixel thinning lines in order to obtain a set of parallel thinning lines;
步骤S4、采用分块采样和双线性插值技术对平行的细化线条进行区域校正,得到相同尺寸的EAN条码校正图像。Step S4, using sub-block sampling and bilinear interpolation techniques to perform area correction on the parallel thinning lines to obtain a corrected image of the EAN barcode with the same size.
所述的非线性畸变EAN条码的校正方法,其中,所述步骤S1中,所述二值化处理的方法为全局二值化算法或者局部自适应二值化算法。The method for correcting the nonlinearly distorted EAN barcode, wherein, in the step S1, the binarization processing method is a global binarization algorithm or a local adaptive binarization algorithm.
所述的非线性畸变EAN条码的校正方法,其中,所述步骤S1中,所述反色处理的过程具体为:二值化图像中的明暗条纹分别对应像素值0和255,像素值0对应的区域称之为背景区域,像素值255对应的区域称之为前景区域。The method for correcting the nonlinearly distorted EAN barcode, wherein, in the step S1, the process of the inverse color processing is specifically: the light and dark stripes in the binarized image correspond to pixel values 0 and 255 respectively, and the pixel value 0 corresponds to The area with pixel value 255 is called the foreground area.
所述的非线性畸变EAN条码的校正方法,其中,所述步骤S2中,所述筛选规则为:计算每个前景区域的像素面积,若单个区域面积大于所有前景区域面积的平均值,则保留该前景区域,否则删除。The correction method of the nonlinear distortion EAN barcode, wherein, in the step S2, the screening rule is: calculate the pixel area of each foreground area, if the area of a single area is greater than the average value of the area of all foreground areas, then keep the foreground region, otherwise delete it.
所述的非线性畸变EAN条码的校正方法,其中,所述步骤S3具体包括:The method for correcting the nonlinearly distorted EAN barcode, wherein the step S3 specifically includes:
步骤S31、按顺序选择两条相邻的单像素的细化线条,分别记为Lleft和Lright采用Hausdorff距离度量方法计算单像素的细化线条间的统计距离:其中l1,l2分别表示Lleft和Lright上的点,d(*,*)表示二维欧氏距离;Step S31, select two adjacent single-pixel thinning lines in order, and record them as L left and L right respectively. Use the Hausdorff distance measurement method to calculate the statistical distance between the single-pixel thinning lines: Among them, l 1 and l 2 represent the points on L left and L right respectively, and d(*,*) represents the two-dimensional Euclidean distance;
步骤S32、将单像素的细化线条绘制成直线段,相邻直线段的间距为步骤S31中所述的D(Lleft,Lright);Step S32, draw the thinned line of single pixel into a straight line segment, and the distance between adjacent straight line segments is D(L left , L right ) described in step S31;
步骤S33、重复步骤S31和步骤S32,按顺序依次将其余单像素的细化条纹进行平行校正,得到平行的细化条纹集合。Step S33 , repeating step S31 and step S32 , performing parallel correction on the thinning fringes of the remaining single pixels in order to obtain a set of parallel thinning fringes.
所述的非线性畸变EAN条码的校正方法,其中,所述步骤S4具体包括:The method for correcting the nonlinearly distorted EAN barcode, wherein the step S4 specifically includes:
步骤S41、将两条相邻的平行细化线条上对应的采样点一一连线,采用双线性插值技术将连线上的像素点映射到对应的平行直线段间相应的连线上;Step S41, connect the corresponding sampling points on the two adjacent parallel thinning lines one by one, and use bilinear interpolation technology to map the pixels on the connection line to the corresponding connection line between the corresponding parallel straight line segments;
步骤S42、从上至下逐像素遍历重复上述过程,校正这两条相邻细化线条间所有位置的像素,然后再依顺序遍历所有相邻的细化线条,完成中间线条间的所有位置像素的校正;Step S42: Traversing and repeating the above process pixel by pixel from top to bottom, correcting the pixels at all positions between the two adjacent thinning lines, and then traversing all the adjacent thinning lines in order to complete all the position pixels between the middle lines correction;
步骤S43、对起始细化线条和终止细化线条进行单线条采样区域校正。Step S43 , performing single-line sampling area correction on the starting thinning line and the ending thinning line.
所述的非线性畸变EAN条码的校正方法,其中,所述步骤S41中,连线上的像素点与平行直线段间对应的点映射关系为:The method for correcting the nonlinearly distorted EAN barcode, wherein, in the step S41, the corresponding point mapping relationship between the pixels on the connection line and the parallel straight line segments is:
其中(xleft,yleft)为左边细线条上点Pleft的坐标,(xright,yright)为右边细线条上对应的点Pright的坐标,(xS,yS)为Pleft和Pright连线上某一像素点的坐标,(x,y)为平行直线段间对应点的坐标。 Where (x left , y left ) is the coordinates of point P left on the thin line on the left, (x right , y right ) is the coordinates of the corresponding point P right on the thin line on the right, (x S , y S ) is the coordinates of P left and The coordinates of a certain pixel point on the P right line, (x, y) are the coordinates of the corresponding points between the parallel straight line segments.
所述的非线性畸变EAN条码的校正方法,其中,所述步骤S43具体为:计算边缘线条上采样点的法向方向,计算法线与图像边界的交点和采样点之间的欧氏距离,然后将直线段上与采样点对应的点向图像边界方向水平延伸上述欧氏距离,即得到相应的映射边界点,依此方法完成起始细化线条和终止细化线条的区域校正。The correction method of the nonlinear distortion EAN barcode, wherein, the step S43 is specifically: calculating the normal direction of the sampling point on the edge line, calculating the Euclidean distance between the intersection point of the normal line and the image boundary and the sampling point, Then extend the above-mentioned Euclidean distance horizontally to the image boundary direction on the point corresponding to the sampling point on the straight line segment to obtain the corresponding mapping boundary point. In this way, the area correction of the start thinning line and the ending thinning line is completed.
一种移动终端,包括处理器和与所述处理器通信连接的存储器,所述存储器存储有计算机程序,所述计算机程序被处理器执行时实现如上任一所述的非线性畸变EAN条码的校正方法;所述处理器用于调用所述存储器中的计算机程序,以执行上述任一所述的非线性畸变EAN条码的校正方法。A mobile terminal, comprising a processor and a memory connected in communication with the processor, the memory stores a computer program, and when the computer program is executed by the processor, the correction of the non-linear distortion EAN barcode as described above is realized Method; the processor is used to call the computer program in the memory to execute any one of the methods for correcting the nonlinearly distorted EAN barcode described above.
一种存储装置,所述存储装置存储有计算机程序,所述计算机程序能够加载并执行如上述任一所述的非线性畸变EAN条码的校正方法。A storage device, the storage device stores a computer program, and the computer program can load and execute the method for correcting nonlinearly distorted EAN barcodes as described above.
有益效果:本发明提供了一种非线性畸变EAN条码的校正方法、移动终端及存储设备,本发明的EAN条码校正方法是基于条码自身的形状特征的提取,对畸变类型未作任何限制,可以处理任意非线性畸变变形,通用性高。另外,本发明采用分块采样和插值技术逐步校正,稳定性和精度高,计算量小。Beneficial effects: the present invention provides a method for correcting nonlinearly distorted EAN barcodes, a mobile terminal and a storage device. The method for correcting EAN barcodes of the present invention is based on the extraction of the shape features of the barcode itself, without any restrictions on the type of distortion, and can Handle any nonlinear distortion and deformation with high versatility. In addition, the present invention adopts block sampling and interpolation technology to correct step by step, so the stability and precision are high, and the amount of calculation is small.
附图说明Description of drawings
图1为本发明的一种非线性畸变EAN条码的校正方法的流程图。FIG. 1 is a flowchart of a method for correcting nonlinearly distorted EAN barcodes of the present invention.
图2a为本发明的相邻线条区域校正步骤中在相邻细化线条上取点示意图。Fig. 2a is a schematic diagram of points taken on adjacent thinning lines in the adjacent line area correction step of the present invention.
图2b为本发明的相邻线条区域校正步骤中在平行线段上对应取点示意图。Fig. 2b is a schematic diagram of corresponding points on parallel line segments in the correction step of the adjacent line area of the present invention.
图3a为本发明的单线条区域校正步骤中曲线法线方向计算示意图。Fig. 3a is a schematic diagram of calculating the normal direction of the curve in the single-line area correction step of the present invention.
图3b为本发明的单线条区域校正步骤中采样点映射到校准后的图中示意图。Fig. 3b is a schematic diagram of the mapping of sampling points to the calibrated figure in the single-line region correction step of the present invention.
图4为本发明的一种基于非线性畸变EAN条码校正方法的移动终端的功能原理框图。FIG. 4 is a functional block diagram of a mobile terminal based on a nonlinear distortion EAN barcode correction method according to the present invention.
图5为本发明的非线性畸变EAN条码校正方法中对非线性畸变EAN条码图像二值化和反色处理后的效果图。FIG. 5 is an effect diagram of the non-linearly distorted EAN barcode image after binarization and color inversion processing in the method for correcting the non-linearly distorted EAN barcode of the present invention.
图6为本发明的非线性畸变EAN条码校正方法中对非线性畸变EAN条码图像筛选及细化处理后的效果图。FIG. 6 is an effect diagram after filtering and thinning the nonlinearly distorted EAN barcode image in the nonlinearly distorted EAN barcode correction method of the present invention.
图7为本发明的非线性畸变EAN条码校正方法中对相邻细化线条区域校正结果的效果图。FIG. 7 is an effect diagram of correction results of adjacent thinning line regions in the nonlinear distortion EAN barcode correction method of the present invention.
图8为本发明的非线性畸变EAN条码校正方法最终校正结果的效果图。FIG. 8 is an effect diagram of the final correction result of the nonlinear distortion EAN barcode correction method of the present invention.
具体实施方式detailed description
本发明提供了一种非线性畸变EAN条码的校正方法、移动终端及存储设备,为使本发明的目的、技术方案及效果更加清楚、明确,以下对本发明进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。The present invention provides a method for correcting non-linearly distorted EAN barcodes, a mobile terminal and a storage device. In order to make the purpose, technical solutions and effects of the present invention clearer and clearer, the present invention will be further described in detail below. It should be understood that the specific embodiments described here are only used to explain the present invention, not to limit the present invention.
本发明提供了一种非线性畸变EAN条码的校正方法的较佳实施例,校正流程如图1所示,校正步骤包括:The present invention provides a preferred embodiment of a correction method for nonlinearly distorted EAN barcodes. The correction process is shown in Figure 1. The correction steps include:
步骤S1、对非线性畸变EAN条码图像依次进行二值化处理和反色处理,得到包含背景区域和前景区域的反色图像。Step S1, sequentially perform binarization processing and inversion processing on the non-linearly distorted EAN barcode image to obtain an inversion image including a background area and a foreground area.
具体地,首先对条码图像进行二值化处理。根据实际条码图像的采集质量,二值化算法可以选择固定阈值法或者大津法等全局二值化算法或者局部自适应二值化算法。然后对得到的二值化图像做反色处理。反色后,原始的明暗条纹分别对应像素值0和255。通常情况下,像素0对应的区域称之为背景区域,像素255对应的区域称之为前景区域。Specifically, the barcode image is binarized first. According to the acquisition quality of the actual barcode image, the binarization algorithm can choose a global binarization algorithm such as fixed threshold method or Otsu method or a local adaptive binarization algorithm. Then, reverse color processing is performed on the obtained binarized image. After inversion, the original light and dark stripes correspond to pixel values 0 and 255, respectively. Generally, the area corresponding to pixel 0 is called the background area, and the area corresponding to pixel 255 is called the foreground area.
步骤S2、按照特定筛选规则对前景区域中的条纹进行筛选并提取,然后利用骨架提取技术对保留的条纹进行细化处理,得到单像素的细化线条集合。Step S2: Filter and extract the stripes in the foreground area according to specific screening rules, and then use the skeleton extraction technology to refine the retained stripes to obtain a set of thinned single-pixel lines.
具体地,采用Freeman链码技术提取前景区域的边界轮廓,并计算每个孤立前景区域的像素面积(记为Si,i=1,2,3,…)以及所有前景区域的平均像素面积(记为S0),若Si≥S0,则保留该前景区域,否则删除。这样,就完成了条纹筛选步骤。Specifically, Freeman chain code technology is used to extract the boundary contour of the foreground area, and the pixel area of each isolated foreground area (denoted as S i , i=1, 2, 3,...) and the average pixel area of all foreground areas ( denoted as S 0 ), if S i ≥ S 0 , keep the foreground area, otherwise delete it. In this way, the streak screening step is completed.
从上述筛选规则看出,保留的前景区域集合都是相对面积较大、非单像素宽度的条纹,故而利用骨架提取技术对前景区域进行细化,最终得到单像素宽的线条集合。From the above screening rules, it can be seen that the set of reserved foreground areas are all stripes with relatively large area and non-single-pixel width. Therefore, the skeleton extraction technology is used to refine the foreground area, and finally a set of lines with a single-pixel width is obtained.
需要说明的是,本发明没有提取小于所有前景区域平均像素面积的前景区域对应的窄条纹,是防止提取过程产生较大的误差,影响最终的校正精度,窄条纹将在后续区域校正步骤中直接进行校正,而传统的刚体变换或者仿射变换等对线性畸变的处理方法是无法将宽条纹和细条纹用不同的方法分别处理的。It should be noted that the present invention does not extract the narrow stripes corresponding to the foreground area that is smaller than the average pixel area of all foreground areas, in order to prevent large errors in the extraction process and affect the final correction accuracy. For correction, the traditional rigid body transformation or affine transformation and other processing methods for linear distortion cannot process wide stripes and thin stripes in different ways.
步骤S3、对相邻的单像素的细化线条按顺序两两进行平行校正,得到平行的细化线条集合。Step S3 , parallel correction is performed on adjacent single-pixel thinning lines in order to obtain a set of parallel thinning lines.
得到单像素的细化线条集合后,额外创建一组与单像素的细化条纹尺寸相同的直线段。具体为,按顺序(从左至右或从右至左,本发明“按顺序”均应这样理解)选择两条相邻的细化线条,分别记为Lleft和Lright。由于非线性畸变的影响,线条Lleft和Lright已经不再是平行的线段。采用Hausdorff距离度量方法计算线条间的统计距离: After obtaining the single-pixel thinning line set, additionally create a set of straight line segments with the same size as the single-pixel thinning stripes. Specifically, two adjacent thinning lines are selected in sequence (from left to right or from right to left, "sequence" in the present invention should be understood in this way), which are respectively marked as L left and L right . Due to the influence of nonlinear distortion, the lines L left and L right are no longer parallel line segments. Calculate the statistical distance between lines using the Hausdorff distance metric:
其中l1,l2分别表示线条Lleft和Lright上的点。d(*,*)表示二维欧氏距离。Among them, l 1 and l 2 represent points on the lines L left and L right respectively. d(*,*) represents the two-dimensional Euclidean distance.
假定水平为x方向,竖直为y方向,按照如下规则绘制校正后的竖直线段CLleft和CLright,下面以CLleft为例说明:Assuming that the horizontal direction is the x direction and the vertical direction is the y direction, draw the corrected vertical line segments CL left and CL right according to the following rules. The following uses CL left as an example to illustrate:
第一步、将CLleft的水平方向坐标定义为线条Lleft中所有点的水平方向x坐标平均值。其上端点的竖直方向y坐标定义为线条Lleft的上端点的竖直方向y坐标。In the first step, the horizontal direction coordinate of CL left is defined as the average value of horizontal direction x-coordinates of all points in the line L left . The vertical y-coordinate of its upper endpoint is defined as the vertical y-coordinate of the upper endpoint of the line L left .
第二步、下端点的竖直方向y坐标值定义为CLleft上端点竖直方向y坐标值与线条Lleft的像素长度(255像素的总数)的总和。In the second step, the vertical y-coordinate value of the lower endpoint is defined as the sum of the vertical y-coordinate value of the upper endpoint of CL left and the pixel length of the line L left (the total number of 255 pixels).
第三步、CLleft线段的像素值按照从上至下的顺序依次使用Lleft的像素值赋值。In the third step, the pixel values of the CL left line segment are assigned values from the pixel values of L left in order from top to bottom.
CLright的水平方向坐标定义为CLleft的水平方向x坐标加D(Lleft,Lright)。其他坐标信息定义方式与CLleft完全一致。The horizontal coordinate of CL right is defined as the horizontal x coordinate of CL left plus D(L left , L right ). The definition of other coordinate information is exactly the same as CL left .
按照上面的步骤,将单像素细化线条绘制成同长度的直线条,按顺序依次将所有的细化线条校正为平行的细化线条,相邻平行线条间的间距为上面所述的D(Lleft,Lright)。According to the above steps, the single-pixel thinning lines are drawn into straight lines of the same length, and all the thinning lines are corrected into parallel thinning lines in sequence, and the distance between adjacent parallel lines is D( L left , L right ).
步骤S4、采用分块采样和双线性插值技术对平行的细化线条进行区域校正,得到相同尺寸的EAN条码校正图像。Step S4, using sub-block sampling and bilinear interpolation techniques to perform area correction on the parallel thinning lines to obtain a corrected image of the EAN barcode with the same size.
首先进行双线条区域校正,即在两条相邻的细化线条上对应取采样点,将采样点一一对应连线,例如将Lleft上第一个像素点和Lright上第一个像素点连线,Lleft上第二个像素点和Lright上第二个像素点连线,Lleft上第三个像素点和Lright上第三个像素点连线,依次类推。采用双线性插值技术将连线上的像素点映射到对应的平行直线段间相应的连线上。First perform double-line area correction, that is, take corresponding sampling points on two adjacent thinning lines, and connect the sampling points one by one, for example, the first pixel on L left and the first pixel on L right Pixel connection, the connection between the second pixel on L left and the second pixel on L right , the connection between the third pixel on L left and the third pixel on L right , and so on. The bilinear interpolation technology is used to map the pixel points on the connection line to the corresponding connection line between the corresponding parallel straight line segments.
具体地,比如从左边开始,选择两条相邻的细化线条Lleft和Lright,设对应校正后的平行直线段为CLleft和CLright。Lleft和CLleft的长度相等,Lright和CLright的长度相等,分别记为Lengthleft和Lengthright。假设Pleft是Lleft上从上至下排序第k个坐标点,那么其在Lright上的对应点Pright定义为从上至下排序为的坐标点。Pleft和Pright在校正图像上的对应点CPleft和CPright定义为从上至下排序排序为k和的坐标点。如图2a和图2b所示。Specifically, for example, starting from the left, select two adjacent thinning lines L left and L right , and set the corresponding corrected parallel straight line segments as CL left and CL right . The lengths of L left and CL left are equal, and the lengths of L right and CL right are equal, which are recorded as Length left and Length right respectively. Assuming that P left is the kth coordinate point sorted from top to bottom on L left , then its corresponding point P right on L right is defined as sorted from top to bottom as coordinate point. The corresponding points CP left and CP right of P left and P right on the corrected image are defined as k and coordinate point. As shown in Figure 2a and Figure 2b.
相邻细化线条间的区域校正过程如下:The process of area correction between adjacent thinning lines is as follows:
假定Pleft的坐标为(xleft,yleft),Pright的坐标为(xright,yright),CPleft的坐标为(cxleft,cyleft),CPright的坐标为(cxright,cyright)。线段CPleft CPright上任一点CP(x,y),其在原始图像上对应的坐标P(xS,yS)由如下公式计算:Assume that the coordinates of P left are (x left , y left ), the coordinates of P right are (x right , y right ), the coordinates of CP left are (cx left , cy left ), and the coordinates of CP right are (cx right , cy right ). For any point CP(x,y) on the line segment CP left CP right , its corresponding coordinate P(x S , y S ) on the original image is calculated by the following formula:
那么CP(x,y)的像素值就赋值为P(xS,yS)的像素值。Then the pixel value of CP(x,y) is assigned as the pixel value of P(x S ,y S ).
从上至下逐像素遍历重复上述过程,便可以校正两条相邻线条区域间的所有位置的像素。依此方法按顺序遍历所有相邻的线条,可以完成线条间的所有位置像素的校正。By traversing and repeating the above process pixel by pixel from top to bottom, pixels at all positions between two adjacent line regions can be corrected. In this way, all adjacent lines are traversed in sequence, and the correction of all position pixels between the lines can be completed.
上述校正方法针对的都是中间区域的校正,不仅包括已经提取的条纹的校正,还包括未提取的细条纹的直接校正。但是起始线条和终止线条所在的最左侧线条往左的区域和最右侧线条往右的区域不包含在内,需要对边缘两条细化线条进行单线条采样区域校正。校正方法是,计算边缘线条上采样点的法向方向,计算法线与图像边界的交点和采样点之间的欧氏距离,然后将直线段上与采样点对应的点向图像边界方向水平延伸上述欧氏距离,即得到相应的映射边界点,依此方法可完成起始细化线条和终止细化线条的区域校正。The above correction methods are all aimed at the correction of the middle area, including not only the correction of the extracted fringes, but also the direct correction of the unextracted thin fringes. However, the area to the left of the leftmost line and the area to the right of the most right line where the start line and the end line are located are not included, and a single-line sampling area correction needs to be performed on the two thinning lines on the edge. The correction method is to calculate the normal direction of the sampling point on the edge line, calculate the Euclidean distance between the intersection point of the normal line and the image boundary and the sampling point, and then extend the point corresponding to the sampling point on the straight line segment horizontally toward the image boundary direction The above-mentioned Euclidean distance is to obtain the corresponding mapping boundary points, and the area correction of the starting thinning line and the ending thinning line can be completed by this method.
下面以最右侧线条为例,阐述单线条采样区域校正的方法。Taking the rightmost line as an example, the method for correcting the sampling area of a single line is described below.
与双线条不同之处在于,单线条没有右侧对应的边。和前述步骤中定义一样,假定Pleft的坐标为(xleft,yleft),CPleft的坐标为(cxleft,cyleft)。下面给出虚拟Pright的坐标的方法,如图3a和图3b所示。Unlike double lines, single lines do not have a corresponding edge on the right. As defined in the preceding steps, it is assumed that the coordinates of P left are (x left , y left ), and the coordinates of CP left are (cx left , cy left ). The method of coordinates of the virtual P right is given below, as shown in Fig. 3a and Fig. 3b.
首先计算点Pleft处的法向方向,曲线法向方向计算的具体方法为:给定曲线按照y坐标大小进行升序排序,记为{Curve[i],i=1,2,...,N}。曲线上任一点P,序号为p,分为两种情况:First calculate the normal direction at the point P left . The specific method for calculating the normal direction of the curve is: the given curve is sorted in ascending order according to the size of the y coordinate, which is recorded as {Curve[i],i=1,2,..., N}. Any point P on the curve, with the serial number p, can be divided into two cases:
(1)点P落在曲线的头部或者尾部区域,即P的序号p≤5或者p≥N-4。以点P落在头部为例,则取采样点集合Curve[0],Curve[1],..,Curve[p+5]。将该集合数据拟合成直线fitL,取fitL的方向作为该点的切向,然后计算其偏向右侧的法方向作为点P的近似法向。(1) The point P falls in the head or tail area of the curve, that is, the sequence number of P is p≤5 or p≥N-4. Taking the point P falling on the head as an example, the sampling point set Curve[0], Curve[1],...,Curve[p+5] is taken. Fit the set data to a straight line fitL, take the direction of fitL as the tangent direction of the point, and then calculate its normal direction to the right as the approximate normal direction of point P.
(2)点P落在曲线中间。采样点集合为Curve[p-5],...,Curve[p],..,Curve[p+5]。剩余计算方式与步骤(1)相同。此处不再赘述。(2) Point P falls in the middle of the curve. The collection of sampling points is Curve[p-5],...,Curve[p],...,Curve[p+5]. The remaining calculation method is the same as step (1). I won't repeat them here.
然后沿着法向方向取射线,射线与图像边界的交点记为Pright。计算其欧氏距离Lengthleft。由于CLleft本身是竖直方向线段,所以CPright的取值即是CPleft向右延伸距离Lengthleft的坐标。至此,Pleft,Pright与其对应的CPleft和CPright都已经得到。按照此计算过程,可以校正最右侧线条往右的区域。同理,可以校正最左侧线条往左的区域。Then a ray is taken along the normal direction, and the intersection point of the ray and the image boundary is marked as P right . Calculate its Euclidean distance Length left . Since CL left itself is a vertical line segment, the value of CP right is the coordinate of CP left extending to the right by Length left . So far, P left , P right and their corresponding CP left and CP right have been obtained. Following this calculation process, the area to the right of the rightmost line can be corrected. In the same way, the area where the leftmost line goes to the left can be corrected.
本发明还提供了一种移动终端,如图4所示,所述移动终端包括:处理器(processor)10、存储器(memory)20、通信接口(Communications Interface)30和总线40。其中,所述处理器10、存储器20、通信接口30通过所述总线40完成相互间的通信;所述通信接口30用于所述移动终端的通信设备之间的信息传输;所述处理器10用于调用所述存储器20中的计算机程序,以执行上述各方法实施例所提供的方法。The present invention also provides a mobile terminal. As shown in FIG. 4 , the mobile terminal includes: a processor (processor) 10 , a memory (memory) 20 , a communication interface (Communications Interface) 30 and a bus 40 . Wherein, the processor 10, memory 20, and communication interface 30 complete mutual communication through the bus 40; the communication interface 30 is used for information transmission between communication devices of the mobile terminal; the processor 10 It is used to call the computer program in the memory 20 to execute the methods provided by the above method embodiments.
当系统启动时,移动终端获取非线性畸变EAN条码图像,并依次进行二值化处理和反色处理,得到包含背景区域和前景区域的反色图像,处理后的效果如图5所示;然后按照特定筛选规则对前景区域中的条纹进行筛选并提取,并利用骨架提取技术对保留的条纹进行细化处理,得到单像素的细化线条集合,如图6所示;再对对相邻的单像素的细化线条按顺序两两进行平行校正,得到平行的细化线条集合,最后采用分块采样和双线性插值技术对平行的细化线条进行区域校正,得到相同尺寸的EAN条码校正图像,如图7和图8所示。When the system starts, the mobile terminal obtains the non-linearly distorted EAN barcode image, and sequentially performs binarization and inversion processing to obtain an inversion image including the background area and the foreground area. The processed effect is shown in Figure 5; then Filter and extract the stripes in the foreground area according to specific screening rules, and use the skeleton extraction technology to refine the retained stripes to obtain a single-pixel thinned line set, as shown in Figure 6; and then compare the adjacent Single-pixel thinning lines are parallel-corrected in pairs in order to obtain a set of parallel thinning lines. Finally, block sampling and bilinear interpolation techniques are used to perform area correction on parallel thinning lines to obtain EAN barcode corrections of the same size. Images, as shown in Figure 7 and Figure 8.
本发明还提供一种存储装置,其中,所述存储装置存储有计算机程序,所述计算机程序能够被执行以实现所述非线性畸变EAN条码的校正方法。The present invention also provides a storage device, wherein the storage device stores a computer program that can be executed to implement the method for correcting the nonlinearly distorted EAN barcode.
综上所述,本发明提供了一种非线性畸变EAN条码的校正方法、移动终端及存储设备,本发明的EAN条码校正方法是基于条码自身的形状特征的提取,对畸变类型未作任何限制,可以处理任意非线性畸变变形,通用性高。另外,本发明采用分块采样和插值技术逐步校正,稳定性和精度高,计算量小。In summary, the present invention provides a method for correcting nonlinearly distorted EAN barcodes, a mobile terminal and a storage device. The method for correcting EAN barcodes of the present invention is based on the extraction of the shape features of the barcode itself, without any restrictions on the type of distortion , can handle any nonlinear distortion deformation, and has high versatility. In addition, the present invention adopts block sampling and interpolation technology to correct step by step, so the stability and precision are high, and the amount of calculation is small.
当然,本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关硬件(如处理器,控制器等)来完成,所述的程序可存储于一计算机可读取的存储介质中,该程序在执行时可包括如上述各方法实施例的流程。其中所述的存储介质可为存储器、磁碟、光盘等。Of course, those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be implemented through computer programs to instruct related hardware (such as processors, controllers, etc.), and the programs can be stored in a In the computer-readable storage medium, the program may include the processes of the above-mentioned method embodiments when executed. The storage medium mentioned herein may be a memory, a magnetic disk, an optical disk, and the like.
应当理解的是,本发明的应用不限于上述的举例,对本领域普通技术人员来说,可以根据上述说明加以改进或变换,所有这些改进和变换都应属于本发明所附权利要求的保护范围。It should be understood that the application of the present invention is not limited to the above examples, and those skilled in the art can make improvements or transformations according to the above descriptions, and all these improvements and transformations should belong to the protection scope of the appended claims of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710424250.1A CN107358138B (en) | 2017-06-07 | 2017-06-07 | Correction method of nonlinear distortion EAN bar code, mobile terminal and storage device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710424250.1A CN107358138B (en) | 2017-06-07 | 2017-06-07 | Correction method of nonlinear distortion EAN bar code, mobile terminal and storage device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107358138A true CN107358138A (en) | 2017-11-17 |
CN107358138B CN107358138B (en) | 2020-03-24 |
Family
ID=60273532
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710424250.1A Expired - Fee Related CN107358138B (en) | 2017-06-07 | 2017-06-07 | Correction method of nonlinear distortion EAN bar code, mobile terminal and storage device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107358138B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113592782A (en) * | 2021-07-07 | 2021-11-02 | 山东大学 | Method and system for extracting X-ray image defects of composite carbon fiber core rod |
CN116804532A (en) * | 2023-08-24 | 2023-09-26 | 苏州中科行智智能科技有限公司 | 3D measurement method for distance between parallel line segments |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102096795A (en) * | 2010-11-25 | 2011-06-15 | 西北工业大学 | Method for recognizing worn two-dimensional barcode image |
CN102799850A (en) * | 2012-06-30 | 2012-11-28 | 北京百度网讯科技有限公司 | Bar code recognition method and device |
US20130069003A1 (en) * | 2009-04-02 | 2013-03-21 | Sicpa Holding Sa | Identification and authentication using polymeric liquid crystal material markings |
CN102156970B (en) * | 2011-04-14 | 2013-04-10 | 复旦大学 | Fisheye image correction method based on distorted straight slope calculation |
-
2017
- 2017-06-07 CN CN201710424250.1A patent/CN107358138B/en not_active Expired - Fee Related
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20130069003A1 (en) * | 2009-04-02 | 2013-03-21 | Sicpa Holding Sa | Identification and authentication using polymeric liquid crystal material markings |
CN102096795A (en) * | 2010-11-25 | 2011-06-15 | 西北工业大学 | Method for recognizing worn two-dimensional barcode image |
CN102156970B (en) * | 2011-04-14 | 2013-04-10 | 复旦大学 | Fisheye image correction method based on distorted straight slope calculation |
CN102799850A (en) * | 2012-06-30 | 2012-11-28 | 北京百度网讯科技有限公司 | Bar code recognition method and device |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113592782A (en) * | 2021-07-07 | 2021-11-02 | 山东大学 | Method and system for extracting X-ray image defects of composite carbon fiber core rod |
CN113592782B (en) * | 2021-07-07 | 2023-07-28 | 山东大学 | Method and system for extracting X-ray image defects of composite material carbon fiber core rod |
CN116804532A (en) * | 2023-08-24 | 2023-09-26 | 苏州中科行智智能科技有限公司 | 3D measurement method for distance between parallel line segments |
CN116804532B (en) * | 2023-08-24 | 2023-11-28 | 苏州中科行智智能科技有限公司 | 3D measurement method for distance between parallel line segments |
Also Published As
Publication number | Publication date |
---|---|
CN107358138B (en) | 2020-03-24 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110866924B (en) | Line structured light center line extraction method and storage medium | |
CN109753838B (en) | Two-dimensional code identification method, device, computer equipment and storage medium | |
CN114529459B (en) | Method, system and medium for enhancing image edge | |
WO2020119301A1 (en) | Two-dimensional code identification method, apparatus, and device | |
CN102902945B (en) | Distortion correction method of outer contour based on quick response matrix code | |
CN104700062B (en) | A method and device for identifying two-dimensional codes | |
CN107633192A (en) | Bar code segmentation and reading method under a kind of complex background based on machine vision | |
CN110033471A (en) | A kind of wire detection method based on connected domain analysis and morphological operation | |
CN110647882A (en) | Image correction method, device, equipment and storage medium | |
CN102222229A (en) | Method for preprocessing finger vein images | |
CN107045634A (en) | A kind of text positioning method based on maximum stable extremal region and stroke width | |
CN110570442A (en) | Contour detection method under complex background, terminal device and storage medium | |
CN107273777A (en) | A kind of Quick Response Code identification of code type method matched based on slide unit | |
CN113557520B (en) | Character processing and character recognition method, storage medium and terminal device | |
CN103606220A (en) | Check printed number recognition system and check printed number recognition method based on white light image and infrared image | |
CN104715221A (en) | Decoding method and system for ultra-low-contrast two-dimension code | |
CN112419207A (en) | Image correction method, device and system | |
CN110263778A (en) | A kind of meter register method and device based on image recognition | |
CN108197624A (en) | The recognition methods of certificate image rectification and device, computer storage media | |
CN114444565A (en) | Image tampering detection method, terminal device and storage medium | |
CN116958600A (en) | Similarity calculation and optimization method, similarity calculation and optimization device and storage medium | |
CN109242917A (en) | One kind being based on tessellated camera resolution scaling method | |
CN107358138A (en) | Bearing calibration, mobile terminal and the storage device of nonlinear distortion EAN bar codes | |
CN106778766A (en) | A kind of rotary digital recognition methods and system based on anchor point | |
CN118747811A (en) | Improved monocular SLAM image feature matching method based on ORB algorithm |
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 | ||
CF01 | Termination of patent right due to non-payment of annual fee | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20200324 |