Giter Club home page Giter Club logo

darknet-ocr's Introduction

本项目基于yolo3crnn 实现中文自然场景文字检测及识别

训练代码(master分支)

ocr训练数据集

ocr ctc训练数据集(压缩包解码:chineseocr)
百度网盘地址:链接: https://pan.baidu.com/s/1UcUKUUELLwdM29zfbztzdw 提取码: atwn
gofile地址:http://gofile.me/4Nlqh/uT32hAjbx 密码 https://github.com/chineseocr/chineseocr

实现功能

  • 文字方向检测 0、90、180、270度检测(支持dnn/tensorflow)
  • 支持(darknet/opencv dnn /keras)文字检测,支持darknet/keras训练
  • 不定长OCR训练(英文、中英文) crnn\dense ocr 识别及训练 ,新增pytorch转keras模型代码(tools/pytorch_to_keras.py)
  • 支持darknet 转keras, keras转darknet, pytorch 转keras模型
  • 身份证/火车票结构化数据识别
  • 新增CNN+ctc模型,支持DNN模块调用OCR,单行图像平均时间为0.02秒以下
  • CPU版本加速
  • 支持基于用户字典OCR识别
  • 新增语言模型修正OCR识别结果
  • 支持树莓派实时识别方案

环境部署

GPU部署 参考:setup.md
CPU部署 参考:setup-cpu.md

下载编译darknet(如果直接运用opencv dnn或者keras yolo3 可忽略darknet的编译)

git clone https://github.com/pjreddie/darknet.git 
mv darknet chineseocr/
##编译对GPU、cudnn的支持 修改 Makefile
#GPU=1
#CUDNN=1
#OPENCV=0
#OPENMP=0
make 

修改 darknet/python/darknet.py line 48
root = '/root/'##chineseocr所在目录
lib = CDLL(root+"chineseocr/darknet/libdarknet.so", RTLD_GLOBAL)

下载模型文件

模型文件地址:

模型转换(非必须)

pytorch ocr 转keras ocr

python tools/pytorch_to_keras.py  -weights_path models/ocr-dense.pth -output_path models/ocr-dense-keras.h5

darknet 转keras

python tools/darknet_to_keras.py -cfg_path models/text.cfg -weights_path models/text.weights -output_path models/text.h5

keras 转darknet

python tools/keras_to_darknet.py -cfg_path models/text.cfg -weights_path models/text.h5 -output_path models/text.weights

模型选择

参考config.py文件

构建docker镜像

##下载Anaconda3 python 环境安装包(https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh) 放置在chineseocr目录下   
##建立镜像   
docker build -t chineseocr .   
##启动服务   
docker run -d -p 8080:8080 chineseocr /root/anaconda3/bin/python app.py

web服务启动

cd chineseocr## 进入chineseocr目录
python app.py 8080 ##8080端口号,可以设置任意端口

访问服务

http://127.0.0.1:8080/ocr

识别结果展示

参考

  1. yolo3 https://github.com/pjreddie/darknet.git
  2. crnn https://github.com/meijieru/crnn.pytorch.git
  3. ctpn https://github.com/eragonruan/text-detection-ctpn
  4. CTPN https://github.com/tianzhi0549/CTPN
  5. keras yolo3 https://github.com/qqwweee/keras-yolo3.git
  6. darknet keras 模型转换参考 参考:https://www.cnblogs.com/shouhuxianjian/p/10567201.html
  7. 语言模型实现 https://github.com/lukhy/masr

darknet-ocr's People

Contributors

wenlihaoyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

darknet-ocr's Issues

想问下,返回的boxes坐标是什么顺序呢?

array([[ 69.375 , 70.10526316, 244.63815789, 68.64473684,
244.63815789, 101.50657895, 69.375 , 102.23684211],
[ 69.375 , 163.57894737, 361.48026316, 164.30921053,
361.48026316, 198.63157895, 69.375 , 197.90131579],
[ 57.69078947, 341.03289474, 595.16447368, 342.49342105,
595.16447368, 378.27631579, 57.69078947, 376.81578947],
[361.48026316, 249.75 , 384.84868421, 249.75 ,
384.84868421, 274.57894737, 361.48026316, 274.57894737],
[ 57.69078947, 213.96710526, 420.63157895, 221.26973684,
419.90131579, 254.86184211, 56.96052632, 247.55921053],
[ 45.27631579, 119.76315789, 314.74342105, 116.11184211,
315.47368421, 148.97368421, 46.00657895, 152.625 ],
[116.11184211, 248.28947368, 303.78947368, 252.67105263,
303.05921053, 284.07236842, 115.38157895, 280.42105263]])

这个坐标顺序是什么呢?

UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position...

env:
python 3.7.1
web.py==0.40.dev0

problem:
return Template(open(path).read(), filename=path, **self._keywords)
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 410: illegal multibyte sequence

temporary solution

open the file lib\site-packages\web\template.py

old: return Template(open(path).read(), filename=path, **self._keywords)
new: return Template(open(path,encoding='utf-8').read(), filename=path, **self._keywords)

浏览器兼容性太差

IE, Chrome,Firefox 都无法正常显示,也无法识别图片,自带的一些图片也无法识别。
上传图片,点击识别,提示异常
1

请及时看看问题

How to solve it please

I run app.py but it is a error, how to solve it? Thanks

OSError: dlopen(darknet/libdarknet.so, 10): image not found

数据集问题

大佬你的数据集是生成么,如果是请指点一下生成所需要考虑到的细节因素,还有您使用字符集是多少个的、有没有使用专业语料库之类的

服务起不来network_predict_image_vgg找不到

$ python3 app.py 8080
app.py:81: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if 'uuid' is not None and (url is not None or imgString is not None):
Traceback (most recent call last):
File "app.py", line 14, in
from dnn.text import detect_lines
File "/Users/akore/Downloads/darknet-ocr-master/dnn/text.py", line 13, in
from dnn.darknet import load_net,predict_image,array_to_image
File "/Users/akore/Downloads/darknet-ocr-master/dnn/darknet.py", line 112, in
predict_image =lib.network_predict_image_vgg
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/init.py", line 382, in getattr
func = self.getitem(name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/init.py", line 387, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7ff287681f10, network_predict_image_vgg): symbol not found

什么python3的版本

感觉启动后好多问题都是在templates/text.htm 中的python格式各种语法报错
我的是mac的3.8的python,跑起来比较艰难

运行报错,搜索无果,请指导,非常感谢

(base) xxxx@ubuntu:~/darknet-ocr-master$ python app.py 8080
Traceback (most recent call last):
File "app.py", line 14, in
from dnn.text import detect_lines
File "/home/xxx/darknet-ocr-master/dnn/text.py", line 13, in
from dnn.darknet import load_net,predict_image,array_to_image
File "/home/xxx/darknet-ocr-master/dnn/darknet.py", line 112, in
predict_image =lib.network_predict_image_vgg
File "/home/xxx/anaconda3/lib/python3.6/ctypes/init.py", line 357, in getattr
func = self.getitem(name)
File "/home/xxx/anaconda3/lib/python3.6/ctypes/init.py", line 362, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: ../darknet/libdarknet.so: undefined symbol: network_predict_image_vgg

多方查找资料,也多次编译darknet但问题依然,请指导,非常感谢

win10下关于ocr问题

win10下CPU模式,python3.6.5,已编译cpu版makefile

请问CPU模式下,config.py设置GPU为False,是否需要修改ocr.py第19行 if 1: 为 if gpu: ???

若不修改,调用predict_darknet 和 predict_cpu均无任何输出,无报错信息,程序就直接结束
image

若修改,输出结果均为乱码,如下图。
image

提示:识别异常

Windows10, Python 3.5.2 直接上传本地图片 /test/orc.jpeg
提示:识别异常
cmd窗口 log 如下:

python app.py 8080
http://0.0.0.0:8080/
127.0.0.1:58197 - - [13/Oct/2019 21:18:50] "HTTP/1.1 GET /text" - 200 OK
127.0.0.1:58200 - - [13/Oct/2019 21:18:50] "HTTP/1.1 GET /static/css/main.css" - 304 Not Modified
127.0.0.1:58198 - - [13/Oct/2019 21:18:50] "HTTP/1.1 GET /static/js/jquery.js" - 304 Not Modified
127.0.0.1:58199 - - [13/Oct/2019 21:18:50] "HTTP/1.1 GET /static/js/helps.js" - 304 Not Modified
127.0.0.1:58197 - - [13/Oct/2019 21:18:50] "HTTP/1.1 GET /static/img/loading.gif" - 304 Not Modified
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\web.py-0.40-py3.5.egg\web\application.py", line 289, in process
return self.handle()
File "C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\web.py-0.40-py3.5.egg\web\application.py", line 280, in handle
return self._delegate(fn, self.fvars, args)
File "C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\web.py-0.40-py3.5.egg\web\application.py", line 530, in delegate
return handle_class(cls)
File "C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\site-packages\web.py-0.40-py3.5.egg\web\application.py", line 508, in handle_class
return tocall(*args)
File "app.py", line 73, in POST
data = json.loads(data)
File "C:\Users\admin\AppData\Local\Programs\Python\Python35\lib\json_init
.py", line 312, in loads
s.class.name))
TypeError: the JSON object must be str, not 'bytes'

127.0.0.1:58197 - - [13/Oct/2019 21:19:00] "HTTP/1.1 POST /text" - 500 Internal Server Error

: Unknown error 1362440885

大神,您好:

大概测试了一下,cpu版本是没有问题的,
但gpu版本在运行时,会报:: Unknown error 1362440885 的错误,程序退出。
初步定位了下,是在:dnn/text.py 的14行:
textNet = load_net(textPath.replace('.weights','.cfg').encode(),textPath.encode(), 0)
运行这一步时,报的错, 没有其他输出信息。
请问这个是什么原因导致的? 谢谢。

模型训练数据

您好!您用了多少数据进行的训练,有训练数据吗?

日语模型识别失败

image

以下是结果:
序号 值
0 海政面憶九拳衝釘釧貝ャ割握視晩キ稼熔材井釘窒×芭赤稼村政朗台憶造_鎖劣條壊胆療塚政あ海●五困

请问日语模型是不是还不能使用

Win10下启动后立即退出

1、采用cygwin make好darknet并部署
2、pip安装了库
python app.py 8080 后,命令行直接退出,无任何提示,浏览器无法访问,
请问有人遇到过吗?

make出错

看到更新了ocr识别的模型,马上拿来用一下,自己是windows10的系统,也没有gpu,但是在编译的时候出错了,我电脑上装的MinGW来make的,请问windows系统应该怎么编译呢 是不是要改一下makefile文件,谢谢哈,或者是否可以将build好的library也直接传上来下载后直接用呢
E:\pycharm_workspace\darknet-ocr-master\darknet>make
make: *** No rule to make target 'obj', needed by 'all'. Stop.

text.weights模型文件無法下載

版主您好,我點進模型文建下載時百度網盤說網頁不存在了,不知道是不是地區的關係從來沒有一次從百度網盤下在成功,方便提供其他的載點嗎,謝謝!

darknet编译错误目前已发现两处代码错误,麻烦大佬更新下bug

<1>在src中的network.cu中1005行:
void sync_n
ets(network **nets, int n, int interval)
正确应该为:void sync_nets(network **nets, int n, int interval)
<2>在src中的maxpool_layer_kernels.cu中36,37行:
int cur_h = h_offset + istride[0] + l;
int cur_w = w_offset + j
stride[1] + m;
正确应为:
int cur_h = h_offset + istrideh + l;
int cur_w = w_offset + j
stridew + m;
<3>在src中的maxpool_layer_kernels.cu中55行:
int area = (size-1)/stride;
这个stride到底是strideh 还是stridew ,我也蒙圈了

报错Unknown error 47391493

Ubuntu 16.04
python3.7
无GPU,编译好了darknet,config也设置了darkRoot
测试运行dnn/ocr.py 报错Unknown error 47391493
定位错误是在dnn/ocr.py 23行 ocrNet = load_net(ocrPath.replace('.weights','.cfg').encode(),ocrPath.encode(), 0)

exec app.py error

Traceback (most recent call last):
File "app.py", line 14, in
from dnn.text import detect_lines
File "/home/wanghe/darknet-ocr/dnn/text.py", line 13, in
from dnn.darknet import load_net,predict_image,array_to_image
File "/home/wanghe/darknet-ocr/dnn/darknet.py", line 112, in
predict_image =lib.network_predict_image_vgg
File "/usr/lib64/python3.6/ctypes/init.py", line 356, in getattr
func = self.getitem(name)
File "/usr/lib64/python3.6/ctypes/init.py", line 361, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: ../darknet/libdarknet.so: undefined symbol: network_predict_image_vgg

this is my error,i git clone darknet and make it,then exec /bin/python3 app.py 8080
i make the darknet-ocr,but it does not work,prompt make: *** There are no rules to create the target "obj" required by "all". stop

ocr.cfg

作者你好,想问一下ocr.cfg该如何使用呢,训练数据是怎样标注的?

不管什么图片,都提示异常

127.0.0.1:48050 - - [14/Jan/2020 18:12:47] "HTTP/1.1 POST /text" - 500 Internal Server Error
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.5/site-packages/web/application.py", line 289, in process
return self.handle()
File "/home/ubuntu/.local/lib/python3.5/site-packages/web/application.py", line 280, in handle
return self._delegate(fn, self.fvars, args)
File "/home/ubuntu/.local/lib/python3.5/site-packages/web/application.py", line 530, in _delegate
return handle_class(cls)
File "/home/ubuntu/.local/lib/python3.5/site-packages/web/application.py", line 508, in handle_class
return tocall(*args)
File "app.py", line 66, in POST
data = json.loads(data)
File "/usr/lib/python3.5/json/init.py", line 312, in loads
s.class.name))
TypeError: the JSON object must be str, not 'bytes'

127.0.0.1:48236 - - [14/Jan/2020 18:13:35] "HTTP/1.1 POST /text" - 500 Internal Server Error

OpenCV报Inconsistent shape for ConcatLayer in function 使用的是身份证正面图片

223.73.120.86:30801 - - [14/Oct/2019 11:43:45] "HTTP/1.1 POST /text" - 500 Internal Server Error
Traceback (most recent call last):
  File "/opt/miniconda3/envs/darknet-ocr/lib/python3.6/site-packages/web/application.py", line 257, in process
    return self.handle()
  File "/opt/miniconda3/envs/darknet-ocr/lib/python3.6/site-packages/web/application.py", line 248, in handle
    return self._delegate(fn, self.fvars, args)
  File "/opt/miniconda3/envs/darknet-ocr/lib/python3.6/site-packages/web/application.py", line 488, in _delegate
    return handle_class(cls)
  File "/opt/miniconda3/envs/darknet-ocr/lib/python3.6/site-packages/web/application.py", line 466, in handle_class
    return tocall(*args)
  File "app.py", line 83, in POST
    res = job(uuid,url,imgString,iscut,isclass,billModel,ip)
  File "app.py", line 34, in job
    boxes,scores = detect_lines(image,scale=scale,maxScale=maxScale)
  File "/opt/darknet-ocr/dnn/text.py", line 48, in detect_lines
    scores,boxes,rate,w,h = detect_box(image,scale,maxScale)
  File "/opt/darknet-ocr/dnn/text.py", line 22, in detect_box
    out  = textNet.forward(outputName)[0]
cv2.error: OpenCV(4.0.0) /io/opencv/modules/dnn/src/layers/concat_layer.cpp:95: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes'

环境:
ubuntu 16.04 amd64

GPU版本未识别到文字

采用cpu 识别结果正常,采用gpu则没有识别到。无异常log输出。环境为多卡gtx1080ti GPU,ubuntu16

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.