import oss2
import json
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import requests
AccessKeyId="xxxxx"
AccessKeySecret="xxxxx"
auth = oss2.Auth(AccessKeyId, AccessKeySecret)
bucket = oss2.Bucket(auth, 'https://oss-cn-shanghai.aliyuncs.com', 'ocr-yjs')
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.auth.credentials import StsTokenCredential
credentials = AccessKeyCredential(AccessKeyId, AccessKeySecret)
client = AcsClient(region_id='cn-shanghai', credential=credentials)
import seaborn as sns
"""
https://help.aliyun.com/document_detail/159146.html
人脸滤镜
摄影后期制作:添加AI滤镜,对输入图片进行统一的风格修改。
视频直播:对直播视频进行统一的风格处理,使得内容更有个性
"""
from aliyunsdkfacebody.request.v20191230.FaceFilterRequest import FaceFilterRequest
request = FaceFilterRequest()
request.set_accept_format('json')
filepath="images/test2.jpg"
with open(filepath, 'rb') as fileobj:
bucket.put_object(filepath, fileobj)
url="https://ocr-yjs.oss-cn-shanghai.aliyuncs.com/"+filepath
print(url)
request.set_ImageURL(url)
request.set_ResourceType("向日葵")
request.set_Strength(0.8)
response = client.do_action_with_exception(request)
response=json.loads(str(response, encoding='utf-8'))
print(response)
https://ocr-yjs.oss-cn-shanghai.aliyuncs.com/images/test2.jpg
{'RequestId': '11521381-4430-5C7C-8272-1F78C527C870', 'Data': {'ImageURL': 'http://algo-app-taobao-mm-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/pixelai-portrait-filter/2020_11_17/e4810bed76b22657_test2.jpg?Expires=1629509438&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=ykQnkhjQA69FeW%2FIMtArJ778r0w%3D'}}
ImageURL=response["Data"]["ImageURL"]
ImageURL
'http://algo-app-taobao-mm-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/pixelai-portrait-filter/2020_11_17/e4810bed76b22657_test2.jpg?Expires=1629509438&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=ykQnkhjQA69FeW%2FIMtArJ778r0w%3D'
"""
ResourceType String 是 垦丁
选择图片风格,包括:默认、向日葵、桔梗、垦丁、大理、丽江。
Strength Float 是 0.8
滤镜强度,取值范围0~1。
"""
'\nResourceType\tString\t是\t垦丁\t\n选择图片风格,包括:默认、向日葵、桔梗、垦丁、大理、丽江。\n\nStrength\tFloat\t是\t0.8\t\n滤镜强度,取值范围0~1。\n'
with open("images/人脸滤镜后.jpg",'wb') as file:
file.write(requests.get(ImageURL).content)