调用百度智能云API实现图像增强和特效

1、百度智能云图像增强和特效API文档链接如下:
https://cloud.baidu.com/product/imageprocess/enhancement
2、接口能力一览表:
在这里插入图片描述
3、步骤
3.1 在百度智能云注册账号;
3.2 然后在线申请应用,获得AppID、API Key、 Secret Key;
4、注意:
4.1 每个API可以免费调用3000次。**
4.2 每个API对图像输入的尺寸要求不一样,这是小细节。
在这里插入图片描述
5、代码部分:

from aip import AipImageProcess
import base64
import numpy as np
import cv2

""" 你的 APPID API_KEY SECRET_KEY  """
APP_ID = 'xxxxx'
API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxx'
client = AipImageProcess(APP_ID, API_KEY, SECRET_KEY)

""" 读取图片 """
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

""" base64图片解码 """
def base64_to_image(base64_code):
    # base64解码
    img_data = base64.b64decode(base64_code)
    # 转换为np数组
    img_array = np.fromstring(img_data, np.uint8)
    # 转换成opencv可用格式
    img = cv2.imdecode(img_array, cv2.COLOR_RGB2BGR)
    return img

img_path = 'xxx.jpg'
ori_img = cv2.imread(img_path)
image = get_file_content(img_path)

# """ 调用图像无损放大 """
# img2 = client.imageQualityEnhance(image);
""" 调用黑白图像上色 """
img = client.colourize(image)
# """ 调用图像对比度增强 """
# img = client.contrastEnhance(image)

img = img['image']
show_img = base64_to_image(img)
imgs = np.hstack([ori_img,show_img])

cv2.imshow('img',imgs)
cv2.imwrite('%s.jpg'%(img_path.split('.')[0]+'2'),imgs,[cv2.IMWRITE_JPEG_QUALITY, 100])
cv2.waitKey(0)

6、效果展示
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值