PHP:用Face++ 接口的问题

查看:167
本文介绍了PHP:用Face++ 接口的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

1.问题
当image_url参数 我换了什么图片链接都会出现
{"time_used": 35, "error_message": "INVALID_IMAGE_URL", "request_id": "1490261884,fc7b3994-1be7-412e-b7ae-6ff17ddffe61"}
2.官方参考文档
https://console.faceplusplus....
官方的PHP参考例子是2015年的
一些参数变了很多
https://github.com/FacePlusPl...
3.我的代码

<?php
/**
 * 问题:
 * image_url 当带入图片链接 我是用的您官网的图片链接
 * 返回错误信息
 *  '{"time_used": 23, "error_message": "INVALID_IMAGE_URL", "request_id": "1490260190,5fcf1ce6-53c2-4652-b67a-4808b2bdd5a2"}'
 *  换了图片链接也一样
 */


$api_key = "cK25pkbERhS8UoPWw2dBKWsNnGPdn6vG";
$api_secret = "oo8swPRXW3bwV_JxSBGO6sjK-b-wemyI";

$detect_api_url  ="https://api-cn.faceplusplus.com/facepp/v3/detect";

//image_url 
$image_url = "https://bj-mc-prod-asset.oss-cn-beijing.aliyuncs.com/mc-official/images/demo/demo-pic11.jpg";

//image_file
$image_file = "D:/image/01.jpg";
$image_info = getimagesize($image_file);
$image_data = fread(fopen($image_file, 'r'), filesize($image_file));
$image_file = base64_encode($image_data);

$return_landmark = "1";
$return_attributes="gender";

$url = "{$detect_api_url}";

$data = [
    "api_key" => "{$api_key}",
    "api_secret" => "{$api_secret}",
    "image_url" => "@$image_url",
    "return_landmark" => "{$return_landmark}",
    "return_attributes" => "{$return_attributes}"
];

//初始化一个cURL会话
$ch = curl_init();

//
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在

//设置请求选项
curl_setopt($ch, CURLOPT_URL, $detect_api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER,0);

//这是请求类型
curl_setopt($ch, CURLOPT_POST, TRUE);
//添加post数据到请求中
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$response = curl_exec($ch);

//错误处理
if($response == FALSE){
    echo "错误信息:".curl_error($ch)."<br/>";
}
//获取curl请求的具体信息
$curl_info = curl_getinfo($ch);
echo "收到的http回复的code:".$curl_info["http_code"]."<br/>";
//


curl_close($ch);
//输出返回信息
var_dump($response);

解决方案

$data = [
    "api_key" => "{$api_key}",
    "api_secret" => "{$api_secret}",
    "image_url" => "$image_url",//不加@
    "return_landmark" => "{$return_landmark}",
    "return_attributes" => "{$return_attributes}"
];

//上传本地文件
$data = [
    "api_key" => "{$api_key}",
    "api_secret" => "{$api_secret}",
    "image_file" => new CURLFile(realpath('test.jpg')),
    "return_landmark" => "{$return_landmark}",
    "return_attributes" => "{$return_attributes}"
];
//返回数组比较大

Array
(
    [image_id] => w74xxf1O2bqKOo+vm0tQpQ==
    [request_id] => 1490266400,f195454e-f957-4902-a446-f5fb70c6ab22
    [time_used] => 304
    [faces] => Array
        (
            [0] => Array
                (
                    [landmark] => Array
                        (
                            [mouth_upper_lip_left_contour2] => Array
                                (
                                    [y] => 351
                                    [x] => 220
                                )

                            [mouth_upper_lip_top] => Array
                                (
                                    [y] => 352
                                    [x] => 241
                                )

                            [mouth_upper_lip_left_contour1] => Array
                                (
                                    [y] => 350
                                    [x] => 232
                                )

                            [left_eye_upper_left_quarter] => Array
                                (
                                    [y] => 246
                                    [x] => 149
                                )

                            [left_eyebrow_lower_middle] => Array
                                (
                                    [y] => 230
                                    [x] => 160
                                )

                            [mouth_upper_lip_left_contour3] => Array
                                (
                                    [y] => 357
                                    [x] => 225
                                )

                            [left_eyebrow_lower_left_quarter] => Array
                                (
                                    [y] => 231
                                    [x] => 145
                                )

                            [right_eyebrow_lower_left_quarter] => Array
                                (
                                    [y] => 216
                                    [x] => 261
                                )

这篇关于PHP:用Face++ 接口的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆