diff --git a/ECTrainer2/ECTrainer.cpp b/ECTrainer2/ECTrainer.cpp index 185a974..77d3790 100644 --- a/ECTrainer2/ECTrainer.cpp +++ b/ECTrainer2/ECTrainer.cpp @@ -1,4 +1,5 @@ + #include "ECTrainer.h" #include "ECTrainerGUI.h" #include "SceneCamera.h" @@ -20,14 +21,26 @@ } // ������ -bool ECTrainer::Init() { +bool ECTrainer::Process() { if (!_pGui->Init()) return false; + if (!_pSceneCam->Init()) return false; + + DWORD dwThreadId; + HANDLE hThSceneCam = CreateThread(NULL, 0, SceneCamThreadEntry, this, 0, &dwThreadId); + + _pGui->MainLoop(); + + if (WaitForSingleObject(hThSceneCam, 1000) == WAIT_OBJECT_0) { +#ifdef _DEBUG + std::cout << "Scene Cam thread end." << std::endl; +#endif + } + CloseHandle(hThSceneCam); + return true; } -// ���C�����[�v -bool ECTrainer::Loop() { - _pGui->MainLoop(); - - return true; +DWORD WINAPI ECTrainer::SceneCamThreadEntry(LPVOID lpParameter) { + ((ECTrainer*)lpParameter)->_pSceneCam->MainLoop(); + return 0; } diff --git a/ECTrainer2/ECTrainer.h b/ECTrainer2/ECTrainer.h index be7c13f..523e748 100644 --- a/ECTrainer2/ECTrainer.h +++ b/ECTrainer2/ECTrainer.h @@ -1,5 +1,7 @@ #pragma once +#include + class ECTrainerGUI; class SceneCamera; @@ -10,11 +12,13 @@ SceneCamera* _pSceneCam; bool _Running; + static DWORD SceneCamThreadEntry(LPVOID lpParameter); + public: ECTrainer(); ~ECTrainer(); - bool Init(); - bool Loop(); + bool Process(); bool IsRunning() { return _Running; } void Stop() { _Running = false; } + ECTrainerGUI* GetGui() { return _pGui; } }; diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp index ba40979..4d79311 100644 --- a/ECTrainer2/ECTrainerGUI.cpp +++ b/ECTrainer2/ECTrainerGUI.cpp @@ -39,6 +39,8 @@ } _Logo = cv::imread("../images/ECTrainerLogo640x91.png"); _DispBuffer = cv::imread("../images/calib.png"); + _SceneBuffer.create(SCENE_BUFFER_SIZE, CV_8UC3); + _SceneBuffer = CV_RGB(0, 0, 0); return true; } @@ -74,7 +76,7 @@ cvui::beginColumn(); cvui::text("View camera"); cvui::space(); - //cvui::image(scene); + cvui::image(_SceneBuffer); cvui::endColumn(); cvui::endRow(); @@ -89,6 +91,10 @@ return true; } +void ECTrainerGUI::SetSceneBuffer(cv::Mat& img) { + cv::resize(img, _SceneBuffer, SCENE_BUFFER_SIZE); +} + // �S�f�B�X�v���C�̏����擾 void ECTrainerGUI::GetDisplayInfo() { EnumDisplayMonitors(NULL, NULL, diff --git a/ECTrainer2/ECTrainerGUI.h b/ECTrainer2/ECTrainerGUI.h index 6b80cbd..372c0df 100644 --- a/ECTrainer2/ECTrainerGUI.h +++ b/ECTrainer2/ECTrainerGUI.h @@ -12,13 +12,15 @@ private: const cv::String WIN_DISP = "ECTrainer Display"; const cv::String WIN_MAIN = "Eye Contact Trainer"; + const cv::Size SCENE_BUFFER_SIZE = cv::Size(320, 240); const int KEY_ESC = 27; ECTrainer* _pEct; std::vector _Displays; cv::Mat _MainFrame; // ���C���E�C���h�E�t���[�� - cv::Mat _DispFrame; // �\���E�C���h�E�t���[�� - cv::Mat _DispBuffer; // �\������R���e���c + cv::Mat _DispFrame; // �h���\���E�C���h�E�t���[�� + cv::Mat _DispBuffer; // �h���\���R���e���c + cv::Mat _SceneBuffer; // ����摜�R���e���c cv::Mat _Logo; void GetDisplayInfo(); @@ -28,4 +30,5 @@ ECTrainerGUI(ECTrainer* ect); bool Init(); bool MainLoop(); + void SetSceneBuffer(cv::Mat &img); }; diff --git a/ECTrainer2/SceneCamera.cpp b/ECTrainer2/SceneCamera.cpp index ea41a83..9db27cd 100644 --- a/ECTrainer2/SceneCamera.cpp +++ b/ECTrainer2/SceneCamera.cpp @@ -4,6 +4,7 @@ #include "ECTrainer.h" #include "SceneCamera.h" +#include "ECTrainerGUI.h" // �R���X�g���N�^ SceneCamera::SceneCamera(ECTrainer* pEct) @@ -24,12 +25,13 @@ } // ���[�v -bool SceneCamera::Loop() { +bool SceneCamera::MainLoop() { while (_pEct->IsRunning()) { // �V�[���B�e cv::Mat scene; _SceneCam >> scene; - cv::resize(scene, scene, cv::Size(320, 240)); + std::cout << scene.cols << "," << scene.rows << std::endl; + _pEct->GetGui()->SetSceneBuffer(scene); } return true; diff --git a/ECTrainer2/SceneCamera.h b/ECTrainer2/SceneCamera.h index 84db5c1..583baf3 100644 --- a/ECTrainer2/SceneCamera.h +++ b/ECTrainer2/SceneCamera.h @@ -14,5 +14,5 @@ public: SceneCamera(ECTrainer* pEct); bool Init(); - bool Loop(); + bool MainLoop(); }; diff --git a/ECTrainer2/main.cpp b/ECTrainer2/main.cpp index ff31260..1149ff9 100644 --- a/ECTrainer2/main.cpp +++ b/ECTrainer2/main.cpp @@ -14,11 +14,10 @@ #endif { ECTrainer ect; - if (!ect.Init()) return 1; - ect.Loop(); + if (!ect.Process()) return 1; -//#ifdef _DEBUG -// std::cin.get(); -//#endif +#ifdef _DEBUG + //std::cin.get(); +#endif return 0; }