public async void GetTestFace() { TestFace tf = new TestFace(); string personImageDir = @"C:\Users\v-altsai\Pictures\Original"; string[] ImagePathArray = Directory.GetFiles(personImageDir, "*.jpg"); this.IdentifyState = "Analysis your face..."; loading_animation.Visibility = Visibility.Visible; Console.WriteLine("Call Face API"); string s = await tf.Testpicture(ImagePathArray[0]); JSONHelper helper = new JSONHelper(); SendMessageToCloud sc = new SendMessageToCloud(); People p = new People(); p = helper.ConvertJSonToObject <People>(s.ToString()); identify_name = p.Name; identify_Gender = p.Gender; identify_Age = p.Age; identify_Emotion = p.Emotion; identify_EmotionScoreList = p.Emotionlistscore; foreach (KeyValuePair <string, float> row in identify_EmotionScoreList) { Console.WriteLine("Key: " + row.Key + " Value: " + row.Value); } if (p.Name == "none") { this.IdentifyState = "You aren't permitted to access!"; } else { sc.sendWindTurbineMessageToCloudAsync(identify_name, identify_Age, identify_Gender, identify_Emotion, identify_EmotionScoreList, deviceConnectionString); this.IdentifyState = "Hi " + p.Name + ",\nYou are permitted to access!"; } this.PersonName = "Name: " + p.Name + "\nGender: " + p.Gender + "\nAge: " + p.Age + "\nEmotion: " + p.Emotion; viewmode = true; if (viewmode) { BackGround_Screen.Source = bg_pool; badge_Screen.Source = badge[0]; Load_FigureImage(); loading_animation.Visibility = Visibility.Collapsed; Figure_Screen.Visibility = Visibility.Visible; BackGround_Screen.Visibility = Visibility.Visible; badge_Screen.Visibility = Visibility.Visible; viewmode = false; Delete dd = new Delete(); dd.DeletleImage(personImageDir); } }
private async void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e) { bool dataReceived = false; using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame()) { if (bodyFrame != null) { bodyFrame.GetAndRefreshBodyData(this.bodies); dataReceived = true; } } // if detect body then capture the face if (dataReceived) { foreach (Body body in bodies) { if (!body.IsTracked) { continue; } //Console.Write("Check Body "); Joint userJoint_Head = body.Joints[JointType.Head]; cameraSpacePoints[0] = userJoint_Head.Position; List.Add(cameraSpacePoints[0].Z); if (_detectedBackButton == true && idDictionary.ContainsKey(body.TrackingId) == false) { try { Console.WriteLine("Detect more people add to idlist"); idDictionary.Add(body.TrackingId, false); badge_Screen.Visibility = Visibility.Collapsed; BackGround_Screen.Visibility = Visibility.Collapsed; Figure_Screen.Visibility = Visibility.Collapsed; _detectedBackButton = false; identify_name = null; System.IO.File.Delete(@"C:\Users\v-altsai\Pictures\allfix.jpg"); } catch (Exception) { } } SendMessageToCloud sc = new SendMessageToCloud(); if (List.Count >= 30 && _detectedBackButton == false && identify_name != null && idDictionary.ContainsKey(body.TrackingId) != false && idDictionary[body.TrackingId] == true) { try { sc.sendWindTurbineMessageToCloudAsync(identify_name, identify_Age, identify_Gender, identify_Emotion, identify_EmotionScoreList, deviceConnectionString); identify_name = null; identify_Age = null; identify_Gender = null; identify_Emotion = null; List.Clear(); } catch (Exception) { } } while (List.Count >= 30 && _detectedBackButton == false && idDictionary.ContainsKey(body.TrackingId) != false && idDictionary[body.TrackingId] == false && identify_name == null) { try { Console.WriteLine("Check Body Z : {0}", cameraSpacePoints[0].Z); if (List[29] < 0.9 && idDictionary[body.TrackingId] == false) { this.IdentifyState = "Image Capturing..."; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); //引用stopwatch物件 sw.Reset(); //碼表歸零 sw.Start(); //碼表開始計時 count_timer = new DispatcherTimer(); count_timer.Interval = new TimeSpan(0, 0, 0, 1, 0); count_timer.Tick += CountTimer_Tick; count_timer.Start(); idDictionary[body.TrackingId] = true; } else if (List[29] > 0.9 && idDictionary[body.TrackingId] == false) { this.IdentifyState = "Get closer... " + Convert.ToString(cameraSpacePoints[0].Z); } List.Clear(); //BackGround_Screen.Visibility = Visibility.Collapsed; } catch (Exception) { } } } } }