Beispiel #1
0
        async Task Detect(global::Android.Net.Uri uri, int requestCode)
        {
            try
            {
                using (var bitmap = ContentResolver.LoadSizeLimitedBitmapFromUri(uri))
                {
                    if (bitmap != null)
                    {
                        FindViewById(Resource.Id.all_faces).Visibility = ViewStates.Visible;

                        SetAllButtonsEnabledStatus(false);

                        var faces = await ExecuteDetection(bitmap);

                        SetAllButtonsEnabledStatus(true);

                        switch (requestCode)
                        {
                        case REQUEST_ADD_FACE:

                            if (faces?.Count > 0)
                            {
                                faceListAdapter.AddFaces(faces, bitmap);

                                var textView = FindViewById <TextView> (Resource.Id.text_all_faces);
                                textView.Text = $"Face database: {faces.Count} face{(faces.Count != 1 ? "s" : "")} in total";
                            }
                            break;

                        case REQUEST_SELECT_IMAGE:

                            targetFaceListAdapter = new FaceImageListAdapter();
                            var listView = FindViewById <ListView> (Resource.Id.list_faces);
                            listView.Adapter = targetFaceListAdapter;

                            if (faces?.Count > 0)
                            {
                                targetFaceListAdapter.AddFaces(faces, bitmap);
                                // Set the default face ID to the ID of first face, if one or more faces are detected.
                                targetFaceListAdapter.SetSelectedIndex(0);

                                // Show the thumbnail of the default face.
                                var imageView = FindViewById <ImageView> (Resource.Id.image);
                                imageView.SetImageBitmap(targetFaceListAdapter.GetThumbnailForPosition(0));
                            }
                            break;
                        }

                        RefreshFindSimilarFaceButtonEnabledStatus();
                        SetInfo("Detection is done");
                    }
                }
            }
            catch (Exception e)
            {
                AddLog(e.Message);
                SetInfo("No face detected!");
            }
        }
Beispiel #2
0
        async Task ExecuteDetection()
        {
            try
            {
                AddLog("Request: Detecting in image");
                //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");
                SetInfo($"{faces.Count} face{(faces.Count != 1 ? "s" : "")} detected");

                faceListAdapter = new FaceImageListAdapter(faces, bitmap);

                // Set the default face ID to the ID of first face, if one or more faces are detected.
                if (faces?.Count > 0)
                {
                    faceListAdapter.SetSelectedIndex(0);

                    // Show the thumbnail of the default face.
                    var imageView = FindViewById <ImageView> (Resource.Id.image_0);
                    imageView.SetImageBitmap(faceListAdapter.GetThumbnailForPosition(0));

                    SetVerifyButtonEnabledStatus();
                }
                else
                {
                    SetInfo("No face detected!");
                }

                // Show the list of detected face thumbnails.
                listView_faces.Adapter    = faceListAdapter;
                listView_faces.Visibility = ViewStates.Visible;

                bitmap.Dispose();
                bitmap = null;
            }
            catch (Exception e)
            {
                AddLog(e.Message);
                SetInfo("No face detected!");
            }

            SetSelectImageButtonEnabledStatus(true);
            //progressDialog.Dismiss ();
            SetVerifyButtonEnabledStatus();
        }
Beispiel #3
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();
        }
Beispiel #4
0
            public FaceGroupsAdapter(GroupResult result, FaceImageListAdapter faceListAdapter)
            {
                this.faceListAdapter = faceListAdapter;

                if (result != null)
                {
                    faceGroups = result.Groups;

                    if (result.MessyGroup != null)
                    {
                        faceGroups.Add(result.MessyGroup);
                    }
                }
            }
Beispiel #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_grouping);

            progressDialog = new ProgressDialog(this);
            progressDialog.SetTitle(Application.Context.GetString(Resource.String.progress_dialog_title));

            add_faces = FindViewById <Button> (Resource.Id.add_faces);
            group     = FindViewById <Button> (Resource.Id.group);
            view_log  = FindViewById <Button> (Resource.Id.view_log);

            faceListAdapter = new FaceImageListAdapter();
            FindViewById <GridView> (Resource.Id.all_faces).Adapter = faceListAdapter;

            SetGroupButtonEnabledStatus(false);

            LogHelper.ClearLog(LogType.Grouping);
        }
Beispiel #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_find_similar_face);

            progressDialog = new ProgressDialog(this);
            progressDialog.SetTitle(Application.Context.GetString(Resource.String.progress_dialog_title));

            add_faces          = FindViewById <Button> (Resource.Id.add_faces);
            select_image       = FindViewById <Button> (Resource.Id.select_image);
            find_similar_faces = FindViewById <Button> (Resource.Id.find_similar_faces);
            view_log           = FindViewById <Button> (Resource.Id.view_log);

            SetFindSimilarFaceButtonEnabledStatus(false);

            InitializeFaceList();
            faceListAdapter = new FaceImageListAdapter();
            FindViewById <GridView> (Resource.Id.all_faces).Adapter = faceListAdapter;

            LogHelper.ClearLog(LogType.FindSimilarFaces);
        }
Beispiel #7
0
            public override View GetView(int position, View convertView, ViewGroup parent)
            {
                if (convertView == null)
                {
                    var layoutInflater = (LayoutInflater)Application.Context.GetSystemService(LayoutInflaterService);
                    convertView = layoutInflater.Inflate(Resource.Layout.item_face_group, parent, false);
                }

                convertView.Id = position;

                var faceGroup     = faceGroups [position];
                var faceGroupName = $"{faceGroup.Title}: {faceGroup.Faces.Count} face(s)";

                convertView.FindViewById <TextView> (Resource.Id.face_group_name).Text = faceGroupName;

                var thumbnails = faceListAdapter.GetThumbnailsForFaceList(faceGroup.Faces);

                var facesAdapter = new FaceImageListAdapter(faceGroup.Faces, thumbnails);
                var gridView     = convertView.FindViewById <EmbeddedGridView> (Resource.Id.faces);

                gridView.Adapter = facesAdapter;

                return(convertView);
            }
Beispiel #8
0
 public SimilarFaceListAdapter(List <SimilarFaceResult> similarFaceResults, FaceImageListAdapter faceListAdapter)
 {
     this.similarFaceResults = similarFaceResults;
     this.faceListAdapter    = faceListAdapter;
 }