private void SetLabelButton() { // Label missing if (Setting.Label == null || Setting.Label.Equals("")) { this.ShowMessageAsync(GlobalLanguage.FindText("Common_Notice"), GlobalLanguage.FindText("MainWindow_LabelNotFound")); return; } // Get label labelList = new List <string>(); foreach (string label in Setting.Label.Split('|')) { labelList.Add(label); } // Set label Button[] button = new Button[labelList.Count()]; for (int i = 0; i < labelList.Count(); i++) { button[i] = new Button { Content = labelList[i], Margin = new Thickness(5d), ToolTip = i }; button[i].Click += button_Template_Click; wrapPanel_Button.Children.Add(button[i]); } }
private void MetroWindow_Loaded(object sender, RoutedEventArgs e) { GlobalLanguage.SetLanguage(Setting.MainLanguage); SetLabelButton(); uiData.progressRing_IsActive = false; grid_Main.DataContext = uiData; cntkFacialHelper = new EvaluatorHelper(Setting.FacialCNNModelPath, 48, 48, 3); }
private void button_LoadDownloadPath_Click(object sender, RoutedEventArgs e) { string path = Other.Tools.GetFolder(GlobalLanguage.FindText("MainWindow_LoadDownloadPath_Title"), true); if (path != string.Empty) { MainWindow.totalData.DownloadDefaultFolderPath = path; DirectoryInfo info = new DirectoryInfo(path); Space = Other.Tools.GetHardDiskFreeSpace(info.Root.FullName); } }
private void Button_Copy_Click(object sender, RoutedEventArgs e) { switch (textBox_ShowPassword.Visibility) { case Visibility.Visible: Clipboard.SetText(string.Format(GlobalLanguage.FindText("GenerateShareLinkWindow_Copy_Format"), ShareLink, Password)); break; case Visibility.Hidden: Clipboard.SetText(ShareLink); break; } DialogResult = true; }
/// <summary> /// Init EvaluatorHelper and create network. /// </summary> /// <param name="ModelPath">Model Path,used full path.</param> /// <param name="DeviceId">deviceId = -1 for CPU, >=0 for GPU devices.</param> public EvaluatorHelper(string ModelPath, int DeviceId = -1) { if (!File.Exists(ModelPath)) { MessageBox.Show(GlobalLanguage.FindText("Message_Notice_FileNotExist"), GlobalLanguage.FindText("Message_Notice")); return; } this.modelPath = ModelPath; this.deviceId = DeviceId; this.model = new IEvaluateModelManagedF(); this.model.CreateNetwork(string.Format("modelPath=\"{0}\"", this.modelPath), this.deviceId); this.inputDims = this.model.GetNodeDimensions(NodeGroup.Input); this.outputDims = this.model.GetNodeDimensions(NodeGroup.Output); }
private async void Thread_StartShowAndLabel(object dic) { try { Dictionary <string, Rect[]> dictionary = (Dictionary <string, Rect[]>)dic; foreach (KeyValuePair <string, Rect[]> row in dictionary) { uiData.progressRing_IsActive = true; filePathNowLoaded = row.Key; int result = await ShowImage(row.Key); await Task.Delay(200); UIImageActualRect = new Rect(0, 0, image_Show.ActualWidth, image_Show.ActualHeight); List <Rect> list = ConvertBBox(row.Value.ToList()); BboxList = row.Value.ToList(); if (autoResetEvent != null) { autoResetEvent.Dispose(); } autoResetEvent = new AutoResetEvent(false); image_RGB = new Image <Rgb, float>(image); uiData.progressRing_IsActive = false; foreach (Rect rect in list) { CallDrawBbox_Delegate(ref BboxGD, rect, ref BboxLabelPen, ref drawingBboxNoticePen); if (PreRecognition) { AutoRecognition(); } autoResetEvent.WaitOne(); CountBBox++; } CountBBox = 0; image_RGB.Dispose(); image_RGB = null; } await this.Dispatcher.Invoke(async() => { await this.ShowMessageAsync(GlobalLanguage.FindText("Common_Done"), GlobalLanguage.FindText("MainWindow_Thread_StartShowAndLabel_DoneMessage")); }); }catch (Exception ex) { await this.Dispatcher.Invoke(async() => { await this.ShowMessageAsync(GlobalLanguage.FindText("Common_Error"), ex.Message); }); } }
private void AutoRecognition() { try { Rect rect = BboxList[CountBBox]; Image <Rgb, float> image_Converted = image_RGB.GetSubRect(new System.Drawing.Rectangle(Convert.ToInt32(BboxList[CountBBox].X), Convert.ToInt32(BboxList[CountBBox].Y), Convert.ToInt32(BboxList[CountBBox].Width), Convert.ToInt32(BboxList[CountBBox].Height))).Convert <Gray, byte>().Resize(48, 48, Emgu.CV.CvEnum.Inter.Cubic).Convert <Rgb, float>(); var result = cntkFacialHelper.RecognizeWithConvNet(ref image_Converted, ref rect); uiData.FacialResult = string.Format("无表情:{0}%, 高兴:{1}%, 惊讶:{2}%, 沮丧:{3}%, 恐惧:{4}%, 生气:{5}%, 厌恶:{6}%", Math.Round(result[0] * 100, 1), Math.Round(result[1] * 100, 1), Math.Round(result[2] * 100, 1), Math.Round(result[3] * 100, 1), Math.Round(result[4] * 100, 1), Math.Round(result[5] * 100, 1), Math.Round(result[6] * 100, 1)); image_Converted.Dispose(); image_Converted = null; }catch (Exception ex) { this.Dispatcher.Invoke(async() => { await this.ShowMessageAsync(GlobalLanguage.FindText("Common_Error"), ex.Message); }); } }
/// <summary> /// Show image on Mainwindow /// </summary> /// <param name="file">Image file path</param> private Task <int> ShowImage(string file) { return(Task.Factory.StartNew(() => { if (image != null) { image.Dispose(); image = null; } //uiData.progressRing_IsActive = true; filePathNowLoaded = file; FileInfo info = new FileInfo(file); uiData.TextMessage = string.Format(GlobalLanguage.FindText("MainWindow_ShowImage_Message"), info.Name); CallResetOtherImage_Delegate(); image = System.Drawing.Bitmap.FromFile(file) as System.Drawing.Bitmap; BitmapSource bitmap = Imaging.CreateBitmapSourceFromBitmap(ref image); uiData.UIImage = bitmap; //uiData.progressRing_IsActive = false; //image.Dispose(); bitmap = null; return uiData.LastCount--; })); }
/// <summary> /// Init EvaluatorHelper and create network for image classification. /// </summary> /// <param name="ModelPath">Model Path,used full path.</param> /// <param name="ImageWidth">The network input image width.</param> /// <param name="ImageHeigh">The network input image heigh.</param> /// <param name="ImageChannel">The network input image channel.</param> /// <param name="DeviceId">deviceId = -1 for CPU, >=0 for GPU devices.</param> public EvaluatorHelper(string ModelPath, int ImageWidth, int ImageHeigh, int ImageChannel, int DeviceId = -1) { if (!File.Exists(ModelPath)) { MessageBox.Show(GlobalLanguage.FindText("EvaluatorHelper_ModelNotExist"), GlobalLanguage.FindText("Common_Notice")); return; } if (ImageWidth <= 0 || ImageHeigh <= 0 || ImageChannel <= 0) { MessageBox.Show(GlobalLanguage.FindText("EvaluatorHelper_ImageSizeError"), GlobalLanguage.FindText("Common_Error")); return; } this.modelPath = ModelPath; this.deviceId = DeviceId; this.model = new IEvaluateModelManagedF(); this.model.CreateNetwork(string.Format("modelPath=\"{0}\"", this.modelPath), this.deviceId); this.image_Width = ImageWidth; this.image_Heigh = ImageHeigh; this.image_Channel = ImageChannel; this.inputDims = this.model.GetNodeDimensions(NodeGroup.Input); this.outputDims = this.model.GetNodeDimensions(NodeGroup.Output); }
private async void button_LoadLocalFile_Click(object sender, RoutedEventArgs e) { try { string[] infoFile = Tools.GetFile(GlobalLanguage.FindText("MainWindow_Button_LoadLocalFile_Title"), "Info.dat|*.dat|Info.txt|*.txt", Setting.BasePath); if (infoFile == null || infoFile.Count() != 1 || infoFile[0].Equals("")) { await this.ShowMessageAsync(GlobalLanguage.FindText("Common_Notice"), GlobalLanguage.FindText("MainWindow_Button_LoadLocalFile_FileSelectError")); return; } var result = await SplitInfo(infoFile[0]); uiData.LastCount = result.Count(); Thread thread = new Thread(new ParameterizedThreadStart(Thread_StartShowAndLabel)); thread.IsBackground = true; thread.Start(result); }catch (Exception ex) { await this.ShowMessageAsync(GlobalLanguage.FindText("Common_Error"), ex.Message); } }