NO.56——Face Swapping with Face++ API(换脸)
在上篇博客中,介绍了应用dlib和openCV进行人脸融合的方法,这里介绍一个更简单、效果更好的方法,就是调用旷世科技的人脸融合接口:https://api-cn.faceplusplus.com/imagepp/v1/mergeface。
在实际运用过程中,还调用了人脸检测接口:https://api-cn.faceplusplus.com/facepp/v3/detect。
效果如图,可见,比前一种方法效果好很多:
具体代码如下:
import requests
import simplejson
import json
#接口的报文是通过base64加密传输的,这种加密方式是可逆的。所以在进行接口自动化时,需要对所传的参数进行base64编码
import base64#Face++网址:[url]https://console.faceplusplus.com.cn/dashboard[/url]
#第一步,获取人脸关键点
def find_face(imgpath):print("正在查找……")http_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'data = {"api_key": 'api_key',"api_secret": 'api_secret',"image_url": imgpath, "return_landmark": 1}files = {"image_file": open(imgpath, "rb")}response = requests.post(http_url, data=data, files=files)req_con = response.content.decode('utf-8')req_dict = json.JSONDecoder().decode(req_con)this_json = simplejson.dumps(req_dict)this_json2 = simplejson.loads(this_json)print(this_json2)faces = this_json2['faces']list0 = faces[0]rectangle = list0['face_rectangle']#print(rectangle)return rectangle#第二步,换脸,其中图片的大小应不超过2M
# number表示换脸的相似度
def merge_face(image_url1, image_url2, image_url, number):ff1 = find_face(image_url1)ff2 = find_face(image_url2)rectangle1 = str(str(ff1['top']) + "," + str(ff1['left']) + "," + str(ff1['width']) + "," + str(ff1['height']))rectangle2 = str(ff2['top']) + "," + str(ff2['left']) + "," + str(ff2['width']) + "," + str(ff2['height'])print(rectangle2)url_add = "https://api-cn.faceplusplus.com/imagepp/v1/mergeface"f1 = open(image_url1, 'rb')f1_64 = base64.b64encode(f1.read())f1.close()f2 = open(image_url2, 'rb')f2_64 = base64.b64encode(f2.read())f2.close()data = {"api_key": 'api_key',"api_secret": 'api_secret',"template_base64": f1_64, "template_rectangle": rectangle1,"merge_base64": f2_64, "merge_rectangle": rectangle2, "merge_rate": number}response = requests.post(url_add, data=data)req_con1 = response.content.decode('utf-8')#print(req_con1)req_dict = json.JSONDecoder().decode(req_con1)result = req_dict['result']imgdata = base64.b64decode(result)file = open(image_url, 'wb')file.write(imgdata)file.close()image1 = '/Users/chenyan/Desktop/AI/googleAI/faceswap_Face++/11.jpg'
image2 = '/Users/chenyan/Desktop/AI/googleAI/faceswap_Face++/bb.jpg'
image = '/Users/chenyan/Desktop/AI/googleAI/faceswap_Face++/testbb.jpg'merge_face(image2, image1, image, 80)
NO.56——Face Swapping with Face++ API(换脸)相关推荐
- 范式转变_设计师的10种范式转变
范式转变 For $250, a business can pay a graphic designer to create a logo for their business. Or, for $1 ...
- Python轻松实现AI换脸
目录 引言 思路 代码 效果 引言 在网上看到一篇基于python实现AI换脸的文章,觉得很好玩复现了一下.研究了几个小时后成功把迪丽热巴的脸换到关晓彤上,很好看:另外还把蔡徐坤的脸换到特朗普上,效果 ...
- mysql_cluster
2019独角兽企业重金招聘Python工程师标准>>> MySQL Cluster 是一种技术,该技术允许在无共享的系统中部署"内存中"数据库的 Cluster ...
- go语言mysql视频_Go语言实战流媒体视频网站
第1章 课程介绍 介绍这门课程大纲,技术堆栈以及环境 1-1 prestudy 1-2 课程介绍及知识要点预习 第2章 一个例子了解golang工具链 通过一个简单的webservice具体从gola ...
- python 大数据学习 遇到的问题,及解决方法。
最近开始跟随<子雨大数据之Spark入门教程(Python版)> 学习大数据方面的知识. 这里是网页教程的链接: http://dblab.xmu.edu.cn/blog/1709-2/ ...
- Android Studio常见报错及处理办法
在Android Studio上点了update,系统自动升级,自动重启Android Studio后,以前的项目Gradle正常编译: Unable to start the daemon proc ...
- python微服务开发pdf_《微服务设计》中文完整版PDF电子书下载
版权声明 1. 本站文章和资源均来自互联网收集和整理,本站不承担任何责任及版权问题. 2. 相关版权归作者及其公司所有,仅供学习研究用途,请勿用于商业目的. 3. 请于下载后24小时内删除,如果喜欢此 ...
- 读取Excel 数据并写入到Word示例
读取Excel 数据并写入到Word示例 0x01 读取Excel 数据并写入到Word示例 1.1 配置pom.xml 1.2 配置 application.properties 1.3 自定义配置 ...
- Syncthing - P2P文件同步工具 - 快速开始
文章目录 一.Syncthing 0. 什么是Syncthing 1. 开始 第一步:安装 第二步:启动 第三步:配置 2. 理解Syncthing同步原理 Blocks Scanning 扫描 Sy ...
最新文章
- matlab-JDBC操作MYSQL数据库中文乱码解决
- 【未完待续】Git个人solo实际常用命令
- php转换图片属性a,PHP 提取图片img标记中的任意属性
- Java笔记-使用BindingResult把表单错误传出来
- java类成员方法(成员函数)的初步介绍
- NeurIPS 2020 | 基于“单目标域样本”的领域自适应方法
- Elasticsearch--springcloud整合 high-level-client-测试-复杂检索---全文检索引擎ElasticSearch工作笔记025
- 国内滴滴面临“讨伐”,国外Uber日子更难过!活该不?
- php列表代码怎么做的,php项目实战:代码讲解之订单列表问题
- MySQL读写分离详解(一)——基本原理
- Matlab 单形法原理,实验报告(单纯形法的matlab程序).doc
- 如何***内网windows xp的几种思路和方法
- Linux 阻塞和非阻塞I/O
- 巴黎世家土味病毒营销,B端创业初期,如何用营销壮大你的种子用户?
- ANSYS Products19.1下载及安装教程
- GPU 渲染管线与着色器 大白话总结 ---- 一篇就够
- 关于深度学习优化器 optimizer 的选择,你需要了解这些
- torch.autograd.grad求二阶导数
- Keil无法跳转到(go to definition)函数定义的地方,而是出现Browser
- ios swift UIActivityIndicatorView 菊花 加载中...