赞
踩
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、效果展示
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。