diff --git a/ECTrainer2/Stimulus.cpp b/ECTrainer2/Stimulus.cpp index 7a0d724..f64df05 100644 --- a/ECTrainer2/Stimulus.cpp +++ b/ECTrainer2/Stimulus.cpp @@ -292,9 +292,12 @@ if (_SoftCalibNo + 1 < (int)_SoftCalibInfoSet.size()) { SetSoftCalib(_SoftCalibNo + 1); - //Ect()->PWorker()->PostMsg((int)ECTMSG::EXP_NEXT); } else { - Ect()->PWorker()->PostMsg((int)ECTMSG::SOFTCALIB_OK); + _SoftCalibNo = -1; + if (Ect()->PWorker()->IsCalibCheckOK()) + Ect()->PWorker()->PostMsg((int)ECTMSG::SOFTCALIB_OK); + else + Ect()->PWorker()->PostMsg((int)ECTMSG::CALIB_FAILED); } return true; } diff --git a/ECTrainer2/Worker.cpp b/ECTrainer2/Worker.cpp index 4f220d5..2b52d8e 100644 --- a/ECTrainer2/Worker.cpp +++ b/ECTrainer2/Worker.cpp @@ -100,6 +100,12 @@ _ShiftLog.push_back(shift ); //nkc::wut::DebugPrintf(_T("Shift %.1f,%.1f\n"), shift.x, shift.y); } + } if (Ect()->PStimulus()->IsCalibCheck()) { + // キャリブレーションチェック + if (Ect()->PStimulus()->GetStimTime() >= SHIFT_LOG_STARTTIME && elems.size() > 0) { + auto shift = gazeI - cv::Point2f(elems[0].x, elems[0].y); + _ErrorLog.push_back(shift); + } } else { if (hit >= 0) { _ContactTime += frameInterval; @@ -157,6 +163,20 @@ return true; } +// キャリブレーションチェックの判定 +bool Worker::IsCalibCheckOK() { + if (_ErrorLog.size() == 0) return false; + cv::Point2f sum(0, 0), error; + for (auto& x : _ErrorLog) sum += x; + error.x = sum.x / _ErrorLog.size(); + error.y = sum.y / _ErrorLog.size(); + auto totalError = sqrtf(error.x * error.x + error.y * error.y); + nkc::wut::DebugPrintf(_T("Error x=%.1f, y=%.1f, total=%.1f (Tole=%.1f)\n"), + error.x, error.y, totalError, CALIB_ERROR_TOLERANCE); + _ErrorLog.clear(); + return totalError <= CALIB_ERROR_TOLERANCE; +} + // 判定パラメータをリセット void Worker::ResetParams() { _pContactTimer->Reset(); diff --git a/ECTrainer2/Worker.h b/ECTrainer2/Worker.h index a23124a..cf01fc0 100644 --- a/ECTrainer2/Worker.h +++ b/ECTrainer2/Worker.h @@ -28,6 +28,7 @@ const int FEEDBACK_TIME = 3000; // フィードバックの時間(1レベル)msec const int SHIFT_LOG_STARTTIME = 2000; // 注視点ずれ記録開始時間 const float TRAINING_LEVEL_EFFECT = 0.1F; // トレーニングレベルによる目標領域縮小量 + const float CALIB_ERROR_TOLERANCE = 150.F; // キャリブレーション誤差の許容値 APP_STATUS _AppStatus; // アプリケーション状態 nkc::HPTimer* _pExpTimer; // 実験経過タイマー nkc::HPTimer* _pContactTimer; // 目標コンタクトタイマー @@ -41,6 +42,7 @@ bool _EnableTrainLevel; // トレーニングレベル機能の有効フラグ int _TrainingLevel; // トレーニングレベル(高いほど難度UP) std::vector _ShiftLog; // 注視点のずれ記録 + std::vector _ErrorLog; // 注視点チェックのずれ記録 cv::Point2f _Shift; // 注視点のずれ int _StartStage; // 開始ステージ Logger _DataLog; // データログ @@ -91,4 +93,6 @@ bool* EnableTrainLevelPtr() { return &_EnableTrainLevel; } // ずれ記録のクリア void ClearShift() { _ShiftLog.clear(); } + // キャリブレーションチェックの判定 + bool IsCalibCheckOK(); }; diff --git a/config/softcalib.txt b/config/softcalib.txt index 0c9a6f5..2b923c0 100644 --- a/config/softcalib.txt +++ b/config/softcalib.txt @@ -3,4 +3,4 @@ 3,../images/SoftCalib/SoftCalib2.png,3,../images/SoftCalib/SoftCalib2.csv,_,_ 3,../images/SoftCalib/SoftCalib3.png,3,../images/SoftCalib/SoftCalib3.csv,_,_ 3,../images/SoftCalib/SoftCalib4.png,3,../images/SoftCalib/SoftCalib4.csv,_,_ -4,../images/SoftCalib/SoftCalib1.png,5,../images/SoftCalib/SoftCalib1.csv,_,_ +4,../images/SoftCalib/SoftCalibCheck.png,5,../images/SoftCalib/SoftCalibCheck.csv,_,_