Verification code recognition, invoice number recognition, verification code recognition invoice number

Source: Internet
Author: User

Verification code recognition, invoice number recognition, verification code recognition invoice number

I did a simple research on verification code recognition in my graduation project, but I didn't have any in-depth research on it. It was very difficult to design graphics and images, such as deep water, neural networks, and machine learning. This is only an analysis in the traditional way.

I have never sorted out my work this year. A guy asked this demo a few days ago. I collected a bunch of things and packed them for him. He was too busy and I sorted out the records. This is also the last assignment of the University, which has many memories and memories.

The original intention of this demo is not to identify the verification code, but to apply the verification Image Processing Method to other aspects, such as tickets and tickets.

Here is a case of invoice identification:

Address: http://v.youku.com/v_show/id_XMTI1MzUxNDY3Ng==.html

 

The demo contains a demo of the verification code recognition and processing process, an automatic identification tool library, and a demo of invoice recognition.

Using the graphic Verification Code of 7 websites as a case, of course, it is still targeted, avoiding the adhesion, the distortion is too powerful:

 

Final recognition rate:

  • The verification code image processing process involves verification code generation, grayscale processing, background color removal, noise processing, binarization, image character segmentation, image normalization, and Image Signature generation;

Grayscale ProcessingThere are three main methods:

Background Removal

In this process, the background is converted to pure white, that is, the color outside the target character is converted to white as much as possible. The most difficult part in this phase is to determine the image background and foreground split point, which is the critical value. Because the R value of each pixel in this image (the RGB value of the grayscale image is the same) is changed to 255 (white) for the RGB value greater than the critical value ). This critical point remains unchanged throughout the processing process.

The difference between the foreground and the background indicates that the foreground and the background are the most obvious under this split point, just like a glass layer, which divides the river water into the upper and lower parts, and precipitated below, which is relatively turbid, the above is clear, so the difference between the two parts is quite obvious. The position of the glass is the key.

Common critical point threshold determination Algorithms

Noise judgment and Removal

First, the border is removed. Some verification codes draw a black border on the border of the image. According to the principle of background removal, this border is not removed. It is easy to remove this border. You can judge each pixel loaded into a two-dimensional array. If the x-axis of the vertex is equal to 0 or the image width is reduced by one, or the total coordinate is equal to 0 or the vertical coordinate is equal to the Image Height minus one, and its position is the border position. Remove borders directly with RGB 0.

For non-border points, it is not the most direct target point to judge whether the target pixel is a noise, but to observe the points around it. The nine cells centered on this point, that is, there are eight pixels around the target point, and the number of non-background (white) vertices in these eight vertices is calculated, if the value is greater than the given defined value (this value is related to the number of noise in the image without a verification code and the noise adhesion. It cannot be obtained dynamically and can only be found based on the comparison of the processing results ), it indicates that the target point is more likely to be a certain pixel in a character, and the ancient point cannot be used as a noise; otherwise, it will be processed as a noise. Assume that the defined value for this operation is 2, then:

 

Binarization

Binarization is different from grayscale. The RGB values of each pixel are the same between 0 and, however, binarization requires that the RGB value of each pixel be either 0 or 255. completely black and white the image.

The binarization process is to process each pixel of the de-noise Verification Code image. If the R value of this vertex is not 255, then the RGB value of this vertex is changed to 0 (pure black ), in this way, the normal image becomes a real black-and-white image.

 

Main Image Segmentation Algorithms

Image segmentation technology plays a very important role in image processing. images are a complex medium for transmitting information, and not all information on each image is expected, because of this, it is very important to "filter" the images in the target area on the image, which uses the image segmentation technology.

Image character segmentation is the most difficult step in the verification code recognition process and also a step that determines the recognition result. No matter how complicated the verification code can be accurately cut out, it can be identified. There are various ways to split, and the detailed processing after the split is also complicated and diverse.

The following describes several mature segmentation algorithms:

 

Figure 3-7 Projection Method

3.6.2 Edge Detection Segmentation Algorithm

The program uses the Edge Detection Method to Determine the boundary of each character. The steps for this algorithm are as follows:

 

Figure 3-8 Image Segmentation

As you can see, when the program determines the boundary of the character "6:

"4" this character boundary is also obtained, but in step 1, the scanning start position X coordinate 0 is changed to B + 1.

Every time you judge the B-A, if his value is smaller than the smallest width of your verification code character, (Suppose it is set here is 4), then stop looking for the boundary to add the coordinates to the set can be.

For example, in the school's verification code character, the shortest width is 1, but its width is greater than 4, so there is no problem with this setting, depending on the situation, generally the width is less than 4, the verification code is very small, which is not conducive to reading.

After the above process, we get the abscissa, ordinate, that is (A, B-1, C, D-1) of the top and bottom four boundary points ); draw the area of the original verification code corresponding to the area identified by the four points to a small image. Then, the small image is normalized according to the set height and width, and the processed image is put into the set and returned. Wait for the next step.

Before Splitting: the effect of the split is as follows:

Special processing after split

In this process, due to the partial adhesion of the image, the splitting results will not achieve the expected results, and the small image is also strange. However, considering that most websites currently have four verification code characters, this means that the number of small images to be cut is also four. In this case, I have further processed the problem, first, let's take a look at the possible situations after cutting:

This verification code is a two-valued verification code. Obviously, the first and second characters are stuck with each other. The pictures cut out by the program should be three small pictures, similar to this:

Obviously, ① Is not what the program wants. In this case, that is, after the first part is cut, find the widest one and then open it from the middle. Obtain four images.

Correspondingly, there are two parts:

This is not our ideal situation. It is also the same principle. We split the middle of the two parts to get four small images.

In this case, the first cut is completely one:

We only need to divide it equally by 4 points.

Of course, the above processing will cause the corresponding error, but as long as the number of subsequent fonts is large enough, the cutting processing effect is still acceptable.

This time, only four characters are specially processed, and other numbers are not processed. The specific method will be described in the summary.

 

Die Creation

In this process, the cut image is converted into a feature matrix, and the small image set returned during the image cutting process is obtained for the feature value. During the image cutting process, the program has normalized the cut small image, that is, the length and width are the same, traversing each pixel. If the R value of this point is 255, A 0 is recorded, if the R value of this point is 255, A 1 is recorded. In this way, records 0, 1 are concatenated into a string, which is the signature of the image. Then the character corresponding to the image is prefixed and connected. In this way, an image has a feature value string corresponding to it. After writing the feature value string to a text or database, the basic model library is created. Because the size of the thumbnail is 20*30 when the image is normalized, the data size of each model is 20*30 + 3 + 2 (Press enter to wrap) = 605 characters.

The larger the workload of the model database, the higher the recognition accuracy. However, the larger the workload, the more data the model consumes, the more time the comparison consumes, and the lower the efficiency. Below is a part of the Pattern Library:

Verification Code Recognition

To identify the verification code, you must have a prepared model database and then perform the following process:

3. calculate the similarity, read the model data in the model database, compare the pattern data with the normalized small image, and calculate the similarity. Record the character C corresponding to the data item with the highest similarity.

4. The recognition result is concatenated by the character C, and the obtained string is the recognition result of the verification code.

The following describes how to identify a verification code:

Font Library maintenance

The verification code recognition process has been analyzed in detail to identify the key points one in the cutting, one in the word model library quality. The model library involves two problems: one is the duplicate problem, and the other is the model data. This phase is mainly implemented:

Image Processing Design

The image processing class follows the object-oriented design. It encapsulates the methods used in the image processing process, sets the default and variable parameters of common parameter values, and reloads the methods. This class is a static class for developers to call. Boundry is a class that stores the boundary information of small images. It has four boundary value attributes.

Developers can directly call the GetYZMCode () method to identify and process the verification code. This is a heavy load method. The other methods will introduce the design of the specific method in the specific implementation below, the following class diagram shows the main processing methods and relationships in the ImageProcess class:

 

Invoice ID Recognition

This is implemented based on aforge.net. For details, refer to the code of a foreign poker card recognition.

The process is to first determine the invoice location, then locate the invoice number, cut out the invoice number, call the automatic identification class library to identify the number, and then write the identification data to the screen. Of course, we also need to implement the training model;

 

It is interesting to complete this demo process. Thanks to our predecessors who are active in the blog Park, csdn, github, and open-source Chinese strackoverflow communities, they shared with the open-source community and contributed to more developer benefits, on their shoulders, We cainiao can go further.

 

The source code is attached:

Https://github.com/ccccccmd/ReCapcha

The specific cases are in the source code.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.