static void Main(string[] args) { Console.WriteLine("------------------------------------------"); Console.WriteLine("MetriCam 2 Minimal Sample."); Console.WriteLine("Get MetriCam 2 at http://www.metricam.net/"); Console.WriteLine("------------------------------------------"); // Create camera object Camera camera; try { camera = new Kinect2(); } catch (Exception e) { Console.WriteLine(Environment.NewLine + "Error: Could not create a PrimeSense camera object."); Console.WriteLine((e.InnerException == null) ? e.Message : e.InnerException.Message); Console.WriteLine("Press any key to exit."); Console.ReadKey(); return; } // Connect, get one frame, disconnect Console.WriteLine("Connecting camera"); camera.Connect(); Console.WriteLine("Fetching one frame"); camera.Update(); try { Console.WriteLine("Accessing color data"); ColorCameraImage img = (ColorCameraImage)camera.CalcChannel(ChannelNames.Color); Bitmap rgbBitmapData = img.ToBitmap(); } catch (ArgumentException ex) { Console.WriteLine(String.Format("Error getting channel {0}: {1}.", ChannelNames.Color, ex.Message)); } try { Console.WriteLine("Accessing distance data"); FloatCameraImage distancesData = (FloatCameraImage)camera.CalcChannel(ChannelNames.Distance); } catch (ArgumentException ex) { Console.WriteLine(String.Format("Error getting channel {0}: {1}.", ChannelNames.Distance, ex.Message)); } Console.WriteLine("Disconnecting camera"); camera.Disconnect(); Console.WriteLine("Finished. Press any key to exit."); Console.ReadKey(); }
static void Main(string[] args) { MetriLog log = new MetriLog(); Kinect2 cam = new Kinect2(); try { cam.Connect(); } catch (MetriCam2.Exceptions.ConnectionFailedException) { log.Error("Connection failed. Closing window in 5 sec."); Thread.Sleep(5 * 1000); return; } cam.ActivateChannel(ChannelNames.Color); bool running = false; while (running) { cam.Update(); } ProjectiveTransformationZhang pt; try { pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color); } catch (FileNotFoundException) { log.Warn("No PT found."); } try { pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color); } catch (FileNotFoundException) { log.Warn("No PT found."); } try { pt = (ProjectiveTransformationZhang)cam.GetIntrinsics(ChannelNames.Color); } catch (FileNotFoundException) { log.Warn("No PT found."); } try { RigidBodyTransformation rbt = cam.GetExtrinsics(ChannelNames.Color, ChannelNames.ZImage); } catch (FileNotFoundException) { log.Warn("No fwd RBT found."); } try { RigidBodyTransformation rbtInverse = cam.GetExtrinsics(ChannelNames.ZImage, ChannelNames.Color); } catch (FileNotFoundException) { log.Warn("No inverse RBT found."); } cam.Disconnect(); log.Info("Program ended. Closing window in 5 sec."); Thread.Sleep(5 * 1000); }