python实现视频ai换脸_python 实现 AI 换脸

#!/usr/bin/python

# -*- coding: utf-8 -*-

# @Time : 2019/9/1 8:50

# @Author : cuijianzhe

# @File : AI换脸.py

# @Software: PyCharm

import requests

import simplejson

import json

import base64

import argparse

import os

import cv2

import subprocess

from cv2 import VideoWriter, VideoWriter_fourcc, imread, resize

from PIL import Image, ImageFont, ImageDraw

## 面部识别

def find_face(imgfile):

print("finding")

http_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'

data = {"api_key": 'nFnE8LQ32lteRvt99pA-kaMGCG9PRkGI',

"api_secret": '0RD-G7z9LNEmd4WDdd7PJSmq7vQaIuTs', "image_url": imgfile, "return_landmark": 1}

files = {"image_file": open(imgfile, "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)

faces = this_json2['faces']

list0 = faces[0]

rectangle = list0['face_rectangle']

# print(rectangle)

return rectangle

#number表示换脸的相似度

def merge_face(image_url_1,image_url_2,image_url_3,number):

ff1 = find_face(image_url_1)

ff2 = find_face(image_url_2)

rectangle1 = str(str(ff1['top']) + "," + str(ff1['left']) + "

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值