Giter VIP home page Giter VIP logo

daybreak-u / chineseocr_lite Goto Github PK

View Code? Open in Web Editor NEW
11.4K 11.4K 2.2K 467.65 MB

超轻量级中文ocr,支持竖排文字识别, 支持ncnn、mnn、tnn推理 ( dbnet(1.8M) + crnn(2.5M) + anglenet(378KB)) 总模型仅4.7M

License: GNU General Public License v2.0

Python 2.37% Dockerfile 0.05% CMake 1.08% C++ 75.69% C 0.86% Kotlin 10.98% Batchfile 1.54% Shell 1.84% Java 0.60% C# 2.41% Visual Basic .NET 2.57%
ncnn ocr pytorch

chineseocr_lite's People

Contributors

benjaminwan avatar dandandj avatar daybreak-u avatar dependabot[bot] avatar fanqie03 avatar lsjsoft avatar misteo avatar nihui avatar pad0y avatar znsoftm 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  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

chineseocr_lite's Issues

vertical text traning

hi, I looked your crnn_lite.py and crnn_full.py ,according to your readme ,crnn_lite.py is the network trained for vertical text recognition, but the difference between orign and vertical text recognition network is what?
I saw the crnn_lite is also like crnn_full ,So could you tell me the difference between the orign and vertical text recognition networks?
Thank you very much!

识别不准确

你好 我编译app.py时也出现了很多包缺失 web numpy cv2 等 后面都install跑起来了 但是感觉不是特别准确 不知道是不是哪里操作问题
ocr

web端访问项目时,报错:web/template.py raise SecurityError, execution of 'Constant' statements is denied

File "/usr/local/python3/lib/python3.8/site-packages/web/template.py", line 948, in compile_template
SafeVisitor().walk(ast_node, filename)
File "/usr/local/python3/lib/python3.8/site-packages/web/template.py", line 1167, in walk
raise SecurityError('\n'.join([str(err) for err in self.errors]))
web.template.SecurityError: /usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:3 - execution of 'Constant' statements is denied
/usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:6 - execution of 'Constant' statements is denied
/usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:7 - execution of 'Constant' statements is denied
/usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:8 - execution of 'Constant' statements is denied
/usr/local/python3/lib/python3.8/site-packages/web/debugerror.py:9 - execution of 'Constant' statements is denied

训练集问题

您好,是否方便提供少量的竖排训练集的样例呢?

app.py中的变量定义有问题?local variable 'res' referenced before assignment

192.168.11.99:53801 - - [12/Mar/2020 17:36:51] "HTTP/1.1 POST /ocr" - 500 Internal Server Error
192.168.11.99:53995 - - [12/Mar/2020 17:40:27] "HTTP/1.1 GET /ocr" - 200 OK
192.168.11.99:54217 - - [12/Mar/2020 17:43:11] "HTTP/1.1 GET /ocr" - 200 OK
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.8/site-packages/web/application.py", line 257, in process
return self.handle()
File "/usr/local/python3/lib/python3.8/site-packages/web/application.py", line 248, in handle
return self._delegate(fn, self.fvars, args)
File "/usr/local/python3/lib/python3.8/site-packages/web/application.py", line 488, in _delegate
return handle_class(cls)
File "/usr/local/python3/lib/python3.8/site-packages/web/application.py", line 466, in handle_class
return tocall(*args)
File "/root/data/chineseocr_lite_0311/chineseocr_lite-master/app.py", line 120, in POST
return json.dumps({'res':res,'timeTake':round(timeTake,4)},ensure_ascii=False)
UnboundLocalError: local variable 'res' referenced before assignment

192.168.11.99:54227 - - [12/Mar/2020 17:43:52] "HTTP/1.1 POST /ocr" - 500 Internal Server Error

psenet编译报错

make
g++ -o pse.so -I include -std=c++11 -O3 -I/home/wuqiang/anaconda3/envs/OCR00/include/python3.6m -I/home/wuqiang/anaconda3/envs/OCR00/include/python3.6m -Wno-unused-result -Wsign-compare -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O3 -ffunction-sections -pipe -fdebug-prefix-map=/tmp/build/80754af9/python_1564510748219/work=/usr/local/src/conda/python-3.6.9 -fdebug-prefix-map=/home/wuqiang/anaconda3/envs/OCR00=/usr/local/src/conda-prefix -fuse-linker-plugin -ffat-lto-objects -flto-partition=none -flto -DNDEBUG -fwrapv -O3 -Wall -L/home/wuqiang/anaconda3/envs/OCR00/lib/python3.6/config-3.6m-x86_64-linux-gnu -L/home/wuqiang/anaconda3/envs/OCR00/lib -lpython3.6m -lpthread -ldl -lutil -lrt -lm -Xlinker -export-dynamic pse.cpp --shared -fPIC
g++: error: unrecognized command line option ‘-fno-plt’
Makefile:10: recipe for target 'pse.so' failed
make: *** [pse.so] Error 1

不需要竖着的文本检测

作者你好,我调试你的ncnn代码,效果非常不错,特别是检测。
我正在往项目上用,你确实给很多的我这类的人,提供了生存之道。

我实际应用不需要竖着的文字检测,有办法解决,或者你之前有这类模型(不用检测竖着的问题)
1
2

python3.7 编译的无法执行

from .pse import pse_cpp
ImportError: Python version mismatch: module was compiled for Python 3.6, but the interpreter version is incompatible: 3.7.1 (default, Dec 18 2019, 23:13:02)

你好,识别不出,网页一直在转

你好,我是部署到阿里云服务器docker里面的,我在浏览器里面可以访问到,但上传身份证图片进行识别的时候,一直在转,没有识别出结果。服务器有时候报错kill(直接退出)、有时候报RuntimeError: can't alloc,就卡在这里。不知道是什么原因?

layer LSTM not exists or registered

使用ncnn_project下的crnn显示LSTM层不支持。
./Text_recognition ../models/crnn_lite_lstm_v2.bin ../models/crnn_lite_lstm_v2.param test.jpg
输出:
输入尺寸 (277, 32, 1)
layer LSTM not exists or registered
段错误 (核心已转储)

编译使用的是ocr目录下的ncnn lib库和include头文件。

我在Windows下不能执行make指令,也不能执行.so文件,安装docker可以运行make和.so?

图片

图片
图片

这是在用anaconda配置好环境后,在IDEA和cmd中出错都是这个, 找不到对应的包或者模块导入,在网上找了许多方法无法解决,本人是在Windows下搭建运行,不能像Ubuntu那样下载运行.so文件,也不能使用make,求助这里面的模块属于python的哪些包

我的.so文件是linux下的,你可以尝试在windows下使用docker

Originally posted by @ouyanghuiyu in #45 (comment)

如果不能执行make,是不是我只能在Linux环境下运行了?[难过][伤心]

识别结果不正确

image

你好,默认启动app后,识别算法怎么选择?
这个默认的结果感觉不正常~

为什么模型中文识别不准确啊

你好,最开始通用OCR识别还是很准确的,后来你更新代码后就不准确了,还有就是火车票和身份证识别一直不准确啊,现在的识别结果如下:
test1

Windows直接执行Make命令报错,求大佬写个CMakeLists

Windows直接执行Make命令报错,求大佬写个CMakeLists

image

#48 大佬表示根据Makefile写个CMakeLists.txt,利用cmake生成sln文件,用Visual Studio编译成Windows平台DLL库,再给python调用

对于这方面实在是无从下手,求指教,跪谢~~~

mac下执行报错

find: -xtype: unknown primary or operator
make: `pse.so' is up to date.
device: cpu
load models
device: cpu
load models
device: cpu
load models
device: cpu
load model
Traceback (most recent call last):
File "/Users/dane/anaconda3/lib/python3.7/site-packages/web/utils.py", line 526, in take
yield next(seq)
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "app.py", line 126, in
app = web.application(urls, globals())
File "/Users/dane/anaconda3/lib/python3.7/site-packages/web/application.py", line 62, in init
self.init_mapping(mapping)
File "/Users/dane/anaconda3/lib/python3.7/site-packages/web/application.py", line 130, in init_mapping
self.mapping = list(utils.group(mapping, 2))
File "/Users/dane/anaconda3/lib/python3.7/site-packages/web/utils.py", line 531, in group
x = list(take(seq, size))
RuntimeError: generator raised StopIteration

在mac上运行出错

出错信息:Segmentation fault: 11
位置是:psenet/PSENET.py 中 preds, boxes_list,rects = pse_decode(preds[0], self.scale)
不知道是否可以fix一下。。

windows 下 执行make报错

D:\chineseocrlite\chineseocr_lite-master\psenet\pse>make
FIND: 参数格式不正确
process_begin: CreateProcess(NULL, python3-config --cflags, ...) failed.
process_begin: CreateProcess(NULL, python3-config --ldflags, ...) failed.
g++ -o pse.so -I include -std=c++11 -O3 pse.cpp --shared -fPIC
In file included from include/pybind11/pytypes.h:12:0,
from include/pybind11/cast.h:13,
from include/pybind11/attr.h:13,
from include/pybind11/pybind11.h:44,
from pse.cpp:8:
include/pybind11/detail/common.h:112:20: fatal error: Python.h: No such file or
directory
#include <Python.h>
^
compilation terminated.
Makefile:10: recipe for target 'pse.so' failed
make: *** [pse.so] Error 1

Anglenet的输出是什么意思?

想请教一下,anglenet的输出是什么意思?看ncnn_project里给的示例是判断文本行的正反,但是网络输出了四个分类结果,后面两个是什么意思?这部分是否有相关的参考文档?

运行app.py后文件缺失,网上找了许多方法无法解决,求助

图片

图片
图片

这是在用anaconda配置好环境后,在IDEA和cmd中出错都是这个, 找不到对应的包或者模块导入,在网上找了许多方法无法解决,本人是在Windows下搭建运行,不能像Ubuntu那样下载运行.so文件,也不能使用make,求助这里面的模块属于python的哪些包

报错 Segmentation fault

device: cpu
load model
device: cpu
load model
device: cpu
load model
device: cpu
load model
http://0.0.0.0:8080/
36.27.60.250:56848 - - [12/Mar/2020 11:14:48] "HTTP/1.1 GET /ocr" - 200 OK
Segmentation fault

上传一个图片识别后,直接就报了Segmentation fault这个错误,我是在阿里云上跑的,难道是硬件不支持?

500 Internal Server Error

运行python app.py 8080后终端显示:
make: Entering directory '/home/amither/Downloads/chineseocr_lite-master/psenet/pse'
make: 'pse.so' is up to date.
make: Leaving directory '/home/amither/Downloads/chineseocr_lite-master/psenet/pse'
device: cpu
load models
device: cpu
load models
device: cpu
load models
device: cpu
load model
http://0.0.0.0:8080/
127.0.0.1:58938 - - [10/Mar/2020 16:34:06] "HTTP/1.1 GET /ocr" - 200 OK

然后当我选择了一张图片后,就会一直打转不出结果,终端显示如下:
127.0.0.1:58938 - - [10/Mar/2020 16:34:06] "HTTP/1.1 GET /favicon.ico" - 404 Not Found
Traceback (most recent call last):
File "/home/amither/tensorflow/lib/python3.5/site-packages/web/application.py", line 257, in process
return self.handle()
File "/home/amither/tensorflow/lib/python3.5/site-packages/web/application.py", line 248, in handle
return self._delegate(fn, self.fvars, args)
File "/home/amither/tensorflow/lib/python3.5/site-packages/web/application.py", line 488, in _delegate
return handle_class(cls)
File "/home/amither/tensorflow/lib/python3.5/site-packages/web/application.py", line 466, in handle_class
return tocall(*args)
File "/home/amither/Downloads/chineseocr_lite-master/app.py", line 51, 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:58938 - - [10/Mar/2020 16:34:12] "HTTP/1.1 POST /ocr" - 500 Internal Server Error

Platform: VMware Ubuntu 16.04 python3.5.2 Pytorch1.4.0+cpu
请问这是为什么?

[Maybe Feature]Support Flask Api

import time
import uuid

import numpy as np
from PIL import Image
from flask import Flask, request, jsonify

from config import *
from model import text_predict, crnn_handle
from apphelper.image import base64_to_PIL
from application import trainTicket, idcard

file_lock = "file.lock"
if os.path.exists(file_lock):
    os.remove(file_lock)

app = Flask(__name__)


@app.route("/ocr", methods=["POST"])
def ocr():
    if request.method == "POST":
        request_start_time = time.time()
        uid_job = uuid.uuid1().__str__()
        data = request.json

        # 模型参数
        bill_model = data.get("billModel", "")

        # 文字检测
        # text_angle = data.get('textAngle', False)

        # 只进行单行识别
        text_line = data.get("textLine", False)

        img_str = data["imgString"].encode().split(b";base64,")[-1]
        img = base64_to_PIL(img_str)
        if img is None:
            response_time = time.time() - request_start_time
            return jsonify({"res": [], "timeTake": round(response_time, 4)})
        else:
            img = np.array(img)
            h, w = img.shape[:2]

            final_result: list = []
            while time.time() - request_start_time <= TIMEOUT:
                if os.path.exists(file_lock):
                    continue
                else:
                    with open(file_lock, "w") as f:
                        f.write(uid_job)
                    if text_line:
                        # 单行识别
                        part_img = Image.fromarray(img)
                        text = crnn_handle.predict(part_img)
                        final_result = [
                            {"text": text, "name": "0", "box": [0, 0, w, 0, w, h, 0, h]}
                        ]
                        os.remove(file_lock)
                        break
                    else:
                        result = text_predict(img)
                        if bill_model == "" or bill_model == "通用OCR":
                            final_result = [
                                {
                                    "text": x["text"],
                                    "name": str(i),
                                    "box": {
                                        "cx": x["cx"],
                                        "cy": x["cy"],
                                        "w": x["w"],
                                        "h": x["h"],
                                        "angle": x["degree"],
                                    },
                                }
                                for i, x in enumerate(result)
                            ]
                        elif bill_model == "火车票":
                            train_ticket_result = trainTicket.trainTicket(result)
                            result = train_ticket_result.res
                            final_result = [
                                {"text": result[key], "name": key, "box": {}}
                                for key in result
                            ]
                        elif bill_model == "身份证":
                            id_card_result = idcard.idcard(result)
                            result = id_card_result.res
                            final_result = [
                                {"text": result[key], "name": key, "box": {}}
                                for key in result
                            ]
                        os.remove(file_lock)
                        break

            response_time = time.time() - request_start_time
            return jsonify({"res": final_result, "timeTake": round(response_time, 4)})


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=9001, debug=True)
  • 🚀 One more suggestion: you can use flake8, black to format your code, and also focus some words spelling.

缺少包

ModuleNotFoundError: No module named 'torchvision.models.utils',但是我已经安装了'torchvision

train file

@ouyanghuiyu 你好
1)请问三个模型的训练文件什么时候会开源
2)将模型转为ncnn库模型,再训练吗,这样做的目的是什么

缺少包

Traceback (most recent call last):
File "C:\Users\Administrator\Downloads\chineseocr_lite-master\app.py", line 8, in
import web
ModuleNotFoundError: No module named 'web'
缺少了web.py?
我是在Windows7 python3.7.4 x64下运行的

编译不通过

g++: error: unrecognized command line option ‘-fno-plt’
Makefile:10: recipe for target 'pse.so' failed
make: *** [pse.so] Error 1

ModuleNotFoundError: No module named 'crnn.CRNN'

Traceback (most recent call last):
File "app.py", line 12, in
from model import text_predict,crnn_handle
File "/home/wangdawei/github/ocr/chineseocr_lite/model.py", line 1, in
from config import *
File "/home/wangdawei/github/ocr/chineseocr_lite/config.py", line 40, in
from crnn.keys import alphabetChinese as alphabet
File "/home/wangdawei/github/ocr/chineseocr_lite/crnn/init.py", line 3, in
from .CRNN import CRNNHandle
ModuleNotFoundError: No module named 'crnn.CRNN'

run.py error?

@ouyanghuiyu any suggestions?
image
environment ubuntu16.04 torch 1.12

Loading Error

Loading test image from web browser got this error:
`find: -xtype: unknown primary or operator
make: pse.so is up to date.
device: cpu
load models
device: cpu
load models
device: cpu
load models
device: cpu
load models
http://0.0.0.0:8080/
127.0.0.1:57218 - - [04/Mar/2020 16:53:54] "HTTP/1.1 GET /ocr" - 200 OK
Traceback (most recent call last):
File "/Users/oblivion/anaconda3/envs/tf37/lib/python3.7/site-packages/web/application.py", line 289, in process
return self.handle()
File "/Users/oblivion/anaconda3/envs/tf37/lib/python3.7/site-packages/web/application.py", line 280, in handle
return self._delegate(fn, self.fvars, args)
File "/Users/oblivion/anaconda3/envs/tf37/lib/python3.7/site-packages/web/application.py", line 530, in _delegate
return handle_class(cls)
File "/Users/oblivion/anaconda3/envs/tf37/lib/python3.7/site-packages/web/application.py", line 508, in handle_class
return tocall(*args)
File "/Users/oblivion/chineseocr_lite/app.py", line 83, in POST
result= text_predict(img)
File "/Users/oblivion/chineseocr_lite/model.py", line 119, in text_predict
preds, boxes_list, rects_re, t = text_handle.predict(img, long_size=pse_long_size)
File "/Users/oblivion/chineseocr_lite/psenet/PSENET.py", line 99, in predict
preds, boxes_list,rects = pse_decode(preds[0], self.scale)
File "/Users/oblivion/chineseocr_lite/psenet/pse/init.py", line 58, in decode
pred, label_values = pse_warpper(preds, 5)
File "/Users/oblivion/chineseocr_lite/psenet/pse/init.py", line 19, in pse_warpper
from .pse import pse_cpp
ImportError: dlopen(/Users/oblivion/chineseocr_lite/psenet/pse/pse.so, 2): no suitable image found. Did find:
/Users/oblivion/chineseocr_lite/psenet/pse/pse.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03
/Users/oblivion/chineseocr_lite/psenet/pse/pse.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x03

127.0.0.1:57226 - - [04/Mar/2020 16:54:43] "HTTP/1.1 POST /ocr" - 500 Internal Server Error
`

Any idea what happened?
Platform: MacOS 10.15.3 Python 3.7 Pytorch 1.4.0

mac 上 make的时候报错

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pse.so] Error 1

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.