private async void confirmButton_Click(object sender, EventArgs e)
        {
            //aws -> MiddleService
            EmotDetector ed = new EmotDetector();

            //SimpleService.SimpleSoapClient webClient = new SimpleService.SimpleSoapClient();
            try
            {
                //aws -> MiddleService
                bool response = await ed.IsReferencePhotoValid(path);

                //var response = webClient.isRefPhotoValid(path);

                //if the photo is valid we close this window and proceed to regular menu
                if (Info.index > 0)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    this.Hide();
                    MainForm mainForm = new MainForm();
                    mainForm.ShowDialog();
                }
            } catch (InvalidReferencePictureException)
            {
                MessageBox.Show("Invalid photo! Please use a photo which contains only YOUR face!");
            }
        }
Пример #2
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (resultCode == Result.Ok)
            {
                var imageView = FindViewById <ImageView>(Resource.Id.selectedPhotoView);
                imageView.SetImageURI(data.Data);

                //prepare for analysis
                string path = Android.OS.Environment.GetExternalStoragePublicDirectory(
                    Android.OS.Environment.DirectoryPictures).AbsolutePath;
                string myPath = data.Data.Path;
                //EmotDetector ed = new EmotDetector();

                Android.Net.Uri uri    = data.Data;
                Stream          stream = ContentResolver.OpenInputStream(uri);

                string filepath = GetFilePath(uri);

                EmotDetector ed = new EmotDetector();
                ed.uploadPhotoAndroid(filepath);
                Toast.MakeText(this, filepath, ToastLength.Short).Show();
            }

            string GetFilePath(Android.Net.Uri uri)
            {
                string filePath = "";
                //
                string imageId = DocumentsContract.GetDocumentId(uri);
                string id      = imageId.Split(':')[1];

                string[] proj = { MediaStore.Images.Media.InterfaceConsts.Data };
                string   sel  = MediaStore.Images.Media.InterfaceConsts.Id + "=?";

                using (ICursor cursor = ContentResolver.Query(MediaStore.Images.Media.ExternalContentUri, proj, sel, new string[] { id }, null))
                {
                    int columnIndex = cursor.GetColumnIndex(proj[0]);
                    if (cursor.MoveToFirst())
                    {
                        filePath = cursor.GetString(columnIndex);
                    }
                }
                return(filePath);
            }
        }
Пример #3
0
 public string HelloWorld()
 {
     return(EmotDetector.Hi());
 }
Пример #4
0
        private async void Button1_Click(object sender, EventArgs e)
        {
            string value = System.Configuration.ConfigurationManager.AppSettings["eventName"];
            string eventNamePattern;

            //MessageBox.Show("val is: " + value + " much");
            if (value == "text")
            {
                eventNamePattern = @"\w*[a-zA-Z]\w*";
            }
            else
            {
                eventNamePattern = "(.*?)";
            }

            string eventName = StringChanger.ChangeFirstLetterCase(eventText.Text);

            bool isEventNameValid = Regex.IsMatch(eventText.Text, eventNamePattern);

            if (!isEventNameValid)
            {
                add <string> conct = Concate;
                GenError <string>(conct("Please enter a valid event name, you entered - ", eventText.Text));
                //MessageBox.Show("Please enter a valid event name");
            }
            else
            {
                confirmButton.Enabled = false;
                LoadingScreen ls = new LoadingScreen();
                ls.Open();

                EmotDetector ed       = new EmotDetector();
                string       emotions = await ed.WhatEmot(path, fileName);

                emotions = emotions.Replace("\"", "");
                //MessageBox.Show(emotions);

                //creating enum
                Emotion  emos         = new Emotion();
                int      i            = 0;
                string[] emotionArray = emotions.Split(',');

                if (emotionArray[0] == "")
                {
                    emos     = Emotion.UNKNOWN;
                    emotions = "UNKNOWN";
                }
                else
                {
                    foreach (string emotion in emotionArray)
                    {
                        if (i == 0)
                        {
                            emos = (Emotion)Enum.Parse(typeof(Emotion), emotion);
                            add <int> sum = AddNumber;
                            i = sum(i, 1);
                            //i++;
                        }
                        else
                        {
                            emos = emos | (Emotion)Enum.Parse(typeof(Emotion), emotion);
                        }
                    }
                }

                string binaryEmotions = Convert.ToString((int)emos, 2);
                // Send found emotions to loading screen
                ls.setEmotions(emotions);

                Byte[]            image  = File.ReadAllBytes(fileDir);
                Info              info   = new Info(eventName, emos);
                IEquatable <Info> narrow = info;
                if (Info.index > 1 && dublicateBox.Checked)
                {
                    EventArgs arg = new EventArgs();
                    PossiblyDublicateUploads(this, arg);
                }
                else
                {
                    //this.tableTableAdapter.Insert(info, image);
                    //this.tableTableAdapter.Update(this.appData.Table);
                    using (var context = new Database1Entities())
                    {
                        context.Photoinfoes.Add(new Photoinfo(info, image));
                        context.SaveChanges();
                    }
                }

                ls.WaitForClose();
                confirmButton.Enabled = true;

                if (Info.index > 2)
                {
                    Info infoCurrent = info[Info.index - 1];

                    if (infoCurrent.emotion == 0 &&
                        info[Info.index - 2].emotion == 0 &&
                        info[Info.index - 3].emotion == 0)
                    {
                        int counter = 1;
                        for (int n = Info.index - counter; n >= 0 && info[n].emotion == 0; n--)
                        {
                            counter++;
                        }

                        MultipleUnknownPhotosEventArgs arg = new MultipleUnknownPhotosEventArgs(counter - 1);
                        PossiblyBadReferencePicture(arg);
                    }
                    //MessageBox.Show(info[0].eventName + '\n' +
                    //    info[1].eventName + '\n' +
                    //    info[2].eventName);
                }
            }
        }