php优图人脸融合接口

1.下载优图官方SDK

2.将以下代码添加到TencentYoutuyun/Youtu.php中

public static function faceFusion($image_path) {

        $real_image_path = realpath($image_path);
        if (!file_exists($real_image_path))
        {
            return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array());
        }

        $expired = time() + self::EXPIRED_SECONDS;
        $postUrl = Conf::$END_POINT . 'cgi-bin/pitu_open_access_for_youtu.fcg';
        $sign = Auth::appSign($expired, Conf::$USER_ID);

        $image_data = file_get_contents($real_image_path);
        $post_data = array(
            'app_id' =>  Conf::$APPID,
            'rsp_img_type' => 'url',
            'img_data' => base64_encode($image_data),
            'opdata' => [array(
                'cmd' => 'doFaceMerge',
                'params' => array(
                    "model_id"=>"cf_yuren_baozha"
                )
            )]
        );

        $req = array(
            'url' => $postUrl,
            'method' => 'post',
            'timeout' => 10,
            'data' => json_encode($post_data),
            'header' => array(
                'Authorization:'.$sign,
                'Content-Type:text/json',
            ),
        );
        $rsp  = Http::send($req);
        $ret  = json_decode($rsp, true);
        if(!$ret){
            return self::getStatusText();
        }
        return $ret;
    }

3.sample.php中的代码

<?php

require('./include.php');
use TencentYoutuyun\Youtu;
use TencentYoutuyun\Conf;


// 设置APP 鉴权信息 请在http://open.youtu.qq.com 创建应用

$appid='你在优图申请的appid';
$secretId='你在优图申请的secretId';
$secretKey='你在优图申请的secretKey';
$userid='你的QQ号';


Conf::setAppInfo($appid, $secretId, $secretKey, $userid,conf::API_YOUTU_END_POINT );


// 人脸融合 调用列子
error_reporting(0);
$uploadRet = YouTu::faceFusion('zxc.jpg');  //图片地址  or  图片名称
echo '<pre>';
print_r($uploadRet);



?>

 

转载于:https://www.cnblogs.com/maqimeng/p/9521978.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值