vickylinj

通过查看其API文档,入参除了key和secret(注册账号后申请获得)外,只有模版图、模版图中人脸位置、用户上传图,三个参数。Face++的人脸检测API可在线获取模版图中人脸位置,例如:251,167,169,169。依次代表人脸框左上角纵坐标(top),左上角横坐标(left),人脸框宽度(width),人脸框高度(height),如下图:

 

然后,直接调用人脸融合接口即可,返回融合后的图片base64编码数据,再根据需求直接赋值给img标签显示。

关键代码如下:

var postData = \'api_key=xxx&api_secret=xxx\'
                    + \'&template_url=http://xxx.com/xxx.jpg\'
                    + \'&template_rectangle=251,167,169,169\'
                    + \'&merge_url=http://xxx.com/xxx.jpg\';
 
        $.ajax({
            dataType: \'json\', 
            type: \'POST\' ,
            url: \'https://api-cn.faceplusplus.com/imagepp/v1/mergeface\',
            data: postData,
            success: function(response){ 
                if(typeof(response.error_message) == "undefined"){
                    // todo: 在这里添加生成后的逻辑,response.result 为生成图的base64编码
                    $(\'.uploadpic\').attr(\'src\', \'data:image/jpg/png;base64,\' + response.result); 
                }else{
                    // todo: 在这里添加上传失败的逻辑
                    alert(\'请重新上传照片\');
                } 
            },
            error: function(xhr, status, error){
                console.log(xhr.responseText);
                // todo: 在这里添加上传失败的逻辑
                alert(\'请重新上传照片\');
            }
        });

BTW
        1、注意融合比例参数merge_rate,数字越大融合结果包含越多融合图特征,默认为50。这里可设为100,融合特征会非常明显;

        2、接口规定模版为JPG格式,所以无法直接实现png图的融合。腾讯AI的人脸融合接口是可以用png模版的;

        3、试用账号是不保证并发的,如果要保证并发可以查看官方的价格。

转自:https://blog.csdn.net/gaofei880219/article/details/80805558

分类:

技术点:

相关文章:

  • 2021-12-08
  • 2021-12-04
  • 2021-05-11
  • 2021-05-27
  • 2021-11-13
  • 2021-12-10
猜你喜欢
  • 2021-11-23
  • 2021-11-08
  • 2022-01-04
  • 2021-11-06
  • 2021-12-14
相关资源
相似解决方案