private void ButtonClick(object sender, EventArgs e) { handTracker = HandTracker.Create(); btn_start.Enabled = false; HandleError(handTracker.StartGestureDetection(GestureData.GestureType.HandRaise)); handTracker.OnNewData += HandTrackerOnNewData; }
private void ButtonClick(object sender, EventArgs e) { this.handTracker = HandTracker.Create(); this.btn_start.Enabled = false; HandleError(this.handTracker.StartGestureDetection(GestureData.GestureType.HandRaise)); this.handTracker.OnNewData += this.HandTrackerOnNewData; // FIXED Jun 2013 // * Because of incompatibility between current version of OpenNI and NiTE, // * we can't use event based reading. So we put our sample in a loop. // * You can copy OpenNI.dll from version 2.0 to solve this problem. // * Then you can uncomment above line of code and comment below ones. // */ // while (this.IsHandleCreated) // { // hTracker_onNewData(hTracker); // Application.DoEvents(); // } }
public MainForm() { // Initialize Nuitrack. This should be called before using any Nuitrack module. // By passing the default arguments we specify that Nuitrack must determine // the location automatically. try { Nuitrack.Init(""); } catch (Exception exception) { Console.WriteLine("Cannot initialize Nuitrack."); throw exception; } try { // Create and setup all required modules _depthSensor = DepthSensor.Create(); _colorSensor = ColorSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); _handTracker = HandTracker.Create(); _gestureRecognizer = GestureRecognizer.Create(); } catch (Exception exception) { Console.WriteLine("Cannot create Nuitrack module."); throw exception; } //_depthSensor.SetMirror(false); // Add event handlers for all modules _depthSensor.OnUpdateEvent += onDepthSensorUpdate; _colorSensor.OnUpdateEvent += onColorSensorUpdate; _userTracker.OnUpdateEvent += onUserTrackerUpdate; _userTracker.OnNewUserEvent += onUserTrackerNewUser; _userTracker.OnLostUserEvent += onUserTrackerLostUser; _skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; _handTracker.OnUpdateEvent += onHandTrackerUpdate; _gestureRecognizer.OnNewGesturesEvent += onNewGestures; // Add an event handler for the IssueUpdate event Nuitrack.onIssueUpdateEvent += onIssueDataUpdate; // Create and configure the Bitmap object according to the depth sensor output mode OutputMode mode = _depthSensor.GetOutputMode(); OutputMode colorMode = _colorSensor.GetOutputMode(); if (mode.XRes < colorMode.XRes) { mode.XRes = colorMode.XRes; } if (mode.YRes < colorMode.YRes) { mode.YRes = colorMode.YRes; } _bitmap = new DirectBitmap(mode.XRes, mode.YRes); for (int y = 0; y < mode.YRes; ++y) { for (int x = 0; x < mode.XRes; ++x) { _bitmap.SetPixel(x, y, Color.FromKnownColor(KnownColor.Aqua)); } } // Set fixed form size this.MinimumSize = this.MaximumSize = new Size(mode.XRes, mode.YRes); // Disable unnecessary caption bar buttons this.MinimizeBox = this.MaximizeBox = false; // Enable double buffering to prevent flicker this.DoubleBuffered = true; // Run Nuitrack. This starts sensor data processing. try { Nuitrack.Run(); } catch (Exception exception) { Console.WriteLine("Cannot start Nuitrack."); throw exception; } this.Show(); }
/// <summary> ///3D扫描的构造函数 -byCQZ 2019.6.16 /// /// </summary> private void NuitrackCreate() { try { Nuitrack.Init(""); Console.WriteLine("Initialize succneed."); } catch (nuitrack.Exception exception) { Console.WriteLine("Cannot initialize Nuitrack."); //throw exception; MessageBoxX.Warning("3D摄像头初始化失败,请检查SDK配置和是否进行密钥认证。"); } try { // Create and setup all required modules _depthSensor = DepthSensor.Create(); _colorSensor = ColorSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); _handTracker = HandTracker.Create(); _gestureRecognizer = GestureRecognizer.Create(); } catch (nuitrack.Exception exception) { Console.WriteLine("Cannot create Nuitrack module."); //throw exception; MessageBoxX.Warning("3D摄像头初始化失败,请检查SDK配置和是否进行密钥认证。"); } _depthSensor.SetMirror(false); // Add event handlers for all modules _depthSensor.OnUpdateEvent += onDepthSensorUpdate; _colorSensor.OnUpdateEvent += onColorSensorUpdate; _userTracker.OnUpdateEvent += onUserTrackerUpdate; _skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; _handTracker.OnUpdateEvent += onHandTrackerUpdate; _gestureRecognizer.OnNewGesturesEvent += onNewGestures; // Add an event handler for the IssueUpdate event Nuitrack.onIssueUpdateEvent += onIssueDataUpdate; // Create and configure the Bitmap object according to the depth sensor output mode OutputMode mode = _depthSensor.GetOutputMode(); OutputMode colorMode = _colorSensor.GetOutputMode(); if (mode.XRes < colorMode.XRes) { mode.XRes = colorMode.XRes; } if (mode.YRes < colorMode.YRes) { mode.YRes = colorMode.YRes; } Console.WriteLine(mode.XRes + "=====================" + mode.YRes); _bitmap = new DirectBitmap(mode.XRes, mode.YRes); for (int y = 0; y < mode.YRes; ++y) { for (int x = 0; x < mode.XRes; ++x) { _bitmap.SetPixel(x, y, Color.FromKnownColor(KnownColor.Aqua)); } } try { Nuitrack.Run(); Console.WriteLine("Start Nuitrack."); } catch (nuitrack.Exception exception) { Console.WriteLine("Cannot start Nuitrack."); //throw exception; MessageBoxX.Warning("3D摄像头启动失败,请检查SDK配置和是否进行密钥认证。"); } }
private bool Start() { RegisterFilter(); if (_isIdle && _broadcaster.HasServer()) { MessageBox.Show( @"Only one server is allowed.", @"Multi-Server", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } var isSameDevice = _currentDevice != null && _currentDevice.IsValid && _currentDevice.DeviceInfo.Uri == Settings.Default.DeviceURI; var isSameSensor = isSameDevice && _currentSensor != null && _currentSensor.IsValid && _currentSensor.SensorInfo.GetSensorType() == (Device.SensorType)Settings.Default.CameraType; if (!isSameDevice) { if (Settings.Default.DeviceURI == string.Empty) { _currentDevice = null; MessageBox.Show( @"Please select a device to open and then click Apply.", @"Device Open", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } if (!isSameSensor) { if (Settings.Default.CameraType == -1) { _currentDevice = null; MessageBox.Show( @"Please select a sensor to open and then click Apply.", @"Sensor Create", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } } if (!isSameDevice) { try { _currentDevice = Device.Open(Settings.Default.DeviceURI); } catch (Exception ex) { _currentDevice = null; MessageBox.Show( string.Format("Can not open selected Device. {0}", ex.Message), @"Device Open", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } if (!isSameSensor) { try { _currentSensor = _currentDevice.CreateVideoStream((Device.SensorType)Settings.Default.CameraType); _currentSensor.OnNewFrame += CurrentSensorOnNewFrame; } catch (Exception ex) { _currentSensor = null; MessageBox.Show( string.Format("Can not open selected Sensor from selected Device. {0}", ex.Message), @"Sensor Create", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { _currentSensor.Stop(); } var videoModes = _currentSensor.SensorInfo.GetSupportedVideoModes().ToArray(); VideoMode selectedVideoMode = null; switch (_currentSensor.SensorInfo.GetSensorType()) { case Device.SensorType.Color: _renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb; if (Settings.Default.Color_HD) { foreach (var vm in videoModes) { if (vm.Resolution.Width == 1280 && (vm.Resolution.Height == 960 || vm.Resolution.Height == 1024)) { if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat) && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422) { selectedVideoMode = vm; } } } _isHd = selectedVideoMode != null; if (!_isHd) { MessageBox.Show( @"This device doesn't support ~1.3MP resolution.", @"HD Resolution", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (selectedVideoMode == null) { foreach (var vm in videoModes) { if (vm.Resolution.Width == 640 && vm.Resolution.Height == 480) { if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat) && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422) { selectedVideoMode = vm; } } } } break; case Device.SensorType.Depth: _renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb | VideoFrameRef.CopyBitmapOptions.DepthFillShadow; if (Settings.Default.Depth_Fill) { if (cb_mirror.Enabled && cb_mirror.Checked) { _renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthFillRigthBlack; } else { _renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthFillLeftBlack; } } if (Settings.Default.Depth_Invert) { _renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthInvert; } if (Settings.Default.Depth_Histogram) { _renderOptions |= VideoFrameRef.CopyBitmapOptions.DepthHistogramEqualize; } foreach (var vm in videoModes) { if (vm.Resolution.Width == 640 && vm.Resolution.Height == 480) { if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps) && (vm.DataPixelFormat == VideoMode.PixelFormat.Depth1Mm || vm.DataPixelFormat == VideoMode.PixelFormat.Depth100Um)) { selectedVideoMode = vm; } } } break; case Device.SensorType.Ir: _renderOptions = VideoFrameRef.CopyBitmapOptions.Force24BitRgb; foreach (var vm in videoModes) { if (vm.Resolution.Width == 640 && vm.Resolution.Height == 480) { if ((selectedVideoMode == null || selectedVideoMode.Fps < vm.Fps && vm.DataPixelFormat < selectedVideoMode.DataPixelFormat) && vm.DataPixelFormat != VideoMode.PixelFormat.Jpeg && vm.DataPixelFormat != VideoMode.PixelFormat.Yuv422) { selectedVideoMode = vm; } } } break; } if (selectedVideoMode != null) { try { if (_currentSensor.VideoMode.Fps != selectedVideoMode.Fps || _currentSensor.VideoMode.DataPixelFormat != selectedVideoMode.DataPixelFormat || _currentSensor.VideoMode.Resolution.Width != selectedVideoMode.Resolution.Width || _currentSensor.VideoMode.Resolution.Height != selectedVideoMode.Resolution.Height) { _currentSensor.VideoMode = selectedVideoMode; } } catch (Exception ex) { MessageBox.Show( string.Format("Can not set active video mode to {0}. {1}", selectedVideoMode, ex.Message), @"Sensor Config", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { MessageBox.Show( @"No acceptable video mode found.", @"Sensor Config", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } _softMirror = Settings.Default.Mirroring; if (Settings.Default.SmartCam) { try { if (!isSameDevice || _userTracker == null || _handTracker == null || !_userTracker.IsValid || !_handTracker.IsValid) { _userTracker = UserTracker.Create(_currentDevice); _handTracker = HandTracker.Create(_currentDevice); _handTracker.StartGestureDetection(GestureData.GestureType.HandRaise); _handTracker.OnNewData += NiTeOnNewData; } } catch { // ignored } } if (!HandleError(_currentSensor.Start())) { Stop(false); return(false); } btn_stopstart.Text = @"Stop Streaming"; _isIdle = false; notify.Visible = true; return(true); }
public MainWindow() { InitializeComponent(); try { Nuitrack.Init(); } catch (nuitrack.Exception exception) { Debug.WriteLine("Can not initialize Nuitrack. Exception: ", exception); } try { // Create and setup all required modules _depthSensor = DepthSensor.Create(); _colorSensor = ColorSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); _handTracker = HandTracker.Create(); _gestureRecognizer = GestureRecognizer.Create(); } catch (nuitrack.Exception exception) { Debug.WriteLine("Cannot create Nuitrack module."); throw exception; } // Add event handlers for all modules _depthSensor.OnUpdateEvent += onDepthSensorUpdate; _colorSensor.OnUpdateEvent += onColorSensorUpdate; _userTracker.OnUpdateEvent += onUserTrackerUpdate; _skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; _handTracker.OnUpdateEvent += onHandTrackerUpdate; _gestureRecognizer.OnNewGesturesEvent += onNewGestures; // Add an event handler for the IssueUpdate event Nuitrack.onIssueUpdateEvent += onIssueDataUpdate; // Create and configure the Bitmap object according to the depth sensor output mode OutputMode mode = _depthSensor.GetOutputMode(); OutputMode colorMode = _colorSensor.GetOutputMode(); if (mode.XRes < colorMode.XRes) { mode.XRes = colorMode.XRes; } if (mode.YRes < colorMode.YRes) { mode.YRes = colorMode.YRes; } _bitmap = new DirectBitmap(mode.XRes, mode.YRes); for (int y = 0; y < mode.YRes; ++y) { for (int x = 0; x < mode.XRes; ++x) { _bitmap.SetPixel(x, y, System.Drawing.Color.FromKnownColor(KnownColor.Aqua)); } } }