Python implements image slide verification and recognition methods,

Source: Internet
Author: User

Python implements image slide verification and recognition methods,

1 abstract

As a natural person robot identification tool, verification code is widely used in various scenarios that prevent programs from being automated. The security of traditional validation models has expired, and various new verification codes have sprung up. Currently, the most common form is the slide puzzle"

2 Content Overview

Slide verification was first proposed by a domestic network security company for its first behavior verification. It was presented to the world in the form of sliding puzzle unlocking. After about a few years, all kinds of Slide verification products have come out. What about the security of these seemingly identical products?

In this article, we have chosen some of the latecomer small manufacturers to perform slide verification for the next experiment. We will only analyze the security from the first step of image science. Because my main technical path is image learning, and I am not familiar with front-end js, I just want to learn about image learning. I just want to add some knowledge to some automation technology personnel.

Because the research object is too simple, it is not difficult to learn some image technologies involved in this article. Basically, python beginners can use this program. It is only for everyone to learn.

3 study object

"Slide Verification" provided by small vendors on a small site ":

Use python to write a simple crawler automation script. The verification code resources on the website are requested several times and saved locally to view the image features.

In general, this step is required. You can see many patterns when downloading more images. For example, after you download 100 images from a public page and request 100 resources for this verification continuously.

At a glance, there is only one way to verify the image material, so you can rest assured, because this problem is relatively simple, rather than multi-mode, you must solve multiple problems.

4. Qualitative Analysis

Filter the images in this single mode as follows:

The following features are found:

The pictures related to the front-end display include the box position prompt image A, the small square B, and the complete background image C.

The a diagram is completely composed of B and C.

Obviously, the person who designed the verification image has no security experience, and has not paid attention to the following two product details:

No special processing for images

Too much information is provided to the public

Therefore, it is extremely easy to identify the location of the image.

5. Quantitative Analysis

In the previous section, we only intuitively see some special pictures of these images. However, to answer this question, we still need to quantify them before they can be procedural, and then they can be fully automated.

Use the matplotlib tool to open this image. The following parameters are obtained by quantization:

Overall image specifications: w: 240, h: 450

It is divided into three parts from top to bottom, and the height of each part is 150

6. Solving Images

Obviously, as long as you subtract the pixels corresponding to the first and third images, the magic will happen:

"Top left" minus "bottom right" to get the "bottom left" result.

At this time, the pixels of the R channel in the x direction are accumulated.

The following statistical chart is displayed:

Then, obtain the first derivative of the curve or the position of the y-direction Abrupt Change Point on the leftmost side if a mutation value exceeds a certain percentage of the maximum pixel value.

So far, the position of the image has been solved successfully.

The corresponding python code is as follows:

Import numpy as np... def get_boundary (mask, axis, ratio = 0.6): "perform pixel statistics on a channel in the grayscale image" sum_along_axis = np. sum (mask, axis = axis) max_value = np. max (sum_along_axis) bound_value = max_value * ratio bvalue = (sum_along_axis> = bound_value ). astype ('int8') return np. where (bvalue! = 0) [0] [0] def get_predict_ans (img): "" based on the classified image, find the corresponding image location and input the binary image. The returned result is: param img:: return: "" nd_img = np. array (img) w_pos = get_boundary (nd_img, 0) # return w_pos according to the distribution chart

Summary

The above section describes how to implement image slide verification and identification in Python. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.