Beispiel #1
0
        public static Conf Instance()
        {
            if (instance == null)
            {
                instance = new Conf();
            }

            return instance;
        }
Beispiel #2
0
        /// <summary>
        /// 增加人脸 addface
        /// </summary>
        /// <param name="person_id">新增人脸的个体身份id</param>
        /// <param name="image_path_arr">待增加的包含人脸的图片数据,可加入多张(包体大小<2m)</param>
        /// <param name="facetag">人脸备注信息,用户自解释字段</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string addface(string person_id, List <string> image_path_arr, string facetag = "")
        {
            List <string> faceImgBase64List = new List <string>();

            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/api/addface";
            StringBuilder postData   = new StringBuilder();

            image_path_arr.ForEach(path =>
            {
                faceImgBase64List.Add(Utility.ImgBase64(path));
            });

            string pars = "\"app_id\":\"{0}\",\"images\":{1},\"person_id\":\"{2}\",\"tag\":\"{3}\"";

            pars = string.Format(pars, Conf.Instance().APPID, JsonHelp <string[]> .ToJsonString(faceImgBase64List.ToArray()), person_id, facetag);

            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// 根据用户上传的照片,识别并且获取图片中的文字信息
        /// </summary>
        /// <param name="url">图片的url</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string generalocrurl(string url)
        {
            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/ocrapi/generalocr";
            StringBuilder postData   = new StringBuilder();

            string pars = "\"app_id\":\"{0}\",\"url\":\"{1}\"";

            pars = string.Format(pars, Conf.Instance().APPID, url);
            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// 人脸检测 detectface
        /// </summary>
        /// <param name="image_path">的路径</param>
        /// <param name="isbigface">是否大脸模式 0表示检测所有人脸, 1表示只检测照片最大人脸 适合单人照模式</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string detectface(string image_path, int isbigface = 1)
        {
            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/api/detectface";
            StringBuilder postData   = new StringBuilder();
            string        pars       = "\"app_id\":\"{0}\",\"image\":\"{1}\",\"mode\":{2}";

            pars = string.Format(pars, Conf.Instance().APPID, Utility.ImgBase64(image_path), isbigface);
            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// 名片OCR识别
        /// </summary>
        /// <param name="image_path">图片路径</param>
        /// <param name="retimage ">是否需要返回处理结果图,true 返回,false 不返回</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string namecardocr(string image_path, bool retimage)
        {
            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/ocrapi/namecardocr";
            StringBuilder postData   = new StringBuilder();

            string pars = "\"app_id\":\"{0}\",\"image\":\"{1}\",\"retimage\":\"{2}\"";

            pars = string.Format(pars, Conf.Instance().APPID, Utility.ImgBase64(image_path), retimage);
            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// 设置信息 setinfo
        /// </summary>
        /// <param name="person_id">待设置的个体身份id</param>
        /// <param name="person_name">新设置的个体名字</param>
        /// <param name="person_tag">新设置的人备注信息</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string setinfo(string person_id, string person_name, string person_tag)
        {
            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/api/setinfo";
            StringBuilder postData   = new StringBuilder();
            string        pars       = "\"app_id\":\"{0}\",\"person_name\":\"{1}\",\"person_id\":\"{2}\",\"tag\":\"{3}\"";

            pars = string.Format(pars, Conf.Instance().APPID, person_name, person_id, person_tag);
            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// 删除人脸 delface
        /// </summary>
        /// <param name="person_id">待删除人脸的个体身份id</param>
        /// <param name="face_ids">删除人脸id的列表</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string delface(string person_id, List <string> face_ids)
        {
            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/api/delface";
            StringBuilder postData   = new StringBuilder();
            string        pars       = "\"app_id\":\"{0}\",\"person_id\":\"{1}\",\"face_ids\":{2}";

            pars = string.Format(pars, Conf.Instance().APPID, person_id, JsonHelp <string[]> .ToJsonString(face_ids.ToArray()));
            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// 个体创建 newpersonurl
        /// </summary>
        /// <param name="url">图片的url</param>
        /// <param name="person_id">新建的个体id,用户指定,需要保证app_id下的唯一性</param>
        /// <param name="person_name">姓名</param>
        /// <param name="group_ids">新建的个体存放的组id,可以指定多个组id,用户指定(组默认创建)</param>
        /// <param name="person_tag">备注信息,用户自解释字段</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string newpersonurl(string url, string person_id, string person_name, List <string> group_ids, string person_tag)
        {
            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/api/newperson";
            StringBuilder postData   = new StringBuilder();
            string        pars       = "\"app_id\":\"{0}\",\"url\":\"{1}\",\"group_ids\":{2},\"person_id\":\"{3}\",\"person_name\":\"{4}\",\"tag\":\"{5}\"";

            pars = string.Format(pars, Conf.Instance().APPID, url, JsonHelp <string[]> .ToJsonString(group_ids.ToArray()), person_id, person_name, person_tag);
            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #9
0
        /// <summary>
        /// 人脸对比 facecompare
        /// </summary>
        /// <param name="imageA">待比对的A图片数据</param>
        /// <param name="imageB">待比对的B图片数据</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string facecompare(string imageA, string imageB)
        {
            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/api/facecompare";
            StringBuilder postData   = new StringBuilder();
            string        pars       = "\"app_id\":\"{0}\",\"imageA\":\"{1}\",\"imageB\":\"{2}\"";

            pars = string.Format(pars, Conf.Instance().APPID, Utility.ImgBase64(imageA), Utility.ImgBase64(imageB));
            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #10
0
        /// <summary>
        /// 多人脸检索 multifaceidentifyurl
        /// </summary>
        /// <param name="url">图片的url</param>
        /// <param name="group_id">识别的组id</param>
        /// <param name="group_ids">个体存放的组id,可以指定多个组id</param>
        /// <returns>返回的结果,JSON字符串,字段参见API文档</returns>
        public static string multifaceidentifyurl(string url, string group_id, List <string> group_ids, int topn = 5, int min_size = 40)
        {
            string        expired    = Utility.UnixTime(EXPIRED_SECONDS);
            string        methodName = "youtu/api/faceidentify";
            StringBuilder postData   = new StringBuilder();
            string        pars       = "\"app_id\":\"{0}\",\"group_id\":\"{1}\",\"group_ids\":{2},\"url\":\"{3}\",\"topn\":{4},\"min_size\":{5}";

            pars = string.Format(pars, Conf.Instance().APPID, group_id, JsonHelp <string[]> .ToJsonString(group_ids.ToArray()), url, topn, min_size);
            postData.Append("{");
            postData.Append(pars);
            postData.Append("}");
            Console.WriteLine(postData);
            string result = Http.HttpPost(methodName, postData.ToString(), Auth.appSign(expired, Conf.Instance().USER_ID));

            return(result);
        }
Beispiel #11
0
        /// <summary>
        /// send http request with POST method
        /// </summary>
        /// <param name="methodName">请求的接口名称</param>
        /// <param name="postData">请求数据</param>
        /// <param name="authorization">签名</param>
        /// <returns></returns>
        public static string HttpPost(string methodName, string postData, string authorization)
        {
            string ret = string.Empty;

            try
            {
                byte[]         byteArray = Encoding.UTF8.GetBytes(postData); //转化为UTF8
                HttpWebRequest webReq    = null;

                if (Conf.Instance().END_POINT.StartsWith("https", StringComparison.OrdinalIgnoreCase))
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    webReq = WebRequest.Create((Conf.Instance().END_POINT + methodName)) as HttpWebRequest;
                    webReq.ProtocolVersion = HttpVersion.Version11;
                }
                else
                {
                    webReq = (HttpWebRequest)WebRequest.Create(new Uri(Conf.Instance().END_POINT + methodName));
                }

                webReq.Method      = "POST";
                webReq.ContentType = "text/json";
                webReq.Headers.Add(HttpRequestHeader.Authorization, authorization);
                webReq.ServicePoint.Expect100Continue = false;

                //webReq.Expect = "100-Continue";
                webReq.ContentLength = byteArray.Length;
                Stream newStream = webReq.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                StreamReader    sr       = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                ret = sr.ReadToEnd();
                sr.Close();
                response.Close();
                newStream.Close();
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    var response = ex.Response as HttpWebResponse;
                    if (response != null)
                    {
                        int errorcode = (int)response.StatusCode;
                        ret = Youtu.statusText(errorcode);
                    }
                    else
                    {
                        // no http status code available
                    }
                }
                else
                {
                    // no http status code available
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(ret);
        }
Beispiel #12
0
        /// <summary>
        /// 签名
        /// </summary>
        /// <param name="expired">过期时间</param>
        /// <param name="userid">暂时不用</param>
        /// <returns>签名</returns>
        public static string appSign(string expired, string userid)
        {
            if (string.IsNullOrEmpty(Conf.Instance().SECRET_ID) || string.IsNullOrEmpty(Conf.Instance().SECRET_KEY))
            {
                return(AUTH_SECRET_ID_KEY_ERROR);
            }

            string time = Utility.UnixTime();

            string plainText = SetOrignal(Conf.Instance().USER_ID, Conf.Instance().APPID, Conf.Instance().SECRET_ID, time, expired);

            byte[] signByteArrary = Utility.JoinByteArr(HmacSha1Sign(plainText, Conf.Instance().SECRET_KEY), Utility.StrToByteArr(plainText));

            return(Convert.ToBase64String(signByteArrary));
        }