Esempio n. 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();
        }
Esempio n. 2
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...");
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
0
    static public void Main()
    {
        Console.CancelKeyPress += new ConsoleCancelEventHandler(consoleEventHandler);
        try
        {
            Nuitrack.Init("");

            // get devices list
            List <NuitrackDevice> devices = Nuitrack.GetDeviceList();
            if (devices.Count == 0)
            {
                throw new nuitrack.Exception("No devices found.");
            }

            // print available devices
            Console.Write("\nAvailable devices:\n");
            for (int i = 0; i < devices.Count; i++)
            {
                Console.WriteLine("    [{0}] {1} ({2}), License: {3}",
                                  i,
                                  devices[i].GetInfo(DeviceInfoType.SERIAL_NUMBER),
                                  devices[i].GetInfo(DeviceInfoType.DEVICE_NAME),
                                  ToString(devices[i].GetActivationStatus()));
            }
            // select a device
            int            devIndex = UserInteraction.AskInt("\nSelect the device number: ", 0, devices.Count);
            NuitrackDevice device   = devices[devIndex];

            // select video modes
            selectDeviceVideoMode(device, StreamType.DEPTH);
            selectDeviceVideoMode(device, StreamType.COLOR);

            // activate selected device
            bool isActivated = Convert.ToBoolean(device.GetActivationStatus());
            if (isActivated)
            {
                isActivated = !UserInteraction.Confirm("The device is already activated. Do you want to reactivate it?");
            }

            if (!isActivated)
            {
                string activationKey = UserInteraction.AskString("Enter the activation key: ");
                device.Activate(activationKey);
                Console.WriteLine("Activation status: {0}", ToString(device.GetActivationStatus()));
            }

            // set device and run Nuitrack
            if (UserInteraction.Confirm("Do you want to run Nuitrack with the selected device?"))
            {
                Nuitrack.SetDevice(device);

                DepthSensor depthSensor = DepthSensor.Create();
                ColorSensor colorSensor = ColorSensor.Create();

                depthSensor.OnUpdateEvent += onDepthSensorUpdate;
                colorSensor.OnUpdateEvent += onColorSensorUpdate;

                Nuitrack.Run();
                _run = true;

                while (!_finished)
                {
                    Nuitrack.WaitUpdate(depthSensor);
                }

                colorSensor.OnUpdateEvent -= onColorSensorUpdate;
                depthSensor.OnUpdateEvent -= onDepthSensorUpdate;
            }

            Nuitrack.Release();
        }
        catch (nuitrack.Exception exception)
        {
            Console.WriteLine("Error: " + exception.ToString());
        }
    }
Esempio n. 6
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));
                }
            }
        }