[英]Crop Image using Pyhton
I have a function to crop image using python.我有一个 function 来使用 python 裁剪图像。 Right now it will process the image 1 by 1, however, I want to crop all images in 1 folder.
现在它将逐个处理图像,但是,我想裁剪 1 个文件夹中的所有图像。 I need to modify the function to be able process all images in 1 folder and save the result in excel.
我需要修改 function 以便能够处理 1 个文件夹中的所有图像并将结果保存在 excel 中。
def send_request_croppingsegm(file_path, doctype):
url = 'http://52.77.70.50:8006/detectGeneralDocumentV3/single'
files=[ ('imageFile', (file_path.split('/')[-1], open(file_path, 'rb'), 'image/png')) ]
headers = {}
payload = {'documentType': doctype}
res = requests.request("POST", url, data=payload, files=files, verify=verify).text
res = json.loads(res)
cropped_data64 = base64.b64decode(res['document_image'])
cropped_img = Image.open(io.BytesIO(cropped_data64))
return cropped_img
DEFAULT_DIR = 'C:/Users/API Test'
fn = 'ucf.png'
imgpath = os.path.join(DEFAULT_DIR, fn)
cropped = send_request_croppingsegm(imgpath, 2)
plt.imshow(cropped)
import os
# list all files in directory
for i in os.listdir(DEFAULT_DIR):
# if it ends with '.png'
if i.endswith(".png"):
imgpath = os.path.join(DEFAULT_DIR, i)
cropped = send_request_croppingsegm(imgpath, 2)
plt.imshow(cropped)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.