• Stars
    star
    208
  • Rank 189,015 (Top 4 %)
  • Language
    Python
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OCR;文本检测、文本识别(cnn+ctc、crnn+ctc)。

代码目录

|---- config.py                              # 工程参数配置
|---- ocr_lib                                # 模型、数据生成
|    |---- crnn.py                           # 选用不同模型
|    |---- vgg16.py 
|    |---- vgg19.py 
|    |---- Xception.py 
|    |---- densenet.py
|    |---- data_generator.py
|    |---- data_load.py
|    |---- gen_train_val_data.py
|    |---- random_gen.py
|    |---- fonts                             # 字体
|---- train_net_online.py 
|---- test_net_online.py  
|---- requirements.txt   
  • 代码是基于keras实现的ocr.

主要内容包含:

  1. 相关介绍
  2. 代码使用
  3. 联系

相关介绍

  • 如何进行ocr? 主要方式有:

(1) 文本检测:yolo v3、 ctpn、psenet等,主要是基于检测、分割的方案。

(2) 文本识别:cnn+ctc、crnn+ctc等。

代码使用

  1. OCR模型训练 (训练时间24小时以上,config.py的参数保持默认、或者修改)
$ python train_net_online.py 

2.OCR模型测试

$ python test_net_online.py
  1. OCR模型优化

(1) 选用不同的模型cnn、 crnn等。

(2) 文字生成器选用text_renderer

(3) 还可可参考:PANcrnn.pytorchchineseocrchinese_ocrawesome-ocrPSENettext-detection-ctpnkeras_ocrkeras_PSENetocr_chinese

(4)单字的检测和识别可以参考:CPS-OCR-Engine

测试结果: image

gt>>>>>>> 戒敞古逊罪化综波早洼
pred>>>>> 戒敞古逊罪化综波早洼
gt>>>>>>> 枫矢浙o膝犁苹嫉轨徊
pred>>>>> 枫矢浙o膝犁苹嫉轨徊
gt>>>>>>> 壤驾橘荤僻境追闸择葱
pred>>>>> 壤驾橘荤僻境追闸择葱
gt>>>>>>> 光8旧亏入书丁寸乎}达正
pred>>>>> 光8旧亏入书丁寸乎}达正
gt>>>>>>> 年降姊雕吝奇癣盹印E彪帅
pred>>>>> 年降姊雕吝奇癣盹印E彪
gt>>>>>>> P鞍笼淆喝文姊籽举陨
pred>>>>> P鞍笼淆喝文姊籽举陨
gt>>>>>>> 惩沙掠巧博苗班扣答刽豌樱
pred>>>>> 惩沙掠巧博苗班扣答刽豌樱
gt>>>>>>> 突喜针垄麸汹亏废妒件扯燃
pred>>>>> 突喜针垄麸汹亏废妒件扯燃
gt>>>>>>> 指限蝌艺依铺蔓崩走胡
pred>>>>> 指限蝌艺依铺蔓崩走胡
gt>>>>>>> 支袱葬栖皮这庞法毫穴赫颇
pred>>>>> 支袱葬栖皮这庞法毫穴赫颇
gt>>>>>>> 敞换啊兽倔论涉究搓叔歧沫
pred>>>>> 敞换啊兽倔论涉究搓叔歧沫
gt>>>>>>> 去斥巨化勾]加g风矛召支
pred>>>>> 去斥巨化勾]加g风矛召支
gt>>>>>>> 宁S市扬当a边成计订
pred>>>>> 宁S市扬当a边成计订
gt>>>>>>> 古闪瓦丙迈见礼4旧女凤肉
pred>>>>> 古闪瓦丙迈见礼4旧女凤肉
gt>>>>>>> 捶儿丢覆这抬蔗抢沫肾
pred>>>>> 捶儿丢覆这抬蔗抢沫肾

联系

如何有问题或者建议请联系wechat: lp9628 (需要生成接口、.pb模型可联系)

为了更快的看到效果,只给了两个颜色:random_gen.py

随机生成背景颜色

def randon_gen_bg_color():
    # 图片背景
    '''
    R = random.randrange(0,255,15)
    G = random.randrange(0,255,15)
    B = random.randrange(0,255,15)
    img_color_list = [ (R, G, B) ]'''
    img_color_list = [ (0,0,0), (255,255,255)] #, (255,0,0), (0,255,0), (0,0,255), (0,255,255), (255,0,255), (255,255,0),  (128,128,128), (128,0,0), (0,128,0), (0,0,128), (0,128,128), (128,0,128), (128,128,0) ]
    img_bg_color = random.randint( 0, len(img_color_list)-1 )
    return img_color_list[img_bg_color]

# 随机生成文本颜色
def random_gen_text_color():
    # 文字颜色
    '''
    R = random.randrange(0,255,15)
    G = random.randrange(0,255,15)
    B = random.randrange(0,255,15)
    text_color_list = [ (R, G, B) ]'''
    text_color_list = [ (0,0,0), (255,255,255)] #, (255,0,0), (0,255,0), (0,0,255), (0,255,255), (255,0,255), (255,255,0),  (128,128,128), (128,0,0), (0,128,0), (0,0,128), (0,128,128), (128,0,128), (128,128,0) ]
    text_color = random.randint( 0, len(text_color_list)-1 )
    return text_color_list[text_color]

# 在样本生成的时候没有选用图片作为背景: data_generator.py
flag = np.random.choice([False]) # True


# 随机的调整宽高, 以最大长度初始化
img_size_width = 50 * n_len + 40 + randon_img_width

More Repositories

1

Tensorflow-

Tensorflow实战学习笔记、代码、机器学习进阶系列
Jupyter Notebook
1,129
star
2

TextMatch

QAmatch(qa_match)/文本匹配/文本分类/文本embedding/文本聚类/文本检索(bow/ifidf/ngramtf-df/bert/albert/bm25/…/nn/gbdt/xgb/kmeans/dscan/faiss/….)
Python
839
star
3

CodeFun

DataStructure(SwordOffer、LeetCode)、Deep Learning(Tensorflow、Keras、Pytorch)、Machine Learning(sklearn、spark)、AutoML、AutoDL、ModelDeploying、SQL
Jupyter Notebook
344
star
4

PyTorch_image_classifier

Image classification: efficientnet/resnest/seresnext/.....
Python
212
star
5

train_arch

cnn+rnn+attention: vgg(vgg16,vgg19)+rnn(LSTM, GRU)+attention, resnet(resnet_v2_50,resnet_v2_101,resnet_v2_152)+rnnrnn(LSTM, GRU)+attention, inception_v4+rnn(LSTM, GRU)+attention, inception_resnet_v2+rnn(LSTM, GRU)+attention,..... vgg(vgg16,vgg19), resnet(resnet_v2_50,resnet_v2_101,resnet_v2_152), inception_v4, inception_resnet_v2,.....
Python
189
star
6

OpenCV-

OpenCV学习笔记
C++
95
star
7

TensorFlowTTS_chinese

chinese tts
Jupyter Notebook
76
star
8

train_cnn-rnn

cnn+rnn: vgg(vgg16,vgg19)+rnn(LSTM, GRU), resnet(resnet_v2_50,resnet_v2_101,resnet_v2_152)+rnnrnn(LSTM, GRU), inception_v4+rnn(LSTM, GRU), inception_resnet_v2+rnn(LSTM, GRU),.....
Python
63
star
9

QDServing

ml模型分布式服务部署:grpc,flask;docker
Python
62
star
10

Spark-

Spark学习笔记
Jupyter Notebook
42
star
11

face_stickers

人脸贴纸
Python
32
star
12

train_cnn_GANs

GANs:DCGAN
Python
21
star
13

Pytorch_multi_task_classifier

multi-task classifier
Python
21
star
14

py_workSpace

MachineLP的工具包
Python
18
star
15

conditional-similarity-networks-Tensorflow

Conditional Similarity Networks (CSNs-Tensorflow)
Python
11
star
16

cnn_faceDetection

cpp code: using cnn for face detection
C++
7
star
17

LaneDetection

lane Detection
C++
5
star
18

qa-corpus-zh

问答语料库整理
5
star
19

FashionAI_KeyPoints_Detection

This my project of Fashion AI Key points detection contest.
Python
5
star
20

PyTorch_video_classifier

video recognition
Python
3
star
21

MachineLP

2
star
22

vehicleDetection

C++
2
star
23

Inception_v4_slim

【Ubuntu】slim框架下的inception_v4模型的运行、可视化、导出和使用
Python
1
star