private void resetButton_Click(object sender, EventArgs e) { Gestures.resetGestureInfo(); Gestures.saveData(); Gestures.loadData(Gestures.getPath()); LoadTable(); }
private void editBindingButton_Click(object sender, EventArgs e) { // returns a string form of the given keybinding or // null if no text was inputted to the text box; //usage: using (KeyBindForm keyForm = new KeyBindForm()) { if (DialogResult.OK == keyForm.ShowDialog()) { string gestureName = keyForm.getGestureName(); string appName = keyForm.getAppName(); if (keyForm.getKeyBind() != null && keyForm.getKeyBind().Trim() != "" && keyForm.getGestureName() != null && keyForm.getAppName() != null) { Gestures.setAppKeyForGesture(gestureName, appName, keyForm.getKeyBind()); Gestures.saveData(); gestureDataGridView.Hide(); gestureDataGridView.Controls.Clear(); LoadTable(); gestureDataGridView.Show(); } //label1.Text = mainForm.getKeyBind(); } else { //nothing was found } } }
private void chooseModelButton_Click(object sender, EventArgs e) { var FD = new System.Windows.Forms.OpenFileDialog(); FD.Filter = "model files (*.svm)|*.svm|All files (*.*)|*.*"; if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileToOpen = System.IO.Path.GetFileName(FD.FileName); this.model.ModelFilePath = @fileToOpen; this.modelFileLabel.Text = fileToOpen; // Update gesture data based on model chosen. if (fileToOpen.Equals(GestureStudio.ModelFileNew)) { Gestures.loadData(GestureStudio.GesturesDataPathNew); } else if (fileToOpen.Equals(GestureStudio.ModelFileEmpty)) { Gestures.loadData(GestureStudio.GesturesDataPathEmpty); } else // Demo version { Gestures.loadData(GestureStudio.GesturesDataPathDemo); } } }
private void LoadTable() { gestureDataGridView.Columns.Clear(); Dictionary <int, GestureInfo> gestures = Gestures.getGestures(); string[] applications = KeyControls.getApplications(); // create table with correct size first gestureDataGridView.Columns.Add("Gesture\\App", "Gesture\\App"); for (int i = 0; i < applications.Length; i++) { gestureDataGridView.Columns.Add(applications[i], applications[i]); } foreach (KeyValuePair <int, GestureInfo> gesturePair in gestures) { string[] gestureInfo = new string[gesturePair.Value.getAllCommands().Count + 1]; gestureInfo[0] = gesturePair.Value.getName(); // gesture name if (!gestureInfo[0].Equals("Noise")) { int index = 1; foreach (KeyValuePair <int, AppKeyInfo> command in gesturePair.Value.getAllCommands()) { gestureInfo[index++] = command.Value.ToString(); } gestureDataGridView.Rows.Add(gestureInfo); } } }
private void setGestures() { this.selectGesture.Items.Clear(); foreach (GestureInfo gesture in Gestures.getGestures().Values) { if (!gesture.getName().Equals("Noise")) { this.selectGesture.Items.Add(gesture.getName()); } } }
private void chooseDataFile_Click(object sender, EventArgs e) { DialogResult result = chooseFileDialog.ShowDialog(); if (result == DialogResult.OK) { string file = chooseFileDialog.FileName; try { Gestures.loadData(file); gestureDataGridView.Hide(); gestureDataGridView.Controls.Clear(); LoadTable(); gestureDataGridView.Show(); } catch (IOException) { } } }
private void mainWindowTabs_SelectedIndexChanged(object sender, EventArgs e) { if (mainWindowTabs.SelectedIndex == 1) { try { Gestures.loadData(Gestures.getPath()); gestureDataGridView.Hide(); gestureDataGridView.Controls.Clear(); LoadTable(); gestureDataGridView.Show(); } catch (IOException) { } } this.model.Stop(); this.controlButton.Text = "Start"; this.mainWindow_status.Text = "Your Gesture: []"; this.classifying = false; }
private void startButton_Click(object sender, EventArgs e) { SynchronizationContext ctx = SynchronizationContext.Current; // Save the new gesture name to gestureInfoNew.data string name = gestureName.Text; Gestures.addNewGesture(name); Gestures.saveData(GestureStudio.GesturesDataPathNew); Gestures.loadData(GestureStudio.GesturesDataPathNew); // Count down 5. int countDown = 5; System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Interval = 1000; timer.Tick += (o, src) => { countDown--; ctx.Post((state) => { this.countDownLabel.Text = countDown.ToString(); }, null); if (countDown == 0) { this.OnStart(); timer.Stop(); countDown = 5; this.countDownLabel.Text = countDown.ToString(); this.gestureName.Text = "Name of the new gesture."; } }; timer.Start(); }
void InternalInitialize(Action initializeCallback) { modelBuilder = new SvmModelBuilder(); this.featureVector = new List <double[]>(); // init omp this.imgFeature = new ImageFeature(GestureStudio.GestureLib_DictionartyPath); // update GestureInfo.data if (this.problemFile == null || this.problemFile.Equals(GestureStudio.FeatureFileEmpty)) { Gestures.loadData(GestureStudio.GesturesDataPathEmpty); } else if (this.problemFile.Equals(GestureStudio.FeatureFileNew)) { Gestures.loadData(GestureStudio.GesturesDataPathNew); } else // demo version, this will take a long time. So avoid this in the demo. { Gestures.loadData(GestureStudio.GesturesDataPathDemo); } // done initialization if (initializeCallback != null) { initializeCallback(); } // display trainer form SynchronizationContext ctx = SynchronizationContext.Current; GestureStudio.DisplayTrainerForm(() => { // count down finished, begin this.initialized = true; }); }
private void MainWindow_Load(object sender, EventArgs e) { // instance initialization requires UI thread, wait until load this.model = GestureModel.Instance; this.gestures = Gestures.Instance; this.keyControls = KeyControls.Instance; this.controller = new Control(); this.LoadTable(); this.LoadTutorial(); this.volumeTimer = new Stopwatch(); this.volumeTimer.Start(); this.bWork = new BackgroundWorker(); bWork.DoWork += new DoWorkEventHandler(bw_DoWork); // direct to tutorial page if necessary string[] lines = File.ReadAllLines(GestureStudio.SettingFile); string[] directTutorial = lines[0].Split(':'); if (directTutorial[0] == "directTutorial" && directTutorial[1] == "yes") { using (DirectToTutorialForm directForm = new DirectToTutorialForm()) { DialogResult result = directForm.ShowDialog(); if (DialogResult.Yes == result) { this.mainWindowTabs.SelectedTab = this.tutorialTab; } else if (DialogResult.No == result) { // don't show this dialog next time if (directForm.isIgnoreChecked()) { using (StreamWriter file = new StreamWriter(GestureStudio.SettingFile)) { StringBuilder sb = new StringBuilder(); sb.Append(directTutorial[0] + ":no"); file.WriteLine(sb.ToString()); } } } else { } } } SynchronizationContext ctx = SynchronizationContext.Current; this.model.FrameReady += (s, args) => { if (disabled) { return; } Bitmap fullFrame = this.model.RawDepthFrame.ToBitmap(); Bitmap croppedFrame = this.model.CroppedFrame.ToBitmap(); using (Graphics g = Graphics.FromImage(fullFrame)) { int startX = this.model.CropStartX; int startY = this.model.CropStartY; int croppedWidth = this.model.CroppedFrame.Width; int croppedHeight = this.model.CroppedFrame.Height; Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 5); if (croppedWidth > 10 && croppedHeight > 10 && croppedHeight < 200 && croppedHeight < 200) { g.DrawRectangle(pen, startX + croppedWidth / 2, startY + croppedHeight / 2, 1, 1); g.DrawRectangle(pen, startX, startY, croppedWidth, croppedHeight); } } ctx.Post((o) => { Bitmap fitFull = new Bitmap(fullFrame, this.mainWindow_full.Width, this.mainWindow_full.Height); Bitmap fitCropped; if (GestureStudio.DISPLAY_DETECTED_GESTURE_IMG) { } else { // make sure the cropped image has area if (croppedFrame.Height > 0 && croppedFrame.Width > 0) { // resize images in order to fit into picture box in the home tab double croppedRatio_w_h = (double)croppedFrame.Width / croppedFrame.Height; if (croppedRatio_w_h > Width_To_Height_Ratio) // cropped image is long in horizontal { fitCropped = new Bitmap(croppedFrame, this.mainWindow_cropped.Width, (int)(this.mainWindow_cropped.Width / croppedRatio_w_h)); } else // cropped image is long in vertical { fitCropped = new Bitmap(croppedFrame, (int)(this.mainWindow_cropped.Height * croppedRatio_w_h), this.mainWindow_cropped.Height); } } else fitCropped = null; this.mainWindow_cropped.Image = fitCropped; } this.mainWindow_full.Image = fitFull; framesCount++; }, null); }; this.model.CategoryDetected += (s, args) => { if (disabled) { return; } ctx.Post((o) => { int label = (int)o; if (GestureStudio.GENERIC_GESTURES) { if (this.volumeTimer.ElapsedMilliseconds > 2500) { if (GestureStudio.DISPLAY_DETECTED_GESTURE_IMG) { string img_path = GestureStudio.GestureImagePath + "/" + Gestures.getGestureName(label) + ".png"; Bitmap resized_img = null; if (File.Exists(img_path)) { Bitmap img = new Bitmap(img_path); // resize resized_img = new Bitmap(img, this.mainWindow_cropped.Width, this.mainWindow_cropped.Height); } this.mainWindow_cropped.Image = resized_img; } // lookup which window is focused and find if it is in the gestures list if (Gestures.getGestureName(label) != null && Gestures.getGestureName(label).ToLower() != "noise") { this.mainWindow_status.Text = "Your Gesture: [" + Gestures.getGestureName(label) + "]"; if (Gestures.getGestures()[label].getAllCommands().Count != 0) this.commandLabel.Text = "[" + Gestures.getGestures()[label].getAllCommands()[0].getCommand() + "]"; else this.commandLabel.Text = "[]"; } else { this.mainWindow_status.Text = "Your Gesture: []"; this.commandLabel.Text = "[]"; } // string focusedApp = ... // int appId = Gestures.getAppId(focusedApp); AppKeyInfo appInfo = Gestures.getAppKeyForGesture(label, 0 /*appId*/); if (appInfo == null || KeyControls.getKeyMatches()[0/*appId*/] == null) return; string detectedCommand = KeyControls.getKeyMatches()[0][appInfo.getCommand()]; if (detectedCommand != null && !detectedCommand.Equals("f8") && !detectedCommand.Equals("f9")) { this.volumeTimer.Reset(); this.volumeTimer.Start(); } if (!this.bWork.IsBusy) { this.bWork.RunWorkerAsync(detectedCommand); //() => { this.controller.parseThenExecute(detectedCommand);}); } } } else this.mainWindow_status.Text = "Your Gesture: [" + LabelToString(label) + "]"; }, args.CategoryLabel); }; }
private void MainWindow_Load(object sender, EventArgs e) { // instance initialization requires UI thread, wait until load this.model = GestureModel.Instance; this.gestures = Gestures.Instance; this.keyControls = KeyControls.Instance; this.controller = new Control(); this.LoadTable(); this.LoadTutorial(); this.volumeTimer = new Stopwatch(); this.volumeTimer.Start(); this.bWork = new BackgroundWorker(); bWork.DoWork += new DoWorkEventHandler(bw_DoWork); // direct to tutorial page if necessary string[] lines = File.ReadAllLines(GestureStudio.SettingFile); string[] directTutorial = lines[0].Split(':'); if (directTutorial[0] == "directTutorial" && directTutorial[1] == "yes") { using (DirectToTutorialForm directForm = new DirectToTutorialForm()) { DialogResult result = directForm.ShowDialog(); if (DialogResult.Yes == result) { this.mainWindowTabs.SelectedTab = this.tutorialTab; } else if (DialogResult.No == result) { // don't show this dialog next time if (directForm.isIgnoreChecked()) { using (StreamWriter file = new StreamWriter(GestureStudio.SettingFile)) { StringBuilder sb = new StringBuilder(); sb.Append(directTutorial[0] + ":no"); file.WriteLine(sb.ToString()); } } } else { } } } SynchronizationContext ctx = SynchronizationContext.Current; this.model.FrameReady += (s, args) => { if (disabled) { return; } Bitmap fullFrame = this.model.RawDepthFrame.ToBitmap(); Bitmap croppedFrame = this.model.CroppedFrame.ToBitmap(); using (Graphics g = Graphics.FromImage(fullFrame)) { int startX = this.model.CropStartX; int startY = this.model.CropStartY; int croppedWidth = this.model.CroppedFrame.Width; int croppedHeight = this.model.CroppedFrame.Height; Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 5); if (croppedWidth > 10 && croppedHeight > 10 && croppedHeight < 200 && croppedHeight < 200) { g.DrawRectangle(pen, startX + croppedWidth / 2, startY + croppedHeight / 2, 1, 1); g.DrawRectangle(pen, startX, startY, croppedWidth, croppedHeight); } } ctx.Post((o) => { Bitmap fitFull = new Bitmap(fullFrame, this.mainWindow_full.Width, this.mainWindow_full.Height); Bitmap fitCropped; if (GestureStudio.DISPLAY_DETECTED_GESTURE_IMG) { } else { // make sure the cropped image has area if (croppedFrame.Height > 0 && croppedFrame.Width > 0) { // resize images in order to fit into picture box in the home tab double croppedRatio_w_h = (double)croppedFrame.Width / croppedFrame.Height; if (croppedRatio_w_h > Width_To_Height_Ratio) // cropped image is long in horizontal { fitCropped = new Bitmap(croppedFrame, this.mainWindow_cropped.Width, (int)(this.mainWindow_cropped.Width / croppedRatio_w_h)); } else // cropped image is long in vertical { fitCropped = new Bitmap(croppedFrame, (int)(this.mainWindow_cropped.Height * croppedRatio_w_h), this.mainWindow_cropped.Height); } } else { fitCropped = null; } this.mainWindow_cropped.Image = fitCropped; } this.mainWindow_full.Image = fitFull; framesCount++; }, null); }; this.model.CategoryDetected += (s, args) => { if (disabled) { return; } ctx.Post((o) => { int label = (int)o; if (GestureStudio.GENERIC_GESTURES) { if (this.volumeTimer.ElapsedMilliseconds > 2500) { if (GestureStudio.DISPLAY_DETECTED_GESTURE_IMG) { string img_path = GestureStudio.GestureImagePath + "/" + Gestures.getGestureName(label) + ".png"; Bitmap resized_img = null; if (File.Exists(img_path)) { Bitmap img = new Bitmap(img_path); // resize resized_img = new Bitmap(img, this.mainWindow_cropped.Width, this.mainWindow_cropped.Height); } this.mainWindow_cropped.Image = resized_img; } // lookup which window is focused and find if it is in the gestures list if (Gestures.getGestureName(label) != null && Gestures.getGestureName(label).ToLower() != "noise") { this.mainWindow_status.Text = "Your Gesture: [" + Gestures.getGestureName(label) + "]"; if (Gestures.getGestures()[label].getAllCommands().Count != 0) { this.commandLabel.Text = "[" + Gestures.getGestures()[label].getAllCommands()[0].getCommand() + "]"; } else { this.commandLabel.Text = "[]"; } } else { this.mainWindow_status.Text = "Your Gesture: []"; this.commandLabel.Text = "[]"; } // string focusedApp = ... // int appId = Gestures.getAppId(focusedApp); AppKeyInfo appInfo = Gestures.getAppKeyForGesture(label, 0 /*appId*/); if (appInfo == null || KeyControls.getKeyMatches()[0 /*appId*/] == null) { return; } string detectedCommand = KeyControls.getKeyMatches()[0][appInfo.getCommand()]; if (detectedCommand != null && !detectedCommand.Equals("f8") && !detectedCommand.Equals("f9")) { this.volumeTimer.Reset(); this.volumeTimer.Start(); } if (!this.bWork.IsBusy) { this.bWork.RunWorkerAsync(detectedCommand); //() => { this.controller.parseThenExecute(detectedCommand);}); } } } else { this.mainWindow_status.Text = "Your Gesture: [" + LabelToString(label) + "]"; } }, args.CategoryLabel); }; }