/// <summary> /// /// </summary> public void begin_timer3() { for (int i = 0; i < 40; i++) { obj[i] = new ImgProc(); } timer3.Start(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStart_Click(object sender, EventArgs e) { for (int i = 0; i < 40; i++) { obj[i] = new ImgProc(); } clicks = 0; timer3.Start(); }
/// <summary> /// /// </summary> public void pattern_recognition() { ImgProc main_obj = new ImgProc(); MarkovModelCalculation hmm_obj = new MarkovModelCalculation(); int count = 39; System.IO.StreamWriter file = new System.IO.StreamWriter("D:\\images5\\Centroid.txt"); for (int i = 4; i < count; i++) { file.WriteLine("Frame {0}: {1}, {2}, Quad: {3}", i, cntr[i, 0], cntr[i, 1], cntr[i, 2]); } file.Close(); /* Logic to calculate the state sequence from the captured image frames */ System.IO.StreamWriter file2 = new System.IO.StreamWriter("D:\\images5\\State_seq.txt"); System.IO.StreamWriter file4 = new System.IO.StreamWriter("D:\\images5\\testing_ab.txt"); int beta, a, b, Q; double alpha; int[] O = new int[10]; int[] O2 = new int[5]; for (int k = 0; k < 10; k++) { O[k] = 1; if (k % 2 == 0) { O2[k / 2] = 1; } } /* for O */ for (int i = 0, j = 0; i <= 24; i += 4, j++) { b = cntr[i + 4, 0] - cntr[i, 0]; a = cntr[i + 4, 1] - cntr[i, 1]; if (b == 0) { alpha = 90; } else { alpha = Math.Atan2((Math.Abs(a)), (Math.Abs(b))); alpha = alpha * 180 / 3.14159; } file4.WriteLine("Frame {0}-{1}: a = {2} b: {3} alpha: {4}", i, i + 4, a, b, alpha); beta = alpha > 45 ? ((90 - alpha > alpha - 45) ? 45 : 90) : ((alpha > 45 - alpha) ? 45 : 0); if (a >= 0 && b >= 0) //initially 1,2,4,3 { Q = 4; } else if (a >= 0 && b < 0) { Q = 3; } else if (a < 0 && b >= 0) { Q = 1; } else { Q = 2; } switch (beta) { case 0: if (Q == 1 || Q == 4) { O[j] = 1; } else { O[j] = 5; } break; case 45: if (Q == 1) { O[j] = 8; } else if (Q == 2) { O[j] = 6; } else if (Q == 3) { O[j] = 4; } else { O[j] = 2; } break; case 90: if (Q == 1 || Q == 2) { O[j] = 7; } else { O[j] = 3; } break; } file2.WriteLine("Frame {0}-{1}: State Value = {2} Beta: {3} Alpha: {4}", i, i + 4, O[j], beta, alpha); } file2.Close(); file4.Close(); /* Viterbi Algorithm */ System.IO.StreamWriter file3 = new System.IO.StreamWriter("D:\\images5\\Viterbi_Results.txt"); double prob = 0.0; int label = 0; int[][] labels = new int[8][]; int[] final_obs_seq = new int[13]; for (int k = 0, j = 0; k < O.Length; k++, j++) { if (k <= 5) { final_obs_seq[j] = O[k]; final_obs_seq[++j] = O[k]; } else if (k == 6) { final_obs_seq[j] = O[k]; } else { break; } } for (int j = 0; j < 8; j++) { double p = hmm_obj.Evaluate(final_obs_seq, j + 1); // And select the one which produces the highest probability if (p > prob) { label = j; prob = p; } } using (StreamWriter xfile = File.AppendText("D:\\images5\\Testing_Results.txt")) { int s; for (s = 0; s < (final_obs_seq.Length) - 1; s++) { xfile.Write((final_obs_seq[s] - 1) + "-"); } xfile.Write((final_obs_seq[s] - 1)); xfile.WriteLine(""); xfile.Close(); } int[] result2 = labels[label]; for (int i = 0; i < (final_obs_seq.Length); i++) { file3.Write(final_obs_seq[i] + " "); } file3.WriteLine("\nLabel: " + (label + 1) + " Probability: " + prob); file3.Close(); label += 1; System.IO.StreamWriter file5 = new System.IO.StreamWriter("D:\\images5\\O_Count.txt"); for (int new_i = 0; new_i < O.Length; new_i++) { file5.WriteLine("O[{0}]: {1}", new_i, O[new_i]); } file5.Close(); if (label == 1) //if (O[8] == 1) { MessageBox.Show("Left !!"); switch (index) { case 0: WMP_Control wmp = new WMP_Control(); wmp.ControlMediaPlayer("PreviousSong"); break; case 1: WLPG_Control wlpg = new WLPG_Control(); wlpg.ControlPictureViewer("LeftImage"); break; case 2: Powerpoint pp = new Powerpoint(); pp.ControlPowerpoint("Save"); break; case 3: Notepad n = new Notepad(); n.ControlNotepad("Save"); break; case 4: Prezi p = new Prezi(); p.ControlPrezi("Left"); break; } } else if (label == 2) { MessageBox.Show("Right !!"); switch (index) { case 0: WMP_Control wmp = new WMP_Control(); wmp.ControlMediaPlayer("NextSong"); break; case 1: WLPG_Control wlpg = new WLPG_Control(); wlpg.ControlPictureViewer("RightImage"); break; case 2: Powerpoint pp = new Powerpoint(); pp.ControlPowerpoint("Open"); break; case 3: Notepad n = new Notepad(); n.ControlNotepad("Open"); break; case 4: Prezi p = new Prezi(); p.ControlPrezi("Right"); break; } } else if (label == 3) //else if (O[8] == 7) { MessageBox.Show("Up !!"); switch (index) { case 0: WMP_Control wmp = new WMP_Control(); wmp.ControlMediaPlayer("Increase_Vol"); break; case 1: WLPG_Control wlpg = new WLPG_Control(); wlpg.ControlPictureViewer("Print"); break; case 2: Powerpoint pp = new Powerpoint(); pp.ControlPowerpoint("Print"); break; case 3: Notepad n = new Notepad(); n.ControlNotepad("Print"); break; } } else if (label == 4) //else if (O[8] == 3) { MessageBox.Show("Down !!"); switch (index) { case 0: WMP_Control wmp = new WMP_Control(); wmp.ControlMediaPlayer("Decrease_Vol"); break; case 1: WLPG_Control wlpg = new WLPG_Control(); wlpg.ControlPictureViewer("Slideshow"); break; case 2: Powerpoint pp = new Powerpoint(); pp.ControlPowerpoint("Add_Slide"); break; case 3: Notepad n = new Notepad(); n.ControlNotepad("Selectall"); break; } } else if (label == 5) //else if (O[8] == 3) { MessageBox.Show("Semi-Circle Clockwise !!"); switch (index) { case 0: WMP_Control wmp = new WMP_Control(); wmp.ControlMediaPlayer("Repeat"); break; case 1: WLPG_Control wlpg = new WLPG_Control(); wlpg.ControlPictureViewer("Zoom_In"); break; case 2: Powerpoint pp = new Powerpoint(); pp.ControlPowerpoint("Slideshow_Next"); break; case 3: Notepad n = new Notepad(); n.ControlNotepad("Find"); break; } } else if (label == 6) { MessageBox.Show("Semi-Circle Anticlockwise !!"); switch (index) { case 0: WMP_Control wmp = new WMP_Control(); wmp.ControlMediaPlayer("Shuffle"); break; case 1: WLPG_Control wlpg = new WLPG_Control(); wlpg.ControlPictureViewer("Zoom_Out"); break; case 2: Powerpoint pp = new Powerpoint(); pp.ControlPowerpoint("Slideshow_Previous"); break; case 3: Notepad n = new Notepad(); n.ControlNotepad("Replace"); break; } } else if (label == 7) { MessageBox.Show("Circle Clockwise !!"); switch (index) { case 0: WMP_Control wmp = new WMP_Control(); wmp.ControlMediaPlayer("Play/Pause"); break; case 1: WLPG_Control wlpg = new WLPG_Control(); wlpg.ControlPictureViewer("Rotate_Clock"); break; case 2: Powerpoint pp = new Powerpoint(); pp.ControlPowerpoint("Slideshow_Begin"); break; case 3: Notepad n = new Notepad(); n.ControlNotepad("Highlight"); break; } } else if (label == 8) { MessageBox.Show("Circle Anti-Clockwise !!"); switch (index) { case 0: WMP_Control wmp = new WMP_Control(); wmp.ControlMediaPlayer("Stop"); break; case 1: WLPG_Control wlpg = new WLPG_Control(); wlpg.ControlPictureViewer("Rotate_Anti"); break; case 2: Powerpoint pp = new Powerpoint(); pp.ControlPowerpoint("Slideshow_End"); break; case 3: Notepad n = new Notepad(); n.ControlNotepad("Time_Date"); break; } } else { MessageBox.Show("Processing Completed. Gesture Not Recognized !"); } }