/******************************************************************* * * 処理(hand) * *******************************************************************/ void ReadInput() { while (inputThread.IsAlive) { if (Counter <= SIZE && !cancel_flag && on_flag) { float_raw = thinkGearWrapper.ThinkGearState.Raw; raw = (double)float_raw; raw_array[Counter] = (int)raw; } else { sw.Stop(); Counter = 0; for (int count = 0; count <= SIZE; count++) { double_raw_array[count] = (double)raw_array[count]; } Cursor cursorOrg = Cursor.Current; Cursor.Current = Cursors.WaitCursor; matlab.PutWorkspaceData("data", "base", double_raw_array); matlab.Execute("brain_wave"); System.Array prresult = new double[1, 1]; System.Array piresult = new double[1, 1]; matlab.GetFullMatrix("Result", "base", ref prresult, ref piresult); Result = (int)((double)prresult.GetValue(0, 0)); Cursor.Current = cursorOrg; if (cancel_flag) { btnCancel.Enabled = false; btnSave.Enabled = false; textBox2.Text = sw.ElapsedMilliseconds.ToString(); } else { } on_flag = false; inputThread.Abort(); } Counter++; Thread.Sleep(10); //wait ten milliseconds } }
void MatlabExec() { for (int cnt = 0; cnt < SIZE; cnt++) { double_x1_array[cnt] = (double)formatted_x_array[0, cnt]; double_y1_array[cnt] = (double)formatted_y_array[0, cnt]; double_z1_array[cnt] = (double)formatted_z_array[0, cnt]; double_x2_array[cnt] = (double)formatted_x_array[1, cnt]; double_y2_array[cnt] = (double)formatted_y_array[1, cnt]; double_z2_array[cnt] = (double)formatted_z_array[1, cnt]; } matlab.PutWorkspaceData("x1_data", "base", double_x1_array); matlab.PutWorkspaceData("y1_data", "base", double_y1_array); matlab.PutWorkspaceData("z1_data", "base", double_z1_array); matlab.PutWorkspaceData("x2_data", "base", double_x2_array); matlab.PutWorkspaceData("y2_data", "base", double_y2_array); matlab.PutWorkspaceData("z2_data", "base", double_z2_array); matlab.Execute("hand_motion_classify"); matlab.GetFullMatrix("recognition_result", "base", ref prresult, ref piresult); for (int cnt = 0; cnt < RESULT_MOTION_TYPE; cnt++) { ResultMotionTMP[cnt] = (double)prresult.GetValue(0, cnt); if (cnt == 0) { ResultMotion[0] = ResultMotionTMP[cnt]; } else if (cnt == 1) { ResultMotion[0] = ResultMotionTMP[cnt]; } else if (cnt == 2) { ResultMotion[1] = ResultMotionTMP[cnt]; } else if (cnt == 3) { ResultMotion[0] = ResultMotionTMP[cnt]; } else if (cnt == 4) { ResultMotion[2] = ResultMotionTMP[cnt]; } else if (cnt == 5) { ResultMotion[3] = ResultMotionTMP[cnt]; } else if (cnt == 6) { ResultMotion[4] = ResultMotionTMP[cnt]; } else if (cnt == 7 || cnt == 8 || cnt == 9) { ResultMotion[0] = ResultMotionTMP[cnt]; } else { ResultMotion[cnt] = ResultMotionTMP[cnt]; } } ResultIDX = (int)((double)prresult.GetValue(0, RESULT_IDX_NO)); if (ResultIDX == 1) { ResultIDX = 1; } else if (ResultIDX == 2) { ResultIDX = 1; } else if (ResultIDX == 3) { ResultIDX = 2; } else if (ResultIDX == 4) { ResultIDX = 1; } else if (ResultIDX == 5) { ResultIDX = 3; } else if (ResultIDX == 6) { ResultIDX = 4; } else if (ResultIDX == 7) { ResultIDX = 5; } else if (ResultIDX >= 8) { ResultIDX = 1; } }