Identification code: Where to look for numbers (iii)

Source: Internet
Author: User

1 Unexpected questions

The last machine learning algorithm has been able to find the picture of the full existence of the numbers, choose this image to help identify the next step in the image of the numbers, if the numbers are not complete, it is not to mention the image of the number.

The red border indicates that the algorithm determines the presence of numbers

Just as people sometimes find it hard to figure out which picture is the most complete in a small piece of picture, the algorithm finds a small piece of small squares that contain numbers that are adjacent to each other. So the next thing to do is to make a group of small squares that are judged to contain numbers.

2 forming a group

You must ensure that you are looking from left to right to ensure that the order of numbers in the verification code is not garbled.

def groupparts (predicted): "" "Assume predicted a Boolean 2D array of representing a rectangle Group:area made up of  Adjacent trues values groups:all the group finding from left to the right "" "Partshape = Predicted.shape looked        = Np.zeros (partshape,dtype=bool) nexts = [(1,0), (0,1), ( -1,0), (0,-1)] groups = [] for L in range (Partshape[1]): For C in range (Partshape[0]): If not looked[c,l]: looked[c,l] = True if pre                        DICTED[C,L]: group = [] FIFO = [(c,l)] while Len (FIFO)!=0: TMP = Fifo.pop (0) looked[tmp[0],tmp[1]] = True if predicted                                [Tmp[0],tmp[1]]: Group.append ((tmp[0],tmp[1])) for N in nexts: Nextpos = (n[0]+tmp[0],n[1]+tmp[1]) if 0<=nextpos[0]<partsh Ape[0] and 0<=nextpos[1]<partshape[1]: If not looked[nextpos[0],nextpos[1]]:                    LOOKED[NEXTPOS[0],NEXTPOS[1]] = True fifo.append (nextpos) Groups.append (group) return groups

Write a very bad program. The idea is that, when there are no small squares of numbers, look for them in columns from left to right. The small squares that have been viewed are marked in the looked array to avoid repeated viewing.

Once the number of small squares found, the upper and lower left and right small squares are saved in the FIFO list to be viewed, each time the loop pops up a small square view, if the number is included in the group list, while the upper and lower side of the small square saved in the list to be viewed, until the FIFO is empty. Draw on a breadth-first search.

The result would be this:

Group 1:[(5, 3), (6, 3), (7, 3), (8, 3), (7, 4)]

Group 2:[(4, 8), (5, 8), (6, 8), (5, 9), (6, 9)]

Group 3:[(2, 13), (3, 13), (4, 13), (5, 13), (4, 14)]

Group 4:[(8, 13)]

Group 5:[(3, 18), (4, 18), (5, 18), (6, 18)]

Group 6:[(0, 23), (1, 23), (2, 23), (3, 23), (4, 23), (5, 23)]

3 Dealing with miscalculations

The predicted algorithm is not accurate enough, there are usually some false positives, so the group may exceed the number of verification code number 5. The solution is simple, the group that really contains the numbers is usually longer, and the longest 5 groups are found. Another piece of nasty code.

    Groups = Groupparts (Partimgs,predict_contain.reshape (img.partnum))    Num_threshold = sorted (Map (len,groups), Reverse=true) [4]    groups_filtered = filter (lambda x:len (x) >=num_threshold,groups)

A set of adjacent small squares represents a number that can be simply chosen to have the most number (in the majority), as the result of the prediction.

Identification code: Where to look for numbers (iii)

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.