Ejemplo n.º 1
0
        public KinectCoreV2(ref KinectBase.MasterSettings settings, bool isGUILaunched, int kinectNumber)
        {
            masterSettings = settings;
            dynamic temp = masterSettings.kinectOptionsList[kinectNumber];

            masterKinectSettings = (KinectV2Settings)temp;

            //TODO: Update this to open a specific Kinect v2, if the SDK is ever updated to support multiple on one machine
            kinect   = KinectSensor.GetDefault();
            kinectID = kinectNumber;

            uint tempC = kinect.ColorFrameSource.FrameDescription.LengthInPixels;
            uint tempD = kinect.DepthFrameSource.FrameDescription.LengthInPixels;
            uint tempI = kinect.InfraredFrameSource.FrameDescription.LengthInPixels;

            colorImagePool = new KinectBase.ObjectPool <byte[]>(() => new byte[tempC * 4]);
            depthImagePool = new KinectBase.ObjectPool <byte[]>(() => new byte[tempD * 4]);
            irImagePool    = new KinectBase.ObjectPool <byte[]>(() => new byte[tempI * sizeof(UInt16)]);

            if (isGUILaunched)
            {
                isGUI = true;
                LaunchKinect();
            }
            else
            {
                launchKinectDelegate kinectDelegate = LaunchKinect;
                IAsyncResult         result         = kinectDelegate.BeginInvoke(null, null);
                kinectDelegate.EndInvoke(result);  //Even though this is blocking, the events should be on a different thread now.
            }
        }
Ejemplo n.º 2
0
        //The parent has to be optional to allow for console operation
        public KinectCore(ServerCore mainServer, MainWindow thisParent = null, int?kinectNumber = null)
        {
            if (kinectNumber != null)
            {
                server = mainServer;
                if (server == null)
                {
                    throw new Exception("Server does not exist.");
                }

                parent = thisParent;
                if (parent != null)
                {
                    isGUI = true;
                }

                if (KinectSensor.KinectSensors.Count > kinectNumber)
                {
                    //Get the sensor index in the global list
                    int globalIndex = -1;
                    for (int i = 0; i < KinectSensor.KinectSensors.Count; i++)
                    {
                        if (KinectSensor.KinectSensors[i].DeviceConnectionId == server.serverMasterOptions.kinectOptions[(int)kinectNumber].connectionID)
                        {
                            globalIndex = i;
                            break;
                        }
                    }
                    kinect   = KinectSensor.KinectSensors[globalIndex];
                    kinectID = (int)kinectNumber;
                }
                else
                {
                    throw new System.IndexOutOfRangeException("Specified Kinect sensor does not exist");
                }

                if (isGUI)
                {
                    LaunchKinect();
                }
                else
                {
                    launchKinectDelegate kinectDelegate = LaunchKinect;
                    IAsyncResult         result         = kinectDelegate.BeginInvoke(null, null);
                    kinectDelegate.EndInvoke(result);  //Even though this is blocking, the events should be on a different thread now.
                }
            }
            else
            {
                throw new NullReferenceException("To create a KinectCore object, the KinectNumber must be valid.");
            }
        }
Ejemplo n.º 3
0
        public KinectCoreV1(ref KinectBase.MasterSettings settings, bool isGUILaunched, int?kinectNumber = null)   //Why is the kinectNumber nullable if it is requried later?
        {
            if (kinectNumber != null)
            {
                masterSettings = settings;
                dynamic tempSettings = masterSettings.kinectOptionsList[(int)kinectNumber];  //We have to use dynamic because the type of the Kinect settings in the master list isn't defined until runtime
                masterKinectSettings = (KinectV1Settings)tempSettings;

                //Initialize the object pools
                colorImagePool = new KinectBase.ObjectPool <byte[]>(() => new byte[640 * 480 * 4]);
                depthImagePool = new KinectBase.ObjectPool <byte[]>(() => new byte[640 * 480 * 4]);

                //Note: the kinectNumber could be greater than the number of Kinect v1s if there are other types of sensors in use
                //Therefore, we have to find the correct Kinect, if it exists using this loop
                int globalIndex = -1;
                for (int i = 0; i < KinectSensor.KinectSensors.Count; i++)
                {
                    if (KinectSensor.KinectSensors[i].DeviceConnectionId == masterSettings.kinectOptionsList[(int)kinectNumber].uniqueKinectID)
                    {
                        globalIndex = i;
                        break;
                    }
                }
                if (globalIndex >= 0)
                {
                    kinect   = KinectSensor.KinectSensors[globalIndex];
                    kinectID = (int)kinectNumber;
                }
                else
                {
                    throw new System.IndexOutOfRangeException("Specified Kinect sensor does not exist");
                }

                if (isGUILaunched)
                {
                    isGUI = true;
                    LaunchKinect();
                }
                else
                {
                    launchKinectDelegate kinectDelegate = LaunchKinect;
                    IAsyncResult         result         = kinectDelegate.BeginInvoke(null, null);
                    kinectDelegate.EndInvoke(result);  //Even though this is blocking, the events should be on a different thread now.
                }
            }
            else
            {
                //TODO: Open the default Kinect?
                throw new NullReferenceException("To create a KinectCore object, the KinectNumber must be valid.");
            }
        }