# -*- coding: utf-8 -*-
"""
Created on Mon May 23 11:02:05 2022

@author: 34923
"""

import numpy as np
import requests
import json
import base64
import os
os.chdir(r'D:\Paddle\test_interface')




def cv2_resize(path):
    import cv2
    img=cv2.imread(path)
    x, y = img.shape[0:2]
    img_test1 = cv.resize(img, (int(y / 2), int(x / 2)))
    cv2.imwrite('small.jpg',img_test1)


def cv2_to_base64(image):
    return base64.b64encode(image).decode('utf8')


url = "http://47.98.105.232:5004/ocr/prediction"
test_img = '1.jpg'

f=open('3.png', 'rb')

image_data1 = f.read()
    # print file name

image = cv2_to_base64(image_data1)

data = {"key": ["image"], "value": [image]}

r = requests.post(url=url, data=json.dumps(data))

result = r.json()

print("erro_no:{}, err_msg:{}".format(result["err_no"], result["err_msg"]))
    # check success
if result["err_no"] == 0:
    ocr_result = result["value"][0]
    try:
        for item in eval(ocr_result):
            print("{}, {}".format(item[0], item[1]))
    except Exception as e:
        print("No results")


