Added support for multiple Azure Kinects on same machine

This commit is contained in:
Marek Kowalski
2019-08-16 18:03:41 +01:00
parent f49bcaf5d9
commit e2a03f9c8a
6 changed files with 27 additions and 20 deletions
@@ -12,7 +12,6 @@ public:
~AzureKinectCapture(); ~AzureKinectCapture();
bool Initialize(); bool Initialize();
bool Initialize(int deviceIdx);
bool AcquireFrame(); bool AcquireFrame();
void MapDepthFrameToCameraSpace(Point3f *pCameraSpacePoints); void MapDepthFrameToCameraSpace(Point3f *pCameraSpacePoints);
void MapColorFrameToCameraSpace(Point3f *pCameraSpacePoints); void MapColorFrameToCameraSpace(Point3f *pCameraSpacePoints);
+2 -2
View File
@@ -42,8 +42,8 @@ public:
~Calibration(); ~Calibration();
bool Calibrate(RGB *pBuffer, Point3f *pCameraCoordinates, int cColorWidth, int cColorHeight); bool Calibrate(RGB *pBuffer, Point3f *pCameraCoordinates, int cColorWidth, int cColorHeight);
bool LoadCalibration(); bool LoadCalibration(const string &serialNumber);
void SaveCalibration(); void SaveCalibration(const string &serialNumber);
private: private:
IMarker *pDetector; IMarker *pDetector;
int nSampleCounter; int nSampleCounter;
+2
View File
@@ -56,4 +56,6 @@ public:
BYTE *pBodyIndex; BYTE *pBodyIndex;
RGB *pColorRGBX; RGB *pColorRGBX;
std::vector<Body> vBodies; std::vector<Body> vBodies;
std::string serialNumber;
}; };
+13 -8
View File
@@ -18,19 +18,19 @@ AzureKinectCapture::~AzureKinectCapture()
} }
bool AzureKinectCapture::Initialize() bool AzureKinectCapture::Initialize()
{
return Initialize(K4A_DEVICE_DEFAULT);
}
bool AzureKinectCapture::Initialize(int deviceIdx)
{ {
uint32_t count = k4a_device_get_installed_count(); uint32_t count = k4a_device_get_installed_count();
int deviceIdx = 0;
kinectSensor = NULL; kinectSensor = NULL;
if (K4A_FAILED(k4a_device_open(deviceIdx, &kinectSensor))) while (K4A_FAILED(k4a_device_open(deviceIdx, &kinectSensor)))
{ {
bInitialized = false; deviceIdx++;
return bInitialized; if (deviceIdx >= count)
{
bInitialized = false;
return bInitialized;
}
} }
k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL; k4a_device_configuration_t config = K4A_DEVICE_CONFIG_INIT_DISABLE_ALL;
@@ -64,6 +64,11 @@ bool AzureKinectCapture::Initialize(int deviceIdx)
} }
} while (!bTemp); } while (!bTemp);
size_t serialNoSize;
k4a_device_get_serialnum(kinectSensor, NULL, &serialNoSize);
serialNumber = std::string(serialNoSize, '\0');
k4a_device_get_serialnum(kinectSensor, (char*)serialNumber.c_str(), &serialNoSize);
return bInitialized; return bInitialized;
} }
+4 -6
View File
@@ -124,15 +124,13 @@ bool Calibration::Calibrate(RGB *pBuffer, Point3f *pCameraCoordinates, int cColo
marker3DSamples.clear(); marker3DSamples.clear();
nSampleCounter = 0; nSampleCounter = 0;
SaveCalibration();
return true; return true;
} }
bool Calibration::LoadCalibration() bool Calibration::LoadCalibration(const string &serialNumber)
{ {
ifstream file; ifstream file;
file.open("calibration.txt"); file.open("calibration_" + serialNumber + ".txt");
if (!file.is_open()) if (!file.is_open())
return false; return false;
@@ -149,10 +147,10 @@ bool Calibration::LoadCalibration()
return true; return true;
} }
void Calibration::SaveCalibration() void Calibration::SaveCalibration(const string &serialNumber)
{ {
ofstream file; ofstream file;
file.open("calibration.txt"); file.open("calibration_" + serialNumber + ".txt");
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
file << worldT[i] << " "; file << worldT[i] << " ";
file << endl; file << endl;
+6 -3
View File
@@ -78,8 +78,6 @@ LiveScanClient::LiveScanClient() :
m_vBounds.push_back(0.5); m_vBounds.push_back(0.5);
m_vBounds.push_back(0.5); m_vBounds.push_back(0.5);
m_vBounds.push_back(0.5); m_vBounds.push_back(0.5);
calibration.LoadCalibration();
} }
LiveScanClient::~LiveScanClient() LiveScanClient::~LiveScanClient()
@@ -164,11 +162,14 @@ int LiveScanClient::Run(HINSTANCE hInstance, int nCmdShow)
// Main message loop // Main message loop
while (WM_QUIT != msg.message) while (WM_QUIT != msg.message)
{ {
//HandleSocket();
UpdateFrame(); UpdateFrame();
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
{ {
if (WM_QUIT == msg.message)
{
break;
}
// If a dialog message will be taken care of by the dialog proc // If a dialog message will be taken care of by the dialog proc
if (hWndApp && IsDialogMessageW(hWndApp, &msg)) if (hWndApp && IsDialogMessageW(hWndApp, &msg))
{ {
@@ -223,6 +224,7 @@ void LiveScanClient::UpdateFrame()
if (res) if (res)
{ {
calibration.SaveCalibration(pCapture->serialNumber);
m_bConfirmCalibrated = true; m_bConfirmCalibrated = true;
m_bCalibrate = false; m_bCalibrate = false;
} }
@@ -277,6 +279,7 @@ LRESULT CALLBACK LiveScanClient::DlgProc(HWND hWnd, UINT message, WPARAM wParam,
bool res = pCapture->Initialize(); bool res = pCapture->Initialize();
if (res) if (res)
{ {
calibration.LoadCalibration(pCapture->serialNumber);
m_pDepthRGBX = new RGB[pCapture->nColorFrameWidth * pCapture->nColorFrameHeight]; m_pDepthRGBX = new RGB[pCapture->nColorFrameWidth * pCapture->nColorFrameHeight];
m_pDepthInColorSpace = new UINT16[pCapture->nColorFrameWidth * pCapture->nColorFrameHeight]; m_pDepthInColorSpace = new UINT16[pCapture->nColorFrameWidth * pCapture->nColorFrameHeight];