A bank card identification method, device, computer equipment and storage medium
By combining the differentiable binary algorithm, mobilenet-ssd and CRNN models, combined with the Luhn algorithm check and retry mechanism, the problem of low recognition accuracy in traditional bank card recognition methods is solved, and a recognition accuracy rate of more than 99% is achieved. Improved the accuracy and convenience of bank card identification.
Patent Information
- Application Number
- CN202111432633.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-11-29
AI Technical Summary
Traditional bank card recognition methods have low recognition accuracy due to the uneven quality of bank card pictures uploaded by users, problems such as reflection, blurry photos, jitter, and diverse bank card backgrounds.
The first text box detection model based on the differentiable binary algorithm and the second text box detection model of the mobilenet-ssd algorithm are combined with the CRNN text recognition model. Through preprocessing and multiple recognition verifications, the Luhn algorithm is used to verify the recognition results. , start the retry mechanism to identify again and improve the identification accuracy.
It achieved a recognition accuracy of more than 99% on real test images, solved the problem of recognition of poor-quality images, and improved the accuracy and convenience of bank card recognition.
Smart Images

Figure CN114049646B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology in artificial intelligence, and in particular to a bank card recognition method, device, computer equipment and storage medium. Background Art
[0002] With the development of Internet finance, online financial services (such as payment, financial management, etc.) have gained more and more widespread application demand. For individual consumers, the security and convenience of online financial business transactions directly affect their user experience. The combination of bank card number and password has become a widely accepted online transaction method because of its high security. However, bank card numbers are often long and the bank card background is often complicated. Manually inputting bank card numbers requires users to repeatedly identify and correct them. Therefore, automatically identifying bank card numbers from bank card images through machine learning has become an effective means to improve the convenience of this online transaction method and has gradually attracted attention.
[0003] There is an existing bank card recognition method, which locates the bank card number line, locates each character in the card number line, and finally recognizes each character according to the OCR technology, thereby achieving the purpose of bank card recognition.
[0004] However, the applicant found that traditional bank card recognition is generally not intelligent. Since the quality of bank card images uploaded by users varies, there are problems such as reflection, blurry photos, shaking, and interference of various bank card backgrounds on card number recognition, which makes the traditional bank card recognition method have the problem of low recognition accuracy. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a bank card recognition method, device, computer equipment and storage medium to solve the problem of low recognition accuracy in traditional bank card recognition methods.
[0006] In order to solve the above technical problems, the embodiment of the present application provides a bank card recognition method, which adopts the following technical solution:
[0007] Obtain the bank card image to be identified;
[0008] Performing a preprocessing operation on the bank card image to be identified to obtain a standard bank card image;
[0009] Inputting the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data;
[0010] Inputting the first text box data into a text recognition model to perform a text recognition operation to obtain a first recognition result;
[0011] Verify whether the first recognition result passes according to the Luhn algorithm;
[0012] If the first recognition result is passed, the first recognition result is used as the target bank card number;
[0013] If the first recognition result is not passed, the standard bank card image is input into a second text box detection model based on the mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data;
[0014] The second text box data is input into the text recognition model to perform the text recognition operation to obtain the target bank card number.
[0015] In order to solve the above technical problems, the embodiment of the present application further provides a bank card recognition device, which adopts the following technical solution:
[0016] An image acquisition module, used to acquire the bank card image to be identified;
[0017] A preprocessing module, used for performing a preprocessing operation on the bank card image to be identified to obtain a standard bank card image;
[0018] A first text box recognition module, used for inputting the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data;
[0019] A text recognition module, used for inputting the first text box data into a text recognition model to perform a text recognition operation and obtain a first recognition result;
[0020] A first recognition result verification module, used to verify whether the first recognition result passes according to the Luhn algorithm;
[0021] A first result acquisition module, configured to use the first recognition result as a target bank card number if the first recognition result is passed;
[0022] A second text box recognition module is used for inputting the standard bank card image into a second text box detection model based on the mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data if the first recognition result is a failure;
[0023] The second result acquisition module is used to input the second text box data into the text recognition model to perform the text recognition operation to obtain the target bank card number.
[0024] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0025] The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the bank card identification method as described above when executing the computer-readable instructions.
[0026] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0027] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the bank card identification method described above are implemented.
[0028] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0029] The present application provides a bank card recognition method, including: obtaining a bank card image to be recognized; performing a preprocessing operation on the bank card image to be recognized to obtain a standard bank card image; inputting the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data; inputting the first text box data into a text recognition model to perform a text recognition operation to obtain a first recognition result; verifying whether the first recognition result passes according to a Luhn algorithm; if the first recognition result passes, using the first recognition result as a target bank card number; if the first recognition result fails, inputting the standard bank card image into a second text box detection model based on a Mobilenet-SSD algorithm to perform a second text box recognition operation to obtain second text box data; inputting the second text box data into the text recognition model to perform the text recognition operation to obtain the target bank card number. This application first uses the dbnet+crnn algorithm to perform the first bank card OCR, and then uses the Luhn algorithm to verify the correctness of the recognized card number; if the verification fails, the retry mechanism is started, and the mobilenet-ssd+crnn process is used to perform bank card recognition again, so as to solve the recognition problem of poor quality images; finally, after the project is launched, the recognition accuracy of this method can reach more than 99% on multiple batches of real test images pulled. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0031] Figure 1is an exemplary system architecture diagram to which the present application may be applied;
[0032] Figure 2 This is a flow chart of the implementation of the bank card identification method provided in Example 1 of the present application;
[0033] Figure 3 yes Figure 2 A flowchart of a specific implementation of step S102;
[0034] Figure 4 yes Figure 2 A flowchart of a specific implementation of step S107;
[0035] Figure 5 It is a structural diagram of a bank card recognition device provided in Embodiment 1 of the present application;
[0036] Figure 6 yes Figure 5 A structural diagram of a specific implementation of the preprocessing module 320;
[0037] Figure 7 yes Figure 5 A structural diagram of a specific implementation of the second text box identification module 370;
[0038] Figure 8 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0039] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0040] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0041] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0042] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0043] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0044] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0045] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .
[0046] It should be noted that the bank card identification method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the bank card identification device is generally arranged in the server / terminal device.
[0047] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0048] Continue to refer Figure 2 , shows an implementation flow chart of the bank card identification method provided in Example 1 of the present application. For the sake of convenience of explanation, only the parts related to the present application are shown.
[0049] The above-mentioned bank card recognition method comprises the following steps:
[0050] Step S101, step S102, step S103, step S104, step S105, step S106, step S107 and step S108.
[0051] Step S101: Obtain a bank card image to be identified.
[0052] Step S102: pre-processing the bank card image to be identified to obtain a standard bank card image.
[0053] In the embodiment of the present application, it is considered that the bank card pictures uploaded by the user may have different angles, such as the bank card is tilted. This will affect the subsequent card number detection and recognition. Therefore, we first make a rough angle judgment on the bank card pictures uploaded by the user, which is mainly divided into four directions: 0 degrees, 90 degrees, 180 degrees, and 270 degrees. (Note: the 0 degree here refers to the horizontal direction of the bank card number). After the angle judgment, the non-0 degree is rotated to the 0 degree direction, and then sent to the subsequent steps.
[0054] Step S103: inputting the standard bank card image into a first text box detection model based on a differentiable binarization algorithm (DBNet) to perform a first text box recognition operation to obtain first text box data.
[0055] In the embodiment of the present application, the image is sent to the text detection model to detect the bank card number. The text detection algorithm uses a differentiable binarization algorithm, and in order to have better detection accuracy, we adjusted the network structure, replaced the original backbone network from res18 to res101, increased the network depth, and improved the network's learning ability; in addition, from the data level, we collected a large number of real bank card images and annotated and augmented them, and obtained millions of training data to train the network.
[0056] Step S104: inputting the first text box data into a text recognition model to perform a text recognition operation to obtain a first recognition result.
[0057] In the embodiment of the present application, the bank card number thumbnail is obtained from step S103 and then sent to the text recognition model for card number recognition. The card number recognition algorithm adopts the CRNN model and adjusts the network structure. Since the bank card number does not have contextual connection like a text paragraph, we remove the recurrent neural network model (BiLSTM) of the CRNN part and replace the CNN part with the res101 structure to improve the learning ability.
[0058] Step S105: Check whether the first recognition result is passed according to the Luhn algorithm.
[0059] In the embodiment of the present application, the first recognition result of the card number can be obtained from step S104. At this time, we will verify the card number using the internationally accepted bank card verification algorithm Luhn algorithm.
[0060] Step S106: If the first recognition result is passed, the first recognition result is used as the target bank card number.
[0061] Step S107: If the first recognition result is not passed, the standard bank card image is input into the second text box detection model based on the mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data.
[0062] In the embodiment of the present application, if the verification fails, that is, the card number is not recognized correctly, we have designed a retry mechanism. The reason for designing the retry mechanism is that we found in the process of algorithm development and experiment that the bank card detection model DBNET can obtain accurate detection results for most of the time, but for a small number of poor quality pictures (such as blurred pictures and interference of bank card background on convex card number, etc.), there are inaccurate detections, resulting in inaccurate recognition later. Therefore, in the retry part, we mainly deal with bank cards of poor quality, and do not use text detection algorithms to detect card numbers (from the performance of DBNET, there will be inaccurate detections), but adopt the idea of target detection, use the Mobilenet-SSD algorithm, detect a rough card number text box, and then send it to the text recognition model for recognition. Because when training the text recognition model, the training data contains millions of training data such as rough card number text images and fine card number text images, so that the text recognition model has high-precision recognition capabilities.
[0063] Step S108: input the second text box data into the text recognition model to perform text recognition operation to obtain the target bank card number.
[0064] In an embodiment of the present application, a bank card recognition method is provided, including: obtaining a bank card image to be recognized; performing a preprocessing operation on the bank card image to be recognized to obtain a standard bank card image; inputting the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data; inputting the first text box data into a text recognition model to perform a text recognition operation to obtain a first recognition result; verifying whether the first recognition result passes according to a Luhn algorithm; if the first recognition result passes, using the first recognition result as a target bank card number; if the first recognition result fails, inputting the standard bank card image into a second text box detection model based on a mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data; inputting the second text box data into a text recognition model to perform a text recognition operation to obtain a target bank card number. This application first uses the dbnet+crnn algorithm to perform the first bank card OCR, and then uses the Luhn algorithm to verify the correctness of the recognized card number; if the verification fails, the retry mechanism is started, and the mobilenet-ssd+crnn process is used to perform bank card recognition again, so as to solve the recognition problem of poor quality images; finally, after the project is launched, the recognition accuracy of this method can reach more than 99% on multiple batches of real test images pulled.
[0065] Continue reading Figure 3 , showing Figure 2 A flowchart of a specific implementation of step S102 is shown in FIG. 1 . For ease of explanation, only the part related to the present application is shown.
[0066] In some optional implementations of this embodiment, the above step S102 specifically includes: step S301 and step S302.
[0067] Step S301: grayscale processing is performed on the text image to be recognized to obtain grayscale image data.
[0068] In the embodiment of the present application, the images uploaded by users are generally color images, but the subsequent algorithm processing of the present invention must be grayscale images, so the input image will be converted into a grayscale image.
[0069] In the embodiment of the present application, the grayscale processing refers to converting the three channels (RGB) of the text to be recognized into one channel. Specifically, the grayscale processing can be:
[0070] (1) Averaging method, that is, averaging the RGB values of the three channels at the same pixel position. The averaging is expressed as:
[0071]
[0072] Wherein, x and y represent the two-dimensional coordinate values of pixel point I respectively;
[0073] (2) Maximum-minimum average method, that is, taking the average of the maximum and minimum brightness of the RGB at the same pixel position;
[0074] (3) Weighted average method, expressed as:
[0075] I(x,y)=α×I R(x,y) +β×I G(x,y) +ρ×I B(x,y)
[0076] Among them, α, β, and ρ represent weighting parameters respectively. Specifically, α, β, and ρ may be parameters 0.3, 0.59, and 0.11 adjusted by a human brightness perception system respectively.
[0077] Step S302: performing resolution standardization processing on the grayscale image data according to the standard resolution to obtain a standard bank card image.
[0078] In the embodiment of the present application, the resolution standardization process refers to adjusting the resolution of the image by the same proportion. Specifically, the resolution standardization process can be uniformly scaled to between [600, 1000].
[0079] In an embodiment of the present application, before sending the input image to the text detection model for text line detection, we preprocess the input image and scale the resolution. The purpose of this is to reduce the amount of calculation of the model from the perspective of data volume, thereby improving the model processing time.
[0080] Continue reading Figure 4 , showing Figure 2 A flowchart of a specific implementation of step S107 is shown in the figure. For the sake of convenience, only the part related to the present application is shown.
[0081] In some optional implementations of this embodiment, the above step S107 specifically includes: step S401, step S402, step S403 and step S404.
[0082] Step S401: Obtain the text detection probability corresponding to each pixel point in the text image to be recognized output by the text detection model.
[0083] In the embodiment of the present application, the result output by the text detection model is the probability (0-1) of each pixel in the image. For example, for a 100 pixel x 100 pixel image, after calculation by dbnet, the output is the probability value of these 10,000 pixels belonging to text, that is, how many of the 10,000 pixels correspond to the text in the image, and how many correspond to the blank part or non-text part in the image.
[0084] Step S402: Filtering the pixels of the text image to be identified according to the text detection probability and the preset pixel threshold to obtain a text detection image.
[0085] In an embodiment of the present application, the user can pre-set the pixel threshold according to the specific situation, and divide the above 10,000 pixels into text pixels and non-text pixels by probability value. The non-text pixels can be pixels belonging to the blank part of the picture. In this way, the text detection image can be formed.
[0086] Step S403: Calculate the connected domain of the text detection image according to the opencv toolkit to obtain a connected domain set.
[0087] In the embodiments of the present application, OpenCV is a cross-platform computer vision and machine learning software library released under the BSD license (open source), which can run on Linux, Windows, Android and Mac OS operating systems. [1] It is lightweight and efficient - consisting of a series of C functions and a small number of C++ classes, while providing interfaces for languages such as Python, Ruby, and MATLAB, and implementing many common algorithms in image processing and computer vision.
[0088] Step S404: Calculate the minimum circumscribed matrix of each connected domain in the connected domain set according to the findcontours function, and use each vertex of the minimum circumscribed matrix as the second text box data.
[0089] In the embodiment of the present application, the text behavior output by the text detection model includes at least one text line of text, which can be understood as a text outline image or a text line / column outline image. In a possible implementation, the text line can also be a sub-image including text segmented from the target image.
[0090] In an embodiment of the present application, a text line is a bounding box with specific content as a unit, wherein the specific content can be a word, a line of text, or a single word, etc. The text detection model can generate different text lines based on the type of text in the picture to be identified. For example, when the picture contains English text, the text detection model can frame the English text of the picture in units of words line by line, and generate multiple text lines. It can be understood that the text in the text line determined by this embodiment is a single English word. For another example, when the picture to be identified contains Chinese, the text detection model can frame the Chinese text of the picture in units of lines, and generate multiple text lines. It can be understood that the text in the text line determined by this embodiment is a line of Chinese text. For another example, when the picture to be identified contains Chinese, the text detection model can frame the Chinese text of the picture in units of single words, and generate multiple text lines. It can be understood that the text in the text line determined by this embodiment is a word.
[0091] In an embodiment of the present application, since the text content in the text image is regularly arranged based on straight lines, the difference lies in the size of the gaps between the text content. Therefore, the shape of the minimum circumscribed matrix of the connected domain calculated is generally a four-sided rectangle or a slightly distorted rectangle. Therefore, the vertices of the minimum circumscribed matrix can be used as the four vertex positions of the text box of the second text box data.
[0092] In some optional implementations of this embodiment, the text recognition model is a CNN network with the BiLSTM network omitted.
[0093] In the embodiment of the present application, the recurrent neural network part (BiLSTM) of the original CRNN is removed, and only the backbone network part of the CNN is retained, so as to slim down the network structure and improve the processing time of the model.
[0094] In some optional implementations of this embodiment, the computational model for computing and processing network output data is integrated into the second half of the model, thereby simplifying post-processing operations and reducing the data flow of output results, thereby reducing data flow transmission in actual deployment, saving bandwidth, and preventing network congestion under high concurrency.
[0095] In summary, the present application provides a bank card recognition method, including: obtaining a bank card image to be recognized; performing a preprocessing operation on the bank card image to be recognized to obtain a standard bank card image; inputting the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data; inputting the first text box data into a text recognition model to perform a text recognition operation to obtain a first recognition result; verifying whether the first recognition result passes according to a Luhn algorithm; if the first recognition result passes, using the first recognition result as the target bank card number; if the first recognition result fails, inputting the standard bank card image into a second text box detection model based on a mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data; inputting the second text box data into a text recognition model to perform a text recognition operation to obtain a target bank card number. This application first uses the dbnet+crnn algorithm to perform the first bank card OCR, and then uses the Luhn algorithm to verify the correctness of the recognized card number; if the verification fails, the retry mechanism is started, and the mobilenet-ssd+crnn process is used to perform bank card recognition again, so as to solve the recognition problem of poor quality pictures; finally, after the project is launched, the recognition accuracy of this method can reach more than 99% on multiple batches of real test pictures. At the same time, before sending the input picture to the text detection model for text line detection, we preprocess the input picture and scale the resolution. The purpose of this is to reduce the calculation amount of the model from the data volume level, thereby improving the model processing time.
[0096] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned bank card image to be identified and the target bank card number, the above-mentioned bank card image to be identified and the target bank card number can also be stored in a node of a blockchain.
[0097] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0098] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0099] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the computer-readable instructions are executed, they can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0100] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0101] Embodiment 2
[0102] Further references Figure 5 , as a response to the above Figure 2 The present application provides an embodiment of a bank card recognition device, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0103] like Figure 5 As shown, the bank card recognition device 300 of this embodiment includes: an image acquisition module 310, a preprocessing module 320, a first text box recognition module 330, a text recognition module 340, a first recognition result verification module 350, a first result acquisition module 360, a second text box recognition module 370 and a second result acquisition module 380. Among them:
[0104] An image acquisition module 310 is used to acquire a bank card image to be identified;
[0105] A preprocessing module 320, used to perform preprocessing operations on the bank card image to be recognized to obtain a standard bank card image;
[0106] A first text box recognition module 330 is used to input a standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data;
[0107] The text recognition module 340 is used to input the first text box data into the text recognition model to perform a text recognition operation and obtain a first recognition result;
[0108] A first recognition result verification module 350, used to verify whether the first recognition result passes according to the Luhn algorithm;
[0109] A first result acquisition module 360, configured to use the first recognition result as a target bank card number if the first recognition result is passed;
[0110] The second text box recognition module 370 is used to input the standard bank card image into the second text box detection model based on the mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data if the first recognition result is not passed;
[0111] The second result acquisition module 380 is used to input the second text box data into the text recognition model to perform text recognition operation to obtain the target bank card number.
[0112] In the embodiment of the present application, it is considered that the bank card pictures uploaded by the user may have different angles, such as the bank card is tilted. This will affect the subsequent card number detection and recognition. Therefore, we first make a rough angle judgment on the bank card pictures uploaded by the user, which is mainly divided into four directions: 0 degrees, 90 degrees, 180 degrees, and 270 degrees. (Note: the 0 degree here refers to the horizontal direction of the bank card number). After the angle judgment, the non-0 degree is rotated to the 0 degree direction, and then sent to the subsequent steps.
[0113] In the embodiment of the present application, the image is sent to the text detection model to detect the bank card number. The text detection algorithm uses a differentiable binarization algorithm, and in order to have better detection accuracy, we adjusted the network structure, replaced the original backbone network from res18 to res101, increased the network depth, and improved the network's learning ability; in addition, from the data level, we collected a large number of real bank card images and annotated and augmented them, and obtained millions of training data to train the network.
[0114] In the embodiment of the present application, the bank card number thumbnail is obtained from step S103 and then sent to the text recognition model for card number recognition. The card number recognition algorithm adopts the CRNN model and adjusts the network structure. Since the bank card number does not have contextual connection like a text paragraph, we remove the recurrent neural network model (BiLSTM) of the CRNN part and replace the CNN part with the res101 structure to improve the learning ability.
[0115] In the embodiment of the present application, the first recognition result of the card number can be obtained from step S104. At this time, we will verify the card number using the internationally accepted bank card verification algorithm Luhn algorithm.
[0116] In the embodiment of the present application, if the verification fails, that is, the card number is not recognized correctly, we have designed a retry mechanism. The reason for designing the retry mechanism is that we found in the process of algorithm development and experiment that the bank card detection model DBNET can obtain accurate detection results for most of the time, but for a small number of poor quality pictures (such as blurred pictures and interference of bank card background on convex card number, etc.), there are inaccurate detections, resulting in inaccurate recognition later. Therefore, in the retry part, we mainly deal with bank cards of poor quality, and do not use text detection algorithms to detect card numbers (from the performance of DBNET, there will be inaccurate detections), but adopt the idea of target detection, use the Mobilenet-SSD algorithm, detect a rough card number text box, and then send it to the text recognition model for recognition. Because when training the text recognition model, the training data contains millions of training data such as rough card number text images and fine card number text images, so that the text recognition model has high-precision recognition capabilities.
[0117] In an embodiment of the present application, a bank card recognition device 300 is provided, including: an image acquisition module 310, used to acquire a bank card image to be recognized; a preprocessing module 320, used to perform a preprocessing operation on the bank card image to be recognized to obtain a standard bank card image; a first text box recognition module 330, used to input the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data; a text recognition module 340, used to input the first text box data into a text recognition model to perform a text recognition operation to obtain a first recognition result; the first recognition result Verification module 350 is used to verify whether the first recognition result is passed according to the Luhn algorithm; first result acquisition module 360 is used to use the first recognition result as the target bank card number if the first recognition result is passed; second text box recognition module 370 is used to input the standard bank card image into the second text box detection model based on mobilenet-ssd algorithm to perform the second text box recognition operation and obtain the second text box data if the first recognition result is not passed; second result acquisition module 380 is used to input the second text box data into the text recognition model to perform the text recognition operation and obtain the target bank card number. This application first uses the dbnet+crnn algorithm to perform the first bank card OCR, and then uses the Luhn algorithm to verify the correctness of the recognized card number; if the verification fails, the retry mechanism is started, and the mobilenet-ssd+crnn process is used to perform the bank card recognition again, so as to solve the recognition problem of poor quality pictures; finally, after the project is launched, the recognition accuracy of the method can reach more than 99% on multiple batches of real test pictures pulled.
[0118] Continue reading Figure 6 , Figure 5 The schematic diagram of the structure of a specific implementation of the preprocessing module 320 is shown in the figure. For the convenience of explanation, only the part related to the present application is shown.
[0119] In some optional implementations of this embodiment, the preprocessing module 320 includes: a grayscale processing submodule 321 and a resolution standardization processing submodule 322, wherein:
[0120] Grayscale processing submodule 321, used for performing grayscale processing on the text image to be recognized to obtain grayscale image data;
[0121] The resolution standardization processing submodule 322 is used to perform resolution standardization processing on the grayscale image data according to the standard resolution to obtain a standard bank card image.
[0122] In the embodiment of the present application, the images uploaded by users are generally color images, but the subsequent algorithm processing of the present invention must be grayscale images, so the input image will be converted into a grayscale image.
[0123] In the embodiment of the present application, the grayscale processing refers to converting the three channels (RGB) of the text to be recognized into one channel. Specifically, the grayscale processing can be:
[0124] (1) Averaging method, that is, averaging the RGB values of the three channels at the same pixel position. The averaging is expressed as:
[0125]
[0126] Wherein, x and y represent the two-dimensional coordinate values of pixel point I respectively;
[0127] (2) Maximum-minimum average method, that is, taking the average of the maximum and minimum brightness of the RGB at the same pixel position;
[0128] (3) Weighted average method, expressed as:
[0129] I(x,y)=α×I R(x,y) +β×I G(x,y) +ρ×I B(x,y)
[0130] Among them, α, β, and ρ represent weighting parameters respectively. Specifically, α, β, and ρ may be parameters 0.3, 0.59, and 0.11 adjusted by a human brightness perception system respectively.
[0131] In the embodiment of the present application, the resolution standardization process refers to adjusting the resolution of the image by the same proportion. Specifically, the resolution standardization process can be uniformly scaled to between [600, 1000].
[0132] In an embodiment of the present application, before sending the input image to the text detection model for text line detection, we preprocess the input image and scale the resolution. The purpose of this is to reduce the amount of calculation of the model from the perspective of data volume, thereby improving the model processing time.
[0133] Continue reading Figure 7 , Figure 5 A structural diagram of a specific implementation of the second text box identification module 370 is shown in FIG. 3 . For ease of explanation, only the part related to the present application is shown.
[0134] In some optional implementations of this embodiment, the second text box identification module 370 includes: a detection probability acquisition submodule 371, a screening submodule 372, a connected domain calculation submodule 373 and a second text box confirmation submodule 374, wherein:
[0135] The detection probability acquisition submodule 371 is used to acquire the text detection probability corresponding to each pixel point in the text image to be recognized output by the text detection model;
[0136] A screening submodule 372, configured to screen the pixels of the text image to be identified according to the text detection probability and a preset pixel threshold, to obtain a text detection image;
[0137] A connected domain calculation submodule 373 is used to calculate the connected domain of the text detection image according to the opencv toolkit to obtain a connected domain set;
[0138] The second text box confirmation submodule 374 is used to calculate the minimum circumscribed matrix of each connected domain in the connected domain set according to the findcontours function, and use each vertex of the minimum circumscribed matrix as the second text box data.
[0139] In the embodiment of the present application, the result output by the text detection model is the probability (0-1) of each pixel in the image. For example, for a 100 pixel x 100 pixel image, after calculation by dbnet, the output is the probability value of these 10,000 pixels belonging to text, that is, how many of the 10,000 pixels correspond to the text in the image, and how many correspond to the blank part or non-text part in the image.
[0140] In an embodiment of the present application, the user can pre-set the pixel threshold according to the specific situation, and divide the above 10,000 pixels into text pixels and non-text pixels by probability value. The non-text pixels can be pixels belonging to the blank part of the picture. In this way, the text detection image can be formed.
[0141] In the embodiments of the present application, OpenCV is a cross-platform computer vision and machine learning software library released under the BSD license (open source), which can run on Linux, Windows, Android and Mac OS operating systems. [1] It is lightweight and efficient - consisting of a series of C functions and a small number of C++ classes, while providing interfaces for languages such as Python, Ruby, and MATLAB, and implementing many common algorithms in image processing and computer vision.
[0142] In the embodiment of the present application, the text behavior output by the text detection model includes at least one text line of text, which can be understood as a text outline image or a text line / column outline image. In a possible implementation, the text line can also be a sub-image including text segmented from the target image.
[0143] In an embodiment of the present application, a text line is a bounding box with specific content as a unit, wherein the specific content can be a word, a line of text, or a single word, etc. The text detection model can generate different text lines based on the type of text in the picture to be identified. For example, when the picture contains English text, the text detection model can frame the English text of the picture in units of words line by line, and generate multiple text lines. It can be understood that the text in the text line determined by this embodiment is a single English word. For another example, when the picture to be identified contains Chinese, the text detection model can frame the Chinese text of the picture in units of lines, and generate multiple text lines. It can be understood that the text in the text line determined by this embodiment is a line of Chinese text. For another example, when the picture to be identified contains Chinese, the text detection model can frame the Chinese text of the picture in units of single words, and generate multiple text lines. It can be understood that the text in the text line determined by this embodiment is a word.
[0144] In an embodiment of the present application, since the text content in the text image is regularly arranged based on straight lines, the difference lies in the size of the gaps between the text content. Therefore, the shape of the minimum circumscribed matrix of the connected domain calculated is generally a four-sided rectangle or a slightly distorted rectangle. Therefore, the vertices of the minimum circumscribed matrix can be used as the four vertex positions of the text box of the second text box data.
[0145] In some optional implementations of this embodiment, the text recognition model is a CNN network with the BiLSTM network omitted.
[0146] In the embodiment of the present application, the recurrent neural network part (BiLSTM) of the original CRNN is removed, and only the backbone network part of the CNN is retained, so as to slim down the network structure and improve the processing time of the model.
[0147] In some optional implementations of this embodiment, the computational model for computing and processing network output data is integrated into the second half of the model, thereby simplifying post-processing operations and reducing the data flow of output results, thereby reducing data flow transmission in actual deployment, saving bandwidth, and preventing network congestion under high concurrency.
[0148] In summary, the present application provides a bank card recognition device 300, including: an image acquisition module 310, used to acquire a bank card image to be recognized; a preprocessing module 320, used to perform a preprocessing operation on the bank card image to be recognized to obtain a standard bank card image; a first text box recognition module 330, used to input the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data; a text recognition module 340, used to input the first text box data into a text recognition model to perform a text recognition operation to obtain a first recognition result; a first recognition result verification module 341, used to verify the first recognition result; Module 350 is used to verify whether the first recognition result is passed according to the Luhn algorithm; the first result acquisition module 360 is used to use the first recognition result as the target bank card number if the first recognition result is passed; the second text box recognition module 370 is used to input the standard bank card image into the second text box detection model based on the mobilenet-ssd algorithm to perform a second text box recognition operation to obtain the second text box data if the first recognition result is not passed; the second result acquisition module 380 is used to input the second text box data into the text recognition model to perform a text recognition operation to obtain the target bank card number. This application first uses the dbnet+crnn algorithm to perform the first bank card OCR, and then uses the Luhn algorithm to verify the correctness of the recognized card number; if the verification fails, the retry mechanism is started, and the mobilenet-ssd+crnn process is used to perform the bank card recognition again, so as to solve the recognition problem of poor quality pictures; finally, after the project is launched, the recognition accuracy of the method can reach more than 99% on multiple batches of real test pictures pulled. At the same time, before sending the input image to the text detection model for text line detection, we preprocess the input image and scale the resolution. The purpose of this is to reduce the amount of model calculation from the perspective of data volume, thereby improving the model processing time.
[0149] To solve the above technical problems, the present application also provides a computer device. Figure 8 , Figure 8 This is a basic structural block diagram of the computer device in this embodiment.
[0150] The computer device 200 includes a memory 210, a processor 220, and a network interface 230 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 200 having components 210-230, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0151] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0152] The memory 210 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 210 can be an internal storage unit of the computer device 200, such as a hard disk or memory of the computer device 200. In other embodiments, the memory 210 can also be an external storage device of the computer device 200, such as a plug-in hard disk equipped on the computer device 200, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. Of course, the memory 210 can also include both the internal storage unit of the computer device 200 and its external storage device. In this embodiment, the memory 210 is generally used to store the operating system and various application software installed on the computer device 200, such as computer-readable instructions of the bank card recognition method, etc. In addition, the memory 210 can also be used to temporarily store various data that have been output or will be output.
[0153] The processor 220 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 220 is generally used to control the overall operation of the computer device 200. In this embodiment, the processor 220 is used to run the computer-readable instructions stored in the memory 210 or process data, such as computer-readable instructions for running the bank card recognition method.
[0154] The network interface 230 may include a wireless network interface or a wired network interface. The network interface 230 is generally used to establish a communication connection between the computer device 200 and other electronic devices.
[0155] The computer device provided by this application first uses the dbnet+crnn algorithm to perform the first bank card OCR, and then uses the Luhn algorithm to verify the correctness of the recognized card number; if the verification fails, the retry mechanism is started, and the mobilenet-ssd+crnn process is used to perform bank card recognition again, so as to solve the problem of recognizing poor quality pictures; finally, after the project is launched, the recognition accuracy of this method can reach more than 99% on multiple batches of real test pictures pulled.
[0156] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the bank card identification method as described above.
[0157] The computer-readable storage medium provided by the present application first uses the dbnet+crnn algorithm to perform the first bank card OCR, and then uses the Luhn algorithm to verify the correctness of the recognized card number; if the verification fails, the retry mechanism is started, and the mobilenet-ssd+crnn process is used to perform bank card recognition again, so as to solve the problem of recognition of poor quality images; finally, after the project is launched, the recognition accuracy of this method can reach more than 99% on multiple batches of real test images pulled.
[0158] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0159] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A bank card recognition method, characterized in that: The steps include: Obtain the bank card image to be identified; Performing a preprocessing operation on the bank card image to be identified to obtain a standard bank card image, wherein the standard bank card image is an image after grayscale processing and resolution standardization processing; Inputting the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data; Inputting the first text box data into a text recognition model to perform a text recognition operation to obtain a first recognition result; Verify whether the first recognition result passes according to the Luhn algorithm; If the first recognition result is passed, the first recognition result is used as the target bank card number; If the first recognition result is not passed, the standard bank card image is input into a second text box detection model based on the mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data, wherein the step of inputting the standard bank card image into a second text box detection model based on the mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data if the first recognition result is not passed specifically includes the following steps: Obtaining the text detection probability corresponding to each pixel point in the to-be-recognized text image output by the second text box detection model, specifically, each text detection probability represents a probability value of a corresponding pixel point in the to-be-recognized text image belonging to a pixel point in the text area; Performing a screening operation on the pixel points of the to-be-recognized text image according to the text detection probability and a preset pixel threshold to obtain a text detection image; Performing connected domain calculation on the text detection image according to the opencv toolkit to obtain a connected domain set; Calculate the minimum circumscribed matrix of each connected domain in the connected domain set according to the findcontours function, and use the vertices of the minimum circumscribed matrix as the second text box data. Specifically, use the four vertices of the minimum circumscribed matrix as the four vertices of the second text box; The second text box data is input into the text recognition model to perform the text recognition operation to obtain the target bank card number.
2. The bank card recognition method according to claim 1, characterized in that: The step of performing a preprocessing operation on the bank card image to be identified to obtain a standard bank card image specifically includes the following steps: Performing grayscale processing on the text image to be recognized to obtain grayscale image data; The grayscale image data is subjected to resolution standardization processing according to a standard resolution to obtain the standard bank card image.
3. The bank card recognition method according to claim 1, characterized in that: The text recognition model is a CNN network with the BiLSTM network omitted.
4. The bank card recognition method according to claim 1, characterized in that: After the step of inputting the second text box data into the text recognition model to perform the text recognition operation to obtain the target bank card number, the method further includes: The bank card image to be identified and the target bank card number are stored in the blockchain.
5. A bank card recognition device, characterized in that: The bank card recognition device is used to implement the steps of the bank card recognition method according to any one of claims 1 to 4, and the bank card recognition device comprises: An image acquisition module, used to acquire the bank card image to be identified; A preprocessing module, used for performing a preprocessing operation on the bank card image to be identified to obtain a standard bank card image; A first text box recognition module, used for inputting the standard bank card image into a first text box detection model based on a differentiable binarization algorithm to perform a first text box recognition operation to obtain first text box data; A text recognition module, used for inputting the first text box data into a text recognition model to perform a text recognition operation and obtain a first recognition result; A first recognition result verification module, used to verify whether the first recognition result passes according to the Luhn algorithm; A first result acquisition module, configured to use the first recognition result as a target bank card number if the first recognition result is passed; A second text box recognition module, configured to input the standard bank card image into a second text box detection model based on the mobilenet-ssd algorithm to perform a second text box recognition operation to obtain second text box data if the first recognition result is a failure; The second result acquisition module is used to input the second text box data into the text recognition model to perform the text recognition operation to obtain the target bank card number.
6. The bank card recognition device according to claim 5, characterized in that: The preprocessing module comprises: A grayscale processing submodule, used for performing grayscale processing on the text image to be recognized to obtain grayscale image data; The resolution standardization processing submodule is used to perform resolution standardization processing on the grayscale image data according to a standard resolution to obtain the standard bank card image.
7. The bank card recognition device according to claim 5, characterized in that: The second text box recognition module includes: A detection probability acquisition submodule, used to acquire the text detection probability corresponding to each pixel point in the to-be-recognized text image output by the text detection model; A screening submodule, used for screening the pixels of the to-be-recognized text image according to the text detection probability and a preset pixel threshold, to obtain a text detection image; A connected domain calculation submodule is used to perform connected domain calculation on the text detection image according to the opencv toolkit to obtain a connected domain set; The second text box confirmation submodule is used to calculate the minimum circumscribed matrix of each connected domain in the connected domain set according to the findcontours function, and use each vertex of the minimum circumscribed matrix as the second text box data.
8. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the bank card identification method according to any one of claims 1 to 4 when executing the computer-readable instructions.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the bank card identification method according to any one of claims 1 to 4 are implemented.
