protected override string RunInBackground(params Stream[] @params)
        {
            try
            {
                PublishProgress("PLEASE WAIT...");
                var faceServiceClient = new FaceServiceRestClient("https://westcentralus.api.cognitive.microsoft.com/face/v1.0", "5e729af046e44898beda9b4917f6db8d");
                Xamarin.Cognitive.Face.Droid.Contract.Face[] result = faceServiceClient.Detect(@params[0], true, false, null);

                if (result == null)
                {
                    PublishProgress("detection failed");
                    return(null);
                }

                PublishProgress("Detection finished" + result.Length + "faces detected");
                Gson gson = new Gson();
                return(gson.ToJson(result));
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return(null);
            }
            finally
            {
                _spinner.Dismiss();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Detecting Face with Cognitive API
        /// </summary>
        /// <param name="params"></param>
        /// <returns></returns>
        protected override string RunInBackground(params Stream[] @params)
        {
            try
            {
                faceServiceClient = new FaceServiceRestClient(FaceKey);
                PublishProgress("잠시만 기다려주세요. 얼굴 인식 중입니다.");
                //Get Congnitive API result
                Com.Microsoft.Projectoxford.Face.Contract.Face[] result = faceServiceClient.Detect(@params[0],
                                                                                                   true, //return FaceId
                                                                                                   false, new FaceServiceClientFaceAttributeType[] { FaceServiceClientFaceAttributeType.Age, FaceServiceClientFaceAttributeType.Gender
                                                                                                                                                     , FaceServiceClientFaceAttributeType.FacialHair
                                                                                                                                                     , FaceServiceClientFaceAttributeType.Smile
                                                                                                                                                     , FaceServiceClientFaceAttributeType.Glasses
                                                                                                                                                     , FaceServiceClientFaceAttributeType.HeadPose });

                if (result != null)
                {
                    //parse json to String
                    Gson gson = new Gson();
                    return(gson.ToJson(result));
                }
                return(null);
            }
            catch (System.Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        protected override string RunInBackground(params Stream[] @params)
        {
            PublishProgress("Detecting...");
            var faceServiceClient = new FaceServiceRestClient(endPoint, key);

            Com.Microsoft.Projectoxford.Face.Contract.Face[] result = faceServiceClient.Detect(@params[0],
                                                                                               true,  //FaceId
                                                                                               false, // Face LandMarks
                                                                                               new FaceServiceClientFaceAttributeType[] {
                FaceServiceClientFaceAttributeType.Gender,
                FaceServiceClientFaceAttributeType.Age,
                FaceServiceClientFaceAttributeType.Smile,
                FaceServiceClientFaceAttributeType.FacialHair,

                FaceServiceClientFaceAttributeType.Glasses
            });

            // return Face Attributes : age, gender ..etc

            if (result == null)
            {
                PublishProgress("Detection Finished. Nothing detected");
                return(null);
            }
            PublishProgress($"Detection Finished. {result.Length} face(s) detected");

            Gson gson = new Gson();

            var strResult = gson.ToJson(result);

            Console.WriteLine(strResult + "ABC");
            return(strResult);
        }
Ejemplo n.º 4
0
            protected override string RunInBackground(params Stream[] @params)
            {
                var resultado = mainActivity.ServicioFace.Detect(@params[0], true, false, null);

                if (resultado == null)
                {
                    return(null);
                }
                Gson gson            = new Gson();
                var  stringresultado = gson.ToJson(resultado);

                return(stringresultado);
            }
Ejemplo n.º 5
0
            protected override string RunInBackground(params Stream[] @params)
            {
                var result = mainActivity.faceServiceRestClient.Detect(@params[0], true, false, null);

                if (result == null)
                {
                    return(null);
                }

                Gson gson         = new Gson();
                var  stringResult = gson.ToJson(result);

                return(stringResult);
            }
Ejemplo n.º 6
0
 protected override string RunInBackground(params string[] @params)
 {
     try
     {
         UUID uuid      = UUID.FromString(@params[0]);
         var  persona   = mainActivity.ServicioFace.GetPerson(grupoPersonaId, uuid);
         Gson gson      = new Gson();
         var  resultado = gson.ToJson(persona);
         return(resultado);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Ejemplo n.º 7
0
        public List <FaceModel> GetSecondFaceId(Stream imageStream)
        {
            var faceServiceClient = new FaceServiceRestClient("https://westcentralus.api.cognitive.microsoft.com/face/v1.0", "a7c0326b9c374041808d54073dd15932");

            Xamarin.Cognitive.Face.Droid.Contract.Face[] result = faceServiceClient.Detect(imageStream, true, true, null);
            if (result == null)
            {
                return(null);
            }

            Gson gson = new Gson();
            var  json = gson.ToJson(result);

            FaceObject2 = JsonConvert.DeserializeObject <List <FaceModel> >(json);
            return(FaceObject2);
        }
            public void OnSearchResult(Java.Lang.Object results)
            {
                TextSearchResponse ResultWrapper = (TextSearchResponse)results;
                IList <Site>       SiteList;

                if (ResultWrapper == null || ResultWrapper.TotalCount <= 0 || (SiteList = ResultWrapper.Sites) == null ||
                    SiteList.Count <= 0)
                {
                    ResultTextView.Text = "Result is Empty!";
                    return;
                }

                System.Text.StringBuilder ResultText = new System.Text.StringBuilder();
                ResultText.AppendLine("Success");
                int              count = 1;
                AddressDetail    addressDetail;
                Coordinate       location;
                Poi              poi;
                CoordinateBounds viewport;

                foreach (Site site in SiteList)
                {
                    addressDetail = site.Address;
                    location      = site.Location;
                    poi           = site.Poi;
                    viewport      = site.Viewport;
                    string item = "[{0}] siteId: '{1}', name: {2}, formatAddress: {3}, country: {4}, countryCode: {5}, location: {6}, poiTypes: {7}, viewport: {8} ";
                    ResultText.Append(string.Format(item,
                                                    (count++).ToString(), site.SiteId, site.Name, site.FormatAddress,
                                                    (addressDetail == null ? "" : addressDetail.Country),
                                                    (addressDetail == null ? "" : addressDetail.CountryCode),
                                                    (location == null ? "" : (location.Lat + "," + location.Lng)),
                                                    (poi == null ? "" : string.Join(",", poi.PoiTypes.ToArray())),
                                                    (viewport == null ? "" : "northeast{lat=" + viewport.Northeast.Lat + ", lng=" + viewport.Northeast.Lng + "},"
                                                     + "southwest{lat=" + viewport.Southwest.Lat + ", lng=" + viewport.Southwest.Lng + "}")));
                    if ((poi != null))
                    {
                        Gson   gson       = new Gson();
                        string jsonString = gson.ToJson(poi.GetChildrenNodes());
                        ResultText.Append(string.Format("childrenNode: {0} \n\n", jsonString));
                    }
                }
                ResultTextView.Text = ResultText.ToString();
                Log.Debug(KeywordSearchActivity.TAG, "OnTextSearchResult: " + ResultText.ToString());
            }
Ejemplo n.º 9
0
            protected override string RunInBackground(params string[] @params)
            {
                try
                {
                    UUID uuid = UUID.FromString(@params[0]);

                    var  person = mainActivity.faceServiceRestClient.GetPerson(personGroupId, uuid);
                    Gson gson   = new Gson();
                    var  result = gson.ToJson(person);
                    return(result);
                }
                catch (Exception ex)
                {
                    return(null);

                    System.Console.WriteLine("PersonDetectionTask exception has thrown.");
                }
            }
Ejemplo n.º 10
0
            protected override string RunInBackground(params string[] @params)
            {
                try
                {
                    UUID[] listaUuid = new UUID[(@params.Length)];
                    for (int i = 0; i < @params.Length; i++)
                    {
                        listaUuid[i] = UUID.FromString(@params[i]);
                    }
                    var resultado = mainActivity.ServicioFace.Identity(grupoPersonaId, listaUuid, 1);

                    Gson gson            = new Gson();
                    var  resultadoString = gson.ToJson(resultado);
                    return(resultadoString);
                }
                catch (Exception ex)
                {
                    return(null);
                }
            }
Ejemplo n.º 11
0
        public List <FaceModel> GetFirstFaceId(Stream imageStream)
        {
            try
            {
                var faceServiceClient = new FaceServiceRestClient("https://westcentralus.api.cognitive.microsoft.com/face/v1.0", "a7c0326b9c374041808d54073dd15932");
                Xamarin.Cognitive.Face.Droid.Contract.Face[] result = faceServiceClient.Detect(imageStream, true, true, null);
                if (result == null)
                {
                    return(null);
                }

                Gson gson = new Gson();
                var  json = gson.ToJson(result);
                FaceObject1 = JsonConvert.DeserializeObject <List <FaceModel> >(json);
                return(FaceObject1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return(null);
            }
        }
Ejemplo n.º 12
0
            public void OnSearchResult(Java.Lang.Object resultObject)
            {
                DetailSearchResponse detailSearchResponse = (DetailSearchResponse)resultObject;
                StringBuilder        resultText           = new StringBuilder();
                Site site = detailSearchResponse.Site;

                if (site == null)
                {
                    ResultTextView.Text = "Result is Empty!";
                    return;
                }

                System.Text.StringBuilder ResultText = new System.Text.StringBuilder();
                ResultText.AppendLine("Success");
                AddressDetail    addressDetail = site.Address;
                Coordinate       location      = site.Location;
                Poi              poi           = site.Poi;
                CoordinateBounds viewport      = site.Viewport;

                string item = "siteId: '{0}', name: {1}, formatAddress: {2}, country: {3}, countryCode: {4}, location: {5}, poiTypes: {6}, viewport: {7} ";

                ResultText.Append(string.Format(item,
                                                site.SiteId, site.Name, site.FormatAddress,
                                                (addressDetail == null ? "" : addressDetail.Country),
                                                (addressDetail == null ? "" : addressDetail.CountryCode),
                                                (location == null ? "" : (location.Lat + "," + location.Lng)),
                                                (poi == null ? "" : string.Join(",", poi.PoiTypes.ToArray())),
                                                (viewport == null ? "" : "northeast{lat=" + viewport.Northeast.Lat + ", lng=" + viewport.Northeast.Lng + "},"
                                                 + "southwest{lat=" + viewport.Southwest.Lat + ", lng=" + viewport.Southwest.Lng + "}")));
                if ((poi != null))
                {
                    Gson   gson       = new Gson();
                    string jsonString = gson.ToJson(poi.GetChildrenNodes());
                    ResultText.Append(string.Format("childrenNode: {0} \n\n", jsonString));
                }

                ResultTextView.Text = ResultText.ToString();
                Log.Debug(KeywordSearchActivity.TAG, "OnDetailSearchResult: " + ResultText.ToString());
            }
Ejemplo n.º 13
0
            protected override string RunInBackground(params string[] @params)
            {
                try
                {
                    UUID[] uuidList = new UUID[@params.Length];
                    for (int i = 0; i < @params.Length; i++)
                    {
                        uuidList[i] = UUID.FromString(@params[i]);
                    }

                    var result = mainActivity.faceServiceRestClient.Identity(personGroupId
                                                                             , uuidList
                                                                             , 1);

                    Gson gson         = new Gson();
                    var  resultString = gson.ToJson(result);
                    return(resultString);
                }
                catch (System.Exception)
                {
                    return(null);
                }
            }
            public void OnSearchResult(Java.Lang.Object results)
            {
                QueryAutocompleteResponse ResultWrapper = (QueryAutocompleteResponse)results;

                if (ResultWrapper == null)
                {
                    ResultTextView.Text = "Result is Empty!";
                    return;
                }

                System.Text.StringBuilder ResultText = new System.Text.StringBuilder();
                IList <Site> SiteList;
                IList <AutoCompletePrediction> predictions;

                predictions = ResultWrapper.Predictions;
                if (predictions != null && predictions.Count > 0)
                {
                    ResultText.Append("AutoCompletePrediction[ ]:\n");
                    int PredictionCount = 1;
                    foreach (AutoCompletePrediction mPrediction in predictions)
                    {
                        ResultText.Append(string.Format("[{0}] Prediction, description = {1} ,", "" + (PredictionCount++), mPrediction.Description));

                        Word[] matchedKeywords = mPrediction.GetMatchedKeywords();
                        foreach (Word matchedKeyword in matchedKeywords)
                        {
                            ResultText.Append("matchedKeywords: " + matchedKeyword.ToString());
                        }

                        Word[] matchedWords = mPrediction.GetMatchedWords();
                        foreach (Word matchedWord in matchedWords)
                        {
                            ResultText.Append(",matchedWords: " + matchedWord.ToString());
                        }

                        ResultText.Append("\n");
                    }
                }
                else
                {
                    ResultText.Append("Predictions 0 results");
                }

                ResultText.Append("\n\nSite[ ]:\n");
                SiteList = ResultWrapper.Sites;
                if (SiteList != null && SiteList.Count > 0)
                {
                    int              SiteCount = 1;
                    AddressDetail    addressDetail;
                    Coordinate       location;
                    Poi              poi;
                    CoordinateBounds viewport;
                    foreach (Site site in SiteList)
                    {
                        addressDetail = site.Address;
                        location      = site.Location;
                        poi           = site.Poi;
                        viewport      = site.Viewport;
                        string item = "[{0}] siteId: '{1}', name: {2}, formatAddress: {3}, utcOffset: {4}, country: {5}, countryCode: {6}, location: {7}, distance: {8}, poiTypes: {9}, viewport: {10}, streetNumber: {11}, postalCode: {12} , tertiaryAdminArea: {13}, ";
                        ResultText.Append(string.Format(item,
                                                        (SiteCount++).ToString(), site.SiteId, site.Name, site.FormatAddress, site.UtcOffset,
                                                        (addressDetail == null ? "" : addressDetail.Country),
                                                        (addressDetail == null ? "" : addressDetail.CountryCode),
                                                        (location == null ? "" : (location.Lat + "," + location.Lng)), site.Distance,
                                                        (poi == null ? "" : string.Join(",", poi.PoiTypes.ToArray())),
                                                        (viewport == null ? "" : "northeast{lat=" + viewport.Northeast.Lat + ", lng=" + viewport.Northeast.Lng + "},"
                                                         + "southwest{lat=" + viewport.Southwest.Lat + ", lng=" + viewport.Southwest.Lng + "}"),
                                                        (addressDetail == null ? "" : addressDetail.StreetNumber),
                                                        (addressDetail == null ? "" : addressDetail.PostalCode),
                                                        (addressDetail == null ? "" : addressDetail.TertiaryAdminArea)));
                        if ((poi != null))
                        {
                            Gson   gson       = new Gson();
                            string jsonString = gson.ToJson(poi.GetChildrenNodes());
                            ResultText.Append(string.Format("childrenNode: {0} \n\n", jsonString));
                        }
                    }
                }
                else
                {
                    ResultText.Append("sites 0 results\n");
                }
                ResultTextView.Text = ResultText.ToString();
                Log.Debug(QueryAutoCompleteActivity.TAG, "OnAutoCompleteResult: " + ResultText.ToString());
            }