12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- # -*- coding: utf-8 -*-
- # @Time : 2021/6/30 0030 17:01
- # @Author : LF
- # @FileName: mathpix_ recognition_V1.py
- # @Software: PyCharm
- import requests
- import base64
- import cv2
- import time
- # url = 'http://10.19.1.11:7080/segment/formula/' # 线上服务器地址
- url = 'http://192.168.1.208:8001/segment/formula/' # 本地测试服务器地址
- def mathpix_recognition_with_img_path(img_path, img_only_flag, latex_img):
- """
- :param img_path: 图片路径 服务器静态地址'http://************.png'
- :return: result 包括参数:"image_url": img_path,输入图片的名称 ; "texts": 识别结果; "is_success": 是否识别成功 --- 0:识别错误 1:识别正确 99:接口调用错误
- """
- data = {'img_url': img_path, 'img_only': img_only_flag, 'latex_img': latex_img}
- result = requests.post(url=url, data=data).json()
- if result['is_success'] == 1:
- txt_result = result['texts'] # 识别的最终结果
- return txt_result
- def get_image_base64(img_path):
- with open(img_path, "rb") as f:
- base64_byte = base64.b64encode(f.read())
- return base64_byte.decode('utf-8')
- def mathpix_recognition_with_base64Img(img_path):
- """
- :param img_path: 图片路径 'img_url':base64img
- :return: result 包括参数:"image_url": img_path,输入图片的名称 ; "texts": 识别结果; "is_success": 是否识别成功 --- 0:识别错误 1:识别正确 99:接口调用错误
- """
- data = {'img_url': get_image_base64(img_path)}
- result = requests.post(url=url, data=data).json()
- if result['is_success'] == 1:
- txt_result = result['texts'] # 识别的最终结果
- return txt_result
- res = mathpix_recognition_with_base64Img(r'Z:\datas\formula_online\png_test_32/0ad997808e.png')
- print(res)
- # '''梅阳阳调用方式'''
- # import requests
- # res = requests.post('http://192.168.1.208:8001/segment/formula/', data={
- # 'img_only': 1, 'latex_img': 1
- # 'img_url': 'url'}).json()
|