Exemplo n.º 1
0
        /// <summary>
        /// Function to update a histogram from RGBD at rates rf and rb.
        /// The labeling is done on the frame Mask before this function call.
        /// </summary>
        /// <param name="rf"></param>
        /// <param name="rb"></param>
        public void UpdateHistogramFromLabeledMask(float rf, float rb, Texture2D colorTex, short[] Mask)
        {
            ColorHistogram tmpHist = new ColorHistogram(this.BinsNumber, this.FrameWidth, this.FrameHeight);             // TODO can this be optimzed?

            BuildHistogram(colorTex, Mask);
            this.UpdateHistogram(tmpHist, rf, rb);
        }
Exemplo n.º 2
0
 // Update histogram based on an existing histogram
 /// <summary>
 /// Function to update current HistogramRGB given a new HistogramRGB. However, update it
 /// at a decaying rate. Update the foreground at rf rate and background at rb rate.
 /// </summary>
 public void UpdateHistogram(ColorHistogram newHist, float rf, float rb)
 {
     for (int i = 0; i < dim; i++)
     {
         this.data_normalized [i].x = this.data_normalized [i].x * (1 - rf) + newHist.data_normalized [i].x * rf;
         this.data_normalized[i].y  = this.data_normalized[i].y * (1 - rb) + newHist.data_normalized[i].y * rb;
         this.posterior[i]          = this.data_normalized[i].x / (this.data_normalized[i].x + this.data_normalized[i].y);
     }
 }
Exemplo n.º 3
0
        // Constructor
        public FrameManager()
        {
            _Sensor = KinectSensor.GetDefault();

            if (_Sensor != null)
            {
                _Mapper = _Sensor.CoordinateMapper;

                _Reader = _Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth);

                var depthFrameDesc = _Sensor.DepthFrameSource.FrameDescription;
                DepthWidth     = depthFrameDesc.Width;
                DepthHeight    = depthFrameDesc.Height;
                DepthData_full = new ushort[depthFrameDesc.LengthInPixels];
                DepthData      = new ushort[depthFrameDesc.LengthInPixels / (defines.DOWNSAMPLE * defines.DOWNSAMPLE)];
                //DepthRaw = new byte[depthFrameDesc.LengthInPixels * 4];
                //DepthTexture_full = new Texture2D( DepthWidth, DepthHeight, TextureFormat.RGBA32, false );

                // Set FrameWidth and FrameHeight to the downsampled size
                Width  = DepthWidth / defines.DOWNSAMPLE;
                Height = DepthHeight / defines.DOWNSAMPLE;

                var colorFrameDesc = _Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
                ColorWidth         = colorFrameDesc.Width;
                ColorHeight        = colorFrameDesc.Height;
                ColorData_full     = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels];
                ColorData          = new byte[colorFrameDesc.BytesPerPixel * Width * Height];
                ColorTexture_full  = new Texture2D(ColorWidth, ColorHeight, TextureFormat.RGBA32, false);
                ColorTexture       = new Texture2D(Width, Height, TextureFormat.RGBA32, false);
                ColorTextureVisual = new Texture2D(Width, Height, TextureFormat.RGBA32, false);

                //PfImage = new Texture2D( Width, Height, TextureFormat.RGBA32, false );

                // Set buffers to align depth data to RGB and to align camera points
                ColorPoints_full    = new ColorSpacePoint[depthFrameDesc.LengthInPixels];
                Camera3DPoints_full = new CameraSpacePoint[DepthWidth * DepthHeight];
                Camera3DPoints      = new CameraSpacePoint[Width * Height];
                PfVec = new float[Width * Height];
                Mask  = new short[Width * Height];

                // Save camera intrinsics matrix
                CameraIntrinsics intrinsics = _Mapper.GetDepthCameraIntrinsics();
                K     = new Matrix4x4();
                K.m00 = intrinsics.FocalLengthX / defines.DOWNSAMPLE;
                K.m01 = 0;
                K.m02 = intrinsics.PrincipalPointX / defines.DOWNSAMPLE;
                K.m10 = 0;
                K.m11 = intrinsics.FocalLengthY / defines.DOWNSAMPLE;
                K.m12 = intrinsics.PrincipalPointY / defines.DOWNSAMPLE;
                K.m20 = 0; K.m21 = 0;
                K.m22 = 1.0f;// / defines.DOWNSAMPLE;

                // TODO print K
                Debug.Log("K = " + K);
                Debug.Log("Color Width: " + ColorWidth + " Color Height: " + ColorHeight);
                Debug.Log("Depth Width: " + DepthWidth + " Depth Height: " + DepthHeight);
                Debug.Log(" Width: " + Width + " Height: " + Height);

                // Initialize color histogram
                histogram = new ColorHistogram(defines.HISTOGRAM_NBIN, Width, Height);


                HistogramTexture = new Texture2D(4, 4, TextureFormat.RFloat, false);
                //Debug.Log( HistogramTexture.width );
                //Debug.Log( HistogramTexture.height );
                //Debug.Log( histogram.posterior.Length );

                if (!_Sensor.IsOpen)
                {
                    _Sensor.Open();
                }
            }
        }