Пример #1
0
    private FrameSourceTypes GetSourceTypes()
    {
        FrameSourceTypes frameSourceTypes = FrameSourceTypes.None;

        if (useColorInput)
        {
            Debug.Log("Using Color source");
            frameSourceTypes |= FrameSourceTypes.Color;
        }
        if (useDepthInput)
        {
            Debug.Log("Using Depth source");
            frameSourceTypes |= FrameSourceTypes.Depth;
        }
        if (useBodyInput)
        {
            Debug.Log("Using Body source");
            frameSourceTypes |= FrameSourceTypes.Body;
        }
        if (useBodyIndexInput)
        {
            Debug.Log("Using BodyIndex source");
            frameSourceTypes |= FrameSourceTypes.BodyIndex;
        }

        return(frameSourceTypes);
    }
Пример #2
0
 public KinectFrameEventArgs(byte[] framePixels, FrameSourceTypes frameType, IList <Body> bodies, IList <Face> faces)
 {
     this.FrameType   = frameType;
     this.FramePixels = framePixels;
     this.Bodies      = bodies;
     this.Faces       = faces;
 }
Пример #3
0
//////// FPS - END


    private void InitializeDefaultSensor()
    {
        kinectSensor = KinectSensor.GetDefault();
//TODO: Find solution!
        // "GetDefault" returns something even if no Kinect is connected
        if (kinectSensor == null)
        {
            Debug.LogError("ERROR: No Kinect found!");
            return;
        }

        coordinateMapper = kinectSensor.CoordinateMapper;

        kinectSensor.Open();
        if (!kinectSensor.IsOpen)
        {
            Debug.LogError("ERROR: Can't open Kinect!");
            return;
        }

        FrameSourceTypes frameSourceTypes = GetSourceTypes();

        if (frameSourceTypes == FrameSourceTypes.None)
        {
            Debug.LogError("ERROR: No source selected!");
            return;
        }

        multiSourceFrameReader = kinectSensor.OpenMultiSourceFrameReader(frameSourceTypes);
        multiSourceFrameReader.MultiSourceFrameArrived += MultiFrameArrived;

//////// INIT_CHECK - BEGIN
//            init = true;
//////// INIT_CHECK - END
    }
Пример #4
0
        public KinectManager(FrameSourceTypes frameSourceTypes)
        {
            _FrameSourceTypes = frameSourceTypes;

            _KinectSensor = KinectSensor.GetDefault();
            _KinectSensor.IsAvailableChanged += Kinect_IsAvailableChanged;

            if (_FrameSourceTypes.HasFlag(FrameSourceTypes.Color))
            {
                _ColorFrameDescription = _KinectSensor.ColorFrameSource.CreateFrameDescription(ImageFormat);
            }

            if (_FrameSourceTypes.HasFlag(FrameSourceTypes.Depth))
            {
                _DepthFrameDescription = _KinectSensor.DepthFrameSource.FrameDescription;
            }

            if (_FrameSourceTypes.HasFlag(FrameSourceTypes.BodyIndex))
            {
                _BodyIndexFrameDescription = _KinectSensor.BodyIndexFrameSource.FrameDescription;
            }

            _MultiSourceFrameReader = _KinectSensor.OpenMultiSourceFrameReader(_FrameSourceTypes);

            _MultiSourceFrameReader.MultiSourceFrameArrived += FrameReader_MultiSourceFrameArrived;

            InitializeArrays(_KinectSensor.ColorFrameSource.CreateFrameDescription(ImageFormat),
                             _KinectSensor.DepthFrameSource.FrameDescription,
                             _KinectSensor.BodyIndexFrameSource.FrameDescription,
                             _KinectSensor.BodyFrameSource.BodyCount);
        }
Пример #5
0
 public PoseTranslator(AdditionalActions additionalActions)
 {
     //This is just a frankly unnecesary wrapper
     this.Sensor            = KinectSensor.GetDefault();
     sourceTypes            = FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.Infrared | FrameSourceTypes.Body;
     this.additionalActions = additionalActions;
 }
Пример #6
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Sensor
                kinect = KinectSensor.GetDefault();
                kinect.Open();

                // Coordinate Mapper
                coordinateMapper = kinect.CoordinateMapper;

                // Multi Reader
                FrameSourceTypes types = FrameSourceTypes.Color
                                         | FrameSourceTypes.Depth
                                         | FrameSourceTypes.Infrared
                                         | FrameSourceTypes.Body;
                multiFrameReader = kinect.OpenMultiSourceFrameReader(types);
                multiFrameReader.MultiSourceFrameArrived += MultiFrameArrived;

                // Description
                colorFrameDescription = kinect.ColorFrameSource.CreateFrameDescription(colorFormat);
                colorRect             = new Int32Rect(0, 0, colorFrameDescription.Width, colorFrameDescription.Height);
                colorStride           = colorFrameDescription.Width * (int)colorFrameDescription.BytesPerPixel;
                colorBuffer           = new byte[colorFrameDescription.LengthInPixels * colorFrameDescription.BytesPerPixel];

                depthFrameDescription = kinect.DepthFrameSource.FrameDescription;
                depthRect             = new Int32Rect(0, 0, depthFrameDescription.Width, depthFrameDescription.Height);
                depthStride           = depthFrameDescription.Width;
                depthBuffer           = new ushort[depthFrameDescription.LengthInPixels];
                buffer = new byte[depthFrameDescription.LengthInPixels];

                infraredFrameDescription = kinect.InfraredFrameSource.FrameDescription;
                infraredRect             = new Int32Rect(0, 0, infraredFrameDescription.Width, infraredFrameDescription.Height);
                infraredStride           = infraredFrameDescription.Width * (int)infraredFrameDescription.BytesPerPixel;
                infraredBuffer           = new ushort[infraredFrameDescription.LengthInPixels];

                bodies = new Body[kinect.BodyFrameSource.BodyCount];

                // Bitmap
                colorBitmap    = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96, 96, PixelFormats.Bgra32, null);
                depthBitmap    = new WriteableBitmap(depthFrameDescription.Width, depthFrameDescription.Height, 96, 96, PixelFormats.Gray8, null);
                infraredBitmap = new WriteableBitmap(infraredFrameDescription.Width, infraredFrameDescription.Height, 96, 96, PixelFormats.Gray16, null);

                Color.Source    = colorBitmap;
                Depth.Source    = depthBitmap;
                Infrared.Source = infraredBitmap;

                // Kinect Studio
                studio = new KinectStudio();

                // Data Writer
                writer = new DataWriter();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Close();
            }
        }
Пример #7
0
        /// <summary>
        /// Opens the MultiSourceFrameReader
        /// </summary>
        private void OpenMultiReader()
        {
            FrameSourceTypes types = FrameSourceTypes.Body;// for now, Body cannot be disabled.

            if (IsChannelActive(ChannelNames.Distance) || IsChannelActive(ChannelNames.Point3DImage))
            {
                types |= FrameSourceTypes.Depth;
            }
            if (IsChannelActive(ChannelNames.Amplitude))
            {
                types |= FrameSourceTypes.Infrared;
            }
            if (IsChannelActive(ChannelNames.Color))
            {
                types |= FrameSourceTypes.Color;
            }
            if (IsChannelActive(CustomChannelNames.LongExposureIR))
            {
                types |= FrameSourceTypes.LongExposureInfrared;
            }
            if (IsChannelActive(CustomChannelNames.BodyIndex))
            {
                types |= FrameSourceTypes.BodyIndex;
            }
            if (multiReader != null)
            {
                multiReader.IsPaused = true;
                multiReader.Dispose();
                multiReader = null;
                GC.Collect();
            }
            multiReader          = kinectSensor.OpenMultiSourceFrameReader(types);
            multiReader.IsPaused = false;

            if (IsChannelActive(ChannelNames.Color))
            {
                FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.FrameDescription;
                if (null == colorFrameData ||
                    ColorWidth != colorFrameDescription.Width ||
                    ColorHeight != colorFrameDescription.Height)
                {
                    // Color channel is active and has changed
                    ColorWidth          = colorFrameDescription.Width;
                    ColorHeight         = colorFrameDescription.Height;
                    this.colorFrameData = new byte[ColorWidth * ColorHeight * this.bytesPerPixel];
                }
            }
            else
            {
                // Color channel is deactivated
                ColorWidth     = 0;
                ColorHeight    = 0;
                colorFrameData = null;
            }
        }
Пример #8
0
        private void StartKinect()
        {
            if (this.disposed)
            {
                throw new ObjectDisposedException(nameof(KinectSensor));
            }

            this.kinectSensor = Microsoft.Kinect.KinectSensor.GetDefault();
            this.kinectSensor.CoordinateMapper.CoordinateMappingChanged += this.CoordinateMapper_CoordinateMappingChanged;

            this.whichFrames = FrameSourceTypes.None;

            if (this.configuration.OutputBodies)
            {
                this.whichFrames |= FrameSourceTypes.Body;
            }

            if (this.configuration.OutputColor)
            {
                this.whichFrames |= FrameSourceTypes.Color;
            }

            if (this.configuration.OutputDepth)
            {
                this.whichFrames |= FrameSourceTypes.Depth;
            }

            if (this.configuration.OutputInfrared)
            {
                this.whichFrames |= FrameSourceTypes.Infrared;
            }

            if (this.configuration.OutputLongExposureInfrared)
            {
                this.whichFrames |= FrameSourceTypes.LongExposureInfrared;
            }

            if (this.whichFrames != FrameSourceTypes.None)
            {
                this.multiFrameReader = this.kinectSensor.OpenMultiSourceFrameReader(this.whichFrames);
                this.multiFrameReader.MultiSourceFrameArrived += this.MultiFrameReader_FrameArrived;
            }

            if (this.configuration.OutputAudio)
            {
                this.audioBeamFrameReader = this.kinectSensor.AudioSource.OpenReader();
                this.audioBeamFrameReader.FrameArrived += this.AudioBeamFrameReader_FrameArrived;
            }

            this.kinectSensor.Open();
        }
Пример #9
0
        // Token: 0x0600298B RID: 10635 RVA: 0x000D43FC File Offset: 0x000D27FC
        public MultiSourceFrameReader OpenMultiSourceFrameReader(FrameSourceTypes enabledFrameSourceTypes)
        {
            if (this._pNative == IntPtr.Zero)
            {
                throw new ObjectDisposedException("KinectSensor");
            }
            IntPtr intPtr = KinectSensor.Windows_Kinect_KinectSensor_OpenMultiSourceFrameReader(this._pNative, enabledFrameSourceTypes);

            ExceptionHelper.CheckLastError();
            if (intPtr == IntPtr.Zero)
            {
                return(null);
            }
            return(NativeObjectCache.CreateOrGetObject <MultiSourceFrameReader>(intPtr, (IntPtr n) => new MultiSourceFrameReader(n)));
        }
        public FrameController()
        {
            FrameSourceTypes type = FrameSourceTypes.Color;

            dataExtractor = new DataExtractor(type);
            dataExtractor.OnFrameArrived += KinectFrameReceivedEvent;

            this.FrameHeightColor = dataExtractor.FrameHeightColor;
            this.FrameWidthColor  = dataExtractor.FrameWidthColor;
            this.FrameHeightDepth = dataExtractor.FrameHeightDepth;
            this.FrameWidthDepth  = dataExtractor.FrameWidthDepth;

            this.Sensor = dataExtractor.Sensor;

            this.people = new Person[Sensor.BodyFrameSource.BodyCount];

            this.settings = Settings.Instance();
            //this.recModel = Database.LoadModel(CVModelType.PCA_SVM);
        }
Пример #11
0
        public MultiSourceFrameReader OpenMultiSourceFrameReader(
            FrameSourceTypes enabledFrameSourceTypes)
        {
            if (_pNative == RootSystem.IntPtr.Zero)
            {
                throw new RootSystem.ObjectDisposedException("KinectSensor");
            }

            var objectPointer =
                Windows_Kinect_KinectSensor_OpenMultiSourceFrameReader(_pNative, enabledFrameSourceTypes);

            ExceptionHelper.CheckLastError();
            if (objectPointer == RootSystem.IntPtr.Zero)
            {
                return(null);
            }

            return(NativeObjectCache.CreateOrGetObject(objectPointer,
                                                       n => new MultiSourceFrameReader(n)));
        }
        public DataExtractor(FrameSourceTypes type)
        {
            Sensor = KinectSensor.GetDefault();

            if (Sensor != null)
            {
                Sensor.Open();

                FrameWidthColor  = Sensor.ColorFrameSource.FrameDescription.Width;
                FrameHeightColor = Sensor.ColorFrameSource.FrameDescription.Height;
                FrameWidthDepth  = Sensor.InfraredFrameSource.FrameDescription.Width;
                FrameHeightDepth = Sensor.InfraredFrameSource.FrameDescription.Height;

                this.depthFrameDescription    = Sensor.DepthFrameSource.FrameDescription;
                this.infraredFrameDescription = Sensor.InfraredFrameSource.FrameDescription;

                _pixelsColor = new byte[FrameWidthColor * FrameHeightColor * 4];
                _pixelsInfra = new byte[FrameWidthDepth * FrameHeightDepth];
                _pixelsDepth = new byte[FrameWidthDepth * FrameHeightDepth];

                this.frameSourceType = type;

                bodyCountTotal = Sensor.BodyFrameSource.BodyCount;

                this.FaceTrackers = new FaceTracker[bodyCountTotal];
                this._faces       = new Face[bodyCountTotal];
                this._bodies      = new Body[bodyCountTotal];

                for (int i = 0; i < this.bodyCountTotal; i++)
                {
                    this.FaceTrackers[i] = new FaceTracker(Sensor, 0);
                    this.FaceTrackers[i].Source.TrackingIdLost += HdFaceSource_TrackingIdLost;
                    this._faces[i] = new Face();
                }

                _reader = Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.Color | FrameSourceTypes.Infrared | FrameSourceTypes.Depth);
                _reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
            }
        }
Пример #13
0
        /// <summary>
        /// Converts the MultiSourceFrameArrived event to an observable sequence.
        /// </summary>
        /// <param name="kinectSensor">The kinect sensor.</param>
        /// <param name="types">The sources to include in the MultiSourceFrameReader.</param>
        /// <returns>The observable sequence.</returns>
        public static IObservable <MultiSourceFrameArrivedEventArgs> MultiSourceFrameArrivedObservable(this KinectSensor kinectSensor, FrameSourceTypes types = FrameSourceTypes.None)
        {
            if (kinectSensor == null)
            {
                throw new ArgumentNullException("kinectSensor");
            }
            if (types == FrameSourceTypes.None)
            {
                types = FrameSourceTypes.Body | FrameSourceTypes.Color | FrameSourceTypes.Depth;
            }

            return(Observable.Create <MultiSourceFrameArrivedEventArgs>(observer =>
            {
                var reader = kinectSensor.OpenMultiSourceFrameReader(types);

                var disposable = kinectSensor.MultiSourceFrameArrivedObservable(reader)
                                 .Subscribe(x => observer.OnNext(x),
                                            e => observer.OnError(e),
                                            () => observer.OnCompleted());

                return new CompositeDisposable {
                    disposable, reader
                };
            }));
        }
Пример #14
0
 private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_OpenMultiSourceFrameReader(
     RootSystem.IntPtr pNative, FrameSourceTypes enabledFrameSourceTypes);
 public void ChangeFrameType(FrameSourceTypes type)
 {
     dataExtractor.UpdateSettings(type);
 }
Пример #16
0
 /// <summary>
 /// Set up a custom multi source reader who is serving the given frameSourceTypes.
 ///
 /// </summary>
 /// <param name="frameSourceTypes">FrameSourceTypes to deliver.</param>
 public void SetUpCustomMultiSourceReader(FrameSourceTypes frameSourceTypes)
 {
     _customMultireader = _sensor.OpenMultiSourceFrameReader(frameSourceTypes);
     _customMultireader.MultiSourceFrameArrived += OnCustomMultiSourceFrameArrived;
 }
 public void UpdateSettings(FrameSourceTypes type)
 {
     this.frameSourceType = type;
 }