地址:/
这里使用python接口,需要传入的是access_token
,返回是一个字典,其中image
字段就是处理后的图片的base64编码。
其中,access_token
需要去获取,如下:
获取链接:
利用如下程序获取:
需要提供client_id
和client_secret
两个字段。
这两个字段需要去创建应用订单后才能获取。链接如下:
填写以下内容:
然后拿到client_id
和client_secret
两个字段即可:
完整接口调用过程如下:
import requests
# client_id 为官网获取的AK, client_secret 为官网获取的SK
client_id = "[你自己的client_id]"
client_secret = "[你自己的client_secret ]"
host = '.0/token?grant_type=client_credentials&client_id={}&client_secret={}'.format(client_id,client_secret)
response = (host)
if response:print(response.json())
上面代码会返回一个字典,提取上面字典的access_token
即可。
然后调用如下代码做图像增强:
# encoding:utf-8
import os
import requests
import base64'''
图像清晰度增强
'''
if __name__ == "__main__":request_url = ".0/image-process/v1/image_definition_enhance"access_token = '[上面代码获取到的你的access_token ]'request_url = request_url + "?access_token=" + access_tokenheaders = {'content-type': 'application/x-www-form-urlencoded'}rawPicPath = r"./data"enhancedPicPath = r"./output"for pic in os.listdir(rawPicPath):pic_path = os.path.join(rawPicPath, pic)# 二进制方式打开图片文件f = open(pic_path, 'rb')img = base64.ad())params = {"image": img}response = requests.post(request_url, data=params, headers=headers)if response:# 提取返回的图像的base64信息image_base64 = response.json()['image'] # 解码为图像数据image_data = base64.b64decode(image_base64)# 保存到本地f = open(os.path.join(enhancedPicPath, pic), 'wb')f.write(image_data)
效果还是比较明显的:
上面是原始结果,下面是增强后结果。
本文发布于:2024-02-04 12:34:39,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170707353755618.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |