diff --git a/ECTrainer2/ECTrainer.cpp b/ECTrainer2/ECTrainer.cpp
index 99ab15a..7578b21 100644
--- a/ECTrainer2/ECTrainer.cpp
+++ b/ECTrainer2/ECTrainer.cpp
@@ -6,6 +6,7 @@
#include "Marker.h"
#include "ImageProc.h"
#include "EyeTrack.h"
+#include "TobiiREST.h"
// �R���X�g���N�^
ECTrainer::ECTrainer(HINSTANCE hInstance)
@@ -52,6 +53,8 @@
HANDLE hThreadEyeTrack = CreateThread(NULL, 0, EyeTrackThreadEntry, this, 0, &dwThreadIdEyeTrack);
HANDLE hThreadKeepAlive = CreateThread(NULL, 0, KeepAliveThreadEntry, this, 0, &dwThreadIdKeepAlive);
+ _TobiiREST.GetCalibID();
+
_pGui->MainLoop();
HANDLE handles[] = { hThreadSceneCam , hThreadStimulus, hThreadImageProc, hThreadEyeTrack, hThreadKeepAlive };
@@ -71,8 +74,14 @@
}
// �L�����u���[�V����
-void ECTrainer::Calib() {
+void ECTrainer::CalibStart() {
_pStimulus->Calibration();
+ _TobiiREST.StartCalibration();
+}
+
+// �L�����u���[�V�������ʎ擾
+void ECTrainer::CalibGetResult() {
+ _TobiiREST.GetCalibResult();
}
// �J�n
diff --git a/ECTrainer2/ECTrainer.h b/ECTrainer2/ECTrainer.h
index 6187d51..4a47d7d 100644
--- a/ECTrainer2/ECTrainer.h
+++ b/ECTrainer2/ECTrainer.h
@@ -23,6 +23,7 @@
Marker* _pMarker;
ImageProc* _pImageProc;
EyeTrack* _pEyeTrack;
+ TobiiREST _TobiiREST;
bool _Running; // ���s���t���O
bool _HomographyOK; // �ϊ��s��̊l���L��
cv::Size _SceneSize; // ���E�J�����̉摜�T�C�Y
@@ -37,7 +38,8 @@
ECTrainer(HINSTANCE hInstance);
~ECTrainer();
bool Process();
- void Calib();
+ void CalibStart();
+ void CalibGetResult();
void Start();
void Next();
void SetSceneBuffer(cv::Mat& img);
diff --git a/ECTrainer2/ECTrainer2.vcxproj b/ECTrainer2/ECTrainer2.vcxproj
index f178ccc..002bd6b 100644
--- a/ECTrainer2/ECTrainer2.vcxproj
+++ b/ECTrainer2/ECTrainer2.vcxproj
@@ -149,8 +149,10 @@
+
+
@@ -161,11 +163,23 @@
+
+
+
+
+
+
+
+
+ このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。
+
+
+
\ No newline at end of file
diff --git a/ECTrainer2/ECTrainer2.vcxproj.filters b/ECTrainer2/ECTrainer2.vcxproj.filters
index 3bb2aaa..2499498 100644
--- a/ECTrainer2/ECTrainer2.vcxproj.filters
+++ b/ECTrainer2/ECTrainer2.vcxproj.filters
@@ -42,6 +42,12 @@
ソース ファイル
+
+ ソース ファイル
+
+
+ ソース ファイル
+
@@ -77,5 +83,14 @@
ヘッダー ファイル
+
+ ヘッダー ファイル
+
+
+ ヘッダー ファイル
+
+
+
+
\ No newline at end of file
diff --git a/ECTrainer2/ECTrainerGUI.cpp b/ECTrainer2/ECTrainerGUI.cpp
index 20fbb70..f814705 100644
--- a/ECTrainer2/ECTrainerGUI.cpp
+++ b/ECTrainer2/ECTrainerGUI.cpp
@@ -91,7 +91,7 @@
cv::Mat blank(cv::Size(IMAGE_WIDTH, 480), CV_8UC3, cv::Scalar(0));
blank.copyTo(_SceneBuffer);
blank.copyTo(_DispImage);
- _Logo = cv::imread("../images/ECTrainerLogo640x91.png");
+ _Logo = cv::imread("../images/ECTLogo2_1480l.png");
return InitDx(hInstance);
}
@@ -139,7 +139,8 @@
bool fShowEyesPos = true;
bool fStimulus = false;
bool fContact = false;
- bool fKeepContact = false;
+ bool fCalib = false;
+ //bool fKeepContact = false;
int contactLevel = 0;
float targetSize = 2.0;
clock_t startContact = 0;
@@ -232,17 +233,23 @@
contactLevel = 0;
}
+ // �L�����u���[�V��������
+ if (fCalib) {
+ _pEct->CalibGetResult();
+ fCalib = false;
+ }
+
// UI�`��
cvui::image(_MainFrame, 0, 0, _Logo);
cvui::beginColumn(_MainFrame, 10, 100, 140, -1, 10);
if (fStimulus) {
if (cvui::button(140, 30, "STOP")) {
if (!StopMovie()) _pEct->Stop();
- fKeepContact = false;
+ //fKeepContact = false;
fStimulus = false;
}
if (cvui::button(140, 30, "NEXT")) {
- fKeepContact = false;
+ //fKeepContact = false;
if (!StopMovie()) _pEct->Stop();
_PlayIndex = (_PlayIndex + 1) % _MovieFiles.size();
if (!PlayMovie()) _pEct->Stop();
@@ -252,10 +259,13 @@
cvui::checkbox("Show Eyes", &fShowEyesPos);
cvui::text(fContact ? "Eyes Contact!" : "No contact");
} else {
- if (cvui::button(140, 30, "CALIBRATION")) _pEct->Calib();
+ if (cvui::button(140, 30, "CALIBRATION")) {
+ _pEct->CalibStart();
+ fCalib = true;
+ }
if (cvui::button(140, 30, "START")) {
fStimulus = true;
- fKeepContact = false;
+ //fKeepContact = false;
if (!PlayMovie()) _pEct->Stop();
//_pEct->Start();
}
diff --git a/ECTrainer2/REST_Handler.cpp b/ECTrainer2/REST_Handler.cpp
new file mode 100644
index 0000000..a1c1030
--- /dev/null
+++ b/ECTrainer2/REST_Handler.cpp
@@ -0,0 +1,44 @@
+#include "REST_Handler.h"
+
+http_response REST_Handler::POST_Request(const TCHAR* baseURL,
+ json::value data) {
+
+ http_client httpClient(baseURL);
+ http_response httpResponse = httpClient.request(methods::POST, L"",
+ data == json::value::Null ? _T("") : data.serialize(), L"application/json").get();
+ return httpResponse;
+}
+
+std::wstring REST_Handler::WaitForStatus(
+ const TCHAR* baseURL,
+ std::wstring key,
+ std::vector values) {
+ int count = 0;
+ bool running = true;
+ int maxTries = 20;
+ json::value json;
+ std::wcout << baseURL << std::endl;
+ while (running) {
+ auto response = GET_Request(baseURL);
+ json = response.extract_json().get();
+ std::wcout << _T("Status: ") << json[key].as_string() << std::endl;
+ if (count >= maxTries) running = false;
+ else {
+ for (int i = 0; i < values.size(); i++) {
+ if (json[key].as_string().compare(values[i]) == 0) {
+ running = false;
+ }
+ }
+ }
+ if (!running) break;
+ Sleep(1000);
+ count++;
+ }
+ return json[key].as_string();
+}
+
+http_response REST_Handler::GET_Request(const TCHAR* baseURL) {
+ http_client httpClient(baseURL);
+ http_response httpResponse = httpClient.request(methods::GET, L"", L"", L"application/json").get();
+ return httpResponse;
+}
diff --git a/ECTrainer2/REST_Handler.h b/ECTrainer2/REST_Handler.h
new file mode 100644
index 0000000..4b809b4
--- /dev/null
+++ b/ECTrainer2/REST_Handler.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include
+#include
+#include
+
+using namespace web;
+using namespace web::http;
+using namespace web::http::client;
+
+class REST_Handler
+{
+public:
+ static http_response POST_Request(
+ const TCHAR* baseURL,
+ json::value data = json::value::Null);
+
+ static std::wstring WaitForStatus(
+ const TCHAR* baseURL,
+ std::wstring key,
+ std::vector values);
+
+ static http_response GET_Request(
+ const TCHAR* baseURL);
+};
diff --git a/ECTrainer2/Stimulus.h b/ECTrainer2/Stimulus.h
index 809c1d6..6550041 100644
--- a/ECTrainer2/Stimulus.h
+++ b/ECTrainer2/Stimulus.h
@@ -14,7 +14,7 @@
class Stimulus : public BaseProcess
{
- const cv::String OPENING_FILE = "../images/ECTrainerLogo640x91.png";
+ const cv::String OPENING_FILE = "../images/ECT_toppage.png";
const cv::String CALIB_FILE = "../images/calib.png";
const std::string DATA_FILE = "StimData.txt";
Marker* _pMarker;
diff --git a/ECTrainer2/TobiiREST.cpp b/ECTrainer2/TobiiREST.cpp
new file mode 100644
index 0000000..b10d20e
--- /dev/null
+++ b/ECTrainer2/TobiiREST.cpp
@@ -0,0 +1,71 @@
+#include "TobiiREST.h"
+
+bool TobiiREST::GetCalibID() {
+ try
+ {
+ json::value json = REST_Handler::POST_Request(SERVER _T("/api/projects")).extract_json().get();
+ auto prId = json[_T("pr_id")].as_string();
+ std::wcout << "prId=" << prId << std::endl;
+
+ json::value postData;
+ postData[L"pa_project"] = json::value::string(prId);
+ json = REST_Handler::POST_Request(SERVER _T("/api/participants"), postData).extract_json().get();
+ auto paId = json[_T("pa_id")].as_string();
+ std::wcout << "paId=" << paId << std::endl;
+
+ json::value postData2;
+ postData2[L"ca_project"] = json::value::string(prId);
+ postData2[L"ca_type"] = json::value::string(L"default");
+ postData2[L"ca_participant"] = json::value::string(paId);
+ json = REST_Handler::POST_Request(SERVER _T("/api/calibrations"), postData2).extract_json().get();
+ _CalibID = json[_T("ca_id")].as_string();
+ std::wcout << "caId=" << _CalibID << std::endl;
+
+ return true;
+ }
+ catch (const std::exception & e)
+ {
+ std::cout << "Error " << e.what() << std::endl;
+ return false;
+ }
+}
+
+bool TobiiREST::StartCalibration() {
+ try
+ {
+ std::wstring url = SERVER _T("/api/calibrations/") + _CalibID + _T("/start");
+ json::value json = REST_Handler::POST_Request(url.c_str()).extract_json().get();
+ std::wcout << "Calibration start" << std::endl;
+ return true;
+ }
+ catch (const std::exception& e)
+ {
+ std::cout << "Error " << e.what() << std::endl;
+ return false;
+ }
+}
+
+// GetCalibResult
+// �߂�l -1:�G���[ 0:���s 1:����
+int TobiiREST::GetCalibResult() {
+ try
+ {
+ std::wstring url = SERVER _T("/api/calibrations/") + _CalibID + _T("/status");
+ std::vector values;
+ values.push_back(_T("failed"));
+ values.push_back(_T("calibrated"));
+ std::wstring status = REST_Handler::WaitForStatus(url.c_str(), _T("ca_state"), values);
+ if (status == _T("failed")) {
+ std::wcout << _T("Calibration failed.") << std::endl;
+ return 0;
+ }
+ std::wcout << _T("Calibration successful.") << std::endl;
+ return 1;
+ }
+ catch (const std::exception & e)
+ {
+ std::cout << "Error " << e.what() << std::endl;
+
+ return -1;
+ }
+}
diff --git a/ECTrainer2/TobiiREST.h b/ECTrainer2/TobiiREST.h
new file mode 100644
index 0000000..806b03a
--- /dev/null
+++ b/ECTrainer2/TobiiREST.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "REST_Handler.h"
+#include
+
+#define SERVER _T("http://192.168.71.50")
+
+class TobiiREST
+{
+ utility::string_t _CalibID;
+
+public:
+ bool GetCalibID();
+
+ bool StartCalibration();
+
+ int GetCalibResult();
+};
+
diff --git a/ECTrainer2/packages.config b/ECTrainer2/packages.config
new file mode 100644
index 0000000..5e043ca
--- /dev/null
+++ b/ECTrainer2/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/images/ECTLogo2_1480l.png b/images/ECTLogo2_1480l.png
new file mode 100644
index 0000000..dd46029
--- /dev/null
+++ b/images/ECTLogo2_1480l.png
Binary files differ
diff --git a/images/ECT_toppage.png b/images/ECT_toppage.png
new file mode 100644
index 0000000..b06d6d9
--- /dev/null
+++ b/images/ECT_toppage.png
Binary files differ
diff --git a/images/ECTrainerLogo.png b/images/ECTrainerLogo.png
deleted file mode 100644
index 9ae7c1e..0000000
--- a/images/ECTrainerLogo.png
+++ /dev/null
Binary files differ
diff --git a/images/ECTrainerLogo640x91.png b/images/ECTrainerLogo640x91.png
deleted file mode 100644
index f4c9f54..0000000
--- a/images/ECTrainerLogo640x91.png
+++ /dev/null
Binary files differ