diff --git a/ECTrainer2/ECTrainer.cpp b/ECTrainer2/ECTrainer.cpp index 025a60a..cc7b7a2 100644 --- a/ECTrainer2/ECTrainer.cpp +++ b/ECTrainer2/ECTrainer.cpp @@ -29,6 +29,7 @@ _pStimulus = new Stimulus(this, _pMarker); _pEyeTrack = new EyeTrack(this, _pMarker); _pTobiiREST = new TobiiREST(this); + _MovieToShow = _T(""); } // �f�X�g���N�^ @@ -94,12 +95,17 @@ } // �J�n -void ECTrainer::Start() { +void ECTrainer::StartStim() { _pStimulus->SetPage(Stimulus::PAGES::START); } +// �J�n +void ECTrainer::StopStim() { + _pStimulus->SetPage(Stimulus::PAGES::STOP); +} + // ���� -void ECTrainer::Next() { +void ECTrainer::NextStim() { _pStimulus->SetPage(Stimulus::PAGES::NEXT); } diff --git a/ECTrainer2/ECTrainer.h b/ECTrainer2/ECTrainer.h index e9d9d94..d0c0129 100644 --- a/ECTrainer2/ECTrainer.h +++ b/ECTrainer2/ECTrainer.h @@ -2,6 +2,7 @@ #include #include +#include #include "myOpenCV.h" #define ADDR "192.168.71.50" @@ -29,6 +30,7 @@ bool _HomographyOK; // �ϊ��s��̊l���L�� int _CalibResult; // �L�����u���[�V�������� 0:�����{ 1:���� -1:���s cv::Size _SceneSize; // ���E�J�����̉摜�T�C�Y + std::wstring _MovieToShow; // �Đ����铮��t�@�C�� // �X���b�h�J�n�_ static DWORD WINAPI ThreadEntry(LPVOID lpParameter); @@ -40,8 +42,9 @@ bool Process(); void CalibStart(); int CheckCalibResult(); - void Start(); - void Next(); + void StartStim(); + void StopStim(); + void NextStim(); void SetSceneBuffer(cv::Mat& img); void SetDispBuffer(cv::Mat& img); void SetGazeV(cv::Point gazeV); @@ -59,4 +62,27 @@ void SetSceneSize(cv::Size s) { _SceneSize = s; } cv::Size GetSceneSize() { return _SceneSize; } void SetCalibResult(int result) { _CalibResult = result; } + void SetMovieToShow(std::wstring file) { _MovieToShow = file; } + std::wstring GetMovieToShow() { return _MovieToShow; } + + static std::wstring Multi2Wide(std::string const& src) + { + //std::size_t converted{}; + //std::vector dest(src.size(), L'\0'); + //if (::_mbstowcs_s_l(&converted, dest.data(), dest.size(), src.data(), _TRUNCATE, ::_create_locale(LC_ALL, "jpn")) != 0) { + // throw std::system_error{ errno, std::system_category() }; + //} + //dest.resize(std::char_traits::length(dest.data())); + //dest.shrink_to_fit(); + //return std::wstring(dest.begin(), dest.end()); + + auto const dest_size = ::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, nullptr, 0U); + std::vector dest(dest_size, L'\0'); + if (::MultiByteToWideChar(CP_ACP, 0U, src.data(), -1, dest.data(), dest.size()) == 0) { + throw std::system_error{ static_cast(::GetLastError()), std::system_category() }; + } + dest.resize(std::char_traits::length(dest.data())); + dest.shrink_to_fit(); + return std::wstring(dest.begin(), dest.end()); + } }; diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index 183f1e6..3ad1eab 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -139,7 +139,7 @@ bool fShowEyesPos = true; bool fStimulus = false; bool fContact = false; - bool fCaliblated = false; + bool fCaliblated = true; //bool fKeepContact = false; int contactLevel = 0; float targetSize = 2.0; @@ -241,15 +241,16 @@ cvui::beginColumn(_MainFrame, 10, 100, 140, -1, 10); if (fStimulus) { if (cvui::button(140, 30, "STOP")) { - if (!StopMovie()) _pEct->Stop(); + //if (!StopMovie()) _pEct->Stop(); //fKeepContact = false; + _pEct->StopStim(); fStimulus = false; } if (cvui::button(140, 30, "NEXT")) { //fKeepContact = false; - if (!StopMovie()) _pEct->Stop(); - _PlayIndex = (_PlayIndex + 1) % _MovieFiles.size(); - if (!PlayMovie()) _pEct->Stop(); + //if (!StopMovie()) _pEct->Stop(); + //_PlayIndex = (_PlayIndex + 1) % _MovieFiles.size(); + //if (!PlayMovie()) _pEct->Stop(); //_pEct->Next(); } cvui::trackbar(140, &targetSize, (float)0, (float)3.0); @@ -264,8 +265,8 @@ if (cvui::button(140, 30, "START")) { fStimulus = true; //fKeepContact = false; - if (!PlayMovie()) _pEct->Stop(); - //_pEct->Start(); + //if (!PlayMovie()) _pEct->Stop(); + _pEct->StartStim(); } } } @@ -283,13 +284,25 @@ cvui::text(_MainFrame, DISP_IMAGE_POS.x, 100, "STIMULUS IMAGE"); cvui::image(_MainFrame, DISP_IMAGE_POS.x, DISP_IMAGE_POS.y, _DispImage); + // �h������ + std::wstring movieToShow = _pEct->GetMovieToShow(); + if (movieToShow.size() > 0) { + _pEct->SetMovieToShow(L""); + if (movieToShow == L"STOP") { + if (!StopMovie()) _pEct->Stop(); + } else { + if (!PlayMovie(movieToShow)) _pEct->Stop(); + } + } + + // �Đ��I���̃`�F�b�N if (_pMediaEvent) { long eventCode; _pMediaEvent->WaitForCompletion(1, &eventCode);//����̏�Ԃ�⑫ if (eventCode != 0) { if (!StopMovie()) _pEct->Stop(); - _PlayIndex = (_PlayIndex + 1) % _MovieFiles.size(); - if (!PlayMovie()) _pEct->Stop(); + //_PlayIndex = (_PlayIndex + 1) % _MovieFiles.size(); + //if (!PlayMovie()) _pEct->Stop(); } } @@ -332,8 +345,8 @@ } // ����Đ� -bool ECTrainerGUI::PlayMovie() { - if (_PlayIndex < 0 || _PlayIndex >= _MovieFiles.size()) return false; +bool ECTrainerGUI::PlayMovie(std::wstring movie) { + //if (_PlayIndex < 0 || _PlayIndex >= _MovieFiles.size()) return false; // �t�B���^�O���t�}�l�[�W���̍쐬 CHECK(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&_pGB)); @@ -354,7 +367,7 @@ CHECK(pVMRWndCont->SetVideoClippingWindow(_hWnd)); // �\�[�X�t�B���^�̐����Ɠo�^ - CHECK(_pGB->AddSourceFilter(_MovieFiles[_PlayIndex].c_str(), _MovieFiles[_PlayIndex].c_str(), &_pSource)); + CHECK(_pGB->AddSourceFilter(movie.c_str(), movie.c_str(), &_pSource)); // CaptureGraphBuilder2�C���^�[�t�F�C�X�̎擾 CHECK(CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&_pCGB2)); diff --git a/ECTrainer2/ECTrainerGUI.h b/ECTrainer2/ECTrainerGUI.h index 76e1a53..6b046f1 100644 --- a/ECTrainer2/ECTrainerGUI.h +++ b/ECTrainer2/ECTrainerGUI.h @@ -48,7 +48,7 @@ IMediaEvent* _pMediaEvent; bool InitDx(HINSTANCE hInstance); - bool PlayMovie(); + bool PlayMovie(std::wstring movie); bool StopMovie(); void GetDisplayInfo(); static BOOL CALLBACK MonitorEnumProc(HMONITOR hMon, HDC hdcMon, LPRECT lpMon, LPARAM dwDate); diff --git a/ECTrainer2/StimData.txt b/ECTrainer2/StimData.txt index f7dde49..5f536df 100644 --- a/ECTrainer2/StimData.txt +++ b/ECTrainer2/StimData.txt @@ -1,4 +1,8 @@ -1 ../images/LookNose.jpg 5 _ 0 +1 ../images/CalibCheck1.png 4 _ 0 +1 ../images/CalibCheck2.png 4 _ 0 +1 ../images/CalibCheck3.png 4 _ 0 +1 ../images/CalibCheck4.png 4 _ 0 +1 ../images/LookNose.png 5 _ 0 2 ../movies/test1_0525.avi 30 ../movies/test1.csv 2 -1 ../images/LookEyes.jpg 5 _ 0 +1 ../images/LookEyes.png 5 _ 0 2 ../movies/test0421.avi 30 ../movies/test0421.csv 1 diff --git a/ECTrainer2/Stimulus.cpp b/ECTrainer2/Stimulus.cpp index 0a8f19a..8c71060 100644 --- a/ECTrainer2/Stimulus.cpp +++ b/ECTrainer2/Stimulus.cpp @@ -11,7 +11,7 @@ Stimulus::Stimulus(ECTrainer* pEct, Marker* pMarker) :BaseProcess(pEct) , _pMarker(pMarker) - , _StimNo(0) + , _StimNo(-1) { } @@ -38,37 +38,82 @@ // ���[�v bool Stimulus::MainLoop() { - while (_pEct->IsRunning()) { - _pEct->SetDispBuffer(_DispBuffer); + while (_pEct->IsRunning()) { + if (_StimNo >= 0) { + DWORD current = GetTickCount(); + if ((float)(current - _StartTime) / 1000.F > _StimInfoSet[_StimNo].dulation) { + if (_StimInfoSet[_StimNo].type == 2) { + SetPage(PAGES::WHITE); + _pEct->SetMovieToShow(L"STOP"); + } + if (++_StimNo < _StimInfoSet.size()) { + SetStimulus(); + } else { + SetPage(PAGES::STOP); + } + } + } Sleep(30); } return true; } -// �h���摜�\�� +// �h���� +bool Stimulus::SetStimulus() { + if (_StimNo < 0 || _StimNo >= _StimInfoSet.size()) return false; + + _StartTime = GetTickCount(); + if (_StimInfoSet[_StimNo].type == 1) { + _DispBuffer = cv::imread(_StimInfoSet[_StimNo].filename); + if (_DispBuffer.empty()) { + MessageBox(NULL, _T("�h���摜���J���܂���"), _T(""), MB_ICONERROR); + return false; + } + _pEct->SetDispBuffer(_DispBuffer); + } else { + std::wstring mov = ECTrainer::Multi2Wide(_StimInfoSet[_StimNo].filename); + _pEct->SetMovieToShow(mov); + } + return true; +} + +// �Œ�y�[�W�\�� void Stimulus::SetPage(PAGES st) { switch (st) { case PAGES::OPENING: _DispBuffer = cv::imread(OPENING_FILE); + _pEct->SetDispBuffer(_DispBuffer); break; case PAGES::CALIB: _DispBuffer = cv::imread(CALIB_FILE); + _pEct->SetDispBuffer(_DispBuffer); break; case PAGES::CALIB_COMPLETE: _DispBuffer = cv::imread(CALIB_COMPLETE_FILE); + _pEct->SetDispBuffer(_DispBuffer); break; case PAGES::CALIB_FAILED: _DispBuffer = cv::imread(CALIB_FAILED_FILE); + _pEct->SetDispBuffer(_DispBuffer); + break; + case PAGES::WHITE: + _DispBuffer = cv::imread(WHITE_FILE); + _pEct->SetDispBuffer(_DispBuffer); break; case PAGES::START: _StimNo = 0; - //StimWithMarker(); + SetStimulus(); + break; + case PAGES::STOP: + _StimNo = -1; + _DispBuffer = cv::imread(OPENING_FILE); + _pEct->SetDispBuffer(_DispBuffer); break; case PAGES::NEXT: - _StimNo = (_StimNo + 1) % _StimInfoSet.size(); - //StimWithMarker(); + if (++_StimNo >= _StimInfoSet.size()) _StimNo = -1; + SetStimulus(); break; } } @@ -80,3 +125,4 @@ // _pMarker->DrawMarker(img); // img.copyTo(_DispBuffer); //} + diff --git a/ECTrainer2/Stimulus.h b/ECTrainer2/Stimulus.h index a5fe216..ffd5be7 100644 --- a/ECTrainer2/Stimulus.h +++ b/ECTrainer2/Stimulus.h @@ -2,6 +2,8 @@ #include "myOpenCV.h" #include "BaseProcess.h" +#include +#include #include #include @@ -23,20 +25,23 @@ class Stimulus : public BaseProcess { public: - enum PAGES {OPENING, CALIB, CALIB_COMPLETE, CALIB_FAILED, START, NEXT}; + enum PAGES {OPENING, CALIB, CALIB_COMPLETE, CALIB_FAILED, START, STOP, NEXT, BACK, WHITE}; private: const cv::String OPENING_FILE = "../images/ECT_toppage.png"; const cv::String CALIB_FILE = "../images/calib.png"; const cv::String CALIB_COMPLETE_FILE = "../images/CalibComplete.png"; const cv::String CALIB_FAILED_FILE = "../images/CalibFailed.png"; + const cv::String WHITE_FILE = "../images/white.png"; const std::string DATA_FILE = "StimData.txt"; Marker* _pMarker; cv::Mat _DispBuffer; std::vector _StimInfoSet; //std::vector _StimImages; - int _StimNo; + int _StimNo; // �h���f�[�^�ԍ��@-1:��~ + DWORD _StartTime; // �h���񎦊J�n���� //void StimWithMarker(); + bool SetStimulus(); public: Stimulus(ECTrainer* pEct, Marker* pMarker); bool Init(); diff --git a/images/CalibCheck1.png b/images/CalibCheck1.png new file mode 100644 index 0000000..5d0d005 --- /dev/null +++ b/images/CalibCheck1.png Binary files differ diff --git a/images/CalibCheck2.png b/images/CalibCheck2.png new file mode 100644 index 0000000..831b557 --- /dev/null +++ b/images/CalibCheck2.png Binary files differ diff --git a/images/CalibCheck3.png b/images/CalibCheck3.png new file mode 100644 index 0000000..e815873 --- /dev/null +++ b/images/CalibCheck3.png Binary files differ diff --git a/images/CalibCheck4.png b/images/CalibCheck4.png new file mode 100644 index 0000000..8a9af92 --- /dev/null +++ b/images/CalibCheck4.png Binary files differ diff --git a/images/white.png b/images/white.png new file mode 100644 index 0000000..f9c0393 --- /dev/null +++ b/images/white.png Binary files differ