Exemplo n.º 1
0
        private SearchFaceResult SearchFace(string faceSetName, string image, ImageType imageType, int topN, double threshold,
                                            SearchSort searchSort, SearchReturnFields searchReturnFields, string filter)
        {
            string uri = string.Format(FrsConstantV2.FACE_SEARCH_URI, projectId, faceSetName);
            Dictionary <string, object> jsonObj = new Dictionary <string, object>();

            switch (imageType)
            {
            case ImageType.BASE64:
                jsonObj.Add("image_base64", image);
                break;

            case ImageType.URL:
                jsonObj.Add("image_url", image);
                break;

            case ImageType.FACEID:
                jsonObj.Add("face_id", image);
                break;
            }
            if (-1 != topN)
            {
                jsonObj.Add("top_n", topN);
            }
            if (Math.Abs(threshold) > 0)
            {
                jsonObj.Add("threshold", threshold);
            }
            if (null != searchSort)
            {
                jsonObj.Add("sort", searchSort.GetString());
            }
            if (null != searchReturnFields)
            {
                jsonObj.Add("return_fields", searchReturnFields.GetString());
            }
            if (null != filter)
            {
                jsonObj.Add("filter", filter);
            }
            HttpWebResponse response = accessService.Post(uri, null, HttpUtils.ObjToData(jsonObj), FrsConstantV2.TYPE_JSON);

            return(HttpUtils.ResponseToObj <SearchFaceResult>(response));
        }
Exemplo n.º 2
0
        public SearchFaceResult SearchFaceByFile(string faceSetName, string imagePath, int topN, double threshold,
                                                 SearchSort searchSort, SearchReturnFields searchReturnFields, string filter)
        {
            string          uri       = string.Format(FrsConstantV2.FACE_SEARCH_URI, this.projectId, faceSetName);
            MultipartWriter multipart = new MultipartWriter();

            multipart.WriteStart();
            multipart.WriteFile("image_file", imagePath, imagePath);
            //top n
            if (-1 != topN)
            {
                multipart.WriteProperty("top_n", topN.ToString());
            }
            //threshold
            if (Math.Abs(threshold) > 0)
            {
                multipart.WriteProperty("threshold", threshold.ToString());
            }
            //search sort
            if (null != searchSort)
            {
                multipart.WriteProperty("sort", searchSort.GetString());
            }
            //return fields
            if (null != searchReturnFields)
            {
                multipart.WriteProperty("return_fields", searchReturnFields.GetString());
            }
            //filter
            if (null != filter)
            {
                multipart.WriteProperty("filter", filter);
            }
            byte[]          data     = multipart.WriteClose();
            HttpWebResponse response = this.accessService.Post(uri, null, data, multipart.GetContentType());

            return(HttpUtils.ResponseToObj <SearchFaceResult>(response));
        }