GithubHelp home page GithubHelp logo

standygirl / ocr-sample-generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mactarvish/ocr-sample-generator

0.0 0.0 0.0 12.42 MB

OCR(光学字符识别)训练样本生成器,可自动生成用于训练OCR检测和识别模型的图片样本和标注

License: Apache License 2.0

Python 100.00%

ocr-sample-generator's Introduction

ocr-sample-generator

OCR样本生成器,可自动生成用于训练OCR检测和识别模型的图片样本和标注。

  • 精简方便的配置模式,快速自定义需要的样本规格
  • 支持随机生成文本行,包括全图文本和单行文本,同时生成精确的四点框坐标和文本内容
  • 支持自定义增广
  • 支持生成样本可视化
  • 支持不同字体
  • 支持自定义文本布局和文本类型

立即使用

先安装依赖

pip install -r requirements.txt

然后执行

python main.py configs/xxx.py dst_dir num_samples

其中,xxx.py表示配置文件,dst_dir表示生成样本的保存目录,样本图片文件保存在dst_dir/global_canvas/images,标注文件保存在dst_dir/global_canvas/labels,可视化图像保存在dst_dir/global_canvas/visualization

例如

python main.py configs/english.py pgs 20

将按照配置文件english.py的规格生成20个样本,保存在pgs文件夹中。

配置文件说明

BASE_NAME= "mix" # 合成图像的前缀名称

fs = (15, 30)
LAYOUT = dict( # 生成图像的布局配置
    IMAGE_WIDTH= (600, 1000), # 图像的宽度范围,()表示从连续区间中取值,长度超出图像宽度的文本行会被忽略
    IMAGE_HEIGHT= (200, 1000), # 图像的高度范围,文本行从上到下对高度进行填充,填满为止
    FONT_SIZE= fs,
    CHAR_SPACING = [0, 0, 0, 0, 0, 0, 1, 2, 5, 10], # 字符间距,[]表示从集合中随机抽取一个
    LINE_SPACING = (int(1 / 5 * fs[0]), int(15 / 25 * fs[0])), # 行间距
)

CONTEXT = dict( # 生成图像的文本内容比例配置
    HANZI_PROPORTION = (0.2, 0.5), # 汉字比例
    LETTER_PROPORTION = (0.2, 0.5), # 英文字母比例
    NUMBER_PROPORTION = (0, 0.1), # 数字比例
    PUNCTUATION_PROPORTION = (0, 0.1), # 标点符号比例
    SPACE_PROPORTION = (0, 0.1), # 空格比例
)
SAVE_RECTIFIED_LINES_SEPARATELY = True # 是否逐行保存,即根据生成的样本把每个文本行裁出来拉正保存(通常用于训练识别模型),使能后会在保存目录下新建一个rectified_lines文件夹保存每张图上的每个文本行

欢迎issue和pr

ocr-sample-generator's People

Contributors

mactarvish 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.