• 大小: 24.5MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-23
  • 语言: 其他
  • 标签: 人工智能  crnn  yolo  v  

资源简介

自然场景OCR(YOLOv3+CRNN),附带整个项目代码,详细代码注释

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
“““
@author: lywen
“““
import os
from PIL import Image
import json
import time
import uuid
import base64
import web
web.config.debug  = True
import model
render = web.template.render(‘templates‘ base=‘base‘)
from config import DETECTANGLE

class OCR:
    “““通用OCR识别“““

    def GET(self):
        post = {}
        post[‘postName‘] = ‘ocr‘##请求地址
        post[‘height‘] = 1000
        post[‘H‘] = 1000
        post[‘width‘] = 600
        post[‘W‘] = 600
        post[‘uuid‘] = uuid.uuid1().__str__()
        return render.ocr(post)

    def POST(self):
        data = web.data()
        data = json.loads(data)
        imgString = data[‘imgString‘].encode().split(b‘;base64‘)[-1]
        imgString = base64.b64decode(imgString)
        jobid = uuid.uuid1().__str__()
        path = ‘/tmp/{}.jpg‘.format(jobid)
        with open(path‘wb‘) as f:
            f.write(imgString)
        img = Image.open(path).convert(“RGB“)
        WH = img.size
        timetake = time.time()
        _resultangle= model.model(img
                                    detectAngle=DETECTANGLE##是否进行文字方向检测
                                    config=dict(MAX_HORIZONTAL_GAP=100##字符之间的最大间隔,用于文本行的合并
                                    MIN_V_OVERLAPS=0.7
                                    MIN_SIZE_SIM=0.7
                                    TEXT_PROPOSALS_MIN_SCORE=0.1
                                    TEXT_PROPOSALS_NMS_THRESH=0.3
                                    TEXT_LINE_NMS_THRESH = 0.99##文本行之间测iou值
                                    MIN_RATIO=1.0
                                    LINE_MIN_SCORE=0.2
                                    TEXT_PROPOSALS_WIDTH=0
                                    MIN_NUM_PROPOSALS=0                                               
                )
                                    leftAdjust=True##对检测的文本行进行向左延伸
                                    rightAdjust=True##对检测的文本行进行向右延伸
                                    alph=0.2##对检测的文本行进行向右、左延伸的倍数
                                    ifadjustDegree=False##是否先小角度调整文字倾斜角度
                                   )
        
        timetake = time.time()-timetake
        res = map(lambda x:{‘w‘:x[‘w‘]‘h‘:x[‘h‘]‘cx‘:x[‘cx‘]‘cy‘:x[‘cy‘]‘degree‘:x[‘degree‘]‘text‘:x[‘text‘]} result)
        res = list(res)

        os.remove(path)
        return json.dumps({‘res‘:res‘timetake‘:round(timetake4)}ensure_ascii=False)




urls = (‘/ocr‘‘OCR‘)

if __name__ == “__main__“:

      app = web.application(urls globals())
      app.run()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-02-26 09:45  chineseocr-master\
     目录           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\
     文件         137  2019-01-22 12:05  chineseocr-master\chineseocr-master\.gitignore
     文件          84  2019-01-22 12:05  chineseocr-master\chineseocr-master\.gitmodules
     文件        2758  2019-01-22 12:05  chineseocr-master\chineseocr-master\app.py
     目录           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\apphelper\
     文件       14144  2019-01-22 12:05  chineseocr-master\chineseocr-master\apphelper\image.py
     文件         917  2019-01-22 12:05  chineseocr-master\chineseocr-master\apphelper\__init__.py
     文件        1186  2019-01-22 12:05  chineseocr-master\chineseocr-master\config.py
     目录           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\
     文件        2079  2019-03-12 23:10  chineseocr-master\chineseocr-master\crnn\crnn.py
     文件        3964  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\dataset.py
     文件       16511  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\keys.py
     目录           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\models\
     文件        3089  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\models\crnn.py
     文件         321  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\models\utils.py
     文件           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\models\__init__.py
     文件        2911  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\util.py
     文件           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\crnn\__init__.py
     目录           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\darknet\
     文件         593  2019-01-22 12:05  chineseocr-master\chineseocr-master\Dockerfile
     文件        1067  2019-01-22 12:05  chineseocr-master\chineseocr-master\LICENSE
     文件        4607  2019-03-13 09:25  chineseocr-master\chineseocr-master\model.py
     目录           0  2019-03-14 09:53  chineseocr-master\chineseocr-master\models\
     文件        2249  2019-01-22 12:05  chineseocr-master\chineseocr-master\README.md
     文件         149  2019-01-22 12:05  chineseocr-master\chineseocr-master\requirements.txt
     文件         712  2019-01-22 12:05  chineseocr-master\chineseocr-master\setup-cpu.md
     文件         727  2019-01-22 12:05  chineseocr-master\chineseocr-master\setup.md
     目录           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\static\
     目录           0  2019-01-22 12:05  chineseocr-master\chineseocr-master\static\css\
     文件      121200  2019-01-22 12:05  chineseocr-master\chineseocr-master\static\css\bootstrap.min.css
............此处省略460个文件信息

评论

共有 条评论