first, the concept of verification code recognition
The main three steps of machine recognition picture are elimination background, cutting characters, identifying characters. And the existing character verification code is designed for these three aspects to design strong verification code.
The following diagram helps you understand the process of validating code recognition:
second, processing flow
One of the most important is the good image processing this step. The image processing module includes image processing techniques such as grayscale, binary, removal of discrete noise points, tilt correction, character cutting and image normalization.
1, the image of Gray
Because of the complexity of the color palette of the 256-color bitmap, many algorithms of image processing have no way to unfold, so it is necessary to do grayscale processing. The so-called grayscale image is the image of each pixel of the R, G, B components of the value is equal. Color image of each pixel of R, G, B value is not the same, so show a variety of colors such as red, green and blue. Grayscale images do not have these color differences, some are only the difference in brightness. The pixels with large gray values are brighter (the maximum pixel value is 255, white), whereas darker (the pixel value is the smallest 0, black). Image grayscale has a variety of different algorithms, a more direct one is to give the pixel RGB value of each one of the weighting coefficient, and then sum up, but also to the palette table items corresponding processing.
2, the image of the value of two
It is important to note that the resulting results must be within one to 0-255. Because this is each byte representation
The limit of the image data.
3. de-noising
The image may be in the process of generation, transmission or acquisition of noise, noise is a common technique in image processing. Usually go to the noise using filtering methods, such as median filter, mean filter. However, such an algorithm is not suitable for processing characters such as a long narrow image, because in the process of filtering is likely to remove the character itself pixels.
One uses the method of removing clutter to make noise processing. The specific algorithm is as follows: Scan the entire image, when the discovery of a black point, and the black point of indirect or directly connected to the number of black dots, if more than a certain value, it means that the point is not discrete points, otherwise is the discrete point, remove it. The recursive method is used when examining the connected black dots. Here, I simply implemented in Python, you can refer to the following.
#coding =utf-8 "" "Creat time:2015.09.14" "" Import cv2 import NumPy as NP from matplotlib import Pyplot as plt from PiL im Port Image,imageenhance,imagefilter img_name = ' 2+.png ' #去除干扰线 im = Image.open (img_name) #图像二值化 enhancer = imageenhance.c Ontrast (IM) im = enhancer.enhance (2) im = Im.convert (' 1 ') data = Im.getdata () w,h = Im.size #im. Show () Black_point = 0 for X in Xrange (1,w-1): For y in Xrange (1,h-1): Mid_pixel = data[w*y+x] #中央像素点像素值 If Mid_pixel = 0: #找出上 Bottom left four direction pixel pixel value Top_pixel = data[w* (y-1) +x] Left_pixel = data[w*y+ (x-1)] Down_pixel = da
ta[w* (y+1) +x] Right_pixel = data[w*y+ (x+1)] #判断上下左右的黑色像素点总个数 If Top_pixel = 0: Black_point + + 1 if Left_pixel = = 0:black_point + 1 if Down_pixel = = 0:black_point + + 1 if Right_pixel = = 0:black_point = 1 if black
_point >= 3: Im.putpixel ((X,y), 0) #print black_point black_point = 0 im.show ()
Original Verification Code:
after processing:
4, Split
The image usually contains more than one number, recognition can only be based on the characteristics of each character to judge, so also to do the character cutting work. This step is to separate the characters in the image of the cut out.
The specific algorithm is as follows:
The first step is to scan the image from top to bottom until the first black pixel is encountered. Write it down. The image is then scanned from top to bottom until the first black pixel is found, thus finding the approximate height range of the image.
The second step , in this height range from left to right column for the scan, encountered the first black pixel is considered to be the beginning of the character cut, and then continue scanning until you encounter a column of no black pixels, it is considered that the character cut end, and then continue to scan, The above method is scanned until the right end of the image. This gets the more precise width range of each character.
The third step is to get the exact height range of each character in the first step by using the Top-down and bottom-up scanning of each character in a more precise width range of the known characters.
5, the normalization of the image
Because the size of the characters in the captured image may differ greatly, or after cutting the character size is not uniform, and relatively speaking, the uniform size of the character recognition is more standard, the accuracy rate is also higher, the normalized image is to the original different characters unified to the same size, In the system implementation, it is unified to the same height, and then the width of the character is adjusted according to the height. The specific algorithm is as follows: first get the height of the original character, compared with the height of the system requirements, to get the coefficient of transformation, and then based on the resulting coefficients to obtain the width of the transformation. After the width and height are obtained, the points in the new image are mapped to the original image in the interpolation method.
Many people think that the two-valued image normalized to 5x9 pixels is ideal because the smaller the size of the image, the higher the recognition speed and the faster the network training. In fact, the 5x9 pixel graph is too small relative to the character image to be recognized. After normalization, the image information is lost a lot, then the image recognition, the accuracy rate is not high. The experiment proves that it is ideal to classify the character image into 10x18 pixel two-valued image, which achieves the better balance point of recognition speed and high accuracy rate. third, identify
Image recognition consists of three chunks: feature extraction, sample training and recognition.
The most important part of verification code recognition is denoising and segmentation, which has a great effect on the precision of your training and recognition. Here only talked about the flow, each of the details have a lot of work to do, here the code word is also difficult to tell clearly, we can take this process as the main line, step-by-step implementation, and ultimately can complete your needs.