当前位置:   article > 正文

AI接口调用

ai接口调用

调用人脸识别的接口,返回分析结果(性别,年龄,头像在图片中的位置和尺寸)

var initParams={};
function analyimg(url){

                $.ajax({  
                    url:"http://apicn.faceplusplus.com/v2/detection/detect?url="+url+"&api_secret=H0vrVbIXs2X7u_56hJO1m3o3J_yAPcyq&api_key=29b3be7651721eed7c32a2243c745628",  
                    dataType:'jsonp',  
                    success:function(result) { 
                        console.dir(result);
                    console.log("%c 识别颜值结束", "font-size:11px;color:grey;")

                        var faces=result.face;
                        if(faces.length<1){
                            console.log("%c 未识别到人脸", "font-size:11px;color:red;")
                        alert("未识别到人脸");
                            return;
                        }
                        var facelist=$("#facelist").empty();
                var i=0;
                            var fitem=faces[i];//返回人脸信息

                         //获取人脸在图片中的位置
                            initParams.left=((fitem.position.center.x-fitem.position.width/2+14.8)*result.img_width)/100+15;    
                            initParams.top=((fitem.position.center.y-fitem.position.height/2+5.8)*result.img_height)/100;

                    //获取人脸的尺寸
                            initParams.width=(fitem.position.width*result.img_width)/100;                           
                            initParams.height=(fitem.position.height*result.img_height)/100;

//获取图中人物的年龄、性别
                            initParams.age=fitem.attribute.age.value;
                            initParams.sex=fitem.attribute.gender.val



                        }           



                });

            }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/922484
推荐阅读
相关标签
  

闽ICP备14008679号