public static void Main(string[] args) { try { OpenNI.Initialize(); device = Device.Open(Device.AnyDevice); depthStream = device.CreateVideoStream(Device.SensorType.Depth); depthStream.VideoMode = new VideoMode { DataPixelFormat = VideoMode.PixelFormat.Depth1Mm, Fps = 30, Resolution = new Size(640, 480) }; colorStream = device.CreateVideoStream(Device.SensorType.Color); colorStream.VideoMode = new VideoMode { DataPixelFormat = VideoMode.PixelFormat.Rgb888, Fps = 30, Resolution = new Size(640, 480) }; device.DepthColorSyncEnabled = true; depthStream.Start(); colorStream.Start(); device.ImageRegistration = Device.ImageRegistrationMode.DepthToColor; Console.WriteLine("Image registration is active and working well."); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Press enter to exit."); Console.ReadLine(); if (device != null) { device.Close(); } OpenNI.Shutdown(); }
public KinectOpenNi2() { HandleError(OpenNI.Initialize()); DeviceInfo[] devices = OpenNI.EnumerateDevices(); if (devices.Length == 0) HandleError(OpenNI.Status.NO_DEVICE); kinectDevice = devices[0].OpenDevice(); colorSensor = kinectDevice.CreateVideoStream(Device.SensorType.COLOR); VideoMode[] videoModes = colorSensor.SensorInfo.getSupportedVideoModes(); colorSensor.VideoMode = videoModes[1]; colorSensor.Start(); colorSensor.onNewFrame += new VideoStream.VideoStreamNewFrame(colorSensor_onNewFrame); depthSensor = kinectDevice.CreateVideoStream(Device.SensorType.DEPTH); videoModes = depthSensor.SensorInfo.getSupportedVideoModes(); depthSensor.VideoMode = videoModes[0]; depthSensor.Start(); depthSensor.onNewFrame += new VideoStream.VideoStreamNewFrame(depthSensor_onNewFrame); }