public Form1() { try { Nuitrack.Init(""); } catch (System.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(); } catch (System.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; _skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; Nuitrack.onIssueUpdateEvent += onIssueDataUpdate; mode = _depthSensor.GetOutputMode(); 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)); } } InitializeComponent(); }
// Use this for initialization void Start() { Nuitrack.Init(); depthSensor = DepthSensor.Create(); depthSensor.OnUpdateEvent += DepthSensor_OnUpdateEvent; skeletonTracker = SkeletonTracker.Create(); skeletonTracker.OnSkeletonUpdateEvent += SkeletonTracker_OnSkeletonUpdateEvent; Nuitrack.Run(); }
public DTWImplementation(KinectSensor s, SkeletonTracker st) { _dtw = new DtwGestureRecognizer(12, 0.6, 2, 2, 10); _video = new ArrayList(); _skeleton = st; kinect = s; System.IO.FileInfo fi = new System.IO.FileInfo(GestureSaveFileLocation); LoadGesturesFromFile(fi.FullName); s.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(DTWSkeletonReady); Skeleton2DDataExtract.Skeleton2DdataCoordReady += NuiSkeleton2DdataCoordReady; }
public GestureMenuScreen(Rectangle initArea, int init_time, string Title, SkeletonTracker skeleton, Texture2D MenuImg, ScreenManager manager) : base(Title) { this._hitArea = initArea; this._threshold = init_time; this._sensor = skeleton.Kinect; this._skeleton = skeleton; this._img = MenuImg; this._hitboxes = new List<KeyValuePair<GestureMenuEntry,Rectangle>>(); if (this._sensor != null) this._sensor.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(CheckGesture); this._manager = manager; this._timer = new Stopwatch(); this._timer.Start(); this.ScreenManager = manager; }
/* Initialize the Nuitrack Environment */ private void Initialize() { try { Nuitrack.Init(""); } catch (nuitrack.Exception exception) { Console.WriteLine("Cannot initialize Nuitrack."); throw exception; } // Select the device _device = SelectDevice(); // Select video configurations _configVideo = SelectVideoMode(); // Activate the license ActivateDevice(); Nuitrack.SetDevice(_device); // Add modules Sensors _depthSensor = DepthSensor.Create(); _colorSensor = ColorSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); // Add modules Events Handlers _depthSensor.OnUpdateEvent += onDepthSensorUpdate; _colorSensor.OnUpdateEvent += onColorSensorUpdate; _userTracker.OnUpdateEvent += onUserTrackerUpdate; _userTracker.OnNewUserEvent += onUserTrackerNewUser; _userTracker.OnLostUserEvent += onUserTrackerLostUser; _skeletonTracker.OnSkeletonUpdateEvent += onSkeletonUpdate; // Connect to remote _streamer = SelectStreamer(); // Run Nuitrack Nuitrack.Run(); _running = true; Console.WriteLine("Nuitrack is Running..."); }
public static IObservable <SkeletonDataEventArgs> SkeletonDataArrived(SkeletonTracker skeletonTracker) { if (skeletonTracker is null) { return(Observable.Empty <SkeletonDataEventArgs>()); } return(Observable.FromEvent <SkeletonTracker.OnSkeletonUpdate, SkeletonDataEventArgs>(handler => { SkeletonTracker.OnSkeletonUpdate cfaHandler = (x) => { handler(new SkeletonDataEventArgs(x)); }; return cfaHandler; }, cfaHandler => skeletonTracker.OnSkeletonUpdateEvent += cfaHandler, cfaHandler => skeletonTracker.OnSkeletonUpdateEvent -= cfaHandler)); }
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配置和是否进行密钥认证。"); Application.Current.Shutdown(); } 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配置和是否进行密钥认证。"); Application.Current.Shutdown(); } _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配置和是否进行密钥认证。"); Application.Current.Shutdown(); } }
static void Main(string[] args) {//UDP writer for OSC UdpWriter udpWrite = new UdpWriter("127.0.0.1", 7000); try { Nuitrack.Init(""); } catch (Exception exception) { Console.WriteLine("Cannot initialize Nuitrack."); throw exception; } try { // Create and setup all required modules _depthSensor = DepthSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); } catch (Exception exception) { Console.WriteLine("Cannot create Nuitrack module."); Console.WriteLine(exception.Message); throw exception; } // Add event handlers for all modules _depthSensor.OnUpdateEvent += OnDepthSensorUpdate; _userTracker.OnNewUserEvent += OnUserTrackerNewUser; _userTracker.OnLostUserEvent += OnUserTrackerLostUser; _skeletonTracker.OnSkeletonUpdateEvent += OnSkeletonUpdate; // Add an event handler for the IssueUpdate event Nuitrack.onIssueUpdateEvent += OnIssueDataUpdate; try { Nuitrack.Run(); Console.WriteLine(DateTime.Now.ToString()); } catch (Exception exception) { Console.WriteLine("Cannot start Nuitrack."); throw exception; } bool a = true; while (a) { int start = (int)DateTime.Now.TimeOfDay.TotalMilliseconds; // Update Nuitrack data. Data will be synchronized with skeleton time stamps. try { Nuitrack.Update(_skeletonTracker); } catch (LicenseNotAcquiredException exception) { Console.WriteLine(DateTime.Now.ToString()); Console.WriteLine("LicenseNotAcquired exception. Exception: {0}", exception); throw exception; } catch (Exception exception) { Console.WriteLine("Nuitrack update failed. Exception: ", exception); } if (_skeletonData != null) { //Create new bundle for each time skeleton data is refreshed OscBundle bundle = new OscBundle(); //const int jointSize = 10; foreach (var skeleton in _skeletonData.Skeletons) { foreach (var joint in skeleton.Joints) { float[] rotationMatrix = joint.Orient.Matrix; //Ignore joints that are not currently used by Nuitrack if (joint.Type == JointType.None || joint.Type == JointType.LeftFingertip || joint.Type == JointType.RightFingertip || joint.Type == JointType.LeftFoot || joint.Type == JointType.RightFoot) { continue; } //Create new message element for joint containing joint type and rotation matrix OscElement jointMessage = new OscElement("/" + joint.Type, joint.Real.X, joint.Real.Y, joint.Real.Z, rotationMatrix[0], rotationMatrix[1], -1 * rotationMatrix[2], rotationMatrix[3], rotationMatrix[4], -1 * rotationMatrix[5], -1 * rotationMatrix[6], -1 * rotationMatrix[7], rotationMatrix[8]); Console.WriteLine(joint.Real.X + " " + joint.Real.Y + " " + joint.Real.Z); bundle.AddElement(jointMessage); } //Send the message bundle with the data udpWrite.Send(bundle); int difference = delay - start - (int)DateTime.Now.TimeOfDay.TotalMilliseconds; System.Threading.Thread.Sleep(delay); } } } Nuitrack.Release(); Console.ReadLine(); }
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)); } } }