diff --git a/ECTrainer2/DShowMovie.cpp b/ECTrainer2/DShowMovie.cpp index cb19002..abf7e34 100644 --- a/ECTrainer2/DShowMovie.cpp +++ b/ECTrainer2/DShowMovie.cpp @@ -1,4 +1,5 @@ #include "DShowMovie.h" +#include "myWinUtils.h" #pragma comment(lib, "dxguid.lib") #pragma comment(lib, "d3d9.lib") @@ -15,9 +16,9 @@ , _pCGB2(NULL) , _pMediaCont(NULL) , _pMediaEvent(NULL) - , _hWnd(NULL) + , _pMediaPosition(NULL) + , _hWnd(NULL) { - } // �f�X�g���N�^ @@ -36,15 +37,15 @@ // DirectX�̏����� bool DShowMovie::InitDx(HINSTANCE hInstance, RECT dispRect) { - _DispRect = dispRect; + // �E�C���h�E�N���X�̐ݒ� TCHAR gName[100] = _T("Video Window"); WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInstance, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1), NULL, (TCHAR*)gName, NULL }; if (!RegisterClassEx(&wcex)) return 0; // �t���X�N���[���p�Ƀ|�b�v�A�b�v�E�B���h�E���쐬 - if (!(_hWnd = CreateWindow(gName, gName, WS_POPUPWINDOW, _DispRect.left, _DispRect.top, - _DispRect.right - _DispRect.left, _DispRect.bottom - _DispRect.top, + if (!(_hWnd = CreateWindow(gName, gName, WS_POPUPWINDOW, dispRect.left, dispRect.top, + dispRect.right - dispRect.left, dispRect.bottom - dispRect.top, NULL, NULL, hInstance, NULL))) return false; @@ -52,8 +53,8 @@ if (!(_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) return false; // �t���X�N���[���p�ɏ������p�����[�^��ݒ� - D3DPRESENT_PARAMETERS d3dpp = { (UINT)(_DispRect.right - _DispRect.left), - (UINT)(_DispRect.bottom - _DispRect.top), D3DFMT_A8R8G8B8, 0, D3DMULTISAMPLE_NONE, 0, + D3DPRESENT_PARAMETERS d3dpp = { (UINT)(dispRect.right - dispRect.left), + (UINT)(dispRect.bottom - dispRect.top), D3DFMT_A8R8G8B8, 0, D3DMULTISAMPLE_NONE, 0, D3DSWAPEFFECT_DISCARD, _hWnd, FALSE, 0, D3DFMT_UNKNOWN, D3DPRESENT_RATE_DEFAULT, 0 }; if (FAILED(_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, _hWnd, @@ -61,9 +62,9 @@ CHECK(_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, _hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &_pD3DDev)); - printf("Software DirectX\n"); + mwut::DebugPrintf(_T("Software DirectX\n")); } else { - printf("Hardware DirectX\n"); + mwut::DebugPrintf(_T("Hardware DirectX\n")); } // COM�̏����� @@ -74,7 +75,7 @@ // ����Đ� bool DShowMovie::PlayMovie(std::wstring movie) { - //if (_PlayIndex < 0 || _PlayIndex >= _MovieFiles.size()) return false; + if (this->IsPlaying()) this->StopMovie(); // �t�B���^�O���t�}�l�[�W���̍쐬 CHECK(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&_pGB)); @@ -132,6 +133,7 @@ // �����~ bool DShowMovie::StopMovie() { if (!IsPlaying()) return false; + _pMediaCont->Stop(); SAFE_RELEASE(_pMediaPosition); SAFE_RELEASE(_pMediaEvent); @@ -147,8 +149,34 @@ // �Đ���Ԃ̊m�F bool DShowMovie::IsPlaying() { - if (!_pMediaCont) return false; + return (_pGB != NULL); +} + +// �Đ���Ԃ̎擾 +FILTER_STATE DShowMovie::GetMovieState() { + if (!_pMediaCont) return State_Stopped; FILTER_STATE fs; _pMediaCont->GetState(100, (OAFilterState*)&fs); - return (fs == State_Running); + return fs; +} + +// �Đ����Ō�܂œ��B������ +bool DShowMovie::IsReachToEnd() { + if (!_pMediaEvent) return false; + long eventCode; + return (_pMediaEvent->WaitForCompletion(0, &eventCode) == S_OK); +} + +// �Đ��ʒu�̎擾 +double DShowMovie::GetPlayPos() { + if (!_pMediaPosition) return -1.0; + REFTIME tm; + _pMediaPosition->get_CurrentPosition(&tm); + return tm; +} + +// �E�B���h�E�v���V�[�W�� +LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { + if (msg == WM_DESTROY) { PostQuitMessage(0); return 0; } + return DefWindowProc(hWnd, msg, wParam, lParam); } diff --git a/ECTrainer2/DShowMovie.h b/ECTrainer2/DShowMovie.h index 22b721f..0ffc5f1 100644 --- a/ECTrainer2/DShowMovie.h +++ b/ECTrainer2/DShowMovie.h @@ -12,7 +12,6 @@ #define CHECK(x) { if(((HRESULT)(x)) < 0) return false; } class DShowMovie { - RECT _DispRect; // DirectShow����\���ʒu HWND _hWnd; LPDIRECT3D9 _pD3D; LPDIRECT3DDEVICE9 _pD3DDev; @@ -31,4 +30,7 @@ bool PlayMovie(std::wstring movie); bool StopMovie(); bool IsPlaying(); + bool IsReachToEnd(); + double GetPlayPos(); + FILTER_STATE GetMovieState(); }; diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index 9a62f55..3964ee3 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -10,17 +10,11 @@ #include "Marker.h" #include "myWinUtils.h" #include "myOpenCVutil.h" -#include #pragma comment(lib,"winmm.lib") -#include #define CVUI_IMPLEMENTATION #include "cvui.h" -//#ifdef _DEBUG -//#include -//#endif - // �R���X�g���N�^ ECTrainerGUI::ECTrainerGUI(ECTrainer* pEct) : BaseProcess(pEct) , _SceneBufferHeight(0) @@ -54,7 +48,6 @@ cv::setWindowProperty(WIN_DISP, cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN); _DispBuffer.create(cv::Size(displays[0].right - displays[0].left, displays[0].bottom - displays[0].top), CV_8UC3); - //_DispRect = _Displays[0]; } else { // �V���O�����j�^�̏ꍇ @@ -62,10 +55,8 @@ cv::moveWindow(WIN_DISP, displays[0].left, displays[0].top); _DispBuffer.create(cv::Size(640, 480), CV_8UC3); cv::moveWindow(WIN_MAIN, displays[0].left + 100, displays[0].top + 100); - //_DispRect = _Displays[0]; } _blank = cv::Mat(DISP_SIZE, CV_8UC3, cv::Scalar(0)); - //blank.copyTo(_SceneBuffer); _blank.copyTo(_DispImage); _Logo = cv::imread("../images/ECTLogo2_1480l.png"); @@ -74,15 +65,10 @@ // �񃁃b�Z�[�W���̏��� bool ECTrainerGUI::Routine() { + // ���C���E�C���h�E�t���[���N���A _MainFrame = cv::Scalar(49, 52, 49); - //cv::Point2f imagePos = cv::Point2f(-1.F, -1.F); - //if (cvui::iarea(DISP_IMAGE_POS.x, DISP_IMAGE_POS.y, IMAGE_WIDTH, _DispImageHeight) == cvui::OVER) { - // imagePos.x = (float)(mp.x - DISP_IMAGE_POS.x) / IMAGE_WIDTH; - // imagePos.y = (float)(mp.y - DISP_IMAGE_POS.y) / _DispImageHeight; - //} - // �\���o�b�t�@���� cv::Mat sceneBuf = _pEct->PImageProc()->GetImage(); if (sceneBuf.empty()) sceneBuf = _blank; @@ -100,38 +86,28 @@ switch (_pEct->PWorker()->GetAppStatus()) { case APP_STATUS::IDLE: if (cvui::button(140, 30, "CALIBRATION")) { - _pEct->PWorker()->Tell(ECTMSG::CALIB_START); + ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::CALIB_START); } if (cvui::button(140, 30, "START")) { - //fStimulus = true; - //fKeepContact = false; - //if (!PlayMovie()) _pEct->Stop(); ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::STIM_START); } break; case APP_STATUS::STIM: if (cvui::button(140, 30, "STOP")) { if (!_dsm->StopMovie()) _pEct->StopApp(); - //fKeepContact = false; ((BaseProcess*)_pEct->PWorker())->Tell(ECTMSG::STIM_STOP); - //_pEct->PWorker()->StopStim(); - //fStimulus = false; } //cvui::trackbar(140, &targetSize, (float)0, (float)3.0); //cvui::checkbox("Show Eyes", &fShowEyesPos); //cvui::text(fContact ? "Eyes Contact!" : "No contact"); break; } - //cvui::printf("Mouse W %d, %d", mp.x, mp.y); - //cvui::printf("Mouse L %.2f, %.2f", imagePos.x, imagePos.y); cvui::printf("View Gaze %.0f, %.0f", _pEct->PEyeTrack()->GetGazeV().x, _pEct->PEyeTrack()->GetGazeV().y); //cvui::printf("Img Gaze %.2f, %.2f", _pEct->GetGazeI().x, _pEct->GetGazeI().y); cvui::text(_pEct->PMarker()->IsDetected() ? "AR Markers OK" : "AR Markers NG"); cvui::printf("Battery %d %%", _pEct->PTobiiREST()->GetBatteryLevel()); if (_dsm->IsPlaying()) { - //REFTIME tm; - //_pMediaPosition->get_CurrentPosition(&tm); - //cvui::printf("Movie pos: %.1f", tm); + cvui::printf("Movie pos: %.1f", _dsm->GetPlayPos()); } bool snapshot = cvui::button(140, 30, "SNAPSHOT"); if (cvui::button(140, 30, "QUIT")) _pEct->StopApp(); @@ -142,14 +118,15 @@ cvui::printf("HeartBeat no device"); } cvui::endColumn(); + + // �摜�\�� cvui::text(_MainFrame, SCENE_BUFFER_POS.x, 100, "SCENE CAMERA"); - //cv::Mat sceneDisp; - //cv::resize(sceneBuf, sceneDisp, DISP_SIZE); cv::Mat resized = KeepAspectResize(sceneBuf, DISP_SIZE.width); cvui::image(_MainFrame, SCENE_BUFFER_POS.x, SCENE_BUFFER_POS.y, resized); + cvui::text(_MainFrame, DISP_IMAGE_POS.x, 100, "STIMULUS IMAGE"); - cv::Mat disp; - cv::resize(CurDisplay, disp, cv::Size(IMAGE_WIDTH, _DispImageHeight)); + cv::Mat disp = KeepAspectResize(CurDisplay, DISP_SIZE.width); + //cv::resize(CurDisplay, disp, cv::Size(IMAGE_WIDTH, _DispImageHeight)); cvui::image(_MainFrame, DISP_IMAGE_POS.x, DISP_IMAGE_POS.y, disp); // �h������ @@ -166,48 +143,23 @@ } } - // �Đ��I���̃`�F�b�N - //if (_pMediaEvent) { - // long eventCode; - // _pMediaEvent->WaitForCompletion(1, &eventCode);//����̏�Ԃ�⑫ - // if (eventCode != 0) { - // if (!_dsm->StopMovie()) _pEct->StopApp(); - // //_PlayIndex = (_PlayIndex + 1) % _MovieFiles.size(); - // //if (!PlayMovie()) _pEct->Stop(); - // } - //} - // ��ʕ\�� cvui::update(); cv::imshow(WIN_MAIN, _MainFrame); - cv::imshow(WIN_DISP, _DispBuffer); - if (snapshot) cv::imwrite("d:/usr/dl/snapshot.jpg", _MainFrame); + if (!_dsm->IsPlaying()) cv::imshow(WIN_DISP, _DispBuffer); + if (snapshot) cv::imwrite(SNAPSHOT_FILE, _MainFrame); + + // �L�[���� int key = cv::waitKey(1); switch (key) { - case '1': - PlaySound(_T("../voices/Good_S.wav"), NULL, SND_FILENAME | SND_ASYNC); - break; - case '2': - PlaySound(_T("../voices/Nice_S.wav"), NULL, SND_FILENAME | SND_ASYNC); - break; - case '3': - PlaySound(_T("../voices/Great_S.wav"), NULL, SND_FILENAME | SND_ASYNC); - break; - case '4': - PlaySound(_T("../voices/Excellent_S.wav"), NULL, SND_FILENAME | SND_ASYNC); - break; - case '5': - PlaySound(_T("../voices/Good_L.wav"), NULL, SND_FILENAME | SND_ASYNC); - break; - case '6': - PlaySound(_T("../voices/Nice_L.wav"), NULL, SND_FILENAME | SND_ASYNC); - break; - case '7': - PlaySound(_T("../voices/Great_L.wav"), NULL, SND_FILENAME | SND_ASYNC); - break; - case '8': - PlaySound(_T("../voices/Excellent_L.wav"), NULL, SND_FILENAME | SND_ASYNC); - break; + case '1': PlaySound(_T("../voices/Good_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + case '2': PlaySound(_T("../voices/Nice_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + case '3': PlaySound(_T("../voices/Great_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + case '4': PlaySound(_T("../voices/Excellent_S.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + case '5': PlaySound(_T("../voices/Good_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + case '6': PlaySound(_T("../voices/Nice_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + case '7': PlaySound(_T("../voices/Great_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; + case '8': PlaySound(_T("../voices/Excellent_L.wav"), NULL, SND_FILENAME | SND_ASYNC); break; } if (key == KEY_ESC) _pEct->StopApp(); @@ -230,13 +182,6 @@ return true; } -// ����摜�o�b�t�@�ɉ摜��ݒ� -//void ECTrainerGUI::SetSceneBuffer(cv::Mat& img) { -// _SceneBufferScale = (float)IMAGE_WIDTH / img.cols; -// _SceneBufferHeight = (int)(img.rows * _SceneBufferScale); -// cv::resize(img, _SceneBuffer, cv::Size(IMAGE_WIDTH, _SceneBufferHeight)); -//} - // �h���摜�o�b�t�@�ɉ摜��ݒ� void ECTrainerGUI::SetDispBuffer(cv::Mat& img) { img.copyTo(_DispImage); @@ -259,12 +204,3 @@ cv::resize(img, roi, roi.size()); buf.copyTo(_DispBuffer); } - -// �E�B���h�E�v���V�[�W�� -LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if (msg == WM_DESTROY) { PostQuitMessage(0); return 0; } - if (msg == WM_CHAR) { - printf("key=%d\n", (int)wParam); - } - return DefWindowProc(hWnd, msg, wParam, lParam); -} diff --git a/ECTrainer2/ECTrainerGUI.h b/ECTrainer2/ECTrainerGUI.h index e13bc95..0c6cb09 100644 --- a/ECTrainer2/ECTrainerGUI.h +++ b/ECTrainer2/ECTrainerGUI.h @@ -12,6 +12,7 @@ private: const cv::String WIN_DISP = "ECTrainer Display"; const cv::String WIN_MAIN = "Eye Contact Trainer"; + const cv::String SNAPSHOT_FILE = "snapshot.jpg"; const cv::Size MAIN_FRAME_SIZE = cv::Size(1480, 620); const int IMAGE_WIDTH = 640; const cv::Size DISP_SIZE = cv::Size(640, 480);