文末福利 | Python3 网络爬虫:老板,需要特殊服务吗?
1
2
3
4
import requestsimport base64import jsonimport cv2import numpy as npimport matplotlib.pyplot as plt%matplotlib inlinebeautify_url = "https://api-cn.faceplusplus.com/facepp/v2/beautify"# 你创建的应用的 API Key 和 API Secret(也叫 Secret Key)AK = ''SK = ''# 可选参数,不填写,默认50# 美白程度 0 - 100whitening = 80# 磨皮程度 0 - 100smoothing = 80# 瘦脸程度 0 - 100thinface = 20# 小脸程度 0 - 100shrink_face = 50# 大眼程度 0 - 100enlarge_eye = 50# 去眉毛程度 0 - 100remove_eyebrow = 50# 滤镜名称,不填写,默认无滤镜filter_type = ''# 二进制方式打开图片img_name = 'test_1.png'f = open(img_name, 'rb')# 转 base64img_base64 = base64.b64encode(f.read())# 使用 whitening、smoothing、thinface 三个可选参数,其他用默认值data = {'api_key': AK,'api_secret': SK,'image_base64': img_base64,'whitening': whitening,'smoothing': smoothing,'thinface': thinface,}r = requests.post(url=beautify_url, data=data)html = json.loads(r.text)# 解析base64图片base64_data = html['result']imgData = base64.b64decode(base64_data)nparr = np.frombuffer(imgData, np.uint8)img_res = cv2.imdecode(nparr, cv2.IMREAD_COLOR)img_res_BGR = cv2.cvtColor(img_res, cv2.COLOR_RGB2BGR)# 原始图片img = cv2.imread(img_name)img_BGR = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)# 显示图片fig, axs = plt.subplots(nrows=1, ncols=2, sharex=False, sharey=False, figsize=(10,10))axs[0].imshow(img_BGR)axs[1].imshow(img_res_BGR)plt.show()
5
精 彩 文 章
