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
        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);
        }
Ejemplo n.º 5
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);
            }
        }