CN114743207A - A kind of bill image recognition method and device - Google Patents
A kind of bill image recognition method and device Download PDFInfo
- Publication number
- CN114743207A CN114743207A CN202210320570.3A CN202210320570A CN114743207A CN 114743207 A CN114743207 A CN 114743207A CN 202210320570 A CN202210320570 A CN 202210320570A CN 114743207 A CN114743207 A CN 114743207A
- Authority
- CN
- China
- Prior art keywords
- target
- characters
- recognized
- area
- image
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 62
- 230000003247 decreasing effect Effects 0.000 claims description 13
- 238000004590 computer program Methods 0.000 claims description 10
- 238000007639 printing Methods 0.000 abstract description 19
- 238000004422 calculation algorithm Methods 0.000 abstract description 7
- 238000012015 optical character recognition Methods 0.000 description 18
- 238000010586 diagram Methods 0.000 description 12
- 238000004891 communication Methods 0.000 description 6
- 239000000976 ink Substances 0.000 description 6
- 230000000694 effects Effects 0.000 description 5
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000006870 function Effects 0.000 description 3
- 230000001788 irregular Effects 0.000 description 3
- 238000001514 detection method Methods 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000004364 calculation method Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 238000011084 recovery Methods 0.000 description 1
- 238000011160 research Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Images
Landscapes
- Character Input (AREA)
Abstract
Description
技术领域technical field
本发明涉及图像识别技术领域,特别是涉及一种票据图像识别方法和装置。The present invention relates to the technical field of image recognition, in particular to a method and device for image recognition of bills.
背景技术Background technique
OCR(Optical Character Recognition,光学字符识别)是指电子设备检查纸上打印的字符,通过检测暗、亮的模式确定其形状,然后用字符识别方法将形状翻译成计算机文字的过程。OCR (Optical Character Recognition) refers to the process in which electronic equipment examines characters printed on paper, determines its shape by detecting dark and light patterns, and then uses character recognition methods to translate the shape into computer text.
在OCR识别之前,需要确定票据上待识别的打印要素所在的目标区域,目前通用的方式是先截取固定的区域,然后进行二值化,再求连通域,通过连通域求外接矩形,外接矩形作为目标区域,从而进行后续的OCR识别。Before OCR recognition, it is necessary to determine the target area where the print elements to be recognized on the bill are located. The current common method is to intercept a fixed area, then perform binarization, and then find the connected domain, and find the circumscribed rectangle through the connected domain. As the target area, the subsequent OCR identification can be performed.
然而,由于打印设备打印不稳定,或者票据摆放不规范,打印的内容会上下偏移、左右偏移,导致无法准确打印在指定区域,因此,截取的固定区域容易造成位置截取错误。此外,使用连通域查找,由于区域内会受到横线、油墨、背景纹理等因素的干扰,造成截取的区域过大或过小,从而影响后续的OCR识别的准确率。However, due to the unstable printing of the printing equipment or the irregular placement of the bills, the printed content will be shifted up and down and left and right, which makes it impossible to accurately print in the designated area. Therefore, the intercepted fixed area is likely to cause position interception errors. In addition, using connected domain search, because the area will be interfered by horizontal lines, ink, background texture and other factors, the intercepted area will be too large or too small, which will affect the accuracy of subsequent OCR recognition.
发明内容SUMMARY OF THE INVENTION
鉴于上述问题,本发明实施例提出一种票据图像识别方法,以解决因打印设备、操作不规范导致待识别区域截取出错的问题。In view of the above problems, an embodiment of the present invention proposes a method for recognizing a bill image, so as to solve the problem that the area to be recognized is cut out incorrectly due to irregular printing equipment and operation.
本发明实施例还提供了一种票据图像识别装置,以保证上述方法的实施。The embodiment of the present invention also provides a bill image recognition device to ensure the implementation of the above method.
本发明实施例公开了一种票据图像识别方法,所述方法包括:An embodiment of the present invention discloses a method for recognizing a bill image, the method comprising:
调用预设模板,并将所述预设模板与所述票据图像进行匹配,获得所述票据图像的初始待识别区域;所述初始待识别区域包括多个字符;calling a preset template, and matching the preset template with the bill image to obtain an initial to-be-recognized area of the bill image; the initial to-be-recognized area includes a plurality of characters;
当确定所述多个字符包括打印字符时,针对所述多个字符的轮廓生成外接矩形,并从所述多个字符的外接矩形中确定目标外接矩形;When it is determined that the plurality of characters include printed characters, generating a circumscribed rectangle for the outlines of the plurality of characters, and determining a target circumscribed rectangle from the circumscribed rectangles of the plurality of characters;
针对所述目标外接矩形进行水平投影和垂直投影,获得所述打印字符的边界,并将所述边界形成的区域确定为所述票据图像的目标待识别区域;Perform horizontal projection and vertical projection on the target circumscribed rectangle, obtain the boundary of the printed character, and determine the area formed by the boundary as the target area to be recognized of the bill image;
针对所述目标待识别区域的打印字符进行识别。Recognize the printed characters in the target area to be recognized.
可选地,所述票据图像包括印刷字符,所述预设模板包括预设字符,所述将所述预设模板与所述票据图像进行匹配,获得所述票据图像的初始待识别区域,包括:Optionally, the ticket image includes printed characters, the preset template includes preset characters, and the matching of the preset template with the ticket image to obtain the initial to-be-recognized area of the ticket image includes: :
确定与所述印刷字符匹配的目标预设字符;determining a target preset character that matches the printed character;
将所述目标预设字符的位置,确定为所述印刷字符的位置;Determine the position of the target preset character as the position of the printed character;
将所述印刷字符的位置进行偏移,获得初始待识别位置;Offset the position of the printed character to obtain the initial position to be recognized;
根据所述初始待识别位置,生成所述票据图像的初始待识别区域。According to the initial to-be-recognized position, an initial to-be-recognized area of the bill image is generated.
可选地,所述方法还包括:Optionally, the method further includes:
在不同光源和不同颜色通道下,对所述票据图像进行二值化,获得多个第一二值图;Under different light sources and different color channels, binarize the bill image to obtain a plurality of first binary images;
分别针对所述多个第一二值图,统计所述初始待识别区域的每一行的具有目标像素值的像素点数量;For each of the plurality of first binary maps, count the number of pixels with target pixel values in each row of the initial to-be-identified region;
若所述像素点数量大于第一数量阈值,则将所述像素点数量所在的行确定为有效行;If the number of pixels is greater than the first number threshold, the row where the number of pixels is located is determined as a valid row;
确定连续的有效行的行数量;Determine the number of consecutive valid lines;
若所述行数量大于第二数量阈值,则确定所述多个字符包括打印字符;If the number of lines is greater than a second number threshold, determining that the plurality of characters include print characters;
若所述行数量不大于第二数量阈值,则确定所述多个字符不包括打印字符。If the number of lines is not greater than the second number threshold, it is determined that the plurality of characters do not include printed characters.
可选地,所述方法还包括:Optionally, the method further includes:
获取多个像素值递减的二值化阈值;Obtain the binarization thresholds with decreasing pixel values;
采用所述多个像素值递减的二值化阈值,分别对所述票据图像进行二值化,获得多个第二二值图;Using the binarization thresholds with decreasing pixel values, binarize the bill images respectively to obtain a plurality of second binary images;
按照像素值从大到小的顺序,从所述多个第二二值图中选取一个第二二值图作为目标二值图;Selecting a second binary image from the plurality of second binary images as the target binary image according to the order of pixel values from large to small;
所述针对所述多个字符的轮廓生成外接矩形,包括:The generating a circumscribed rectangle for the outlines of the plurality of characters includes:
采用所述目标二值图执行所述针对所述多个字符的轮廓生成外接矩形步骤。The step of generating a circumscribed rectangle for the outlines of the plurality of characters is performed using the target binary image.
可选地,所述从所述多个字符的外接矩形中确定目标外接矩形,包括:Optionally, the determining a target circumscribed rectangle from the circumscribed rectangles of the multiple characters includes:
确定所述多个字符的外接矩形的高度;determining the height of the circumscribed rectangle of the plurality of characters;
将高度位于第一预设范围内的外接矩形确定为目标外接矩形。A circumscribing rectangle whose height is within the first preset range is determined as the target circumscribing rectangle.
可选地,所述针对所述目标外接矩形进行水平投影和垂直投影,获得所述打印字符的边界,包括:Optionally, performing horizontal projection and vertical projection on the target circumscribed rectangle to obtain the boundary of the printed character, including:
基于水平投影,遍历所述目标外接矩形的每一行,确定多对上下边界;Based on the horizontal projection, traverse each row of the target circumscribed rectangle to determine multiple pairs of upper and lower boundaries;
从所述多对上下边界中确定目标上下边界;determining a target upper and lower boundary from the plurality of pairs of upper and lower boundaries;
基于垂直投影,遍历所述目标上下边界之间的每一列,确定多对左右边界;Based on the vertical projection, traverse each column between the upper and lower boundaries of the target, and determine multiple pairs of left and right boundaries;
从所述多对左右边界中确定目标左右边界;determining a target left and right boundary from the plurality of pairs of left and right boundaries;
所述将所述边界形成的区域确定为所述票据图像的目标待识别区域,包括:Determining the area formed by the boundary as the target area to be recognized of the bill image includes:
将所述目标上下边界和所述目标左右边界形成的区域,确定为所述票据图像的目标待识别区域。The area formed by the upper and lower boundaries of the target and the left and right boundaries of the target is determined as the target to-be-recognized area of the bill image.
可选地,所述从所述多对上下边界中确定目标上下边界,包括:Optionally, determining the target upper and lower boundaries from the multiple pairs of upper and lower boundaries includes:
确定每一对上下边界的高度;Determine the height of each pair of upper and lower boundaries;
将高度位于第二预设范围内的上下边界确定为目标上下边界;Determine the upper and lower boundaries of the height within the second preset range as the upper and lower boundaries of the target;
所述从所述多对左右边界中确定目标左右边界,包括:The determining the left and right boundaries of the target from the plurality of pairs of left and right boundaries includes:
确定每一对左右边界的宽度;Determine the width of each pair of left and right borders;
将宽度位于第三预设范围内的左右边界确定为目标左右边界。The left and right borders whose widths are within the third preset range are determined as the target left and right borders.
可选地,所述方法还包括:Optionally, the method further includes:
当不存在所述目标外接矩形,或所述目标上下边界,或所述目标左右边界时,按照像素值从大到小的顺序,从所述多个第二二值图中选取下一个第二二值图作为目标二值图。When the target circumscribing rectangle, or the upper and lower boundaries of the target, or the left and right boundaries of the target does not exist, select the next second binary image from the plurality of second binary images in descending order of pixel values. The binary image is used as the target binary image.
本发明实施例还公开了一种票据图像识别装置,所述装置包括:The embodiment of the present invention also discloses a bill image recognition device, the device includes:
初始待识别区域获得模块,用于调用预设模板,并将所述预设模板与所述票据图像进行匹配,获得所述票据图像的初始待识别区域;所述初始待识别区域包括多个字符;The initial to-be-recognized area obtaining module is used to call a preset template and match the preset template with the bill image to obtain the initial to-be-recognized area of the bill image; the initial to-be-recognized area includes a plurality of characters ;
目标外接矩形确定模块,用于当确定所述多个字符包括打印字符时,针对所述多个字符的轮廓生成外接矩形,并从所述多个字符的外接矩形中确定目标外接矩形;a target circumscribed rectangle determination module, configured to generate a circumscribed rectangle for the outlines of the plurality of characters when it is determined that the plurality of characters include printed characters, and determine a target circumscribed rectangle from the circumscribed rectangles of the plurality of characters;
目标待识别区域确定模块,用于针对所述目标外接矩形进行水平投影和垂直投影,获得所述打印字符的边界,并将所述边界形成的区域确定为所述票据图像的目标待识别区域;A target to-be-recognized area determination module, configured to perform horizontal projection and vertical projection on the target circumscribed rectangle, obtain the boundary of the printed character, and determine the area formed by the boundary as the target to-be-recognized area of the bill image;
识别模块,用于针对所述目标待识别区域的打印字符进行识别。The recognition module is used to recognize the printed characters of the target area to be recognized.
可选地,所述票据图像包括印刷字符,所述预设模板包括预设字符,所述初始待识别区域获得模块包括:Optionally, the ticket image includes printed characters, the preset template includes preset characters, and the initial to-be-recognized area obtaining module includes:
匹配子模块,用于确定与所述印刷字符匹配的目标预设字符;a matching submodule for determining a target preset character that matches the printed character;
位置确定子模块,用于将所述目标预设字符的位置,确定为所述印刷字符的位置;a position determination submodule, for determining the position of the target preset character as the position of the printed character;
偏移子模块,用于将所述印刷字符的位置进行偏移,获得初始待识别位置;an offset submodule for offsetting the position of the printed character to obtain an initial position to be recognized;
初始待识别区域生成子模块,用于根据所述初始待识别位置,生成所述票据图像的初始待识别区域。The initial to-be-recognized area generating sub-module is configured to generate the initial to-be-recognized area of the bill image according to the initial to-be-recognized position.
可选地,所述装置还包括:Optionally, the device further includes:
第一二值图获得模块,用于在不同光源和不同颜色通道下,对所述票据图像进行二值化,获得多个第一二值图;a first binary image obtaining module, used for binarizing the bill image under different light sources and different color channels to obtain a plurality of first binary images;
像素点数量统计模块,用于分别针对所述多个第一二值图,统计所述初始待识别区域的每一行的具有目标像素值的像素点数量;a pixel number statistics module, configured to count the number of pixels with target pixel values in each row of the initial to-be-identified region for the plurality of first binary images respectively;
有效行确定模块,用于若所述像素点数量大于第一数量阈值,则将所述像素点数量所在的行确定为有效行;a valid row determination module, configured to determine the row where the number of pixels is located as a valid row if the number of pixels is greater than the first number threshold;
行数量确定模块,用于确定连续的有效行的行数量;The row quantity determination module is used to determine the row quantity of consecutive valid rows;
第一打印字符确定模块,用于若所述行数量大于第二数量阈值,则确定所述多个字符包括打印字符;a first print character determination module, configured to determine that the plurality of characters include print characters if the number of lines is greater than a second number threshold;
第二打印字符确定模块,用于若所述行数量不大于第二数量阈值,则确定所述多个字符不包括打印字符。A second print character determination module, configured to determine that the plurality of characters do not include print characters if the number of lines is not greater than a second number threshold.
可选地,所述装置还包括:Optionally, the device further includes:
二值化阈值获取模块,用于获取多个像素值递减的二值化阈值;The binarization threshold obtaining module is used to obtain the binarization thresholds with decreasing pixel values;
第二二值图获得模块,用于采用所述多个像素值递减的二值化阈值,分别对所述票据图像进行二值化,获得多个第二二值图;A second binary image obtaining module, configured to binarize the bill image respectively by using the plurality of binarization thresholds with decreasing pixel values to obtain a plurality of second binary images;
第一目标二值图选取模块,用于按照像素值从大到小的顺序,从所述多个第二二值图中选取一个第二二值图作为目标二值图;The first target binary image selection module is used to select a second binary image from the plurality of second binary images as the target binary image according to the order of pixel values from large to small;
所述目标外接矩形确定模块包括:The target circumscribed rectangle determination module includes:
外接矩形生成子模块,用于采用所述目标二值图执行所述针对所述多个字符的轮廓生成外接矩形步骤。A sub-module for generating a circumscribed rectangle, configured to use the target binary image to perform the step of generating a circumscribed rectangle for the outlines of the plurality of characters.
可选地,所述目标外接矩形确定模块包括:Optionally, the target circumscribed rectangle determination module includes:
外接矩形的高度确定子模块,用于确定所述多个字符的外接矩形的高度;a submodule for determining the height of the circumscribed rectangle, for determining the height of the circumscribed rectangle of the plurality of characters;
目标外接矩形确定子模块,用于将高度位于第一预设范围内的外接矩形确定为目标外接矩形。The target circumscribing rectangle determination submodule is used for determining the circumscribing rectangle whose height is within the first preset range as the target circumscribing rectangle.
可选地,所述目标待识别区域确定模块包括:Optionally, the target to-be-identified area determination module includes:
第一遍历子模块,用于基于水平投影,遍历所述目标外接矩形的每一行,确定多对上下边界;The first traversal submodule is used to traverse each row of the target circumscribed rectangle based on the horizontal projection to determine multiple pairs of upper and lower boundaries;
目标上下边界确定子模块,用于从所述多对上下边界中确定目标上下边界;a target upper and lower boundary determination submodule, for determining the target upper and lower boundaries from the multiple pairs of upper and lower boundaries;
第二遍历子模块,用于基于垂直投影,遍历所述目标上下边界之间的每一列,确定多对左右边界;The second traversal submodule is used to traverse each column between the upper and lower boundaries of the target based on the vertical projection, and determine multiple pairs of left and right boundaries;
目标左右边界确定子模块,用于从所述多对左右边界中确定目标左右边界;a target left and right boundary determination submodule, configured to determine the target left and right boundaries from the plurality of pairs of left and right boundaries;
所述目标待识别区域确定模块包括:The target to-be-identified area determination module includes:
目标待识别区域确定子模块,用于将所述目标上下边界和所述目标左右边界形成的区域,确定为所述票据图像的目标待识别区域。The target to-be-recognized area determination sub-module is used to determine the area formed by the upper and lower boundaries of the target and the left and right boundaries of the target as the target area to be recognized of the bill image.
可选地,所述目标左右边界确定子模块包括:Optionally, the target left and right boundary determination submodule includes:
上下边界的高度确定单元,用于确定每一对上下边界的高度;The height determination unit of the upper and lower boundaries is used to determine the height of each pair of upper and lower boundaries;
目标上下边界确定单元,用于将高度位于第二预设范围内的上下边界确定为目标上下边界;a target upper and lower boundary determining unit, configured to determine the upper and lower boundaries whose height is within the second preset range as the target upper and lower boundaries;
所述目标左右边界确定子模块包括:The target left and right boundary determination submodules include:
左右边界的宽度确定单元,用于第一高度确定子模块,用于确定每一对左右边界的宽度;a width determination unit for the left and right borders, used for the first height determination submodule, for determining the width of each pair of left and right borders;
目标左右边界确定单元,用于将宽度位于第三预设范围内的左右边界确定为目标左右边界。The target left and right boundary determination unit is configured to determine the left and right boundaries whose width is within the third preset range as the target left and right boundaries.
可选地,所述装置还包括:Optionally, the device further includes:
第二目标二值图选取模块,用于当不存在所述目标外接矩形,或所述目标上下边界,或所述目标左右边界时,按照像素值从大到小的顺序,从所述多个第二二值图中选取下一个第二二值图作为目标二值图。The second target binary image selection module is configured to, when there is no circumscribing rectangle of the target, or the upper and lower boundaries of the target, or the left and right boundaries of the target, select from the plurality of pixel values in descending order of pixel values. In the second binary image, the next second binary image is selected as the target binary image.
本发明实施例还公开了一种电子设备,包括处理器、通信接口、存储器和通信总线,其中,所述处理器、所述通信接口以及所述存储器通过所述通信总线完成相互间的通信;An embodiment of the present invention further discloses an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
所述存储器,用于存放计算机程序;the memory for storing computer programs;
所述处理器,用于执行存储器上所存放的程序时,实现如本发明实施例所述的方法。The processor is configured to implement the method according to the embodiment of the present invention when executing the program stored in the memory.
本发明实施例还公开了一种计算机可读存储介质,其上存储有指令,当由一个或多个处理器执行时,使得所述处理器执行如本发明实施例所述的方法。The embodiment of the present invention also discloses a computer-readable storage medium, on which instructions are stored, and when executed by one or more processors, cause the processors to execute the method according to the embodiment of the present invention.
与现有技术相比,本发明实施例包括以下优点:Compared with the prior art, the embodiments of the present invention include the following advantages:
在本发明实施例中,首先调用预设模板,将预设模板与票据图像进行匹配,获得票据图像的初始待识别区域,其中,初始待识别区域包括多个字符,当确定多个字符包括打印字符时,针对多个字符的轮廓生成外接矩形,然后从多个字符的外接矩形中确定目标外接矩形,针对目标外接矩形进行水平投影和垂直投影,获得打印字符的边界,再将边界形成的区域确定为票据图像的目标待识别区域,最后针对目标待识别区域的打印字符进行识别。本发明实施例适用于各种票据的图像识别,具有很强的通用性和稳定性,可以解决因打印设备、操作不规范导致待识别区域截取出错的问题,提高OCR识别的准确率,提升算法执行的效率。In the embodiment of the present invention, a preset template is called first, and the preset template is matched with the bill image to obtain the initial to-be-recognized area of the bill image, wherein the initial to-be-recognized area includes a plurality of characters. For characters, a circumscribed rectangle is generated for the outlines of multiple characters, and then the target circumscribed rectangle is determined from the circumscribed rectangles of multiple characters. It is determined as the target area to be recognized of the bill image, and finally the printed characters in the target area to be recognized are recognized. The embodiment of the present invention is suitable for image recognition of various bills, has strong versatility and stability, can solve the problem of incorrectly intercepted areas to be recognized due to non-standard printing equipment and operations, improve the accuracy of OCR recognition, and improve the algorithm efficiency of execution.
附图说明Description of drawings
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present invention more clearly, the following briefly introduces the accompanying drawings used in the description of the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.
图1A~图1B是现有技术中待识别区域截取示意图;1A to 1B are schematic diagrams of intercepting a region to be identified in the prior art;
图2是本发明实施例提供的一种票据图像识别方法的步骤流程图;FIG. 2 is a flowchart of steps of a method for recognizing bill image provided by an embodiment of the present invention;
图3是本发明实施例提供的票据图像示意图;3 is a schematic diagram of a ticket image provided by an embodiment of the present invention;
图4是本发明实施例提供的模板匹配示意图;4 is a schematic diagram of template matching provided by an embodiment of the present invention;
图5A~图5B是本发明实施例提供的第一二值图;5A-5B are a first binary graph provided by an embodiment of the present invention;
图6是本发明实施例提供的外接矩形示意图;6 is a schematic diagram of a circumscribed rectangle provided by an embodiment of the present invention;
图7A~图7C是本发明实施例提供的效果展示图;7A to 7C are effect display diagrams provided by an embodiment of the present invention;
图8是本发明实施例提供的票据图像识别流程框图;8 is a flow chart of a receipt image recognition process provided by an embodiment of the present invention;
图9是本发明实施例提供的一种票据图像识别装置的的结构框图。FIG. 9 is a structural block diagram of a bill image recognition device provided by an embodiment of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
在支票、存单、进账单等票据的回收、发票的报销的工作中,工作人员需要针对票面上的打印信息进行核对,而人工核对需要耗费大量的时间,导致效率低下且容易出错。In the recovery of bills such as checks, deposit slips, and incoming bills, and the reimbursement of invoices, the staff needs to check the printed information on the ticket, and manual checking takes a lot of time, resulting in low efficiency and error-prone.
OCR可以很好地解决人工核对存在的效率低下且容易出错的问题。通常地,在OCR识别之前,需要在票据上截取待识别区域,以使OCR针对待识别区域内的字符进行识别。OCR can well solve the inefficiency and error-prone problems of manual verification. Generally, before the OCR recognition, the area to be recognized needs to be cut out on the bill, so that the OCR can recognize the characters in the area to be recognized.
参考图1A~图1B,示出了现有技术中待识别区域截取示意图,其中,图1A是由于打印设备打印不稳定,或者票据摆放不规范,打印的内容会上下偏移、左右偏移,导致无法准确打印在指定区域,因此,截取的固定区域容易造成位置截取错误,参见图1A中的A1~A3区域。此外,图1B是由于票面上存在横线、油墨、背景纹理等无关因素,因此,使用连通域查找,会因为区域内会受到横线、油墨、背景纹理等无关因素的干扰,造成截取的区域过大或过小,参见图1B中的B1~B3区域。由此可见,上述两种情况都会影响后续的OCR识别的准确率。Referring to FIGS. 1A to 1B , schematic diagrams of the area to be identified in the prior art are shown. In FIG. 1A , due to unstable printing of the printing device or irregular placement of bills, the printed content will be shifted up and down, left and right. , so that it cannot be accurately printed in the designated area. Therefore, the intercepted fixed area is likely to cause position interception errors, see areas A1 to A3 in FIG. 1A . In addition, Fig. 1B is due to the existence of irrelevant factors such as horizontal lines, inks, and background textures on the ticket. Therefore, using the connected domain search will cause the intercepted area due to the interference of irrelevant factors such as horizontal lines, ink, and background textures in the area. If it is too large or too small, please refer to the regions B1 to B3 in FIG. 1B . It can be seen that the above two situations will affect the accuracy of subsequent OCR recognition.
针对现有技术中直接截取固定区域造成容易截取错误、票面存在其他无关因素造成容易受到干扰等问题,本发明实施例提供了一种票据图像识别方法,可以适用于各种票据的图像识别,具有很强的通用性和稳定性,可以解决因打印设备、操作不规范导致待识别区域截取出错的问题,提高OCR识别的准确率,提升算法执行的效率。Aiming at the problems in the prior art that the direct interception of a fixed area causes easy interception errors, and other irrelevant factors on the ticket surface cause easy interference, the embodiment of the present invention provides a bill image recognition method, which can be applied to the image recognition of various bills. With strong versatility and stability, it can solve the problem of incorrectly intercepting the area to be recognized due to non-standard printing equipment and operations, improve the accuracy of OCR recognition, and improve the efficiency of algorithm execution.
参照图2,示出了本发明实施例提供的一种票据图像识别方法的步骤流程图,该方法具体可以包括如下步骤:Referring to FIG. 2, a flowchart of steps of a method for recognizing a bill image provided by an embodiment of the present invention is shown, and the method may specifically include the following steps:
步骤201,调用预设模板,并将所述预设模板与所述票据图像进行匹配,获得所述票据图像的初始待识别区域;所述初始待识别区域包括多个字符。
在本发明实施例中,可以应用于票据设备,可以将需要识别的票据放于票据设备上,票据设备可以扫描票据,从而获得该票据的票据图像。其中,票据图像可以是在白光下扫描得到的白光图,票据设备可以将白光图设置为灰度图,从而可以针对灰度图进行后续的模板匹配步骤。In the embodiment of the present invention, it can be applied to a bill device, the bill to be identified can be placed on the bill device, and the bill device can scan the bill to obtain a bill image of the bill. The bill image can be a white light image obtained by scanning under white light, and the bill device can set the white light image as a grayscale image, so that subsequent template matching steps can be performed for the grayscale image.
作为一示例,参照图3,示出了本发明实施例提供的票据图像示意图,其中,票据图像可以包括印刷字符、打印字符、横线、油墨、背景纹理等要素,其中,印刷字符可以是“户名”、“账号”、“金额”、“XX银行”、“XX印章”等内容,打印字符可以是“小华”、“111111111111111111”、“壹仟元整”、“1000.00”等内容。As an example, referring to FIG. 3 , a schematic diagram of a ticket image provided by an embodiment of the present invention is shown, wherein the ticket image may include elements such as printed characters, printed characters, horizontal lines, ink, background texture, etc., wherein the printed characters may be " Account name, "account number", "amount", "XX bank", "XX seal", etc., the printed characters can be "Xiaohua", "111111111111111111", "One thousand yuan", "1000.00" and other contents.
打印字符是后续OCR进行识别的对象,因此,本发明实施例可以调用预设模板,通过将预设模板与票据图像进行匹配,可以获得票据图像的初始待识别区域,其中,初始待识别区域可以包括多个字符,字符可能包括印刷字符和打印字符,初始待识别区域也可以包括横线、油墨、背景纹理等要素。The printed characters are the objects to be recognized by the subsequent OCR. Therefore, in this embodiment of the present invention, a preset template can be called, and by matching the preset template with the ticket image, the initial to-be-recognized area of the ticket image can be obtained, wherein the initial to-be-recognized area can be Including multiple characters, the characters may include printed characters and printed characters, and the initial area to be recognized may also include elements such as horizontal lines, ink, and background textures.
本发明的一个可选实施例中,所述票据图像包括印刷字符,所述预设模板包括预设字符,步骤201可以包括以下子步骤:In an optional embodiment of the present invention, the receipt image includes printed characters, and the preset template includes preset characters. Step 201 may include the following sub-steps:
子步骤S11,确定与所述印刷字符匹配的目标预设字符;Sub-step S11, determine the target preset character matching with the printed character;
子步骤S12,将所述目标预设字符的位置,确定为所述印刷字符的位置;Sub-step S12, the position of the target preset character is determined as the position of the printed character;
子步骤S13,将所述印刷字符的位置进行偏移,获得初始待识别位置;Sub-step S13, offset the position of the printed character to obtain the initial position to be recognized;
子步骤S14,根据所述初始待识别位置,生成所述票据图像的初始待识别区域。In sub-step S14, an initial to-be-recognized area of the bill image is generated according to the initial to-be-recognized position.
在本发明实施例中,票据图像可以包括多个印刷字符,可以针对各种类型的票据,比如支票、存单、进账单等票据,还可以针对不同公司、不同银行出版的同一种类型的票据,比如不同银行出版的存单,本发明实施例进行大量票据的图像研究,从而设置多个预设模板。可以采用多个预设模板,对各种各样的票据图像进行匹配,从而可以获得票据图像的初始待识别区域。In this embodiment of the present invention, the bill image may include multiple printed characters, and may be for various types of bills, such as checks, deposit slips, receipts, etc., or for the same type of bills published by different companies and different banks. For example, for certificates of deposit published by different banks, the embodiment of the present invention conducts image research on a large number of bills, thereby setting multiple preset templates. Multiple preset templates can be used to match various bill images, so as to obtain the initial to-be-recognized area of the bill image.
作为一示例,可以按照预设顺序,依次调用多个预设模板,每个预设模板可以包括一个或多个预设字符。参照图4,示出了本发明实施例提供的模板匹配示意图,其中,M1~M3分别为预设字符,M1’~M3’分别为印刷字符。本发明实施例可以先确定与票据图像上印刷字符匹配的目标预设字符,然后可以将目标预设字符的位置,确定为印刷字符的位置。例如,预设字符M1与印刷字符M1’匹配,预设字符M2与印刷字符M2’匹配,预设字符M3与印刷字符M3’匹配,故可以将预设字符M1的位置确定为印刷字符M1’的位置,将预设字符M2的位置确定为印刷字符M2’的位置,将预设字符M3的位置确定为印刷字符M3’的位置。需要说明的是,如果不存在与印刷字符匹配的目标预设字符,那么可以重新调用预设模板,直至确定与印刷字符匹配的目标预设字符。As an example, multiple preset templates may be called in sequence according to a preset sequence, and each preset template may include one or more preset characters. Referring to FIG. 4 , a schematic diagram of template matching provided by an embodiment of the present invention is shown, wherein M1 to M3 are preset characters respectively, and M1' to M3' are respectively printed characters. In the embodiment of the present invention, the target preset character matching the printed character on the ticket image can be determined first, and then the position of the target preset character can be determined as the position of the printed character. For example, the preset character M1 matches the printed character M1', the preset character M2 matches the printed character M2', and the preset character M3 matches the printed character M3', so the position of the preset character M1 can be determined as the printed character M1' The position of the preset character M2 is determined as the position of the printed character M2', and the position of the preset character M3 is determined as the position of the printed character M3'. It should be noted that, if there is no target preset character matching the printed character, the preset template may be recalled until the target preset character matching the printed character is determined.
在本发明实施例中,票据图像上的印刷字符与打印字符的相对位置可以是固定的,从而设置位置偏移信息。其中,位置偏移信息可以包括偏移距离和偏移方向。在获得印刷字符的位置后,可以按照偏移距离和偏移方向,将印刷字符的位置进行偏移,从而可以获得初始待识别位置,然后可以根据初始待识别位置,生成票据图像的初始待识别区域。In this embodiment of the present invention, the relative positions of the printed characters on the ticket image and the printed characters may be fixed, so that the position offset information is set. The position offset information may include offset distance and offset direction. After the position of the printed character is obtained, the position of the printed character can be offset according to the offset distance and the offset direction, so that the initial position to be recognized can be obtained, and then the initial to-be-recognized position of the bill image can be generated according to the initial to-be-recognized position area.
作为一示例,如图4所示,在获得印刷字符M1’~M3’的位置后,可以按照位置偏移信息,将印刷字符的位置M1’~M3’往右方向偏移X个像素点,从而可以获得初始待识别位置,然后可以以初始待识别位置为中心点,生成票据图像的初始待识别区域,参见图4中的C1~C3区域。需要说明的是,初始待识别区域一般是比较大的,因此,即使打印设备打印不稳定,或者票据摆放不规范,造成打印字符上下偏移、左右偏移,那么本发明实施例的初始待识别区域也会涵盖完整的打印字符。As an example, as shown in FIG. 4 , after obtaining the positions of the printed characters M1' to M3', the positions of the printed characters M1' to M3' can be shifted to the right by X pixels according to the position offset information, Thereby, the initial to-be-recognized position can be obtained, and then the initial to-be-recognized area of the bill image can be generated with the initial to-be-recognized position as the center point, see areas C1 to C3 in FIG. 4 . It should be noted that the initial to-be-recognized area is generally relatively large. Therefore, even if the printing equipment is not stable in printing, or the bills are placed irregularly, causing the printed characters to be shifted up and down and left and right, then the initial to-be-recognized area in the embodiment of the present invention is The recognition area also covers complete printed characters.
本发明的一个可选实施例中,所述方法还可以包括:In an optional embodiment of the present invention, the method may further include:
在不同光源和不同颜色通道下,对所述票据图像进行二值化,获得多个第一二值图;分别针对所述多个第一二值图,统计所述初始待识别区域的每一行的具有目标像素值的像素点数量;若所述像素点数量大于第一数量阈值,则将所述像素点数量所在的行确定为有效行;确定连续的有效行的行数量;若所述行数量大于第二数量阈值,则确定所述多个字符包括打印字符;若所述行数量不大于第二数量阈值,则确定所述多个字符不包括打印字符。Under different light sources and different color channels, binarize the bill image to obtain multiple first binary images; for the multiple first binary images, count each row of the initial to-be-recognized area The number of pixels with the target pixel value; if the number of pixels is greater than the first number threshold, the row where the number of pixels is located is determined as a valid row; the number of consecutive valid rows is determined; if the row If the number is greater than the second number threshold, it is determined that the plurality of characters include print characters; if the number of lines is not greater than the second number threshold, it is determined that the multiple characters do not include print characters.
在实际应用中,可能存在空白票据或者票据上缺少某些内容的无效票据,比如空白存单或者存单上缺少户名的填写。为了避免OCR识别这些无效票据,可以在获得初始待识别区域后,确定初始待识别区域是否存在打印字符。In practical applications, there may be blank bills or invalid bills with some content missing on the bills, such as blank certificates of deposit or the lack of an account name on the certificate of deposit. In order to avoid OCR identifying these invalid bills, after obtaining the initial to-be-recognized area, it may be determined whether there are printed characters in the initial to-be-recognized area.
在实际应用中,由于白光图会有底纹的干扰,容易无要素识别成有,出错概率较大,而红外图虽然干净,但是很多时候由于打印偏淡,阈值的计算会有偏差,容易导致有要素识别成无。因此,本发明实施例可以结合不同光源和不同色道的特性进行要素的检测,从而减少要素检测出错的可能。In practical applications, due to the interference of shading in the white light image, it is easy to identify without elements, and the probability of error is high. Although the infrared image is clean, in many cases, due to the light printing, the calculation of the threshold value will be biased, which is easy to cause There are elements identified as none. Therefore, the embodiments of the present invention can perform element detection in combination with the characteristics of different light sources and different color channels, thereby reducing the possibility of error in element detection.
在本发明实施中,可以将票据图像设置在不同光源和不同颜色通道下扫描得到的图像,其中,光源可以包括白光和红外光,颜色通道可以包括红色(R)、绿色(G)、蓝色(B)。本发明实施可以获取票据图像的白光图和红外图,然后可以根据不同票据选取不同的颜色通道。In the implementation of the present invention, the bill image can be set to scan images obtained under different light sources and different color channels, wherein the light sources can include white light and infrared light, and the color channels can include red (R), green (G), blue (B). The implementation of the present invention can obtain the white light image and the infrared image of the bill image, and then can select different color channels according to different bills.
以存单为例,可以选取存单的白光图的绿色通道,而存单的红外图比较干净,可以不用选取颜色通道,然后可以分别针对绿色通道的白光图和红外图进行二值化,获得多个第一二值图。参照图5A~5B,示出了本发明实施例提供的第一二值图,其中,图5A为绿色通道的白光图的第一二值图,图5B为红外图的第一二值图。由此可见,图5A中第一二值图存在较多底纹的干扰,图5B中第一二值图的打印字符会偏淡很多,本发明实施例分别采用绿色通道的白光图的第一二值图以及红外图的第一二值图,确定初始待识别区域中的多个字符是否包括打印字符。Taking the deposit receipt as an example, the green channel of the white light image of the deposit receipt can be selected, and the infrared image of the deposit receipt is relatively clean, so it is not necessary to select the color channel, and then the white light image and the infrared image of the green channel can be binarized to obtain multiple A binary graph. Referring to FIGS. 5A-5B , a first binary image provided by an embodiment of the present invention is shown, wherein FIG. 5A is a first binary image of a white light image of a green channel, and FIG. 5B is a first binary image of an infrared image. It can be seen that the first binary image in FIG. 5A has more interference from shading, and the printed characters of the first binary image in FIG. 5B are much lighter. In the embodiment of the present invention, the first binary image of the white light image of the green channel is used respectively. The binary image and the first binary image of the infrared image are used to determine whether the plurality of characters in the initial to-be-recognized area include printed characters.
在本发明实施中,票据图像可以包括0~255的像素值,可以先统计每一个像素值对应的像素点个数,然后在这些像素点中选取前30%的像素值作为第一像素值阈值。为了找到最优的阈值,可以根据不同的票据做适当的调整,比如可以在第一像素值阈值的基础上减去一定的偏置量,调整得到最优的第二像素值阈值,从而可以采用第二像素值阈值对票据图像进行二值化。In the implementation of the present invention, the bill image may include pixel values from 0 to 255. The number of pixel points corresponding to each pixel value may be counted first, and then the first 30% of the pixel values may be selected as the first pixel value threshold among these pixel points. . In order to find the optimal threshold, appropriate adjustments can be made according to different bills. For example, a certain offset can be subtracted from the first pixel value threshold to adjust to obtain the optimal second pixel value threshold. The second pixel value threshold binarizes the bill image.
具体地,假设票据图像大小为100*100,那么像素点总数为10000,计算得到30%的像素点为3000,先从最大像素值255开始,累计像素点个数,直至找到前30%的像素值。假设像素值255的像素点个数有1000,像素值254的像素点个数为1000,像素值253的像素点个数为1000,此时累计到的像素点个数为3000,那么下一个像素值252就是前30%的像素值,将像素值252作为第一像素值阈值,然后在第一像素值阈值252的基础上减去一定的偏置量得到最优的第二像素值阈值。假设第二像素值阈值为250,那么可以采用第二像素值阈值250对票据图像进行二值化,得到第一二值图,比如大于或等于第二像素值阈值250的像素值设置为白色,小于第二像素值阈值250的像素值设置为黑色,从而得到的第一二值图呈现黑白效果,其中,白色像素点构成文字部分,黑色像素点构成背景部分。Specifically, assuming that the size of the bill image is 100*100, then the total number of pixels is 10,000, and 30% of the pixels are calculated to be 3,000. Start with the maximum pixel value of 255, and accumulate the number of pixels until the first 30% of the pixels are found. value. Assuming that the number of pixels with a pixel value of 255 is 1000, the number of pixels with a pixel value of 254 is 1000, and the number of pixels with a pixel value of 253 is 1000, the accumulated number of pixels at this time is 3000, then the next pixel The value 252 is the first 30% of the pixel values, the pixel value 252 is used as the first pixel value threshold, and then a certain offset is subtracted from the first pixel value threshold 252 to obtain the optimal second pixel value threshold. Assuming that the second pixel value threshold is 250, then the second pixel value threshold 250 can be used to binarize the bill image to obtain the first binary image, for example, the pixel value greater than or equal to the second pixel value threshold 250 is set to white, The pixel value smaller than the second pixel value threshold 250 is set to black, so that the obtained first binary image presents a black and white effect, wherein the white pixels constitute the text portion, and the black pixels constitute the background portion.
在本发明实施中,在初始待识别区域的每一行中,可以统计具有目标像素值的像素点数量。当像素点数量大于第一数量阈值时,可以将该像素点数量所在的行确定为有效行;当像素点数量不大于第一数量阈值时,可以将该像素点数量所在的行确定为无效行。然后可以统计连续的有效行的行数量,当有效行的行数量大于第二数量阈值时,可以确定多个字符包括打印字符;当有效行的行数量不大于第二数量阈值时,可以确定多个字符不包括打印字符。In the implementation of the present invention, in each row of the initial to-be-identified area, the number of pixel points with the target pixel value can be counted. When the number of pixels is greater than the first number threshold, the row where the number of pixels is located may be determined as a valid row; when the number of pixels is not greater than the first number threshold, the row where the number of pixels is located may be determined as an invalid row . Then the number of consecutive valid lines can be counted, and when the number of valid lines is greater than the second number threshold, it can be determined that multiple characters include printing characters; when the number of valid lines is not greater than the second number threshold, it can be determined that the number of characters excluding print characters.
具体地,由于第一二值图只有白色(255)和黑色(0)这两种像素值,而白色像素点构成文字部分,黑色像素点构成背景部分,因此,可以将白色像素值作为目标像素值。假设第一数量阈值设定为50个,而初始待识别区域内的第1行有20个白色像素点,第2行有30个白色像素点,第3行有51个白色像素点,那么可以将第3行作为有效行,而第1行和第2行作为无效行。然后可以统计连续的有效行的行数量,假设第二数量阈值为8行,而初始待识别区域内的第3行~第13行都是有效行,那么可以确定初始待识别区域内的多个字符包括打印字符。Specifically, since the first binary image has only two pixel values, white (255) and black (0), the white pixels constitute the text part, and the black pixels constitute the background part. Therefore, the white pixel value can be used as the target pixel. value. Assuming that the first number threshold is set to 50, and the first line in the initial to-be-recognized area has 20 white pixels, the second line has 30 white pixels, and the third line has 51 white pixels, then you can Make row 3 a valid row, and rows 1 and 2 as invalid. Then the number of consecutive valid rows can be counted. Assuming that the second threshold is 8 rows, and the 3rd to 13th rows in the initial to-be-recognized area are all valid rows, then multiple Characters include print characters.
步骤202,当确定所述多个字符包括打印字符时,针对所述多个字符的轮廓生成外接矩形,并从所述多个字符的外接矩形中确定目标外接矩形。
在本发明实施中,当确定初始待识别区域内的多个字符包括打印字符时,可以使用票据图像的红外图的二值图,针对多个字符的轮廓生成外接矩形,然后可以从多个字符的外接矩形中确定目标外接矩形。参照图6,示出了本发明实施例提供的外接矩形示意图,其中,图6是红外图的第二二值图,本发明实施例在第二二值图的初始待识别中,基于轮廓查找方式,可以得到各个字符的轮廓,然后针对多个字符的轮廓生成外接矩形,参见图6中的a~g的外接矩形,然后可以从外接矩形a~g中确定目标外接矩形,以采用目标外接矩形进行后续的投影步骤。In the implementation of the present invention, when it is determined that the multiple characters in the initial to-be-recognized area include printed characters, the binary image of the infrared image of the bill image can be used to generate a circumscribed rectangle for the contours of the multiple characters, and then a circumscribed rectangle can be generated from the multiple characters. Determine the target bounding rectangle in the bounding rectangle of . Referring to FIG. 6 , a schematic diagram of a circumscribed rectangle provided by an embodiment of the present invention is shown, wherein FIG. 6 is a second binary image of an infrared image. In the embodiment of the present invention, in the initial pending identification of the second binary image, a contour search is performed. In this way, the outline of each character can be obtained, and then a circumscribed rectangle can be generated for the outlines of multiple characters, referring to the circumscribed rectangles of a to g in FIG. The rectangle undergoes subsequent projection steps.
本发明的一个可选实施例中,所述方法还可以包括:In an optional embodiment of the present invention, the method may further include:
获取多个像素值递减的二值化阈值;采用所述多个像素值递减的二值化阈值,分别对所述票据图像进行二值化,获得多个第二二值图;按照像素值从大到小的顺序,从所述多个第二二值图中选取一个第二二值图作为目标二值图。Obtaining a plurality of binarization thresholds with decreasing pixel values; using the plurality of binarizing thresholds with decreasing pixel values, binarizing the bill image respectively to obtain a plurality of second binary images; In descending order, one second binary image is selected from the plurality of second binary images as the target binary image.
在本发明实施中,可以预先设定多个像素值递减的二值化阈值,在确定初始待识别区域存在打印字符后,可以获取这些二值化阈值,然后可以采用这些二值化阈值,针对票据图像的红外图分别进行二值化,从而可以获得一系列的第二二值图。例如,预先设定10个不同二值化阈值,比如200、198、196、194、192、190、188、186、184、182,然后可以采用这10个不同二值化阈值,针对票据图像的红外图分别进行二值化,从而可以获得一系列的第二二值图。In the implementation of the present invention, a plurality of binarization thresholds with decreasing pixel values can be preset, and after it is determined that there are printed characters in the initial to-be-recognized area, these binarization thresholds can be obtained, and then these binarization thresholds can be used for The infrared images of the bill images are binarized respectively, so that a series of second binary images can be obtained. For example, 10 different binarization thresholds are preset, such as 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, and then these 10 different The infrared images are binarized separately, so that a series of second binary images can be obtained.
本发明的一个可选实施例中,所述步骤202可以包括以下子步骤:In an optional embodiment of the present invention, the
子步骤S21,采用所述目标二值图执行所述针对所述多个字符的轮廓生成外接矩形步骤。Sub-step S21, using the target binary image to perform the step of generating a circumscribed rectangle for the outlines of the plurality of characters.
在本发明实施中,在获得多个第二二值图后,可以按照像素值从大到小的顺序,从多个第二二值图中选取一个第二二值图作为目标二值图,然后可以采用目标二值图执行针对多个字符的轮廓生成外接矩形步骤。例如,可以将最大的像素值(比如200)对应的第二二值图作为目标二值图,在后续找不到符合条件的目标外接矩形或目标上下边界或目标左右边界时,可以返回到此步骤,再将最二大的像素值(比如198)对应的第二二值图作为目标二值图,然后采用目标二值图执行针对多个字符的轮廓生成外接矩形步骤……以此类推,直至找到符合条件的目标外接矩形、目标上下边界、目标左右边界。In the implementation of the present invention, after obtaining multiple second binary images, one second binary image may be selected from the multiple second binary images as the target binary image according to the order of pixel values from large to small. The step of generating a circumscribed rectangle for the contours of multiple characters can then be performed using the target binary image. For example, the second binary image corresponding to the largest pixel value (such as 200) can be used as the target binary image, and when no suitable target circumscribed rectangle or target upper and lower boundaries or target left and right boundaries can be found subsequently, you can return to this Step, then use the second binary image corresponding to the second largest pixel value (such as 198) as the target binary image, and then use the target binary image to perform the step of generating a circumscribed rectangle for the contours of multiple characters... and so on, Until the qualified target circumscribed rectangle, target upper and lower boundaries, and target left and right boundaries are found.
本发明的一个可选实施例中,所述步骤202可以包括以下子步骤:In an optional embodiment of the present invention, the
子步骤S31,确定所述多个字符的外接矩形的高度;Sub-step S31, determining the height of the circumscribed rectangle of the plurality of characters;
子步骤S32,将高度位于第一预设范围内的外接矩形确定为目标外接矩形。Sub-step S32, a circumscribing rectangle whose height is within the first preset range is determined as the target circumscribing rectangle.
在本发明实施中,可以预先设置第一预设范围,在针对各个字符进行轮廓查找之后,可以得到多个外接矩形,参见图6中的a~g的外接矩形,然后可以采用第一预设范围,从多个字符的外接矩形中确定目标外接矩形。具体地,可以先确定各个外接矩形的高度,当外接矩形的高度位于第一预设范围时,可以将该外接矩形确定为目标外接矩形,参见图6中的b~e的目标外接矩形;当外接矩形的高度不位于第一预设范围时,说明该外接矩形过大或者过小,比如噪点a、g的外接矩形以及横线f的外接矩形,可以将这些外接矩形进行过滤。In the implementation of the present invention, the first preset range can be preset, and after the outline search is performed for each character, a plurality of circumscribed rectangles can be obtained, see the circumscribed rectangles a to g in FIG. 6 , and then the first preset can be used. The range determines the target bounding rectangle from the bounding rectangles of multiple characters. Specifically, the height of each circumscribed rectangle may be determined first, and when the height of the circumscribed rectangle is within the first preset range, the circumscribed rectangle may be determined as the target circumscribed rectangle, see the target circumscribed rectangles of b to e in FIG. 6 ; when When the height of the circumscribed rectangle is not within the first preset range, it means that the circumscribed rectangle is too large or too small, such as the circumscribed rectangle of noise points a and g and the circumscribed rectangle of horizontal line f, these circumscribed rectangles can be filtered.
步骤203,针对所述目标外接矩形进行水平投影和垂直投影,获得所述打印字符的边界,并将所述边界形成的区域确定为所述票据图像的目标待识别区域。Step 203: Perform horizontal projection and vertical projection on the target circumscribed rectangle to obtain the boundary of the printed character, and determine the area formed by the boundary as the target area to be recognized of the bill image.
在本发明实施例中,水平投影可以用于查找打印字符的上边界和下边界,垂直投影可以用于查找打印字符的左边界和右边界,通过针对目标外接矩形进行水平投影和垂直投影,可以获得打印字符的上边界、下边界、左边界和右边界,从而可以将上边界、下边界、左边界和右边界所形成的区域,确定为票据图像的目标待识别区域。In this embodiment of the present invention, horizontal projection can be used to find the upper and lower boundaries of printed characters, and vertical projection can be used to find the left and right boundaries of printed characters. By performing horizontal projection and vertical projection on the target circumscribed rectangle, you can The upper boundary, lower boundary, left boundary and right boundary of the printed characters are obtained, so that the area formed by the upper boundary, lower boundary, left boundary and right boundary can be determined as the target area to be recognized of the bill image.
本发明的一个可选实施例中,所述步骤203可以包括以下子步骤:In an optional embodiment of the present invention, the
子步骤S41,基于水平投影,遍历所述目标外接矩形的每一行,确定多对上下边界;Sub-step S41, based on the horizontal projection, traverse each row of the target circumscribed rectangle, and determine multiple pairs of upper and lower boundaries;
子步骤S42,从所述多对上下边界中确定目标上下边界;Sub-step S42, determine target upper and lower boundaries from the multiple pairs of upper and lower boundaries;
子步骤S43,基于垂直投影,遍历所述目标上下边界之间的每一列,确定多对左右边界;Sub-step S43, based on vertical projection, traverse each column between the upper and lower boundaries of the target, and determine multiple pairs of left and right boundaries;
子步骤S44,从所述多对左右边界中确定目标左右边界。In sub-step S44, the left and right boundaries of the target are determined from the pairs of left and right boundaries.
在具体实现中,在目标外接矩形中,可以通过水平投影,从上到下遍历每一行,当遍历到某一行存在白色像素点时,可以将该行记录为打印字符的起始行,继续遍历,当遍历到某一行不存在白色像素点时,可以将该行的上一行记录为打印字符的结束行,然后可以将起始行和结束行确定为一对上下边界,然后可以从多对上下边界中确定目标上下边界。In the specific implementation, in the target circumscribed rectangle, each line can be traversed from top to bottom through horizontal projection. When there are white pixels in a line, the line can be recorded as the starting line of the printed characters, and the traversal can continue. , when there is no white pixel in a line, the previous line of the line can be recorded as the end line of the printed character, and then the start line and the end line can be determined as a pair of upper and lower boundaries, and then multiple pairs of upper and lower boundaries can be determined. The upper and lower boundaries of the target are determined in the boundary.
在具体实现中,在查找到目标上下边界后,可以先对目标上下边界以外的区域的像素点的像素值进行清零,以排除干扰。在目标上下边界中,可以通过垂直投影,从左到右遍历每一列,当遍历到某一列存在白色像素点时,可以将该列记录为打印字符的起始列,继续遍历,当遍历到某一列不存在白色像素点时,可以将该列的前一列记录为打印字符的结束列,然后可以将起始列和结束列确定为一对左右边界,然后可以从多对左右边界中确定目标左右边界。In a specific implementation, after finding the upper and lower boundaries of the target, the pixel values of the pixel points in the areas other than the upper and lower boundaries of the target may be cleared to eliminate interference. In the upper and lower boundaries of the target, each column can be traversed from left to right through vertical projection. When there are white pixels in a column, the column can be recorded as the starting column of the printed characters, and the traversal can continue. When there is no white pixel in a column, the previous column of the column can be recorded as the end column of the printed characters, then the start column and the end column can be determined as a pair of left and right boundaries, and then the target left and right boundaries can be determined from multiple pairs of left and right boundaries boundary.
本发明的一个可选实施例中,所述子步骤S42可以包括以下子步骤:In an optional embodiment of the present invention, the sub-step S42 may include the following sub-steps:
子步骤S421,确定每一对上下边界的高度;Sub-step S421, determine the height of each pair of upper and lower boundaries;
子步骤S422,将高度位于第二预设范围内的上下边界确定为目标上下边界;Sub-step S422, the upper and lower boundaries whose heights are located within the second preset range are determined as the upper and lower boundaries of the target;
在具体实现中,可以预先设置第二预设范围,在针对各个目标外接矩形进行水平投影之后,可以得到多对上下边界,然后可以采用第二预设范围,从多对上下边界中确定目标上下边界。具体地,可以先确定每一对上下边界的高度,当上下边界的高度位于第二预设范围时,可以将上下边界确定为目标上下边界;当上下边界的高度不位于第二预设范围时,说明上下边界之间的距离过大或者过小,这些都不符合打印字符的高度,可以将这些上下边界进行过滤。In a specific implementation, a second preset range can be preset, and after horizontal projection of each target circumscribed rectangle, multiple pairs of upper and lower boundaries can be obtained, and then the second preset range can be used to determine the upper and lower boundaries of the target from the multiple pairs of upper and lower boundaries. boundary. Specifically, the height of each pair of upper and lower boundaries may be determined first, and when the heights of the upper and lower boundaries are within the second preset range, the upper and lower boundaries may be determined as the target upper and lower boundaries; when the heights of the upper and lower boundaries are not within the second preset range , indicating that the distance between the upper and lower boundaries is too large or too small, which do not meet the height of the printed characters, and these upper and lower boundaries can be filtered.
本发明的一个可选实施例中,所述子步骤S44可以包括以下子步骤:In an optional embodiment of the present invention, the sub-step S44 may include the following sub-steps:
子步骤S441,确定每一对左右边界的宽度;Sub-step S441, determine the width of each pair of left and right borders;
子步骤S442,将宽度位于第三预设范围内的左右边界确定为目标左右边界。In sub-step S442, the left and right boundaries whose widths are within the third preset range are determined as the target left and right boundaries.
在具体实现中,可以预先设置第三预设范围,在针对各对目标上下边界进行垂直投影之后,可以得到多对左右边界,然后可以采用第三预设范围,从多对左右边界中确定目标左右边界。具体地,可以先确定每一对左右边界的宽度,当左右边界的宽度位于第三预设范围时,可以将左右边界确定为目标左右边界;当左右边界的宽度不位于第三预设范围时,说明左右边界之间的距离过大或者过小,这些都不符合打印字符的宽度,那么可以从多个第二二值图中选取下一个第二二值图作为目标二值图,重新执行针对多个字符的轮廓生成外接矩形步骤。In specific implementation, a third preset range can be preset, and after vertical projection of the upper and lower boundaries of each pair of targets, multiple pairs of left and right boundaries can be obtained, and then the third preset range can be used to determine the target from the multiple pairs of left and right boundaries. left and right borders. Specifically, the width of each pair of left and right borders may be determined first, and when the width of the left and right borders is within the third preset range, the left and right borders may be determined as the target left and right borders; when the width of the left and right borders is not within the third preset range , indicating that the distance between the left and right boundaries is too large or too small, which do not meet the width of the printed characters, then you can select the next second binary image from multiple second binary images as the target binary image, and execute again The step of generating a circumscribed rectangle for the outlines of multiple characters.
本发明的一个可选实施例中,所述方法还可以包括:In an optional embodiment of the present invention, the method may further include:
当不存在所述目标外接矩形,或所述目标上下边界,或所述目标左右边界时,按照像素值从大到小的顺序,从所述多个第二二值图中选取下一个第二二值图作为目标二值图。When the target circumscribing rectangle, or the upper and lower boundaries of the target, or the left and right boundaries of the target does not exist, select the next second binary image from the plurality of second binary images in descending order of pixel values. The binary image is used as the target binary image.
在具体实现中,当没有查找到符合条件的目标外接矩形时,或者,当没有查找到符合条件的目标上下边界时,或者,当没有查找到符合条件的目标左右边界时,那么可以按照像素值从大到小的顺序,从多个第二二值图中选取下一个第二二值图作为目标二值图,采用目标二值图重新执行针对多个字符的轮廓生成外接矩形步骤,直至查找到符合条件的目标外接矩形、目标上下边界和目标左右边界,从而可以获得精细的目标待识别区域。In the specific implementation, when no qualified target circumscribed rectangle is found, or when no qualified target upper and lower boundaries are found, or when no qualified target left and right boundaries are found, then the pixel value can be used according to the pixel value. From large to small, select the next second binary image from multiple second binary images as the target binary image, and use the target binary image to re-execute the step of generating circumscribed rectangles for the contours of multiple characters until the search is performed. To the qualified target circumscribed rectangle, target upper and lower boundaries and target left and right boundaries, so as to obtain a fine target area to be recognized.
本发明的一个可选实施例中,所述步骤203可以包括以下子步骤:In an optional embodiment of the present invention, the
子步骤S51,将所述目标上下边界和所述目标左右边界形成的区域,确定为所述票据图像的目标待识别区域。Sub-step S51, the area formed by the upper and lower boundaries of the target and the left and right boundaries of the target is determined as the target area to be recognized in the bill image.
在本发明实施例中,在获得目标上下边界和目标左右边界后,可以将目标上下边界和目标左右边界形成的区域,确定为票据图像的目标待识别区域。参见图7A~图7C,示出了本发明实施例提供的效果展示图,其中,图7A与图1A对应,图7B与图1B对应,图7C与图4对应,而图1A~图1B显示的是现有技术中截取的待识别区域。由此可见,相比现有技术中截取的待识别区域A1~A3、B1~B3,本发明实施例中截取的目标待识别区域A1’~A3’、B1’~B3’更为精细,另外,相比本发明实施例最初截取的初始待识别区域C1~C3,本发明实施例最终截取的目标待识别区域C1’~C3’也更为精细。In the embodiment of the present invention, after obtaining the upper and lower boundaries of the target and the left and right boundaries of the target, the area formed by the upper and lower boundaries of the target and the left and right boundaries of the target may be determined as the target area to be recognized of the bill image. Referring to FIGS. 7A to 7C , the effect display diagrams provided by the embodiments of the present invention are shown, wherein, FIG. 7A corresponds to FIG. 1A , FIG. 7B corresponds to FIG. 1B , FIG. 7C corresponds to FIG. 4 , and FIGS. 1A to 1B show is the to-be-identified area intercepted in the prior art. It can be seen that, compared with the to-be-identified areas A1-A3 and B1-B3 intercepted in the prior art, the target to-be-identified areas A1' to A3' and B1' to B3' intercepted in the embodiment of the present invention are more refined. , compared with the initial to-be-identified regions C1 to C3 that are initially intercepted by the embodiment of the present invention, the target to-be-identified regions C1 ′ to C3 ′ finally intercepted by the embodiment of the present invention are also more refined.
步骤204,针对所述目标待识别区域的打印字符进行识别。Step 204: Recognize the printed characters in the target area to be recognized.
在本发明实施例中,票据设备可以包括OCR模块,在获得目标待识别区域后,由于目标待识别区域内不仅涵盖完整的打印字符,还排除横线、油墨、背景纹理等无关因素的干扰,因此,可以采用OCR模块,针对目标待识别区域的打印字符进行识别,从而可以解决因打印设备、操作不规范导致待识别区域截取出错的问题,提高OCR识别的准确率,提升算法执行的效率,而且本发明实施例可以适用于各种票据的图像识别,具有很强的通用性和稳定性。In the embodiment of the present invention, the ticket device may include an OCR module. After the target area to be recognized is obtained, since the target area to be recognized not only covers complete printed characters, but also excludes the interference of irrelevant factors such as horizontal lines, ink, and background textures. Therefore, the OCR module can be used to identify the printed characters in the target area to be recognized, so as to solve the problem that the area to be recognized is intercepted due to non-standard printing equipment and operations, improve the accuracy of OCR recognition, and improve the efficiency of algorithm execution. Moreover, the embodiments of the present invention can be applied to image recognition of various bills, and have strong versatility and stability.
在本发明实施例中,首先调用预设模板,将预设模板与票据图像进行匹配,获得票据图像的初始待识别区域,其中,初始待识别区域包括多个字符,当确定多个字符包括打印字符时,针对多个字符的轮廓生成外接矩形,然后从多个字符的外接矩形中确定目标外接矩形,针对目标外接矩形进行水平投影和垂直投影,获得打印字符的边界,再将边界形成的区域确定为票据图像的目标待识别区域,最后针对目标待识别区域的打印字符进行识别。本发明实施例适用于各种票据的图像识别,具有很强的通用性和稳定性,可以解决因打印设备、操作不规范导致待识别区域截取出错的问题,提高OCR识别的准确率,提升算法执行的效率。In the embodiment of the present invention, a preset template is called first, and the preset template is matched with the bill image to obtain the initial to-be-recognized area of the bill image, wherein the initial to-be-recognized area includes a plurality of characters. For characters, a circumscribed rectangle is generated for the outlines of multiple characters, and then the target circumscribed rectangle is determined from the circumscribed rectangles of multiple characters. It is determined as the target area to be recognized of the bill image, and finally the printed characters in the target area to be recognized are recognized. The embodiment of the present invention is suitable for image recognition of various bills, has strong versatility and stability, can solve the problem of incorrectly intercepted areas to be recognized due to non-standard printing equipment and operations, improve the accuracy of OCR recognition, and improve the algorithm efficiency of execution.
为了使本领域技术人员能够更好地了解本发明实施例,参见图8,示出了本发明实施例提供的票据图像识别流程框图,结合以下示例具体说明票据图像识别过程:In order to enable those skilled in the art to better understand the embodiment of the present invention, referring to FIG. 8 , a flow chart of the receipt image recognition provided by the embodiment of the present invention is shown, and the receipt image recognition process is described in detail with the following examples:
步骤801,获取票据图像;票据图像包括多个印刷字符;
步骤802,按照预设顺序,依次调用多个预设模板;每个预设模板包括一个或多个预设字符;
步骤803,将预设模板与票据图像进行匹配;
步骤804,判断是否存在与印刷字符匹配的目标预设字符;
步骤805,若存在,则将目标预设字符的位置确定为印刷字符的位置,并将印刷字符的位置进行偏移,获得打印初始待识别位置,然后根据打印初始待识别位置,生成打印初始待识别区域;若不存在,则返回到步骤802;
步骤806,分别将票据图像设置为红外图和不同颜色通道的白光图,针对红外图和不同颜色通道的白光图进行二值化,获得多个第一二值图;
步骤807,采用多个第一二值图,判断初始待识别区域是否存在打印字符;
步骤808,若存在,则获取多个像素值递减的二值化阈值,并将票据图像设置为红外图,采用多个像素值递减的二值化阈值,针对红外图进行二值化,获得多个第二二值图;若不存在,则返回到步骤806;Step 808: If there is, obtain multiple binarization thresholds with decreasing pixel values, set the bill image as an infrared image, and use multiple binarization thresholds with decreasing pixel values to binarize the infrared image to obtain multiple thresholds. the second binary image; if it does not exist, return to step 806;
步骤809,按照像素值从大到小的顺序,从多个第二二值图中选取目标二值图;
步骤810,采用目标二值图进行轮廓查找,针对初始待识别区域内的多个字符的轮廓,生成多个字符的外接矩形;
步骤811,从多个字符的外接矩形中,判断是否存在满足第一预设范围的目标外接矩形;
步骤812,若存在,则针对目标外接矩形进行水平投影,生成多对上下边界;若不存在,则返回到步骤809;
步骤813,从多对上下边界中,判断是否存在满足第二预设范围的目标上下边界;
步骤814,若存在,则针对目标上下边界进行垂直投影,生成多对左右边界;若不存在,则返回到步骤809;
步骤815,从多对左右边界中,判断是否存在满足第三预设范围的目标左右边界;
步骤816,若存在,则将目标上下边界和目标左右边界所形成的区域,确定为目标待识别区域;若不存在,则返回到步骤809;
步骤817,针对目标待识别区域的打印字符进行识别。Step 817: Recognize the printed characters in the target area to be recognized.
参照图9,示出了本发明实施例中提供的一种票据图像识别装置的结构框图,具体可以包括如下模块:Referring to FIG. 9 , a structural block diagram of a bill image recognition device provided in an embodiment of the present invention is shown, which may specifically include the following modules:
初始待识别区域获得模块901,用于调用预设模板,并将所述预设模板与所述票据图像进行匹配,获得所述票据图像的初始待识别区域;所述初始待识别区域包括多个字符;The initial to-be-recognized area obtaining module 901 is used to call a preset template and match the preset template with the bill image to obtain the initial to-be-identified area of the bill image; the initial to-be-identified area includes multiple character;
目标外接矩形确定模块902,用于当确定所述多个字符包括打印字符时,针对所述多个字符的轮廓生成外接矩形,并从所述多个字符的外接矩形中确定目标外接矩形;A target circumscribed rectangle determination module 902, configured to generate a circumscribed rectangle for the outlines of the plurality of characters when it is determined that the plurality of characters include printed characters, and determine a target circumscribed rectangle from the circumscribed rectangles of the plurality of characters;
目标待识别区域确定模块903,用于针对所述目标外接矩形进行水平投影和垂直投影,获得所述打印字符的边界,并将所述边界形成的区域确定为所述票据图像的目标待识别区域;The target to-be-recognized area determination module 903 is used to perform horizontal projection and vertical projection for the target circumscribed rectangle, obtain the boundary of the printed character, and determine the area formed by the boundary as the target to-be-recognized area of the bill image ;
识别模块904,用于针对所述目标待识别区域的打印字符进行识别。The recognition module 904 is configured to recognize the printed characters of the target area to be recognized.
本发明的一个可选实施例中,所述票据图像包括印刷字符,所述预设模板包括预设字符,所述初始待识别区域获得模块901可以包括:In an optional embodiment of the present invention, the ticket image includes printed characters, the preset template includes preset characters, and the initial to-be-recognized area obtaining module 901 may include:
匹配子模块,用于确定与所述印刷字符匹配的目标预设字符;a matching submodule for determining a target preset character that matches the printed character;
位置确定子模块,用于将所述目标预设字符的位置,确定为所述印刷字符的位置;a position determination submodule, for determining the position of the target preset character as the position of the printed character;
偏移子模块,用于将所述印刷字符的位置进行偏移,获得初始待识别位置;an offset submodule for offsetting the position of the printed character to obtain an initial position to be recognized;
初始待识别区域生成子模块,用于根据所述初始待识别位置,生成所述票据图像的初始待识别区域。The initial to-be-recognized area generating sub-module is configured to generate the initial to-be-recognized area of the bill image according to the initial to-be-recognized position.
本发明的一个可选实施例中,所述装置还可以包括:In an optional embodiment of the present invention, the apparatus may further include:
第一二值图获得模块,用于在不同光源和不同颜色通道下,对所述票据图像进行二值化,获得多个第一二值图;a first binary image obtaining module, used for binarizing the bill image under different light sources and different color channels to obtain a plurality of first binary images;
像素点数量统计模块,用于分别针对所述多个第一二值图,统计所述初始待识别区域的每一行的具有目标像素值的像素点数量;a pixel number statistics module, configured to count the number of pixels with target pixel values in each row of the initial to-be-identified region for the plurality of first binary images respectively;
有效行确定模块,用于若所述像素点数量大于第一数量阈值,则将所述像素点数量所在的行确定为有效行;a valid row determination module, configured to determine the row where the number of pixels is located as a valid row if the number of pixels is greater than the first number threshold;
行数量确定模块,用于确定连续的有效行的行数量;The row quantity determination module is used to determine the row quantity of consecutive valid rows;
第一打印字符确定模块,用于若所述行数量大于第二数量阈值,则确定所述多个字符包括打印字符;a first print character determination module, configured to determine that the plurality of characters include print characters if the number of lines is greater than a second number threshold;
第二打印字符确定模块,用于若所述行数量不大于第二数量阈值,则确定所述多个字符不包括打印字符。A second print character determination module, configured to determine that the plurality of characters do not include print characters if the number of lines is not greater than a second number threshold.
本发明的一个可选实施例中,所述装置还可以包括:In an optional embodiment of the present invention, the apparatus may further include:
二值化阈值获取模块,用于获取多个像素值递减的二值化阈值;The binarization threshold obtaining module is used to obtain the binarization thresholds with decreasing pixel values;
第二二值图获得模块,用于采用所述多个像素值递减的二值化阈值,分别对所述票据图像进行二值化,获得多个第二二值图;A second binary image obtaining module, configured to binarize the bill image respectively by using the plurality of binarization thresholds with decreasing pixel values to obtain a plurality of second binary images;
第一目标二值图选取模块,用于按照像素值从大到小的顺序,从所述多个第二二值图中选取一个第二二值图作为目标二值图;The first target binary image selection module is used to select a second binary image from the plurality of second binary images as the target binary image according to the order of pixel values from large to small;
所述目标外接矩形确定模块902可以包括:The target circumscribed rectangle determination module 902 may include:
外接矩形生成子模块,用于采用所述目标二值图执行所述针对所述多个字符的轮廓生成外接矩形步骤。The circumscribing rectangle generating submodule is configured to use the target binary image to perform the step of generating a circumscribing rectangle for the outlines of the plurality of characters.
本发明的一个可选实施例中,所述目标外接矩形确定模块902可以包括:In an optional embodiment of the present invention, the target circumscribed rectangle determination module 902 may include:
外接矩形的高度确定子模块,用于确定所述多个字符的外接矩形的高度;a submodule for determining the height of the circumscribed rectangle, for determining the height of the circumscribed rectangle of the plurality of characters;
目标外接矩形确定子模块,用于将高度位于第一预设范围内的外接矩形确定为目标外接矩形。The target circumscribing rectangle determining submodule is used for determining the circumscribing rectangle whose height is within the first preset range as the target circumscribing rectangle.
本发明的一个可选实施例中,所述目标待识别区域确定模块903可以包括:In an optional embodiment of the present invention, the target to-be-identified area determination module 903 may include:
第一遍历子模块,用于基于水平投影,遍历所述目标外接矩形的每一行,确定多对上下边界;The first traversal submodule is used to traverse each row of the target circumscribed rectangle based on the horizontal projection, and determine multiple pairs of upper and lower boundaries;
目标上下边界确定子模块,用于从所述多对上下边界中确定目标上下边界;a target upper and lower boundary determination submodule, for determining the target upper and lower boundaries from the multiple pairs of upper and lower boundaries;
第二遍历子模块,用于基于垂直投影,遍历所述目标上下边界之间的每一列,确定多对左右边界;The second traversal submodule is used to traverse each column between the upper and lower boundaries of the target based on the vertical projection, and determine multiple pairs of left and right boundaries;
目标左右边界确定子模块,用于从所述多对左右边界中确定目标左右边界;a target left and right boundary determination submodule, configured to determine the target left and right boundaries from the plurality of pairs of left and right boundaries;
所述目标待识别区域确定模块903可以包括:The target to-be-identified area determination module 903 may include:
目标待识别区域确定子模块,用于将所述目标上下边界和所述目标左右边界形成的区域,确定为所述票据图像的目标待识别区域。The target to-be-recognized area determination sub-module is used to determine the area formed by the upper and lower boundaries of the target and the left and right boundaries of the target as the target area to be recognized of the bill image.
本发明的一个可选实施例中,所述目标左右边界确定子模块可以包括:In an optional embodiment of the present invention, the target left and right boundary determination submodule may include:
上下边界的高度确定单元,用于确定每一对上下边界的高度;The height determination unit of the upper and lower boundaries is used to determine the height of each pair of upper and lower boundaries;
目标上下边界确定单元,用于将高度位于第二预设范围内的上下边界确定为目标上下边界;a target upper and lower boundary determining unit, configured to determine the upper and lower boundaries whose height is within the second preset range as the target upper and lower boundaries;
所述目标左右边界确定子模块可以包括:The target left and right boundary determination submodule may include:
左右边界的宽度确定单元,用于第一高度确定子模块,用于确定每一对左右边界的宽度;a width determination unit for the left and right borders, used for the first height determination submodule, for determining the width of each pair of left and right borders;
目标左右边界确定单元,用于将宽度位于第三预设范围内的左右边界确定为目标左右边界。The target left and right boundary determination unit is configured to determine the left and right boundaries whose width is within the third preset range as the target left and right boundaries.
本发明的一个可选实施例中,所述装置还可以包括:In an optional embodiment of the present invention, the apparatus may further include:
第二目标二值图选取模块,用于当不存在所述目标外接矩形,或所述目标上下边界,或所述目标左右边界时,按照像素值从大到小的顺序,从所述多个第二二值图中选取下一个第二二值图作为目标二值图。The second target binary image selection module is configured to, when there is no circumscribing rectangle of the target, or the upper and lower boundaries of the target, or the left and right boundaries of the target, select from the plurality of pixel values in descending order of pixel values. In the second binary image, the next second binary image is selected as the target binary image.
在本发明实施例中,首先调用预设模板,将预设模板与票据图像进行匹配,获得票据图像的初始待识别区域,其中,初始待识别区域包括多个字符,当确定多个字符包括打印字符时,针对多个字符的轮廓生成外接矩形,然后从多个字符的外接矩形中确定目标外接矩形,针对目标外接矩形进行水平投影和垂直投影,获得打印字符的边界,再将边界形成的区域确定为票据图像的目标待识别区域,最后针对目标待识别区域的打印字符进行识别。本发明实施例适用于各种票据的图像识别,具有很强的通用性和稳定性,可以解决因打印设备、操作不规范导致待识别区域截取出错的问题,提高OCR识别的准确率,提升算法执行的效率。In the embodiment of the present invention, a preset template is called first, and the preset template is matched with the bill image to obtain the initial to-be-recognized area of the bill image, wherein the initial to-be-recognized area includes multiple characters, and when it is determined that the multiple characters include printing For characters, a circumscribed rectangle is generated for the outlines of multiple characters, and then the target circumscribed rectangle is determined from the circumscribed rectangles of multiple characters. It is determined as the target area to be recognized of the bill image, and finally the printed characters in the target area to be recognized are recognized. The embodiment of the present invention is suitable for image recognition of various bills, has strong versatility and stability, can solve the problem of incorrectly intercepted areas to be recognized due to non-standard printing equipment and operations, improve the accuracy of OCR recognition, and improve the algorithm efficiency of execution.
对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。As for the apparatus embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and reference may be made to the partial description of the method embodiment for related parts.
优选的,本发明实施例还提供了一种电子设备,包括:处理器,存储器,存储在存储器上并可在处理器上运行的计算机程序,该计算机程序被处理器执行时实现上述票据图像识别方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。Preferably, an embodiment of the present invention further provides an electronic device, comprising: a processor, a memory, a computer program stored in the memory and running on the processor, the computer program being executed by the processor to realize the above-mentioned ticket image recognition Each process of the method embodiment can achieve the same technical effect, and in order to avoid repetition, it will not be repeated here.
本发明实施例还提供了一种计算机可读存储介质,计算机可读存储介质上存储有计算机程序,计算机程序被处理器执行时实现上述票据图像识别方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。其中,所述的计算机可读存储介质,如只读存储器(Read-Only Memory,简称ROM)、随机存取存储器(Random Access Memory,简称RAM)、磁碟或者光盘等。Embodiments of the present invention further provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, each process of the above embodiment of the method for recognizing a bill image can be achieved, and can achieve the same The technical effect, in order to avoid repetition, will not be repeated here. The computer-readable storage medium is, for example, a read-only memory (Read-Only Memory, ROM for short), a random access memory (Random Access Memory, RAM for short), a magnetic disk, or an optical disk.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。It should be noted that, herein, the terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements, It also includes other elements not expressly listed or inherent to such a process, method, article or apparatus. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in a process, method, article or apparatus that includes the element.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本发明各个实施例所述的方法。From the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general hardware platform, and of course hardware can also be used, but in many cases the former is better implementation. Based on this understanding, the technical solutions of the present invention can be embodied in the form of software products in essence or the parts that make contributions to the prior art, and the computer software products are stored in a storage medium (such as ROM/RAM, magnetic disk, CD-ROM), including several instructions to make a terminal (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) execute the methods described in the various embodiments of the present invention.
上面结合附图对本发明的实施例进行了描述,但是本发明并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本发明的启示下,在不脱离本发明宗旨和权利要求所保护的范围情况下,还可做出很多形式,均属于本发明的保护之内。The embodiments of the present invention have been described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific embodiments, which are merely illustrative rather than restrictive. Under the inspiration of the present invention, without departing from the spirit of the present invention and the scope protected by the claims, many forms can be made, which all belong to the protection of the present invention.
本领域普通技术人员可以意识到,结合本发明实施例中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。Those skilled in the art can realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of the present invention can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may implement the described functionality using different methods for each particular application, but such implementations should not be considered beyond the scope of the present invention.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system, device and unit described above may refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.
在本申请所提供的实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。The functions, if implemented in the form of software functional units and sold or used as independent products, may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present invention can be embodied in the form of a software product in essence, or the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including Several instructions are used to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: a U disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk, and other media that can store program codes.
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求的保护范围为准。The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention. should be included within the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.
Claims (11)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210320570.3A CN114743207A (en) | 2022-03-29 | 2022-03-29 | A kind of bill image recognition method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210320570.3A CN114743207A (en) | 2022-03-29 | 2022-03-29 | A kind of bill image recognition method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114743207A true CN114743207A (en) | 2022-07-12 |
Family
ID=82277876
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210320570.3A Pending CN114743207A (en) | 2022-03-29 | 2022-03-29 | A kind of bill image recognition method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114743207A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115050015A (en) * | 2022-08-15 | 2022-09-13 | 恒银金融科技股份有限公司 | Method for accurately dividing character area of financial bill account |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH07114619A (en) * | 1993-10-20 | 1995-05-02 | Hitachi Ltd | Document recognition device |
JP2004013548A (en) * | 2002-06-07 | 2004-01-15 | Hitachi Ltd | Character string recognition device and its program |
JP2005011163A (en) * | 2003-06-20 | 2005-01-13 | Toshiba Corp | Form handling device |
CN113627423A (en) * | 2021-07-08 | 2021-11-09 | 广州广电运通金融电子股份有限公司 | Circular seal character recognition method and device, computer equipment and storage medium |
-
2022
- 2022-03-29 CN CN202210320570.3A patent/CN114743207A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPH07114619A (en) * | 1993-10-20 | 1995-05-02 | Hitachi Ltd | Document recognition device |
JP2004013548A (en) * | 2002-06-07 | 2004-01-15 | Hitachi Ltd | Character string recognition device and its program |
JP2005011163A (en) * | 2003-06-20 | 2005-01-13 | Toshiba Corp | Form handling device |
CN113627423A (en) * | 2021-07-08 | 2021-11-09 | 广州广电运通金融电子股份有限公司 | Circular seal character recognition method and device, computer equipment and storage medium |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115050015A (en) * | 2022-08-15 | 2022-09-13 | 恒银金融科技股份有限公司 | Method for accurately dividing character area of financial bill account |
CN115050015B (en) * | 2022-08-15 | 2023-09-12 | 恒银金融科技股份有限公司 | Accurate segmentation method for character area of financial bill account |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11694462B1 (en) | Character count determination for a digital image | |
US7684646B2 (en) | System and method of determining image skew using connected components | |
CN108830133B (en) | Contract image picture identification method, electronic device and readable storage medium | |
EP2682901A1 (en) | Text string cut-out method and text string cut-out device | |
WO2014005456A1 (en) | Paper character recognition method and related device | |
CN112906695B (en) | Form recognition method adapting to multi-class OCR recognition interface and related equipment | |
US8027539B2 (en) | Method and apparatus for determining an orientation of a document including Korean characters | |
CN105631449B (en) | A kind of picture segmentation method, device and equipment | |
CN111814780B (en) | Bill image processing method, device, equipment and storage medium | |
JP2002133426A (en) | Ruled line extraction device for extracting ruled lines from multi-valued images | |
CN103606220A (en) | Check printed number recognition system and check printed number recognition method based on white light image and infrared image | |
CN112419207A (en) | Image correction method, device and system | |
CN114743207A (en) | A kind of bill image recognition method and device | |
CN107358718B (en) | A kind of crown word number identification method, device, equipment and storage medium | |
CN115410191A (en) | Text image recognition method, device, equipment and storage medium | |
CN110321887B (en) | Document image processing method, document image processing apparatus, and storage medium | |
JPH09311905A (en) | Line detecting method and character recognition device | |
CN112016565B (en) | Segmentation method for fuzzy numbers at account number of financial bill | |
KR20090062115A (en) | Media image detection device and method, and media handling system using same | |
JP3086653B2 (en) | Character recognition method and character recognition device | |
JP2017174031A (en) | Image processing apparatus and image processing program | |
CN112183574A (en) | File authentication and comparison method and device, terminal and storage medium | |
JPH10207978A (en) | Pattern matching method and device for characters etc. | |
CN108961531B (en) | Method, device and equipment for identifying serial number of paper currency and storage medium | |
TWI854370B (en) | Profile information generation method, document checking method and system |
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 |