Code Monkey home page Code Monkey logo

production-verification-code's Introduction

Production-verification-code

Production chinese verification code 数据的生成过程

我就写一下步骤吧:

1、产生与真实数据相同的背景

2、产生干扰点,你们会想为什么这么早产生干扰点,因为我是用改变像素点的方法产生,我遍历整个图的像素,根据自己的设定随机改变一些像素值,就会产生了干扰点,而对后面汉字产生没有影响。(经过实验比较好的方法)

3、用drawimage的方法在背景上生成汉字,汉字我用的是shusong.ttf

4、旋转字体,字体写上以后就是整张图旋转了,但是旋转以后背景图的四个角是改变的。因为背景是有层次感的,导致旋转后四个角遮挡不聊了,漏出黑色。

5、这一步大家应该知道,把四个角的黑色三角变成白色。网上很多方法,先对图片根据像素值对其进行截取,只留下汉字所在的方框,然后在放在另外一个背景下,让背景统一。不过博主有一个另外简单想法,就是根据三通道值进行判断哪一部分是黑色三角,如果三通道值都是0,则代表是。但是这种方法应该最前面字体产生有个要求,黑色字体的像素不能是0,要是从1开始,这样对视觉没啥影响吧。

6、旋转以后,我们就要对图片产生干扰线。随机生成四条线,宽度和汉字的相同,颜色随机产生。

7、批量产生,我把常用汉字存到一个字典里,然后产生某个汉字的图片,都放在汉字所对应的key值文件夹下,这样我在训练的时候,根据访问文件夹就知道样本的标签啦。

作者:machine-lv 我的博客原文:https://blog.csdn.net/qq_37100442/article/details/84034983

python版本:2.7

python Production_verification_code.py --out_dir ./dataset --font_dir ./chinese_fonts --width 30 --height 30 --margin 4 --rotate 30 --rotate_step 1

production-verification-code's People

Contributors

machine-lv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.