1332225511

import os
import glob
import json
import requests
import base64,uuid
from PIL import Image
import time
# import model
# from config import DETECTANGLE



def main_one_img():
    im_name = "/home/chen/文档/chen/chineseocr-master/demo/031.jpg"
    with open(im_name,"rb") as ff:
        base64_data = base64.b64encode(ff.read())
    # base64_decode = base64.b64decode(base64_data)
    imgString = base64_data
    data = {"type":"1","imgString":imgString.decode()}
    # print(data)
    data = json.dumps(data)
    # print(data)
    res = requests.post(json=data,url="http://0.0.0.0:8080/ocr",timeout=30)
    print(res.json())
    # print(res)

def main_all():
    # im_names = glob.glob(os.path.join(r'/media/chen/001E57D71E57C3F6/union_card_new','*.jpg'))+glob.glob(os.path.join(r'/media/chen/001E57D71E57C3F6/union_card_new','*.png'))
    im_names = glob.glob(os.path.join(r'/media/chen/001E57D71E57C3F6/yyzz_copy','*.jpg'))+glob.glob(os.path.join(r'/media/chen/001E57D71E57C3F6/yyzz_copy','*.png'))+glob.glob(os.path.join(r'/media/chen/001E57D71E57C3F6/yyzz_copy','*.jpeg'))
    # im_names = glob.glob(os.path.join(r'/media/chen/001E57D71E57C3F6/id_copy','*.png'))+glob.glob(os.path.join(r'/media/chen/001E57D71E57C3F6/id_copy','*.jpeg'))
    i = 0
    # im_names =

    listsss = []

    for im_name in im_names:
        i += 1
        with open(im_name, "rb") as ff:
            base64_data = base64.b64encode(ff.read())
        # base64_decode = base64.b64decode(base64_data)
        imgString = base64_data
        data = {"type": "1", "imgString": imgString.decode()}
        # print(data)
        data = json.dumps(data)
        # print(data)
        try:
            res = requests.post(json=data, url="http://0.0.0.0:8080/ocr", timeout=30)
            # print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
            # print(res.json()['res_org'])
            # print(res.json()['res'])
            print(i)
        except:
            print(im_name)
            listsss.append(im_name)
        # print(res)
    print(listsss)


main_all()
# main_one_img()






    def POST(self):
        data = web.data()
        data = json.loads(data.decode())
        data = eval(data)
        print(data["type"])
        imgString = data["imgString"].encode()
        # # imgString = data['imgString'].encode().split(b';base64,')[-1]
        # # print(type(imgString))
        # imgString = json.load(data)['imgString'].encode()
        # print(imgString)
        # print(type(imgString))
        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")

 

你可能感兴趣的:(1332225511)