Esempio n. 1
0
def init(filepath, pars=dict(textline_method='textboxes')):  # type='special',
    '''
    mage = cv2.imread(filepath,0)
    str_info, position = recog_qrcode(image, roi=None)

    #二维码无法识别
    if str_info == None:
    '''
    timer = Timer()
    timer.tic()

    recog = fp.TextBoxes.recog_invoice_type.InvoiTypeRecog()
    im = caffe.io.load_image(filepath)

    invoice_type = ['spec_and_normal', 'spec_and_normal']
    typeP = invoice_type[recog(im)]

    if typeP == 'spec_and_normal':
        # typeP = 'special'
        typeP = 'normal'
    elif typeP == 'spec_and_normal_bw':
        typeP = 'normal'
    else:
        return "", timer, typeP

    return newMubanDetect(filepath, typeP, pars, timer)
Esempio n. 2
0
def init(filepath, type='special', pars=dict(textline_method='textboxes')):
    '''
    mage = cv2.imread(filepath,0)
    str_info, position = recog_qrcode(image, roi=None)

    #二维码无法识别
    if str_info == None:
    '''
    timer = Timer()
    timer.tic()

    if not views.local_start:
        res = scanQRc(filepath)
        timer.toc(content="二维码识别")

        if res[0] != '':
            # 显示二维码
            plt_rects = []
            plt_rects.append([
                res[1][1][0], res[1][1][1], res[1][3][0] - res[1][0][0],
                res[1][0][1] - res[1][1][1]
            ])
            # 显示
            vis_textline0 = fp.util.visualize.rects(cv2.imread(filepath, 0),
                                                    plt_rects)
            # 运行代码需要如下部分
            pl.imshow(vis_textline0)
            # 保存到line目录
            pltpath = filepath.replace("upload", "line")
            try:
                pl.savefig(pltpath)
            except Exception as e:
                print("绘制行提取图片不支持bmp格式:{}".format(e))

            resArray = getArrayFromStr(res[0])
            # print(resArray)
            js = InterfaceType.JsonInterface.invoice()
            js.setVATInvoiceFromArray(resArray, type)

            jsoni = js.dic
            print(jsoni)
            return json.dumps(jsoni).encode().decode("unicode-escape"), timer
        else:
            return newMubanDetect(filepath, type, pars, timer)
    else:
        # print('newMubanD')
        return newMubanDetect(filepath, type, pars, timer)
    '''
Esempio n. 3
0
def init(filepath, pars=dict(textline_method='textboxes')):  # type='special',
    '''
    mage = cv2.imread(filepath,0)
    str_info, position = recog_qrcode(image, roi=None)

    #二维码无法识别
    if str_info == None:
    '''
    timer = Timer()
    timer.tic()

    recog = fp.TextBoxes.recog_invoice_type.InvoiTypeRecog()
    im = caffe.io.load_image(filepath)

    typeP = recog(im)

    # ['quota', 'elect', 'airticket', 'special', 'trainticket']
    # 01 *增值税专用发票
    # 02 货运运输业增值税专用发票
    # 03 机动车销售统一发票
    # 04 *增值税普通发票
    # 10 *增值税普通发票(电子)
    # 11 *增值税普通发票(卷式)
    # 91 出租车票
    # 92 *火车票
    # 93 *飞机票
    # 94 汽车票
    # 95 *定额发票
    # 96 长途汽车票
    # 97 通用机打发票
    # 98 政府非税收收入一般缴款书
    # 00 其他类型
    # 注:增值税票目前不能区分具体种类,可统一返回01

    if typeP == '01':
        typeP = 'special'
        # typeP = 'normal'
    elif typeP == '04':
        typeP = 'normal'
    else:
        return "", timer, typeP

    if not views.local_start:
        # res = scanQRc(filepath)
        # timer.toc(content="二维码识别")
        #
        # if res[0] != '':
        #     # 显示二维码
        #     plt_rects = []
        #     plt_rects.append(
        #         [res[1][1][0],
        #          res[1][1][1],
        #          res[1][3][0] - res[1][0][0],
        #          res[1][0][1] - res[1][1][1]])
        #     # 显示
        #     vis_textline0 = fp.util.visualize.rects(cv2.imread(filepath, 0), plt_rects)
        #     # 运行代码需要如下部分
        #     pl.imshow(vis_textline0)
        #     # 保存到line目录
        #     pltpath = filepath.replace("upload", "line")
        #     try:
        #         pl.savefig(pltpath)
        #     except Exception as e:
        #         print("绘制行提取图片不支持bmp格式:{}".format(e))
        #
        #     resArray = getArrayFromStr(res[0])
        #     # print(resArray)
        #     js = InterfaceType.JsonInterface.invoice()
        #     js.setVATInvoiceFromArray(resArray, typeP)
        #
        #     jsoni = js.dic
        #     print(jsoni)
        #     return json.dumps(jsoni).encode().decode("unicode-escape"), timer, typeP
        # else:
        #     return newMubanDetect(filepath, typeP, pars, timer)

        # 暂时关闭二维码
        return newMubanDetect(filepath, typeP, pars, timer)
    else:
        # print('newMubanD')
        return newMubanDetect(filepath, typeP, pars, timer)
Esempio n. 4
0
def init(filepath):
    '''
    mage = cv2.imread(filepath,0)
    str_info, position = recog_qrcode(image, roi=None)

    #二维码无法识别
    if str_info == None:
    '''
    timer = Timer()
    timer.tic()

    #recog = fp.TextBoxes.recog_invoice_type.InvoiTypeRecog()
    recog = views.global_recog
    ## load image with OpenCV
    im = cv2.imread(filepath)
    im = cv2.resize(im, (448, 448))
    # im = caffe.io.load_image(filepath)

    typeP = recog(im)

    # 01 *增值税专用发票
    # 02 货运运输业增值税专用发票
    # 03 机动车销售统一发票
    # 04 *增值税普通发票
    # 10 *增值税普通发票(电子)
    # 11 *增值税普通发票(卷式)
    # 91 出租车票
    # 92 *火车票
    # 93 *飞机票
    # 94 汽车票
    # 95 *定额发票
    # 96 长途汽车票
    # 97 通用机打发票
    # 98 政府非税收收入一般缴款书
    # 00 其他类型
    # 注:增值税票目前不能区分具体种类,可统一返回01

    # 201907706 返回:['quota', 'airticket', 'special', 'trainticket']
    print("发票类型识别:", typeP)
    if typeP == '01':
        res = scanQRc(filepath)
        timer.toc(content="二维码识别")
        print("二维码识别调用结束")

        if res[0] != '':
            # 显示二维码
            # plt_rects = []
            # plt_rects.append(
            #     [res[1][1][0],
            #      res[1][1][1],
            #      res[1][3][0] - res[1][0][0],
            #      res[1][0][1] - res[1][1][1]])
            # # 显示
            # vis_textline0 = fp.util.visualize.rects(cv2.imread(filepath, 0), plt_rects)
            # # 运行代码需要如下部分
            # pl.imshow(vis_textline0)
            # # 保存到line目录
            # pltpath = filepath.replace("upload", "line")
            # try:
            #     pl.savefig(pltpath)
            # except Exception as e:
            #     print("绘制行提取图片不支持bmp格式:{}".format(e))

            #关闭绘制二维码 wt 2019.10.19
            pltpath = filepath.replace("upload", "line")
            im = cv2.imread(filepath, 0)
            cv2.imwrite(pltpath, im)

            resArray = getArrayFromStr(res[0])
            print("Loading json", resArray)
            js = InterfaceType.JsonInterface.invoice()
            js.setVATInvoiceFromArray(resArray, typeP)

            jsoni = js.dic
            print(jsoni)
            return json.dumps(jsoni).encode().decode(
                "unicode-escape"), timer, typeP
        else:
            return newMubanDetect(filepath, 'normal', timer)
        #return newMubanDetect(filepath, 'normal', timer)
    elif typeP == '92':
        print("train tk ocr begin")
        return Ocr.init(filepath, 'blue')[0], timer, typeP
    else:
        return "", timer, typeP
Esempio n. 5
0
def init(filepath, pars=dict(textline_method='textboxes')):  # type='special',
    '''
    mage = cv2.imread(filepath,0)
    str_info, position = recog_qrcode(image, roi=None)

    #二维码无法识别
    if str_info == None:
    '''
    timer = Timer()
    timer.tic()

    recog = fp.TextBoxes.recog_invoice_type.InvoiTypeRecog()
    im = caffe.io.load_image(filepath)

    invoice_type = [
        'quota', 'elect', 'airticket', 'spec_and_normal', 'spec_and_normal_bw',
        'trainticket'
    ]
    typeP = invoice_type[recog(im)]

    if typeP == 'spec_and_normal':
        typeP = 'special'
    elif typeP == 'spec_and_normal_bw':
        typeP = 'normal'
    else:
        return "", timer, typeP

    if not views.local_start:
        # res = scanQRc(filepath)
        # timer.toc(content="二维码识别")
        #
        # if res[0] != '':
        #     # 显示二维码
        #     plt_rects = []
        #     plt_rects.append(
        #         [res[1][1][0],
        #          res[1][1][1],
        #          res[1][3][0] - res[1][0][0],
        #          res[1][0][1] - res[1][1][1]])
        #     # 显示
        #     vis_textline0 = fp.util.visualize.rects(cv2.imread(filepath, 0), plt_rects)
        #     # 运行代码需要如下部分
        #     pl.imshow(vis_textline0)
        #     # 保存到line目录
        #     pltpath = filepath.replace("upload", "line")
        #     try:
        #         pl.savefig(pltpath)
        #     except Exception as e:
        #         print("绘制行提取图片不支持bmp格式:{}".format(e))
        #
        #     resArray = getArrayFromStr(res[0])
        #     # print(resArray)
        #     js = InterfaceType.JsonInterface.invoice()
        #     js.setVATInvoiceFromArray(resArray, typeP)
        #
        #     jsoni = js.dic
        #     print(jsoni)
        #     return json.dumps(jsoni).encode().decode("unicode-escape"), timer, typeP
        # else:
        #     return newMubanDetect(filepath, typeP, pars, timer)

        # 暂时关闭二维码
        return newMubanDetect(filepath, typeP, pars, timer)
    else:
        # print('newMubanD')
        return newMubanDetect(filepath, typeP, pars, timer)