Пример #1
0
        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();
        }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        Nuitrack.Init();

        depthSensor = DepthSensor.Create();
        depthSensor.OnUpdateEvent += DepthSensor_OnUpdateEvent;

        skeletonTracker = SkeletonTracker.Create();
        skeletonTracker.OnSkeletonUpdateEvent += SkeletonTracker_OnSkeletonUpdateEvent;

        Nuitrack.Run();
    }
Пример #3
0
        /* 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...");
        }
Пример #4
0
        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();
        }
Пример #5
0
        /// <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();
            }
        }
Пример #6
0
        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();
        }
Пример #7
0
        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));
                }
            }
        }