mirror of
https://github.com/storytold/LiveScan3D.git
synced 2026-10-09 00:09:58 +00:00
Finished Temporal Sync Feature
This commit is contained in:
+7
-7
@@ -29,46 +29,46 @@
|
|||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{973EE923-B423-4BCD-AA08-B03DA40CB51F}</ProjectGuid>
|
<ProjectGuid>{973EE923-B423-4BCD-AA08-B03DA40CB51F}</ProjectGuid>
|
||||||
<RootNamespace>ICP</RootNamespace>
|
<RootNamespace>ICP</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'" Label="Configuration">
|
||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -60,32 +60,32 @@
|
|||||||
<ProjectGuid>{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}</ProjectGuid>
|
<ProjectGuid>{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}</ProjectGuid>
|
||||||
<RootNamespace>KinectClient</RootNamespace>
|
<RootNamespace>KinectClient</RootNamespace>
|
||||||
<ProjectName>LiveScanClient</ProjectName>
|
<ProjectName>LiveScanClient</ProjectName>
|
||||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -193,12 +193,12 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
<Import Project="..\packages\Microsoft.Azure.Kinect.Sensor.1.2.0\build\native\Microsoft.Azure.Kinect.Sensor.targets" Condition="Exists('..\packages\Microsoft.Azure.Kinect.Sensor.1.2.0\build\native\Microsoft.Azure.Kinect.Sensor.targets')" />
|
<Import Project="..\packages\Microsoft.Azure.Kinect.Sensor.1.4.1\build\native\Microsoft.Azure.Kinect.Sensor.targets" Condition="Exists('..\packages\Microsoft.Azure.Kinect.Sensor.1.4.1\build\native\Microsoft.Azure.Kinect.Sensor.targets')" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Error Condition="!Exists('..\packages\Microsoft.Azure.Kinect.Sensor.1.2.0\build\native\Microsoft.Azure.Kinect.Sensor.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.Kinect.Sensor.1.2.0\build\native\Microsoft.Azure.Kinect.Sensor.targets'))" />
|
<Error Condition="!Exists('..\packages\Microsoft.Azure.Kinect.Sensor.1.4.1\build\native\Microsoft.Azure.Kinect.Sensor.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.Kinect.Sensor.1.4.1\build\native\Microsoft.Azure.Kinect.Sensor.targets'))" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Microsoft.Azure.Kinect.Sensor" version="1.2.0" targetFramework="native" />
|
<package id="Microsoft.Azure.Kinect.Sensor" version="1.4.1" targetFramework="native" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -31,6 +31,7 @@ namespace KinectServer
|
|||||||
Socket oServerSocket;
|
Socket oServerSocket;
|
||||||
|
|
||||||
bool bServerRunning = false;
|
bool bServerRunning = false;
|
||||||
|
bool waitForSubToStart = false;
|
||||||
|
|
||||||
KinectSettings oSettings;
|
KinectSettings oSettings;
|
||||||
object oClientSocketLock = new object();
|
object oClientSocketLock = new object();
|
||||||
@@ -232,19 +233,71 @@ namespace KinectServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Send temporal Sync Data to all client
|
||||||
|
/// </summary>
|
||||||
public void SendTemporalSyncData()
|
public void SendTemporalSyncData()
|
||||||
{
|
{
|
||||||
lock (oClientSocketLock)
|
lock (oClientSocketLock)
|
||||||
{
|
{
|
||||||
lClientSockets[0].SendTemporalSyncStatus(true, false);
|
if(lClientSockets.Count > 1 && oSettings.bEnableSync)
|
||||||
|
|
||||||
for (int i = 1; i < lClientSockets.Count; i++)
|
|
||||||
{
|
{
|
||||||
lClientSockets[i].SendTemporalSyncStatus(false, true);
|
byte syncOffSetCounter = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < lClientSockets.Count; i++)
|
||||||
|
{
|
||||||
|
lClientSockets[i].SendTemporalSyncStatus(true, syncOffSetCounter);
|
||||||
|
syncOffSetCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForSubToStart = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < lClientSockets.Count; i++)
|
||||||
|
{
|
||||||
|
lClientSockets[i].SendTemporalSyncStatus(false, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when a sub client has started. This checks if all sub clients have already started. If yes, we initialize the master
|
||||||
|
/// </summary>
|
||||||
|
public void CheckForMasterStart()
|
||||||
|
{
|
||||||
|
if (!oSettings.bEnableSync || !waitForSubToStart)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool allSubsStarted = true;
|
||||||
|
|
||||||
|
lock (oClientSocketLock)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < lClientSockets.Count; i++)
|
||||||
|
{
|
||||||
|
if (!lClientSockets[i].bSubStarted && lClientSockets[i].currentTempSyncState == KinectSocket.eTempSyncConfig.SUBORDINATE)
|
||||||
|
{
|
||||||
|
allSubsStarted = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allSubsStarted)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < lClientSockets.Count; i++)
|
||||||
|
{
|
||||||
|
lClientSockets[i].SendMasterInitialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public bool GetStoredFrame(List<List<byte>> lFramesRGB, List<List<Single>> lFramesVerts)
|
public bool GetStoredFrame(List<List<byte>> lFramesRGB, List<List<Single>> lFramesVerts)
|
||||||
{
|
{
|
||||||
bool bNoMoreStoredFrames;
|
bool bNoMoreStoredFrames;
|
||||||
@@ -373,6 +426,8 @@ namespace KinectServer
|
|||||||
lClientSockets.Add(new KinectSocket(newClient));
|
lClientSockets.Add(new KinectSocket(newClient));
|
||||||
lClientSockets[lClientSockets.Count - 1].SendSettings(oSettings);
|
lClientSockets[lClientSockets.Count - 1].SendSettings(oSettings);
|
||||||
lClientSockets[lClientSockets.Count - 1].eChanged += new SocketChangedHandler(SocketListChanged);
|
lClientSockets[lClientSockets.Count - 1].eChanged += new SocketChangedHandler(SocketListChanged);
|
||||||
|
lClientSockets[lClientSockets.Count - 1].eSubInitialized += new SubOrdinateInitialized(CheckForMasterStart);
|
||||||
|
|
||||||
if (eSocketListChanged != null)
|
if (eSocketListChanged != null)
|
||||||
{
|
{
|
||||||
eSocketListChanged(lClientSockets);
|
eSocketListChanged(lClientSockets);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ using System.Net.Sockets;
|
|||||||
namespace KinectServer
|
namespace KinectServer
|
||||||
{
|
{
|
||||||
public delegate void SocketChangedHandler();
|
public delegate void SocketChangedHandler();
|
||||||
|
public delegate void SubOrdinateInitialized();
|
||||||
|
|
||||||
public class KinectSocket
|
public class KinectSocket
|
||||||
{
|
{
|
||||||
@@ -33,8 +34,10 @@ namespace KinectServer
|
|||||||
public bool bStoredFrameReceived = false;
|
public bool bStoredFrameReceived = false;
|
||||||
public bool bNoMoreStoredFrames = true;
|
public bool bNoMoreStoredFrames = true;
|
||||||
public bool bCalibrated = false;
|
public bool bCalibrated = false;
|
||||||
public bool bIsMaster = false;
|
public bool bSubStarted = false;
|
||||||
public bool bIsSubOrdinate = false;
|
|
||||||
|
public enum eTempSyncConfig { MASTER, SUBORDINATE, STANDALONE }
|
||||||
|
public eTempSyncConfig currentTempSyncState = eTempSyncConfig.STANDALONE;
|
||||||
//The pose of the sensor in the scene (used by the OpenGLWindow to show the sensor)
|
//The pose of the sensor in the scene (used by the OpenGLWindow to show the sensor)
|
||||||
public AffineTransform oCameraPose = new AffineTransform();
|
public AffineTransform oCameraPose = new AffineTransform();
|
||||||
//The transform that maps the vertices in the sensor coordinate system to the world corrdinate system.
|
//The transform that maps the vertices in the sensor coordinate system to the world corrdinate system.
|
||||||
@@ -47,11 +50,14 @@ namespace KinectServer
|
|||||||
public List<Body> lBodies = new List<Body>();
|
public List<Body> lBodies = new List<Body>();
|
||||||
|
|
||||||
public event SocketChangedHandler eChanged;
|
public event SocketChangedHandler eChanged;
|
||||||
|
public event SubOrdinateInitialized eSubInitialized;
|
||||||
|
|
||||||
public KinectSocket(Socket clientSocket)
|
public KinectSocket(Socket clientSocket)
|
||||||
{
|
{
|
||||||
oSocket = clientSocket;
|
oSocket = clientSocket;
|
||||||
sSocketState = oSocket.RemoteEndPoint.ToString() + " Calibrated = false";
|
sSocketState = oSocket.RemoteEndPoint.ToString() + " Calibrated = false";
|
||||||
|
|
||||||
|
UpdateSocketState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CaptureFrame()
|
public void CaptureFrame()
|
||||||
@@ -123,23 +129,38 @@ namespace KinectServer
|
|||||||
SendByte();
|
SendByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendTemporalSyncStatus(bool isMaster, bool isSubOrdinate)
|
/// <summary>
|
||||||
|
/// Send the device the command to restart with Temporal Sync Enabled or Disabled
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tempSyncOn">Enable/Disable Temporal Sync</param>
|
||||||
|
/// <param name="syncOffSetMultiplier">Only set when this device should be a subordinate. Should be a unique number in ascending order for each sub</param>
|
||||||
|
public void SendTemporalSyncStatus(bool tempSyncOn, byte syncOffSetMultiplier)
|
||||||
{
|
{
|
||||||
if (isMaster)
|
if (tempSyncOn)
|
||||||
{
|
{
|
||||||
byteToSend[0] = 7;
|
byte[] data = new byte[2];
|
||||||
SendByte();
|
data[0] = 7;
|
||||||
return;
|
data[1] = syncOffSetMultiplier;
|
||||||
|
if (SocketConnected())
|
||||||
|
oSocket.Send(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSubOrdinate)
|
else
|
||||||
{
|
{
|
||||||
byteToSend[0] = 8;
|
byteToSend[0] = 8;
|
||||||
SendByte();
|
SendByte();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends the master device the command to Start. Should only be called when all subs have started
|
||||||
|
/// </summary>
|
||||||
|
public void SendMasterInitialize()
|
||||||
|
{
|
||||||
|
byteToSend[0] = 9;
|
||||||
|
SendByte();
|
||||||
|
}
|
||||||
|
|
||||||
public void ReceiveCalibrationData()
|
public void ReceiveCalibrationData()
|
||||||
{
|
{
|
||||||
bCalibrated = true;
|
bCalibrated = true;
|
||||||
@@ -167,9 +188,10 @@ namespace KinectServer
|
|||||||
UpdateSocketState();
|
UpdateSocketState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gets the TemporalSyncStatus from the device
|
||||||
public void ReceiveTemporalSyncStatus()
|
public void ReceiveTemporalSyncStatus()
|
||||||
{
|
{
|
||||||
int nToRead;
|
byte tempSyncState;
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
while (oSocket.Available == 0)
|
while (oSocket.Available == 0)
|
||||||
@@ -178,24 +200,40 @@ namespace KinectServer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
oSocket.Receive(buffer, 4, SocketFlags.None);
|
oSocket.Receive(buffer, 3, SocketFlags.None);
|
||||||
nToRead = BitConverter.ToInt32(buffer, 0);
|
tempSyncState = buffer[0];
|
||||||
|
|
||||||
if (nToRead == -1)
|
if (tempSyncState == 0)
|
||||||
{
|
{
|
||||||
bIsSubOrdinate = true;
|
currentTempSyncState = eTempSyncConfig.SUBORDINATE;
|
||||||
bIsMaster = false;
|
bSubStarted = true;
|
||||||
return;
|
eSubInitialized?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nToRead == 0)
|
else if(tempSyncState == 1)
|
||||||
{
|
{
|
||||||
bIsMaster = true;
|
currentTempSyncState = eTempSyncConfig.MASTER;
|
||||||
bIsSubOrdinate = false;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (tempSyncState == 2)
|
||||||
|
{
|
||||||
|
currentTempSyncState = eTempSyncConfig.STANDALONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//MARKED FOR DELETION
|
||||||
|
//if(currentTempSyncState == eTempSyncConfig.SUBORDINATE && confirmSubStarted == 1)
|
||||||
|
//{
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
//else if(currentTempSyncState == eTempSyncConfig.SUBORDINATE && confirmSubStarted == 0)
|
||||||
|
//{
|
||||||
|
// bSubStarted = false;
|
||||||
|
// eSubInitialized?.Invoke();
|
||||||
|
//}
|
||||||
|
|
||||||
UpdateSocketState();
|
UpdateSocketState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReceiveFrame()
|
public void ReceiveFrame()
|
||||||
@@ -343,22 +381,23 @@ namespace KinectServer
|
|||||||
|
|
||||||
public void UpdateSocketState()
|
public void UpdateSocketState()
|
||||||
{
|
{
|
||||||
string tempSyncStatus = "";
|
string tempSyncMessage = "";
|
||||||
|
|
||||||
if (bIsMaster)
|
switch (currentTempSyncState)
|
||||||
{
|
{
|
||||||
tempSyncStatus = "[Master]";
|
case eTempSyncConfig.MASTER:
|
||||||
|
tempSyncMessage = "[MASTER]";
|
||||||
|
break;
|
||||||
|
case eTempSyncConfig.SUBORDINATE:
|
||||||
|
tempSyncMessage = "[SUBORDINATE]";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bIsSubOrdinate)
|
sSocketState = oSocket.RemoteEndPoint.ToString() + " Calibrated = " + bCalibrated + " " + tempSyncMessage;
|
||||||
{
|
|
||||||
tempSyncStatus = "[Subordinate]";
|
|
||||||
}
|
|
||||||
|
|
||||||
sSocketState = oSocket.RemoteEndPoint.ToString() + " Calibrated = " + bCalibrated + " " + tempSyncStatus;
|
eChanged?.Invoke();
|
||||||
|
|
||||||
if (eChanged != null)
|
|
||||||
eChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ namespace KinectServer
|
|||||||
IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
||||||
Stream stream = new FileStream("settings.bin", FileMode.Open, FileAccess.Read);
|
Stream stream = new FileStream("settings.bin", FileMode.Open, FileAccess.Read);
|
||||||
oSettings = (KinectSettings)formatter.Deserialize(stream);
|
oSettings = (KinectSettings)formatter.Deserialize(stream);
|
||||||
|
//This always needs to be set to false on startup, as we can only activate it when all Kinects are already connected
|
||||||
|
oSettings.bEnableSync = false;
|
||||||
stream.Close();
|
stream.Close();
|
||||||
}
|
}
|
||||||
catch(Exception)
|
catch(Exception)
|
||||||
@@ -496,6 +498,7 @@ namespace KinectServer
|
|||||||
for (int i = 0; i < socketList.Count; i++)
|
for (int i = 0; i < socketList.Count; i++)
|
||||||
listBoxItems.Add(socketList[i].sSocketState);
|
listBoxItems.Add(socketList[i].sSocketState);
|
||||||
|
|
||||||
|
|
||||||
lClientListBox.DataSource = listBoxItems;
|
lClientListBox.DataSource = listBoxItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+28
-14
@@ -28,13 +28,13 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.Windows.Forms.Label lbSyncWarning;
|
|
||||||
this.lbMerge = new System.Windows.Forms.Label();
|
this.lbMerge = new System.Windows.Forms.Label();
|
||||||
this.chMerge = new System.Windows.Forms.CheckBox();
|
this.chMerge = new System.Windows.Forms.CheckBox();
|
||||||
this.lbICPIters = new System.Windows.Forms.Label();
|
this.lbICPIters = new System.Windows.Forms.Label();
|
||||||
this.txtICPIters = new System.Windows.Forms.TextBox();
|
this.txtICPIters = new System.Windows.Forms.TextBox();
|
||||||
this.grClient = new System.Windows.Forms.GroupBox();
|
this.grClient = new System.Windows.Forms.GroupBox();
|
||||||
this.grSync = new System.Windows.Forms.GroupBox();
|
this.grSync = new System.Windows.Forms.GroupBox();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
this.chSync = new System.Windows.Forms.CheckBox();
|
this.chSync = new System.Windows.Forms.CheckBox();
|
||||||
this.grBody = new System.Windows.Forms.GroupBox();
|
this.grBody = new System.Windows.Forms.GroupBox();
|
||||||
this.chSkeletons = new System.Windows.Forms.CheckBox();
|
this.chSkeletons = new System.Windows.Forms.CheckBox();
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
this.rAsciiPly = new System.Windows.Forms.RadioButton();
|
this.rAsciiPly = new System.Windows.Forms.RadioButton();
|
||||||
this.txtRefinIters = new System.Windows.Forms.TextBox();
|
this.txtRefinIters = new System.Windows.Forms.TextBox();
|
||||||
this.lbOuterIters = new System.Windows.Forms.Label();
|
this.lbOuterIters = new System.Windows.Forms.Label();
|
||||||
lbSyncWarning = new System.Windows.Forms.Label();
|
this.label3 = new System.Windows.Forms.Label();
|
||||||
this.grClient.SuspendLayout();
|
this.grClient.SuspendLayout();
|
||||||
this.grSync.SuspendLayout();
|
this.grSync.SuspendLayout();
|
||||||
this.grBody.SuspendLayout();
|
this.grBody.SuspendLayout();
|
||||||
@@ -145,24 +145,27 @@
|
|||||||
//
|
//
|
||||||
// grSync
|
// grSync
|
||||||
//
|
//
|
||||||
this.grSync.Controls.Add(lbSyncWarning);
|
this.grSync.Controls.Add(this.label3);
|
||||||
|
this.grSync.Controls.Add(this.label1);
|
||||||
this.grSync.Controls.Add(this.chSync);
|
this.grSync.Controls.Add(this.chSync);
|
||||||
this.grSync.Location = new System.Drawing.Point(271, 211);
|
this.grSync.Location = new System.Drawing.Point(271, 211);
|
||||||
this.grSync.Name = "grSync";
|
this.grSync.Name = "grSync";
|
||||||
this.grSync.Size = new System.Drawing.Size(355, 66);
|
this.grSync.Size = new System.Drawing.Size(355, 80);
|
||||||
this.grSync.TabIndex = 48;
|
this.grSync.TabIndex = 48;
|
||||||
this.grSync.TabStop = false;
|
this.grSync.TabStop = false;
|
||||||
this.grSync.Text = "Temporal Sync (Azure Kinect Only)";
|
this.grSync.Text = "Temporal Sync";
|
||||||
|
this.grSync.Enter += new System.EventHandler(this.grSync_Enter);
|
||||||
//
|
//
|
||||||
// lbSyncWarning
|
// label1
|
||||||
//
|
//
|
||||||
lbSyncWarning.AutoSize = true;
|
this.label1.Location = new System.Drawing.Point(7, 41);
|
||||||
lbSyncWarning.CausesValidation = false;
|
this.label1.MaximumSize = new System.Drawing.Size(0, 60);
|
||||||
lbSyncWarning.Location = new System.Drawing.Point(3, 41);
|
this.label1.MinimumSize = new System.Drawing.Size(0, 30);
|
||||||
lbSyncWarning.Name = "lbSyncWarning";
|
this.label1.Name = "label1";
|
||||||
lbSyncWarning.Size = new System.Drawing.Size(347, 13);
|
this.label1.Size = new System.Drawing.Size(0, 30);
|
||||||
lbSyncWarning.TabIndex = 1;
|
this.label1.TabIndex = 1;
|
||||||
lbSyncWarning.Text = "Notice: Devices need to be connected via sync cabel before enabeling!\r\n";
|
this.label1.Text = "Notice: All devices need to be connected to the server and via sync cabel before" +
|
||||||
|
" enabeling! First Device in Server List will become the master";
|
||||||
//
|
//
|
||||||
// chSync
|
// chSync
|
||||||
//
|
//
|
||||||
@@ -174,7 +177,6 @@
|
|||||||
this.chSync.Text = "Enable Temporal Sync";
|
this.chSync.Text = "Enable Temporal Sync";
|
||||||
this.chSync.UseVisualStyleBackColor = true;
|
this.chSync.UseVisualStyleBackColor = true;
|
||||||
this.chSync.CheckedChanged += new System.EventHandler(this.chSync_CheckedChanged);
|
this.chSync.CheckedChanged += new System.EventHandler(this.chSync_CheckedChanged);
|
||||||
|
|
||||||
//
|
//
|
||||||
// grBody
|
// grBody
|
||||||
//
|
//
|
||||||
@@ -647,6 +649,16 @@
|
|||||||
this.lbOuterIters.Size = new System.Drawing.Size(118, 13);
|
this.lbOuterIters.Size = new System.Drawing.Size(118, 13);
|
||||||
this.lbOuterIters.TabIndex = 26;
|
this.lbOuterIters.TabIndex = 26;
|
||||||
this.lbOuterIters.Text = "Num of refinement iters:";
|
this.lbOuterIters.Text = "Num of refinement iters:";
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
this.label3.Location = new System.Drawing.Point(7, 36);
|
||||||
|
this.label3.Name = "label3";
|
||||||
|
this.label3.Size = new System.Drawing.Size(342, 44);
|
||||||
|
this.label3.TabIndex = 2;
|
||||||
|
this.label3.Text = "Before activating, make sure that all Kinects are connected to the server and pro" +
|
||||||
|
"perly connected via the sync cables. The first device in the server list will be" +
|
||||||
|
"come the master!";
|
||||||
//
|
//
|
||||||
// SettingsForm
|
// SettingsForm
|
||||||
//
|
//
|
||||||
@@ -732,5 +744,7 @@
|
|||||||
private System.Windows.Forms.Label label2;
|
private System.Windows.Forms.Label label2;
|
||||||
private System.Windows.Forms.GroupBox grSync;
|
private System.Windows.Forms.GroupBox grSync;
|
||||||
private System.Windows.Forms.CheckBox chSync;
|
private System.Windows.Forms.CheckBox chSync;
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
|
private System.Windows.Forms.Label label3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,6 +355,14 @@ namespace KinectServer
|
|||||||
UpdateClients();
|
UpdateClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void grSync_Enter(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lbSyncWarning_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,4 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
<metadata name="lbSyncWarning.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
|
||||||
<value>False</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
</root>
|
||||||
@@ -11,12 +11,17 @@ public:
|
|||||||
AzureKinectCapture();
|
AzureKinectCapture();
|
||||||
~AzureKinectCapture();
|
~AzureKinectCapture();
|
||||||
|
|
||||||
bool Initialize();
|
bool Initialize(bool asMaster, bool asSubOrdinate, int syncOffset);
|
||||||
|
bool Close();
|
||||||
bool AcquireFrame();
|
bool AcquireFrame();
|
||||||
void MapDepthFrameToCameraSpace(Point3f *pCameraSpacePoints);
|
void MapDepthFrameToCameraSpace(Point3f *pCameraSpacePoints);
|
||||||
void MapColorFrameToCameraSpace(Point3f *pCameraSpacePoints);
|
void MapColorFrameToCameraSpace(Point3f *pCameraSpacePoints);
|
||||||
void MapDepthFrameToColorSpace(UINT16 *pDepthInColorSpace);
|
void MapDepthFrameToColorSpace(UINT16 *pDepthInColorSpace);
|
||||||
void MapColorFrameToDepthSpace(RGB *pColorInDepthSpace);
|
void MapColorFrameToDepthSpace(RGB *pColorInDepthSpace);
|
||||||
|
int GetSyncJackState();
|
||||||
|
uint64_t GetTimeStamp();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
k4a_device_t kinectSensor = NULL;
|
k4a_device_t kinectSensor = NULL;
|
||||||
int32_t captureTimeoutMs = 1000;
|
int32_t captureTimeoutMs = 1000;
|
||||||
@@ -27,6 +32,8 @@ private:
|
|||||||
k4a_image_t colorImageInDepth = NULL;
|
k4a_image_t colorImageInDepth = NULL;
|
||||||
k4a_image_t depthImageInColor = NULL;
|
k4a_image_t depthImageInColor = NULL;
|
||||||
k4a_transformation_t transformation = NULL;
|
k4a_transformation_t transformation = NULL;
|
||||||
|
bool syncInConnected = false;
|
||||||
|
bool syncOutConnected = false;
|
||||||
|
uint64_t currentTimeStamp;
|
||||||
void UpdateDepthPointCloud();
|
void UpdateDepthPointCloud();
|
||||||
};
|
};
|
||||||
@@ -16,7 +16,7 @@ public:
|
|||||||
// leave filename blank if you want the filename to be generated from the date
|
// leave filename blank if you want the filename to be generated from the date
|
||||||
void setCurrentFilename(std::string filename = "");
|
void setCurrentFilename(std::string filename = "");
|
||||||
|
|
||||||
void writeFrame(std::vector<Point3s> points, std::vector<RGB> colors);
|
void writeFrame(std::vector<Point3s> points, std::vector<RGB> colors, uint64_t timestamp);
|
||||||
bool readFrame(std::vector<Point3s> &outPoints, std::vector<RGB> &outColors);
|
bool readFrame(std::vector<Point3s> &outPoints, std::vector<RGB> &outColors);
|
||||||
|
|
||||||
bool openedForWriting() { return m_bFileOpenedForWriting; }
|
bool openedForWriting() { return m_bFileOpenedForWriting; }
|
||||||
|
|||||||
@@ -40,12 +40,15 @@ public:
|
|||||||
ICapture();
|
ICapture();
|
||||||
~ICapture();
|
~ICapture();
|
||||||
|
|
||||||
virtual bool Initialize() = 0;
|
virtual bool Initialize(bool asMaster, bool asSubOrdinate, int syncOffset) = 0;
|
||||||
virtual bool AcquireFrame() = 0;
|
virtual bool AcquireFrame() = 0;
|
||||||
|
virtual bool Close() = 0;
|
||||||
virtual void MapDepthFrameToCameraSpace(Point3f *pCameraSpacePoints) = 0;
|
virtual void MapDepthFrameToCameraSpace(Point3f *pCameraSpacePoints) = 0;
|
||||||
virtual void MapColorFrameToCameraSpace(Point3f *pCameraSpacePoints) = 0;
|
virtual void MapColorFrameToCameraSpace(Point3f *pCameraSpacePoints) = 0;
|
||||||
virtual void MapDepthFrameToColorSpace(UINT16 *pColorSpacePoints) = 0;
|
virtual void MapDepthFrameToColorSpace(UINT16 *pColorSpacePoints) = 0;
|
||||||
virtual void MapColorFrameToDepthSpace(RGB *pDepthSpacePoints) = 0;
|
virtual void MapColorFrameToDepthSpace(RGB *pDepthSpacePoints) = 0;
|
||||||
|
virtual int GetSyncJackState() = 0;
|
||||||
|
virtual uint64_t GetTimeStamp() = 0;
|
||||||
|
|
||||||
bool bInitialized;
|
bool bInitialized;
|
||||||
|
|
||||||
@@ -57,5 +60,7 @@ public:
|
|||||||
RGB *pColorRGBX;
|
RGB *pColorRGBX;
|
||||||
std::vector<Body> vBodies;
|
std::vector<Body> vBodies;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string serialNumber;
|
std::string serialNumber;
|
||||||
};
|
};
|
||||||
@@ -54,13 +54,16 @@ private:
|
|||||||
bool m_bCaptureFrame;
|
bool m_bCaptureFrame;
|
||||||
bool m_bConnected;
|
bool m_bConnected;
|
||||||
bool m_bConfirmCaptured;
|
bool m_bConfirmCaptured;
|
||||||
bool m_bConfirmMaster;
|
bool m_bConfirmTempSyncState;
|
||||||
bool m_bConfirmSubOrdinate;
|
bool m_bConfirmSubOrdinateStarted;
|
||||||
bool m_bConfirmCalibrated;
|
bool m_bConfirmCalibrated;
|
||||||
bool m_bShowDepth;
|
bool m_bShowDepth;
|
||||||
bool m_bFrameCompression;
|
bool m_bFrameCompression;
|
||||||
int m_iCompressionLevel;
|
int m_iCompressionLevel;
|
||||||
|
|
||||||
|
enum tempSyncConfig { MASTER, SUBORDINATE, STANDALONE };
|
||||||
|
tempSyncConfig currentTempSyncState;
|
||||||
|
|
||||||
FrameFileWriterReader m_framesFileWriterReader;
|
FrameFileWriterReader m_framesFileWriterReader;
|
||||||
|
|
||||||
|
|
||||||
@@ -76,6 +79,7 @@ private:
|
|||||||
double m_fFreq;
|
double m_fFreq;
|
||||||
INT64 m_nNextStatusTime;
|
INT64 m_nNextStatusTime;
|
||||||
DWORD m_nFramesSinceUpdate;
|
DWORD m_nFramesSinceUpdate;
|
||||||
|
int frameRecordCounter;
|
||||||
|
|
||||||
Point3f* m_pCameraSpaceCoordinates;
|
Point3f* m_pCameraSpaceCoordinates;
|
||||||
RGB* m_pColorInDepthSpace;
|
RGB* m_pColorInDepthSpace;
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ enum INCOMING_MESSAGE_TYPE
|
|||||||
MSG_REQUEST_LAST_FRAME,
|
MSG_REQUEST_LAST_FRAME,
|
||||||
MSG_RECEIVE_CALIBRATION,
|
MSG_RECEIVE_CALIBRATION,
|
||||||
MSG_CLEAR_STORED_FRAMES,
|
MSG_CLEAR_STORED_FRAMES,
|
||||||
MSG_SET_MASTER,
|
MSG_SET_TEMPSYNC_ON,
|
||||||
MSG_SET_SUBORDINATE
|
MSG_SET_TEMPSYNC_OFF,
|
||||||
|
MSG_START_MASTER
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OUTGOING_MESSAGE_TYPE
|
enum OUTGOING_MESSAGE_TYPE
|
||||||
|
|||||||
@@ -17,7 +17,14 @@ AzureKinectCapture::~AzureKinectCapture()
|
|||||||
k4a_device_close(kinectSensor);
|
k4a_device_close(kinectSensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AzureKinectCapture::Initialize()
|
/// <summary>
|
||||||
|
/// Initialize the device. If you want to initialize it as Standalone, set "asMaster" and "asSubordinate" to false
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asMaster">Initializes this device as master</param>
|
||||||
|
/// <param name="asSubordinate">Initalizes this devices as subordinate</param>
|
||||||
|
/// <param name="syncOffsetMultiplier">Should only be set when initializing as Subordinate. Each subordinate should have a unique, ascending value</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool AzureKinectCapture::Initialize(bool asMaster, bool asSubordinate, int syncOffsetMultiplier)
|
||||||
{
|
{
|
||||||
uint32_t count = k4a_device_get_installed_count();
|
uint32_t count = k4a_device_get_installed_count();
|
||||||
int deviceIdx = 0;
|
int deviceIdx = 0;
|
||||||
@@ -40,6 +47,27 @@ bool AzureKinectCapture::Initialize()
|
|||||||
config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
|
config.depth_mode = K4A_DEPTH_MODE_NFOV_UNBINNED;
|
||||||
config.synchronized_images_only = true;
|
config.synchronized_images_only = true;
|
||||||
|
|
||||||
|
if (asMaster)
|
||||||
|
{
|
||||||
|
config.wired_sync_mode = K4A_WIRED_SYNC_MODE_MASTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (asSubordinate)
|
||||||
|
{
|
||||||
|
config.wired_sync_mode = K4A_WIRED_SYNC_MODE_SUBORDINATE;
|
||||||
|
//Sets the offset on subordinate devices. Should be a multiple of 160, each subordinate having a different multiplier in ascending order.
|
||||||
|
//This is very important, as it avoids firing the Kinects Lasers at the same time.
|
||||||
|
|
||||||
|
config.subordinate_delay_off_master_usec = 0;
|
||||||
|
|
||||||
|
config.subordinate_delay_off_master_usec = 160 * syncOffsetMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config.wired_sync_mode = K4A_WIRED_SYNC_MODE_STANDALONE;
|
||||||
|
}
|
||||||
|
|
||||||
// Start the camera with the given configuration
|
// Start the camera with the given configuration
|
||||||
bInitialized = K4A_SUCCEEDED(k4a_device_start_cameras(kinectSensor, &config));
|
bInitialized = K4A_SUCCEEDED(k4a_device_start_cameras(kinectSensor, &config));
|
||||||
|
|
||||||
@@ -49,31 +77,51 @@ bool AzureKinectCapture::Initialize()
|
|||||||
bInitialized = false;
|
bInitialized = false;
|
||||||
return bInitialized;
|
return bInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
transformation = k4a_transformation_create(&calibration);
|
transformation = k4a_transformation_create(&calibration);
|
||||||
|
|
||||||
std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
|
//If this device is a subordinate, it is expected to start capturing at a later time (When the master has started), so we skip this check
|
||||||
bool bTemp;
|
if (!asSubordinate)
|
||||||
do
|
|
||||||
{
|
{
|
||||||
bTemp = AcquireFrame();
|
std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
|
||||||
|
bool bTemp;
|
||||||
std::chrono::duration<double> elapsedSeconds = std::chrono::system_clock::now() - start;
|
do
|
||||||
if (elapsedSeconds.count() > 5.0)
|
|
||||||
{
|
{
|
||||||
bInitialized = false;
|
bTemp = AcquireFrame();
|
||||||
break;
|
|
||||||
}
|
std::chrono::duration<double> elapsedSeconds = std::chrono::system_clock::now() - start;
|
||||||
} while (!bTemp);
|
if (elapsedSeconds.count() > 5.0)
|
||||||
|
{
|
||||||
|
bInitialized = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (!bTemp);
|
||||||
|
}
|
||||||
|
|
||||||
size_t serialNoSize;
|
size_t serialNoSize;
|
||||||
k4a_device_get_serialnum(kinectSensor, NULL, &serialNoSize);
|
k4a_device_get_serialnum(kinectSensor, NULL, &serialNoSize);
|
||||||
serialNumber = std::string(serialNoSize, '\0');
|
serialNumber = std::string(serialNoSize, '\0');
|
||||||
k4a_device_get_serialnum(kinectSensor, (char*)serialNumber.c_str(), &serialNoSize);
|
k4a_device_get_serialnum(kinectSensor, (char*)serialNumber.c_str(), &serialNoSize);
|
||||||
|
|
||||||
|
|
||||||
return bInitialized;
|
return bInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AzureKinectCapture::Close()
|
||||||
|
{
|
||||||
|
if (!bInitialized)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
k4a_device_stop_cameras(kinectSensor);
|
||||||
|
k4a_device_close(kinectSensor);
|
||||||
|
|
||||||
|
bInitialized = false;
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool AzureKinectCapture::AcquireFrame()
|
bool AzureKinectCapture::AcquireFrame()
|
||||||
{
|
{
|
||||||
if (!bInitialized)
|
if (!bInitialized)
|
||||||
@@ -96,6 +144,9 @@ bool AzureKinectCapture::AcquireFrame()
|
|||||||
|
|
||||||
colorImage = k4a_capture_get_color_image(capture);
|
colorImage = k4a_capture_get_color_image(capture);
|
||||||
depthImage = k4a_capture_get_depth_image(capture);
|
depthImage = k4a_capture_get_depth_image(capture);
|
||||||
|
|
||||||
|
currentTimeStamp = k4a_image_get_device_timestamp_usec(colorImage);
|
||||||
|
|
||||||
if (colorImage == NULL || depthImage == NULL)
|
if (colorImage == NULL || depthImage == NULL)
|
||||||
{
|
{
|
||||||
k4a_capture_release(capture);
|
k4a_capture_release(capture);
|
||||||
@@ -119,6 +170,7 @@ bool AzureKinectCapture::AcquireFrame()
|
|||||||
memcpy(pColorRGBX, k4a_image_get_buffer(colorImage), nColorFrameWidth * nColorFrameHeight * sizeof(RGB));
|
memcpy(pColorRGBX, k4a_image_get_buffer(colorImage), nColorFrameWidth * nColorFrameHeight * sizeof(RGB));
|
||||||
memcpy(pDepth, k4a_image_get_buffer(depthImage), nDepthFrameHeight * nDepthFrameWidth * sizeof(UINT16));
|
memcpy(pDepth, k4a_image_get_buffer(depthImage), nDepthFrameHeight * nDepthFrameWidth * sizeof(UINT16));
|
||||||
|
|
||||||
|
|
||||||
k4a_capture_release(capture);
|
k4a_capture_release(capture);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -261,3 +313,41 @@ void AzureKinectCapture::MapColorFrameToDepthSpace(RGB *pColorInDepthSpace)
|
|||||||
|
|
||||||
memcpy(pColorInDepthSpace, k4a_image_get_buffer(colorImageInDepth), nDepthFrameHeight * nDepthFrameWidth * 4 * (int)sizeof(uint8_t));
|
memcpy(pColorInDepthSpace, k4a_image_get_buffer(colorImageInDepth), nDepthFrameHeight * nDepthFrameWidth * 4 * (int)sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if this camera is configured as a Master, Subordinate or Standalone.
|
||||||
|
/// This is achieved by looking at how the sync out and sync in ports of the device are connected
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Returns int -1 for Subordinate, int 0 for Master and int 1 for Standalone</returns>
|
||||||
|
int AzureKinectCapture::GetSyncJackState()
|
||||||
|
{
|
||||||
|
if (K4A_RESULT_SUCCEEDED == k4a_device_get_sync_jack(kinectSensor, &syncInConnected, &syncOutConnected))
|
||||||
|
{
|
||||||
|
if (syncInConnected)
|
||||||
|
{
|
||||||
|
return -1; //Device is Subordinate, as it recieves a signal via its "Sync In" Port
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (!syncInConnected && syncOutConnected)
|
||||||
|
{
|
||||||
|
return 0; //Device is Master, as it doens't recieve a signal from its "Sync In" Port, but sends one through its "Sync Out" Port
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1; //Device is Standalone, as it doesn't have a valid cabel configuration on its Sync Ports
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1; //Probably failed because there are no cabels connected, this means the device should be set as standalone
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t AzureKinectCapture::GetTimeStamp()
|
||||||
|
{
|
||||||
|
return currentTimeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ bool FrameFileWriterReader::readFrame(std::vector<Point3s> &outPoints, std::vect
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FrameFileWriterReader::writeFrame(std::vector<Point3s> points, std::vector<RGB> colors)
|
void FrameFileWriterReader::writeFrame(std::vector<Point3s> points, std::vector<RGB> colors, uint64_t timestamp)
|
||||||
{
|
{
|
||||||
if (!m_bFileOpenedForWriting)
|
if (!m_bFileOpenedForWriting)
|
||||||
openNewFileForWriting();
|
openNewFileForWriting();
|
||||||
@@ -94,7 +94,8 @@ void FrameFileWriterReader::writeFrame(std::vector<Point3s> points, std::vector<
|
|||||||
FILE *f = m_pFileHandle;
|
FILE *f = m_pFileHandle;
|
||||||
|
|
||||||
int nPoints = static_cast<int>(points.size());
|
int nPoints = static_cast<int>(points.size());
|
||||||
fprintf(f, "n_points= %d\nframe_timestamp= %d\n", nPoints, getRecordingTimeMilliseconds());
|
//fprintf(f, "n_points= %d\nframe_timestamp= %d\n", nPoints, getRecordingTimeMilliseconds());
|
||||||
|
fprintf(f, "n_points= %d\nframe_timestamp= %d\n", nPoints, timestamp);
|
||||||
if (nPoints > 0)
|
if (nPoints > 0)
|
||||||
{
|
{
|
||||||
fwrite((void*)points.data(), sizeof(points[0]), nPoints, f);
|
fwrite((void*)points.data(), sizeof(points[0]), nPoints, f);
|
||||||
|
|||||||
@@ -206,7 +206,8 @@ void LiveScanClient::UpdateFrame()
|
|||||||
|
|
||||||
if (m_bCaptureFrame)
|
if (m_bCaptureFrame)
|
||||||
{
|
{
|
||||||
m_framesFileWriterReader.writeFrame(m_vLastFrameVertices, m_vLastFrameRGB);
|
uint64_t timeStamp = pCapture->GetTimeStamp();
|
||||||
|
m_framesFileWriterReader.writeFrame(m_vLastFrameVertices, m_vLastFrameRGB, timeStamp);
|
||||||
m_bConfirmCaptured = true;
|
m_bConfirmCaptured = true;
|
||||||
m_bCaptureFrame = false;
|
m_bCaptureFrame = false;
|
||||||
}
|
}
|
||||||
@@ -275,8 +276,8 @@ LRESULT CALLBACK LiveScanClient::DlgProc(HWND hWnd, UINT message, WPARAM wParam,
|
|||||||
// Init Direct2D
|
// Init Direct2D
|
||||||
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);
|
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory);
|
||||||
|
|
||||||
// Get and initialize the default Kinect sensor
|
// Get and initialize the default Kinect sensor as standalone
|
||||||
bool res = pCapture->Initialize();
|
bool res = pCapture->Initialize(false, false, 0);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
calibration.LoadCalibration(pCapture->serialNumber);
|
calibration.LoadCalibration(pCapture->serialNumber);
|
||||||
@@ -444,16 +445,62 @@ void LiveScanClient::HandleSocket()
|
|||||||
//calibrate
|
//calibrate
|
||||||
else if (received[i] == MSG_CALIBRATE)
|
else if (received[i] == MSG_CALIBRATE)
|
||||||
m_bCalibrate = true;
|
m_bCalibrate = true;
|
||||||
//Set this client as master
|
|
||||||
else if (received[i] == MSG_SET_MASTER) {
|
//Enables Temporal sync on this client
|
||||||
m_bIsMaster = true;
|
else if (received[i] == MSG_SET_TEMPSYNC_ON) {
|
||||||
m_bIsSubOrdinate = false;
|
|
||||||
|
i++; //Get next byte (the sync Offset)
|
||||||
|
int syncOffset = received[i];
|
||||||
|
|
||||||
|
//Determine if this device is a subordinate, master, or standalone
|
||||||
|
int jackState = pCapture->GetSyncJackState();
|
||||||
|
|
||||||
|
switch (jackState)
|
||||||
|
{
|
||||||
|
case -1:
|
||||||
|
currentTempSyncState = SUBORDINATE;
|
||||||
|
//Restart this device as Subordinate, with a unique syncOffset (send by the server)
|
||||||
|
pCapture->Close();
|
||||||
|
pCapture->Initialize(false, true, syncOffset);
|
||||||
|
//Confirm to the server, that we set this device as subordinate
|
||||||
|
m_bConfirmTempSyncState = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
currentTempSyncState = MASTER;
|
||||||
|
//Only Close this device, as it needs to wait for all subordinates to start, before starting itself
|
||||||
|
pCapture->Close();
|
||||||
|
m_bConfirmTempSyncState = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1://Device is Standalone
|
||||||
|
currentTempSyncState = STANDALONE;
|
||||||
|
//Restart this device as Standalone
|
||||||
|
pCapture->Close();
|
||||||
|
pCapture->Initialize(false, false, 0);
|
||||||
|
m_bConfirmTempSyncState = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Set this client as subordinate
|
|
||||||
else if (received[i] == MSG_SET_SUBORDINATE) {
|
//Sets this device as Standalone
|
||||||
m_bIsMaster = false;
|
else if (received[i] == MSG_SET_TEMPSYNC_OFF) {
|
||||||
m_bIsSubOrdinate = true;
|
currentTempSyncState = STANDALONE;
|
||||||
|
pCapture->Close();
|
||||||
|
pCapture->Initialize(false, false, 0);
|
||||||
|
m_bConfirmTempSyncState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Got confirmation from the server that all subs have started, and we can now start the master
|
||||||
|
else if (received[i] == MSG_START_MASTER) {
|
||||||
|
if (currentTempSyncState == MASTER)
|
||||||
|
{
|
||||||
|
pCapture->Initialize(true, false, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//receive settings
|
//receive settings
|
||||||
//TODO: what if packet is split?
|
//TODO: what if packet is split?
|
||||||
else if (received[i] == MSG_RECEIVE_SETTINGS)
|
else if (received[i] == MSG_RECEIVE_SETTINGS)
|
||||||
@@ -577,24 +624,25 @@ void LiveScanClient::HandleSocket()
|
|||||||
m_bConfirmCaptured = false;
|
m_bConfirmCaptured = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_bConfirmMaster)
|
//Send validation to the server that this device has been set to a specific Sync State
|
||||||
|
if (m_bConfirmTempSyncState)
|
||||||
{
|
{
|
||||||
int size = 2;
|
int size = 3; //Somehow it doesn't work when sending only two bytes?? (So we send an extra one)
|
||||||
char *buffer = new char[size];
|
|
||||||
buffer[0] = MSG_CONFIRM_TEMP_SYNC_STATUS;
|
|
||||||
buffer[1] = 0;
|
|
||||||
m_pClientSocket->SendBytes(buffer, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_bConfirmSubOrdinate)
|
|
||||||
{
|
|
||||||
int size = 2;
|
|
||||||
char* buffer = new char[size];
|
char* buffer = new char[size];
|
||||||
buffer[0] = MSG_CONFIRM_TEMP_SYNC_STATUS;
|
buffer[0] = MSG_CONFIRM_TEMP_SYNC_STATUS;
|
||||||
buffer[1] = -1;
|
|
||||||
|
switch (currentTempSyncState)
|
||||||
|
{
|
||||||
|
case SUBORDINATE: buffer[1] = 0; break;
|
||||||
|
case MASTER: buffer[1] = 1; break;
|
||||||
|
case STANDALONE: buffer[1] = 2; break;
|
||||||
|
}
|
||||||
|
|
||||||
m_pClientSocket->SendBytes(buffer, size);
|
m_pClientSocket->SendBytes(buffer, size);
|
||||||
|
m_bConfirmTempSyncState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (m_bConfirmCalibrated)
|
if (m_bConfirmCalibrated)
|
||||||
{
|
{
|
||||||
int size = (9 + 3) * sizeof(float) + sizeof(int) + 1;
|
int size = (9 + 3) * sizeof(float) + sizeof(int) + 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user