private void _calibrateButton_Click(object sender, EventArgs e) { var runner = new CalibrationRunner(); try { var result = runner.RunCalibration(_connectedTracker); // if everything went OK start training if (result != null) { test t = new test(); //get experiment stucture experiment ex = t.create(); //loop for (int i = 0; i < ex.Compare.Count; i++) { currentDataItem = new dataItem(Guid.NewGuid()); currentDataItem.RightClass = ex.Compare[i][0]; currentDataItem.LeftClass = ex.Compare[i][1]; currentDataItem.ImgPath = ex.Record[i]; trainingForm f = new trainingForm(ex.Compare[i][0], ex.Compare[i][1]); f.ShowDialog(); focusCalibrationForm focusCal = new focusCalibrationForm(); focusCal.ShowDialog(); rc = new recordForm(this, ex.Record[i]); rc.ShowDialog(); this.dataItems.Add(currentDataItem); } writeGazeExcel(); this.Close(); } else { MessageBox.Show("Not enough data to create a calibration (or calibration aborted)."); } } catch (EyeTrackerException ee) { MessageBox.Show("Failed to calibrate. Got exception " + ee, "Calibration Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public experiment create(string type) { if (type == "V") { this.addVireoCategories(); } else if (type == "W") { this.addWoodPeckersCategories(); } else { return(null); } experiment e = new experiment(); int iterations = 0; foreach (Category c in categories) { iterations += c.ImagesPathCount.Count; } Random rand = new Random(); while (iterations > 0) { //select a category to collect data for bool ok = false; int catIndex = -1; Category selectedCat = null; while (!ok) { catIndex = rand.Next(categories.Count); selectedCat = categories[catIndex]; if (selectedCat.Selected != selectedCat.ImagesPathCount.Count) { selectedCat.Selected++; ok = true; } } //Console.Out.WriteLine("Selected cat for collection: " + selectedCat.CategoryName); //select a category for comparing (training) ok = false; Category selectedCompCat = null; while (!ok) { catIndex = rand.Next(categories.Count); selectedCompCat = categories[catIndex]; if (selectedCat != selectedCompCat) { ok = true; } } //Console.Out.WriteLine("Selected cat for comparing: " + selectedCompCat.CategoryName); List <string> temp = new List <string>(); temp.Add(selectedCat.Image); temp.Add(selectedCompCat.Image); e.Compare.Add(temp); //select image from collection category List <string> Keys = Enumerable.ToList(selectedCat.ImagesPathCount.Keys); int imgKey = -1; ok = false; while (!ok) { imgKey = rand.Next(Keys.Count); if (selectedCat.ImagesPathCount[Keys[imgKey]] == 0) { ok = true; selectedCat.ImagesPathCount[Keys[imgKey]] = 1; } } e.Record.Add(Keys[imgKey]); Console.Out.WriteLine("Selected image for collection: " + Keys[imgKey]); iterations--; Console.Out.WriteLine("Iterations: " + iterations.ToString()); } return(e); }
private void start() { var runner = new CalibrationRunner(); bool calibratedSuccessfully = false; while (!calibratedSuccessfully) { try { var result = runner.RunCalibration(_connectedTracker); // if everything went OK start training if (result != null) { calibratedSuccessfully = true; experimentRunner t = new experimentRunner(); //get experiment stucture experiment ex = t.create(this.type); //loop if (ex != null) { this.IsTracking = true; this.ConnectedTracker.StartTracking(); int correctLabelPos = 0; string correctClass = ""; Random rand = new Random(); for (int i = 0; i < ex.Compare.Count; i++) //for (int i = 0; i < 3; i++) { trainingForm f = null; correctLabelPos = rand.Next(2); if (correctLabelPos == 0) { f = new trainingForm(ex.Compare[i][0], ex.Compare[i][1], Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); correctClass = "Right"; currentDataItem = new dataItem(ex.Compare[i][0], ex.Compare[i][1], f.LocationRight, f.LocationLeft); } else { f = new trainingForm(ex.Compare[i][1], ex.Compare[i][0], Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); correctClass = "Left"; currentDataItem = new dataItem(ex.Compare[i][1], ex.Compare[i][0], f.LocationRight, f.LocationLeft); } f.ShowDialog(); focusCalibrationForm focusCal = new focusCalibrationForm(); currentDataItem = new dataItem(); focusCal.ShowDialog(); recordForm rc = new recordForm(this, ex.Record[i], correctClass, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); currentDataItem = new dataItem(ex.Compare[i][0], ex.Compare[i][1], rc.Location, ex.Record[i]); rc.ShowDialog(); } sw.Flush(); } this.resultScoresLabel.Text = "Correct guess= " + recordForm.correctScore + ", " + "Wrong guess= " + recordForm.wrongScore; this.close.Visible = true; } else { MessageBox.Show("Calibration failed! please try again (focus on the dots)"); } } catch (EyeTrackerException ee) { MessageBox.Show("Failed to calibrate. Got exception " + ee, "Calibration Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }