import os import base64 import requests import json import time # img dir image_dir = "/home/stf/miner_pdf/test_img" # access token access_token = "24.6bbe9987c6bd19ba65e4402917811657.2592000.1724573148.282335-86574608" # request url request_url = f"https://aip.baidubce.com/rest/2.0/ocr/v1/seal?access_token={access_token}" # headers headers = {'content-type': 'application/x-www-form-urlencoded'} # seal save path seal_save_path = "/home/stf/miner_pdf/seal.json" data = {} # 图片文件 for img_name in os.listdir(image_dir): img_path = os.path.join(image_dir, img_name) print(f'processing {img_path} ...') f = open(img_path, 'rb') img = base64.b64encode(f.read()) params = {"image":img} #印章检测 response = requests.post(request_url, data=params, headers=headers) if response: print(response.json()) data[img_name] = response.json() time.sleep(3) with open(seal_save_path, 'w', encoding='utf-8') as f: json.dump(data, f, ensure_ascii=False, indent=4)