Calibration now gets saved and loaded to a file on the client side.

Simplified the calibration data structure on client.
Updated README, LICENSE and gitignore.
This commit is contained in:
Marek Kowalski
2017-01-17 19:04:45 +01:00
parent 8e15bcf917
commit 64027fc77d
7 changed files with 71 additions and 50 deletions
+50 -11
View File
@@ -17,7 +17,7 @@
#include "Kinect.h"
#include "opencv\cv.h"
#include <fstream>
Calibration::Calibration()
{
@@ -25,6 +25,13 @@ Calibration::Calibration()
nSampleCounter = 0;
nRequiredSamples = 20;
worldT = vector<float>(3, 0.0f);
for (int i = 0; i < 3; i++)
{
worldR.push_back(vector<float>(3, 0.0f));
worldR[i][i] = 1.0f;
}
pDetector = new MarkerDetector();
}
@@ -102,17 +109,10 @@ bool Calibration::Calibrate(RGB *pBuffer, Point3f *pCameraCoordinates, int cColo
}
}
cameraR = worldR;
cameraT = RotatePoint(worldT, cameraR);
vector<float> translationIncr(3);
translationIncr[0] = markerPose.t[0];
translationIncr[1] = markerPose.t[1];
translationIncr[2] = markerPose.t[2];
cameraT[0] += translationIncr[0];
cameraT[1] += translationIncr[1];
cameraT[2] += translationIncr[2];
translationIncr[2] = markerPose.t[2];;
translationIncr = InverseRotatePoint(translationIncr, worldR);
@@ -125,9 +125,50 @@ bool Calibration::Calibrate(RGB *pBuffer, Point3f *pCameraCoordinates, int cColo
marker3DSamples.clear();
nSampleCounter = 0;
SaveCalibration();
return true;
}
bool Calibration::LoadCalibration()
{
ifstream file;
file.open("calibration.txt");
if (!file.is_open())
return false;
for (int i = 0; i < 3; i++)
file >> worldT[i];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
file >> worldR[i][j];
}
file >> iUsedMarkerId;
file >> bCalibrated;
return true;
}
void Calibration::SaveCalibration()
{
ofstream file;
file.open("calibration.txt");
for (int i = 0; i < 3; i++)
file << worldT[i] << " ";
file << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
file << worldR[i][j];
file << endl;
}
file << iUsedMarkerId << endl;
file << bCalibrated << endl;
file.close();
}
void Calibration::Procrustes(MarkerInfo &marker, vector<Point3f> &markerInWorld, vector<float> &worldToMarkerT, vector<vector<float>> &worldToMarkerR)
{
int nVertices = marker.points.size();
@@ -232,8 +273,6 @@ bool Calibration::GetMarkerCorners3D(vector<Point3f> &marker3D, MarkerInfo &mark
return true;
}
vector<float> InverseRotatePoint(vector<float> &point, std::vector<std::vector<float>> &R)
{
vector<float> res(3);
+6 -23
View File
@@ -79,6 +79,8 @@ LiveScanClient::LiveScanClient() :
m_vBounds.push_back(0.5);
m_vBounds.push_back(0.5);
m_vBounds.push_back(0.5);
calibration.LoadCalibration();
}
LiveScanClient::~LiveScanClient()
@@ -347,6 +349,9 @@ LRESULT CALLBACK LiveScanClient::DlgProc(HWND hWnd, UINT message, WPARAM wParam,
m_pClientSocket = new SocketClient(address, 48001);
m_bConnected = true;
if (calibration.bCalibrated)
m_bConfirmCalibrated = true;
SetDlgItemTextA(m_hWnd, IDC_BUTTON_CONNECT, "Disconnect");
//Clear the status bar so that the "Failed to connect..." disappears.
SetStatusMessage(L"", 1, true);
@@ -581,20 +586,6 @@ void LiveScanClient::HandleSocket()
i += sizeof(float);
}
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
calibration.cameraR[j][k] = *(float*)(received.c_str() + i);
i += sizeof(float);
}
}
for (int j = 0; j < 3; j++)
{
calibration.cameraT[j] = *(float*)(received.c_str() + i);
i += sizeof(float);
}
//so that we do not lose the next character in the stream
i--;
}
@@ -614,7 +605,7 @@ void LiveScanClient::HandleSocket()
if (m_bConfirmCalibrated)
{
int size = 2 * (9 + 3) * sizeof(float) + sizeof(int) + 1;
int size = (9 + 3) * sizeof(float) + sizeof(int) + 1;
char *buffer = new char[size];
buffer[0] = MSG_CONFIRM_CALIBRATED;
int i = 1;
@@ -630,14 +621,6 @@ void LiveScanClient::HandleSocket()
memcpy(buffer + i, calibration.worldT.data(), 3 * sizeof(float));
i += 3 * sizeof(float);
memcpy(buffer + i, calibration.cameraR[0].data(), 3 * sizeof(float));
i += 3 * sizeof(float);
memcpy(buffer + i, calibration.cameraR[1].data(), 3 * sizeof(float));
i += 3 * sizeof(float);
memcpy(buffer + i, calibration.cameraR[2].data(), 3 * sizeof(float));
i += 3 * sizeof(float);
memcpy(buffer + i, calibration.cameraT.data(), 3 * sizeof(float));
m_pClientSocket->SendBytes(buffer, size);
m_bConfirmCalibrated = false;
}