background

In Keras Introduction (IV), the CAPTCHAs are easily cracked by using CNN model. The CAPTCHAs image tags are implemented by Tornado web pages. This article will describe how to use Tornado to implement image tagging. Our example image is as follows:

We implemented a website with Tornado, which is very helpful for image tagging, that is, we only need to enter the number in the image, and then the saved image name is the input number. Next, let’s take a look at how this function?

The project structure

The name of the project is captcha_tagging, and the complete structure of the project is as follows:

The images in the images folder are the pictures we need to mark, and the marked pictures are stored in the new_images folder, the webpage template file is index.html, and the script of the control program is server.py.

Program implementation

The complete code for index. HTML is as follows:

<! DOCTYPE HTML > < HTML lang="en"> <head> <meta charset=" utf-8 "> <title> </head> <div align="center"> <div align="center"> <br><br> <img src="{{static_url('images/%s' % img_src)}}" style="width:100; height:44"/> <form action='/index' method='post'> value: <input type="text" name="rename" /><br> imgName: <input type="text" name="imgname" value="{{imgname}}"/ bb0 <br> <button type="submit" </button> </form> </div> </body> </body> </html>

The complete code for the script that controls the program, server.py, is as follows:

# -*- coding: utf-8 -*- import cv2 import random import os.path import tornado.web import tornado.ioloop import tornado.options import Tornado. HttpServer from Tornado. Options import define, options # Save image def tag_picture(imagepath, name): image = cv2.imread(imagepath, 1) cv2.imwrite('%s/new_images/%s.png' % (os.path.dirname(os.path.abspath(__file__)), Define ("port", default=9100, type=int) Define ("port", default=9100, type=int) files = os.listdir(dir) return random.choice(files) class ImageHandler(tornado.web.RequestHandler): Def get(self) def get(self) dir = './static/images' img_src = get_image(dir) self.render('index.html', img_src=img_src, Imgname =img_src) # def POST (self): filename = self.get_argument('rename') imgname = self.get_argument('imgname') imagepath = os.path.dirname(__file__)+'/static/images/%s' % imgname tag_picture(imagepath, Print (len(os.listdir('./static/images')) './static/images' img_src = get_image(dir) self.render('index.html', img_src=img_src, Imgname =img_src) # def main() App = nado.web.Application(Handlers =[(r'/index', Handlers =[(r'/index', ImageHandler)], # template_path=os.path.join(os.path.dirname(__file__), "templates"), # static_path=os.path.join(os.path.dirname(__file__), "static"), Static file path) http_server = tornado. # httpserver. Httpserver (app) http_server. Listen (options. The port) tornado.ioloop.IOLoop.instance().start() main()

The program runs

Run server.py and type localhost:9100/index in the browser. The interface looks like this:

Enter the number 8513 in the CAPTCHA in the Value textbox and click Submit. We will see that the image we just marked is saved in the new_images folder and the page will automatically jump to the next image to be marked.

With this program, we only need to mark the pictures we see, and the background will save the result of the mark for you, and delete the original picture, and remind you how many pictures to mark, if the remaining number is shown to be 0, then the mark is finished. The writer flagged 1,000 CAPTCHAs in nearly an hour.

conclusion

To train data with a neural network model, you first need labeled data. If you need to mark the data yourself, it will be a very troublesome and time-consuming process. The author provides an idea of image marking, hoping to give readers some inspiration. This project has been posted on Github at: https://github.com/percent4/CAPTCHA-Recognizition.

Note: I have opened WeChat public account: Python crawler and algorithm (WeChat ID: easy_web_scrape), welcome to pay attention to oh ~~