技术领域technical field
本发明涉及证件识别技术领域,尤其涉及基于图像匹配的证件号码识别方法。The invention relates to the technical field of document identification, in particular to a document number identification method based on image matching.
背景技术Background technique
某一国家某一类型证件(如身份证、驾驶证等),其证件号码的字体是确定的、一致的,基于此,可采用图像匹配的方式进行证件号码的识别;For a certain type of certificate (such as ID card, driver's license, etc.) in a certain country, the font of the certificate number is determined and consistent. Based on this, image matching can be used to identify the certificate number;
证件号码的识别属于光学字符识别技术范畴,常见的方法是人工提取图像特征,然后训练机器学习分类模型进行字符分类,如SVM、XGBOOST等,然后基于深度学习算法,使用卷积神经网络和循环神经网络提取特征,结合CTC或者注意力机制进行字符预测,如CRNN、SATRN等,无论是基于传统人工提取特征和基于深度学习技术,都需要大量标注数据进行模型的训练,并且模型文件往往很大;The recognition of certificate numbers belongs to the category of optical character recognition technology. The common method is to manually extract image features, and then train machine learning classification models for character classification, such as SVM, XGBOOST, etc., and then use convolutional neural networks and cyclic neural networks based on deep learning algorithms Network extraction features, combined with CTC or attention mechanism for character prediction, such as CRNN, SATRN, etc., whether based on traditional manual feature extraction or deep learning technology, require a large amount of labeled data for model training, and the model files are often large;
现有技术专利(CN201810736445.4,基于OpenCV的银行卡号识别方法)也采用模板匹配的方法进行号码识别,需要区分强光照、中光照、弱光照和光照不均匀四种情况,再使用膨胀腐蚀提取号码区域图像;通过列投影法进行字符分割,最后模板匹配得到字符文本,其缺点在于需要区分光照场景,并且膨胀腐蚀进行卡号区域的定位提取也很容易受到背景及光照影响;因此提出基于图像匹配的证件号码识别方法解决上述问题。The prior art patent (CN201810736445.4, bank card number recognition method based on OpenCV) also adopts the method of template matching for number recognition. It is necessary to distinguish four situations of strong light, medium light, weak light and uneven light, and then use expansion and corrosion to extract The image of the number area; the character segmentation is performed by the column projection method, and the character text is finally obtained by template matching. The certificate number identification method of the paper solves the above-mentioned problems.
发明内容Contents of the invention
本发明的目的是为了解决现有技术中无论是基于传统人工提取特征和基于深度学习技术,都需要大量标注数据进行模型的训练,并且模型文件往往很大的问题,而提出的基于图像匹配的证件号码识别方法。The purpose of the present invention is to solve the problem that a large amount of labeled data is required for model training in the prior art, whether it is based on traditional manual feature extraction or based on deep learning technology, and the model files are often very large, and the proposed image matching-based ID number identification method.
为了实现上述目的,本发明采用了如下技术方案:In order to achieve the above object, the present invention adopts the following technical solutions:
基于图像匹配的证件号码识别方法,包括如下步骤,The document number identification method based on image matching comprises the following steps,
S1、证件号码区域定位:使用预先训练的文本检测模型定位该图像所有文本坐标位置,根据文本坐标位置和文本条的宽高比筛选出证件号码区域图像;S1. ID number area positioning: Use the pre-trained text detection model to locate all the text coordinate positions of the image, and filter out the ID number area images according to the text coordinate positions and the aspect ratio of the text bar;
S2、字符分割:对证件号码区域图像进行灰度处理,然后二值化处理得到二值图,对二值图进行连通区域分析,将连通区域转换为边界框,基于这些边界框在二值图上分割出已经二值化处理后的单字符图像;S2. Character segmentation: perform grayscale processing on the image of the document number area, and then binarize to obtain a binary image, analyze the connected areas of the binary image, convert the connected area into a bounding box, and based on these bounding boxes in the binary image Segment the single-character image that has been binarized;
S3、创建证件号码单字符图像模板库:将证件号码文本图像分割成十个单字符图像,挑选字符集,对身份证中0-9十个字符,进行二值化处理,保存作为模板库;S3. Create a document number single-character image template library: divide the document number text image into ten single-character images, select a character set, perform binary processing on ten characters from 0 to 9 in the ID card, and save them as a template library;
S4、字符匹配:通过字符分割后得到多个单字符图像,模板库中字符按0到9进行排序,将每个字符图像都与模板库中的每个字符进行模板匹配,得到N行M列的匹配概率矩阵,在列方向计算最大概率值索引,根据该索引从模板库中可得到N个字符,即为证件号码的识别结果。S4. Character matching: multiple single-character images are obtained after character segmentation, the characters in the template library are sorted by 0 to 9, and each character image is template-matched with each character in the template library to obtain N rows and M columns The matching probability matrix, calculate the maximum probability value index in the column direction, according to the index, you can get N characters from the template library, which is the recognition result of the document number.
优选的,所述S3中证件号码的字符集是固定的,例如国内居民身份证证件号码字符集为0-9这十个数字,所述S3中的模板只需创建一次。Preferably, the character set of the document number in S3 is fixed, for example, the character set of the domestic resident ID card number is ten numbers from 0 to 9, and the template in S3 only needs to be created once.
优选的,所述S3中模板的创建是通过任何编程语言部署得到的,所述编程语言包括但不限于python软件。Preferably, the creation of the template in S3 is obtained through deployment of any programming language, and the programming language includes but not limited to python software.
优选的,所述S1中的文本检测模型是通过人工提取图像特征或者通过基于深度学习算法,使用卷积神经网络和循环神经网络提取特征实现的。Preferably, the text detection model in S1 is realized by manually extracting image features or extracting features based on deep learning algorithms using convolutional neural networks and cyclic neural networks.
优选的,所述S3中的字符分割是通过连通区域分析法实现的。Preferably, the character segmentation in S3 is realized by connected region analysis.
优选的,所述S2中宽和高小于10个像素的边界框被过滤掉,对于剩下的边界框,当一个边界框包含在另一个边界框里面,则将该边界框移除,最后留下的边界框就是各字符的位置。Preferably, bounding boxes whose width and height are less than 10 pixels in the S2 are filtered out, and for the remaining bounding boxes, when a bounding box is included in another bounding box, the bounding box is removed, and finally The bounding box below is the position of each character.
优选的,所述S4中N为证件号码长度,M为模板库中字符数量。Preferably, N in S4 is the length of the certificate number, and M is the number of characters in the template library.
相比现有技术,本发明的有益效果为:Compared with the prior art, the beneficial effects of the present invention are:
本发明旨在识别证件号码,不需要大量标注数据,不需要训练文本识别模型,不需要区分光照情况,因此扩展性更强,运行速度快;同时,使用连通区域分析法获得证件号码图像单字符所在位置,获得的边界框紧贴字符区域,使得裁剪出来的字符更加精准。The invention aims at identifying the certificate number, does not require a large amount of labeling data, does not need to train a text recognition model, and does not need to distinguish lighting conditions, so it has stronger scalability and fast operation speed; at the same time, it uses the connected region analysis method to obtain the single character of the certificate number image position, the obtained bounding box is close to the character area, making the cropped characters more accurate.
附图说明Description of drawings
图1为本发明提出的基于图像匹配的证件号码识别方法的流程结构框图;Fig. 1 is the flow chart of the document number recognition method based on image matching that the present invention proposes;
图2为本发明提出的基于图像匹配的证件号码识别方法中待检测证件号码图像二值化及分割示例图;Fig. 2 is the binarization and segmentation illustration of the document number image to be detected in the document number recognition method based on image matching proposed by the present invention;
图3为本发明提出的基于图像匹配的证件号码识别方法中证件号码模板库的示意图。Fig. 3 is a schematic diagram of a certificate number template library in the certificate number recognition method based on image matching proposed by the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例,基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some of the embodiments of the present invention, not all of them. Based on The embodiments of the present invention and all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
参照图1-3,基于图像匹配的证件号码识别方法,包括如下步骤,Referring to Figure 1-3, the document number recognition method based on image matching includes the following steps,
S1、证件号码区域定位:使用预先训练的文本检测模型定位该图像所有文本坐标位置,根据文本坐标位置和文本条的宽高比筛选出证件号码区域图像;S1. ID number area positioning: Use the pre-trained text detection model to locate all the text coordinate positions of the image, and filter out the ID number area images according to the text coordinate positions and the aspect ratio of the text bar;
S2、字符分割:对证件号码区域图像进行灰度处理,然后二值化处理得到二值图,对二值图进行连通区域分析,将连通区域转换为边界框,基于这些边界框在二值图上分割出已经二值化处理后的单字符图像;S2. Character segmentation: perform grayscale processing on the image of the document number area, and then binarize to obtain a binary image, analyze the connected areas of the binary image, convert the connected area into a bounding box, and based on these bounding boxes in the binary image Segment the single-character image that has been binarized;
S3、创建证件号码单字符图像模板库:将证件号码文本图像分割成十个单字符图像,挑选字符集,对身份证中0-9十个字符,进行二值化处理,保存作为模板库;S3. Create a document number single-character image template library: divide the document number text image into ten single-character images, select a character set, perform binary processing on ten characters from 0 to 9 in the ID card, and save them as a template library;
S4、字符匹配:通过字符分割后得到多个单字符图像,模板库中字符按0到9进行排序,将每个字符图像都与模板库中的每个字符进行模板匹配,得到N行M列的匹配概率矩阵,在列方向计算最大概率值索引,根据该索引从模板库中可得到N个字符,即为证件号码的识别结果。S4. Character matching: multiple single-character images are obtained after character segmentation, the characters in the template library are sorted by 0 to 9, and each character image is template-matched with each character in the template library to obtain N rows and M columns The matching probability matrix, calculate the maximum probability value index in the column direction, according to the index, you can get N characters from the template library, which is the recognition result of the document number.
S3中证件号码的字符集是固定的,例如国内居民身份证证件号码字符集为0-9这十个数字,所述S3中的模板只需创建一次。The character set of the document number in S3 is fixed. For example, the character set of the domestic resident ID card number is ten numbers from 0 to 9. The template in S3 only needs to be created once.
S3中模板的创建是通过任何编程语言部署得到的,编程语言包括但不限于python软件;The creation of templates in S3 is obtained through deployment of any programming language, including but not limited to python software;
值得注意的是,以python为例,依赖opencv图像处理算法库,操作步骤如下:It is worth noting that, taking python as an example, relying on the opencv image processing algorithm library, the operation steps are as follows:
首先,创建模板(如果已经创建过,则无需再创建),先从证件号码图像中裁剪单字符,挑选字符集,如身份证中0-9十个字符,进行二值化处理,保存作为模板库;然后,在检测阶段,先加载模板库,即第一步创建的十个二值化字符图像;其次,读入待检测图像,转换为二值图,分割出单个字符图像;再次,对于每个分割出来的单字符图像,都在模板库中进行模板匹配,模板库中的字符按照0到9进行排序,得到一系列匹配概率值,假设模板库字符集个数为M,证件号码长度为N,则得到N行M列的概率矩阵,在列方向计算最大概率值索引,根据该索引从模板库中可得到N个字符,即为证件号码的识别结果。First, create a template (if it has already been created, there is no need to create it again), first cut out a single character from the ID number image, select a character set, such as ten characters from 0-9 in the ID card, perform binarization processing, and save it as a template library; then, in the detection stage, first load the template library, that is, the ten binary character images created in the first step; secondly, read in the image to be detected, convert it into a binary image, and segment a single character image; again, for Each segmented single-character image is subjected to template matching in the template library. The characters in the template library are sorted from 0 to 9 to obtain a series of matching probability values. Assume that the number of character sets in the template library is M, and the length of the ID number is N, a probability matrix of N rows and M columns is obtained, and the index of the maximum probability value is calculated in the column direction, and N characters can be obtained from the template library according to the index, which is the recognition result of the document number.
S1中的文本检测模型是通过人工提取图像特征或者通过基于深度学习算法,使用卷积神经网络和循环神经网络提取特征实现的。The text detection model in S1 is realized by manually extracting image features or by using convolutional neural network and cyclic neural network to extract features based on deep learning algorithms.
S3中的字符分割是通过连通区域分析法实现的,连通区域分析法为该技术领域中的公知技术,在此不再赘述,使用连通区域分析法获得证件号码图像单字符所在位置,获得的边界框紧贴字符区域,使得裁剪出来的字符更加精准。The character segmentation in S3 is realized by the connected region analysis method, which is a well-known technology in this technical field, and will not be repeated here. Using the connected region analysis method to obtain the position of the single character of the document number image, the obtained boundary The frame is close to the character area, making the cropped characters more precise.
S2中宽和高小于10个像素的边界框被过滤掉,对于剩下的边界框,当一个边界框包含在另一个边界框里面,则将该边界框移除,最后留下的边界框就是各字符的位置。The bounding boxes whose width and height are less than 10 pixels in S2 are filtered out. For the remaining bounding boxes, when one bounding box is contained in another bounding box, the bounding box is removed, and the last bounding box left is The position of each character.
S4中N为证件号码长度,M为模板库中字符数量。In S4, N is the length of the certificate number, and M is the number of characters in the template library.
如图2所示为待检测证件号码图像二值化及分割示例(以印尼身份证件为例,印尼二代身份证号码16位),a为待检测证件号码图像,b为二值化处理后的结果,c为使用连通区域分析法及后处理得到各单字符位置,d为基于c定位结果在b上裁剪的单字符,e为基于c定位结果在a上裁剪的单字符。As shown in Figure 2, it is an example of binarization and segmentation of the image of the document number to be detected (taking the Indonesian ID card as an example, the Indonesian second-generation ID card number has 16 digits), a is the image of the document number to be detected, and b is the image after binarization c is the position of each single character obtained by using the connected region analysis method and post-processing, d is the single character cropped on b based on the positioning result of c, and e is the single character cropped on a based on the positioning result of c.
如图3所示为证件号码模板(以印尼身份证件为例),a为0-9十个单字符原图,b为0-9单字符对应的进行二值化处理后的模板图像。As shown in Figure 3, the document number template (taking the Indonesian ID card as an example), a is the original image of ten single characters from 0 to 9, and b is the template image after binary processing corresponding to the single characters from 0 to 9.
本发明在进行使用时,首先使用预先训练的文本检测模型定位该图像所有文本位置,根据文本坐标位置和文本条的宽高比筛选出证件号码区域图像,然后对证件号码图像进行灰度处理,然后二值化处理得到二值图,对二值图进行连通区域分析,将连通区域转换为边界框,将宽和高小于10个像素的边界框过滤掉,对于剩下的边界框,若一个框包含在另一个框里面,则将该框移除,最后留下的边界框就是各字符的位置,基于这些边界框在二值图上分割出已经二值化处理后的单字符图像,再者,将证件号码文本图像分割成十个单字符图像,挑选字符集,如身份证中0-9十个字符,进行二值化处理,保存作为模板库,最后,通过字符分割后得到多个单字符图像,模板库中字符按0到9进行排序,将每个字符图像都与模板库中的每个字符进行模板匹配,得到N行M列的匹配概率矩阵,其中N为证件号码长度,M为模板库中字符数量,在列方向计算最大概率值索引,根据该索引从模板库中可得到N个字符,即为证件号码的识别结果。When the present invention is in use, first use the pre-trained text detection model to locate all the text positions of the image, filter out the document number area image according to the text coordinate position and the aspect ratio of the text bar, and then perform grayscale processing on the document number image, Then binarize to obtain a binary image, analyze the connected region of the binary image, convert the connected region into a bounding box, and filter out the bounding boxes whose width and height are less than 10 pixels. For the remaining bounding boxes, if a If the box is contained in another box, remove the box, and the last bounding box is the position of each character. Based on these bounding boxes, the binarized single-character image is segmented on the binary image, and then The first step is to divide the ID number text image into ten single-character images, select a character set, such as ten characters from 0-9 in the ID card, perform binarization processing, and save it as a template library. Finally, after character segmentation, multiple For a single character image, the characters in the template library are sorted from 0 to 9, and each character image is template-matched with each character in the template library to obtain a matching probability matrix with N rows and M columns, where N is the length of the document number, M is the number of characters in the template library. Calculate the index of the maximum probability value in the column direction. According to the index, N characters can be obtained from the template library, which is the identification result of the document number.
以上所述,仅为本发明较佳的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,根据本发明的技术方案及其发明构思加以等同替换或改变,都应涵盖在本发明的保护范围之内。The above is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto, any person familiar with the technical field within the technical scope disclosed in the present invention, according to the technical solution of the present invention Any equivalent replacement or change of the inventive concepts thereof shall fall within the protection scope of the present invention.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310370463.6ACN116453150A (en) | 2023-04-04 | 2023-04-04 | Certificate number identification method based on image matching |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310370463.6ACN116453150A (en) | 2023-04-04 | 2023-04-04 | Certificate number identification method based on image matching |
| Publication Number | Publication Date |
|---|---|
| CN116453150Atrue CN116453150A (en) | 2023-07-18 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202310370463.6APendingCN116453150A (en) | 2023-04-04 | 2023-04-04 | Certificate number identification method based on image matching |
| Country | Link |
|---|---|
| CN (1) | CN116453150A (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117037171A (en)* | 2023-08-18 | 2023-11-10 | 中国平安人寿保险股份有限公司 | Certificate image recognition method and device, electronic equipment and storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101751568A (en)* | 2008-12-12 | 2010-06-23 | 汉王科技股份有限公司 | ID No. locating and recognizing method |
| CN107346427A (en)* | 2017-06-23 | 2017-11-14 | 浙江大华技术股份有限公司 | A kind of ID card No. recognition methods and device |
| CN107563330A (en)* | 2017-09-04 | 2018-01-09 | 南京邮电大学 | A kind of horizontal tilt car plate antidote in monitor video |
| CN109034145A (en)* | 2018-07-06 | 2018-12-18 | 西安电子科技大学 | Bank's card number recognition methods based on OpenCV |
| CN113536875A (en)* | 2021-01-07 | 2021-10-22 | 腾讯科技(深圳)有限公司 | Document image recognition method, device, computer equipment and storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101751568A (en)* | 2008-12-12 | 2010-06-23 | 汉王科技股份有限公司 | ID No. locating and recognizing method |
| CN107346427A (en)* | 2017-06-23 | 2017-11-14 | 浙江大华技术股份有限公司 | A kind of ID card No. recognition methods and device |
| CN107563330A (en)* | 2017-09-04 | 2018-01-09 | 南京邮电大学 | A kind of horizontal tilt car plate antidote in monitor video |
| CN109034145A (en)* | 2018-07-06 | 2018-12-18 | 西安电子科技大学 | Bank's card number recognition methods based on OpenCV |
| CN113536875A (en)* | 2021-01-07 | 2021-10-22 | 腾讯科技(深圳)有限公司 | Document image recognition method, device, computer equipment and storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117037171A (en)* | 2023-08-18 | 2023-11-10 | 中国平安人寿保险股份有限公司 | Certificate image recognition method and device, electronic equipment and storage medium |
| Publication | Publication Date | Title |
|---|---|---|
| Bhowmik et al. | Text and non-text separation in offline document images: a survey | |
| CN110298376B (en) | An Image Classification Method of Bank Notes Based on Improved B-CNN | |
| JP5492205B2 (en) | Segment print pages into articles | |
| Shijian et al. | Script and language identification in noisy and degraded document images | |
| CN111091124B (en) | Spine character recognition method | |
| CN114463767B (en) | Letter of credit identification method, device, computer equipment and storage medium | |
| CN104966051A (en) | Method of recognizing layout of document image | |
| CN112200789B (en) | Image recognition method and device, electronic equipment and storage medium | |
| Muresan et al. | Dot matrix OCR for bottle validity inspection | |
| Sarkar et al. | Suppression of non-text components in handwritten document images | |
| Tran et al. | A deep learning-based system for document layout analysis | |
| Xue | Optical character recognition | |
| Dash et al. | An Approach for Handwritten Alphanumeric Character Recognition: Leveraging CNN for Accurate Recognition | |
| Karanje et al. | Survey on text detection, segmentation and recognition from a natural scene images | |
| Dhandra et al. | Kannada handwritten vowels recognition based on normalized chain code and wavelet filters | |
| Ghanei et al. | Localizing scene texts by fuzzy inference systems and low rank matrix recovery model | |
| Van Phan et al. | Collecting handwritten nom character patterns from historical document pages | |
| CN116453150A (en) | Certificate number identification method based on image matching | |
| Dhandra et al. | On Separation of English Numerals from Multilingual Document Images. | |
| CN118135579B (en) | Method for detecting abnormal fonts in ID numbers | |
| Bouressace et al. | A convolutional neural network for Arabic document analysis | |
| Shahzad et al. | Feature engineering meets deep learning: A case study on table detection in documents | |
| Humied | Segmentation accuracy for offline Arabic handwritten recognition based on bounding box algorithm | |
| Islam et al. | Rule Based Filtering Approach for Detection and Localization of Bangla Text from Scene Images | |
| Bagga et al. | CHARACTER SEGMENTATION MACHINE-TYPED DOCUMENTS USING KNN ALGORITHM |
| 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 | ||
| RJ01 | Rejection of invention patent application after publication | Application publication date:20230718 | |
| RJ01 | Rejection of invention patent application after publication |