H5视频活体检测
1l_10111 发布于2019-04 浏览:3048 回复:0
1
收藏
快速回复
最后编辑于2019-04

class Program
    {
      
        private const String host = @"https://aip.baidubce.com/rest/2.0/face/v1/faceliveness/verify?access_token=";
        private const String path = "/efficient/idfaceIdentity";
        private const String method = "POST";
        private const String appcode = "ee5bf581d7294d21b27c6d1bd2231a81";

        //Baidu.Aip.Ocr.Ocr client = null;

        static void Main(string[] args)
        {
            //获取Token
            var Token = com.baidu.ai.AccessToken.getAccessToken();
            //解析Json串
            JObject json = (JObject)JsonConvert.DeserializeObject(Token);
            string token = json["access_token"].ToString().Trim();
            //设置新请求地址,参数解析后的token
            string url = host + token;
            //将视频流转换为Base64编码
            string path = @"C:\Users\Admin\Videos\转码后文件夹\videotest1.mp4";
            FileStream fs = new FileStream(path, FileMode.Open);
            int streamLength = (int)fs.Length;  //获取文件流的长度。  
            byte[] image = new byte[streamLength];    //声明字节数组,用于保存图片文件  
            fs.Read(image, 0, streamLength);    //把图片文件转换成为字节数组保存  
            fs.Close();
            //视频二进制流
            byte[] videos = image;
            string strBase64Videos = Convert.ToBase64String(videos);
            String bodys = @"video_base64=" + strBase64Videos;

            HttpWebRequest httpRequest = null;
            HttpWebResponse httpResponse = null;


            if (host.Contains("https://"))
            {
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
            }
            else
            {
                httpRequest = (HttpWebRequest)WebRequest.Create(url);
            }
            httpRequest.Method = method;
            //请求头文件参数值信息
            //httpRequest.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            ////根据API的要求,定义相对应的Content-Type
            httpRequest.ContentType = "application/x-www-form-urlencoded";
            if (0 < bodys.Length)
            {
                byte[] data = Encoding.UTF8.GetBytes(bodys);
                using (Stream stream = httpRequest.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }
            }
            try
            {
                httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            }
            catch (WebException ex)
            {
                httpResponse = (HttpWebResponse)ex.Response;
            }

            Console.WriteLine(httpResponse.StatusCode);
            Console.WriteLine(httpResponse.Method);
            Console.WriteLine(httpResponse.Headers);
            Stream st = httpResponse.GetResponseStream();
            StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
            Console.WriteLine(reader.ReadToEnd());
            Console.WriteLine("\n");
            Console.ReadLine();

        }

        public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
        {
            return true;
        }

 

返回值是,err_no:216501,err_msg:tracker err(no face)........。第一张图是后台控制器给出的线程图,然后推荐我对准摄像头拍照,我试了好多次都不行,每次都是no face。语言C#,希望大神帮助搞定。

收藏
点赞
1
个赞
TOP
切换版块