Skip to content
Permalink
Browse files

k4a: fix multi cam systems (#199)

  • Loading branch information...
jangernert authored and sisiplac committed Aug 2, 2019
1 parent 3328fc0 commit 888e324719782132dfe48f840830dd8f1e73c14b
Showing with 46 additions and 24 deletions.
  1. +34 −6 BetaCameras/Kinect4Azure/Kinect4Azure.cs
  2. +12 −18 Samples/MinimalSample/Program.cs
@@ -231,23 +231,51 @@ protected override void ConnectImpl()

if (!haveSerial)
{
_device = Device.Open(0);
Device tmpDev = null;
for (int i = 0; i < Device.GetInstalledCount(); i++)
{
try
{
tmpDev = Device.Open(i);
break;
}
catch (Microsoft.AzureKinect.Exception e)
{
log.Warn($"Could not open K4A Device number {i}. The device is probably already in use: {e.Message}");
}
}

_device = tmpDev;
this.SerialNumber = _device.SerialNum;
}
else
{
for(int i = 0; i < Device.GetInstalledCount(); i++)
{
Device tmpDev = Device.Open(i);
if (SerialNumber == tmpDev.SerialNum)
try
{
_device = tmpDev;
break;
Device tmpDev = Device.Open(i);
if (SerialNumber == tmpDev.SerialNum)
{
_device = tmpDev;
break;
}
tmpDev.Dispose();
}
catch (Microsoft.AzureKinect.Exception e)
{
log.Warn($"Could not open K4A Device number {i}. The device is probably already in use: {e.Message}");
}
tmpDev.Dispose();
}
}

if (null == _device)
{
string msg = "No available Kinect4Azure device found.";
log.Error(msg);
throw new ConnectionFailedException(msg);
}

if (ActiveChannels.Count == 0)
{
AddToActiveChannels(ChannelNames.Color);
@@ -22,24 +22,18 @@ static void Main(string[] args)
Console.WriteLine("Get MetriCam 2 at http://www.metricam.net/");
Console.WriteLine("------------------------------------------");

Kinect4Azure camera = new Kinect4Azure();
camera.Connect();

Thread thread = new Thread(() =>
{
while (true)
{
camera.Update();
}
});
thread.Start();

camera.DepthMode = Kinect4Azure.K4ADepthMode.WFOV_2x2Binned;

FloatImage fCImg = (FloatImage)camera.CalcChannel(ChannelNames.ZImage);
ProjectiveTransformationRational pTrans = (ProjectiveTransformationRational)camera.GetIntrinsics(ChannelNames.ZImage);
Point3fImage p3fImg = pTrans.ZImageToWorld(fCImg);
p3fImg.Save("G:\\k4a.p3f");
Kinect4Azure camera1 = new Kinect4Azure();
//camera1.SerialNumber = "000067192412";
camera1.Connect();

Kinect4Azure camera2 = new Kinect4Azure();
//camera2.SerialNumber = "000049192312";
camera2.Connect();

camera1.Update();
camera2.Update();
FloatImage fCImg1 = (FloatImage)camera1.CalcChannel(ChannelNames.ZImage);
FloatImage fCImg2 = (FloatImage)camera2.CalcChannel(ChannelNames.ZImage);

Console.WriteLine("Finished. Press any key to exit.");
Console.ReadKey();

0 comments on commit 888e324

Please sign in to comment.
You can’t perform that action at this time.