private bool HandleError(OpenNI.Status status) { if (status == OpenNI.Status.OK) { return(true); } System.Windows.Forms.MessageBox.Show("Error: " + status.ToString() + " - " + OpenNI.LastError, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Asterisk); return(false); }
public static bool HandleError(OpenNI.Status status) { if (status == OpenNI.Status.Ok) { return(true); } Console.WriteLine("Error: " + status + " - " + OpenNI.LastError); Console.ReadLine(); return(false); }
private void OpenNI2_StartDepth() { if (!this.bIsDeviceOpened) { MessageBox.Show("Opps! Please open the device first.", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (this.mDevice != null && this.mDevice.IsValid) { if (this.mDevice.HasSensor(Device.SensorType.Depth)) { if (this.mStream == null || !this.mStream.IsValid) { this.mStream = this.mDevice.CreateVideoStream(Device.SensorType.Depth); if (this.mStream == null || !this.mStream.IsValid) { MessageBox.Show("Failed to create depth stream.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return; } } OpenNI.Status status = this.mStream.Start(); if (status != OpenNI.Status.Ok) { string errMsg = string.Format(@"Failed to start depth stream: {0} - {1}", status, OpenNI.LastError); MessageBox.Show(errMsg, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { this.mStream.OnNewFrame += this.OpenNI2_OnNewFrame; } VideoMode mode = this.mStream.VideoMode; this.strVideoMode = string.Format("Depth is now streaming: {0} x {1} @ {2}", mode.Resolution.Width, mode.Resolution.Height, mode.Fps); this.Dispatcher.Invoke((Action)(() => { this.txtDevice.Text = this.strDevice + this.strVideoMode; })); } else { MessageBox.Show("Sorry, the device does not support depth stream.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return; } } else { MessageBox.Show("Sorry, the device is not valid.\nPlease try opening device again.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); return; } }
private void HandleError(OpenNI.Status status) { if (status == OpenNI.Status.Ok) { return; } MessageBox.Show( string.Format(@"Error: {0} - {1}", status, OpenNI.LastError), @"Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
private static bool HandleError(OpenNI.Status status) { if (status == OpenNI.Status.Ok) { return(true); } MessageBox.Show( string.Format("Error: {0} - {1}", status, OpenNI.LastError), @"Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); }
private void OpenNI2_Initialize() { OpenNI.Status status = OpenNI.Initialize(); if (status != OpenNI.Status.Ok) { string errMsg = string.Format(@"Failed to initialize OpenNI2: {0} - {1}", status, OpenNI.LastError); MessageBox.Show(errMsg, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } this.Dispatcher.Invoke((Action)(() => { this.txtDevice.Text = "OpenNI2 Module is ready.\n"; })); }
private bool HandleError(OpenNI.Status status) { if (status == OpenNI.Status.OK) { return(true); } MessageBox.Show( "Error: " + status + " - " + OpenNI.LastError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); }
private static void Main() { Console.WriteLine(OpenNI.Version.ToString()); OpenNI.Status status = OpenNI.Initialize(); if (!HandleError(status)) { Environment.Exit(0); } OpenNI.OnDeviceConnected += OpenNiOnDeviceConnected; OpenNI.OnDeviceDisconnected += OpenNiOnDeviceDisconnected; DeviceInfo[] devices = OpenNI.EnumerateDevices(); if (devices.Length == 0) { return; } Device device; // lean init and no reset flags using (device = Device.Open(null, "lr")) { if (device.HasSensor(Device.SensorType.Depth) && device.HasSensor(Device.SensorType.Color)) { VideoStream depthStream = device.CreateVideoStream(Device.SensorType.Depth); VideoStream colorStream = device.CreateVideoStream(Device.SensorType.Color); if (depthStream.IsValid && colorStream.IsValid) { if (!HandleError(depthStream.Start())) { OpenNI.Shutdown(); return; } if (!HandleError(colorStream.Start())) { OpenNI.Shutdown(); return; } new Thread(DisplayInfo).Start(); depthStream.OnNewFrame += DepthStreamOnNewFrame; colorStream.OnNewFrame += ColorStreamOnNewFrame; VideoStream[] array = { depthStream, colorStream }; while (!Console.KeyAvailable) { VideoStream aS; if (OpenNI.WaitForAnyStream(array, out aS) == OpenNI.Status.Ok) { if (aS.Equals(colorStream)) { inlineColor++; } else { inlineDepth++; } aS.ReadFrame().Release(); } } } } Console.ReadLine(); } OpenNI.Shutdown(); Environment.Exit(0); }
public OpenNI.Status Start() { OpenNI.Status status = VideoStream_start(this.Handle); this.isStarted = status == OpenNI.Status.Ok; return(status); }