Ejemplo n.º 1
0
        async Task <List <Model.Face> > ExecuteDetection(Bitmap photo)
        {
            try
            {
                AddLog("Request: Detecting in image");
                progressDialog.Show();
                progressDialog.SetMessage("Detecting...");
                SetInfo("Detecting...");

                var faces = await FaceClient.Shared.DetectFacesInPhoto(() => photo.AsJpegStream());

                AddLog($"Response: Success. Detected {faces.Count} face(s) in image");
                SetInfo($"{faces.Count} face{(faces.Count != 1 ? "s" : "")} detected");

                if (faces != null)
                {
                    AddLog($"Response: Success. Detected {faces.Count} Face(s) in image");
                }

                return(faces);
            }
            catch (Exception e)
            {
                AddLog(e.Message);
                throw;
            }
            finally
            {
                progressDialog.Dismiss();
            }
        }
Ejemplo n.º 2
0
        async Task ExecuteDetection(Bitmap bitmap, int index)
        {
            try
            {
                AddLog($"Request: Detecting in image {index}");
                progressDialog.Show();
                progressDialog.SetMessage("Detecting...");
                SetInfo("Detecting...");

                var faces = await FaceClient.Shared.DetectFacesInPhoto(
                    () => bitmap.AsJpegStream(),
                    true,
                    FaceAttributeType.Age,
                    FaceAttributeType.Gender,
                    FaceAttributeType.Smile,
                    FaceAttributeType.Glasses,
                    FaceAttributeType.FacialHair,
                    FaceAttributeType.Emotion,
                    FaceAttributeType.HeadPose
                    );

                AddLog($"Response: Success. Detected {faces.Count} face(s) in image" + index);
                SetInfo($"{faces.Count} face{(faces.Count != 1 ? "s" : "")} detected");

                var faceListAdapter = new FaceImageListAdapter(faces, bitmap);

                if (faces?.Count != 0)
                {
                    Faces [index] = faces.First();
                    ImageViewAtIndex(index).SetImageBitmap(faceListAdapter.GetThumbnailForPosition(0));
                    faceListAdapter.SetSelectedIndex(0);
                }
                else
                {
                    SetInfo("No face detected!");
                }

                var listView = ListViewAtIndex(index);
                listView.Adapter             = faceListAdapter;
                listView.Visibility          = ViewStates.Visible;
                listView.OnItemClickListener = this;

                Bitmaps [index] = null;

                if (Faces [0] != null && Faces [1] != null)
                {
                    SetVerifyButtonEnabledStatus(true);
                }
            }
            catch (Exception e)
            {
                AddLog(e.Message);
                SetInfo("No face detected!");
            }

            SetSelectImageButtonEnabledStatus(true, index);

            progressDialog.Dismiss();
        }