• 大小: 51.15MB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2024-01-29
  • 语言: 其他
  • 标签: OCR  yolov3+ocr  cv  

资源简介

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

资源截图

代码片段和文件信息

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


billList = [‘通用OCR‘‘火车票‘‘身份证‘]

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__()
        post[‘billList‘] = billList
        return render.ocr(post)

    def POST(self):
        data = web.data()
        data = json.loads(data)
        billModel = data.get(‘billModel‘‘‘)
        textAngle = data.get(‘textAngle‘False)##文字检测
        textLine = data.get(‘textLine‘False)##只进行单行识别
        
        imgString = data[‘imgString‘].encode().split(b‘;base64‘)[-1]
        imgString = base64.b64decode(imgString)
        jobid = uuid.uuid1().__str__()
        path = ‘test/{}.jpg‘.format(jobid)
        with open(path‘wb‘) as f:
            f.write(imgString)
        img = cv2.imread(path)##GBR
        HW = img.shape[:2]
        timetake = time.time()
        if textLine:
            ##单行识别
            partImg = Image.fromarray(img)
            text = model.crnnOcr(partImg.convert(‘L‘))
            res =[ {‘text‘:text‘name‘:‘0‘‘box‘:[00W0WH0H]} ]
        else:
            detectAngle = textAngle
            _resultangle= model.model(img
                                        detectAngle=detectAngle##是否进行文字方向检测,通过web传参控制
                                        config=dict(MAX_HORIZONTAL_GAP=50##字符之间的最大间隔,用于文本行的合并
                                        MIN_V_OVERLAPS=0.6
                                        MIN_SIZE_SIM=0.6
                                        TEXT_PROPOSALS_MIN_SCORE=0.1
                                        TEXT_PROPOSALS_NMS_THRESH=0.3
                                        TEXT_LINE_NMS_THRESH = 0.7##文本行之间测iou值
                                                )
                                        leftAdjust=True##对检测的文本行进行向左延伸
                                        rightAdjust=True##对检测的文本行进行向右延伸
                                        alph=0.01##对检测的文本行进行向右、左延伸的倍数
                                       )



            if billModel==‘‘ or billModel==‘通用OCR‘ :
                result = union_rbox(result0.2)
                res = [{‘text‘:x[‘text‘]
                        ‘name‘:str(i)
                        ‘box‘:{‘cx‘:x[‘cx‘]
                               ‘cy‘:x[‘cy‘]
                               ‘w‘:x[‘w‘]
                               ‘h‘:x[‘h‘]
                               ‘angle‘:x[‘degree‘]

                              }
                       } for ix in enumerate(result)]
                res = a

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-05-12 15:40  chineseocr\
     目录           0  2019-04-15 18:52  chineseocr\.git\
     文件          23  2019-04-15 18:52  chineseocr\.git\HEAD
     目录           0  2019-04-15 18:52  chineseocr\.git\branches\
     文件         269  2019-04-15 18:52  chineseocr\.git\config
     文件          73  2019-04-15 18:52  chineseocr\.git\description
     目录           0  2019-04-15 18:52  chineseocr\.git\hooks\
     文件         478  2019-04-15 18:52  chineseocr\.git\hooks\applypatch-msg.sample
     文件         896  2019-04-15 18:52  chineseocr\.git\hooks\commit-msg.sample
     文件         189  2019-04-15 18:52  chineseocr\.git\hooks\post-update.sample
     文件         424  2019-04-15 18:52  chineseocr\.git\hooks\pre-applypatch.sample
     文件        1642  2019-04-15 18:52  chineseocr\.git\hooks\pre-commit.sample
     文件        1348  2019-04-15 18:52  chineseocr\.git\hooks\pre-push.sample
     文件        4898  2019-04-15 18:52  chineseocr\.git\hooks\pre-rebase.sample
     文件        1239  2019-04-15 18:52  chineseocr\.git\hooks\prepare-commit-msg.sample
     文件        3610  2019-04-15 18:52  chineseocr\.git\hooks\update.sample
     文件       27391  2019-04-15 18:52  chineseocr\.git\index
     目录           0  2019-04-15 18:52  chineseocr\.git\info\
     文件         240  2019-04-15 18:52  chineseocr\.git\info\exclude
     目录           0  2019-04-15 18:52  chineseocr\.git\logs\
     文件         205  2019-04-15 18:52  chineseocr\.git\logs\HEAD
     目录           0  2019-04-15 18:52  chineseocr\.git\logs\refs\
     目录           0  2019-04-15 18:52  chineseocr\.git\logs\refs\heads\
     文件         205  2019-04-15 18:52  chineseocr\.git\logs\refs\heads\master
     目录           0  2019-04-15 18:52  chineseocr\.git\logs\refs\remotes\
     目录           0  2019-04-15 18:52  chineseocr\.git\logs\refs\remotes\origin\
     文件         205  2019-04-15 18:52  chineseocr\.git\logs\refs\remotes\origin\HEAD
     目录           0  2019-04-15 18:52  chineseocr\.git\objects\
     目录           0  2019-04-15 18:52  chineseocr\.git\objects\info\
     目录           0  2019-04-15 18:52  chineseocr\.git\objects\pack\
     文件       25124  2019-04-15 18:52  chineseocr\.git\objects\pack\pack-4225dbcb9a25ef4d1ce971b03cc41054051cef16.idx
............此处省略390个文件信息

评论

共有 条评论