Beispiel #1
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());
        }
    }