Beispiel #1
0
        /// <summary>
        /// Gets 3D points [units = meters] and calculated pf vector
        /// </summary>
        /// <param name="state">State.</param>
        private void PreparePointCloud(HoloProxies.Engine.trackerState state)
        {
            boundingbox = findBoundingBoxFromCurrentState(state);

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    int idx = i * Width + j;

                    // if point is not in the bounding box
                    if (j < boundingbox.x || j >= boundingbox.z || i < boundingbox.y || i >= boundingbox.w)
                    {
                        // mark as not useful
                        Camera3DPoints[idx].X = 0;
                        Camera3DPoints[idx].Y = 0;
                        Camera3DPoints[idx].Z = 0;
                        PfVec[idx]            = defines.OUTSIDE_BB;
                    }
                    else // if it's inside the box
                    {
                        Color pixel = ColorTexture.GetPixel(j, i);
                        PfVec[idx] = GetPf(pixel);
                        // Draw the bounding box region
                        if (drawBox && OnBoxEdge(j, i))
                        {
                            //ColorTextureVisual.SetPixel( j, i, Color.blue );
                            ColorTextureVisual.SetPixel(j, i, Color.Lerp(pixel, Color.blue, 0.3f));
                        }
                    }
                }
            } //end for
        }
Beispiel #2
0
        /// <summary>
        /// Computes the pf image from histogram. Used for visualization.
        /// </summary>
        public void ComputePfImageFromHistogram()
        {
            float pf = 0;

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    int   idx   = i * Width + j;
                    Color pixel = ColorTexture.GetPixel(j, i);
                    pf = GetPf(pixel);
                    if (pf > 0.8f)
                    {
                        if (!ColorTextureVisual.GetPixel(j, i).Equals(Color.blue))   //&& Mask[idx] == defines.HIST_FG_PIXEL)
                        {
                            ColorTextureVisual.SetPixel(j, i, Color.Lerp(pixel, Color.green, 0.5f));

                            if (Mask[idx] == defines.HIST_FG_PIXEL)
                            {
                                ColorTextureVisual.SetPixel(j, i, Color.Lerp(pixel, Color.cyan, 0.5f));
                            }
                        }
                    }
                    else if (pf == 0.3f)
                    {
                        if (!ColorTextureVisual.GetPixel(j, i).Equals(Color.blue))
                        {
                            //ColorTextureVisual.SetPixel( j, i, Color.Lerp( pixel, Color.yellow, 0.2f ) );
                        }
                    }
                }
            }
            ColorTextureVisual.Apply();
        }
Beispiel #3
0
        /// <summary>
        /// Updates the frame by grabbing the rgb and depth from the Kinnect.
        /// </summary>
        /// <returns><c>true</c>, if frame was successfully updated, <c>false</c> otherwise.</returns>
        /// <param name="state">State.</param>
        public bool UpdateFrame(HoloProxies.Engine.trackerState state)
        {
            bool success = false;

            if (_Reader != null)
            {
                var frame = _Reader.AcquireLatestFrame();
                if (frame != null)
                {
                    //Debug.Log( "in here1" );
                    var colorFrame = frame.ColorFrameReference.AcquireFrame();
                    if (colorFrame != null)
                    {
                        //Debug.Log( "in here2" );
                        var depthFrame = frame.DepthFrameReference.AcquireFrame();
                        if (depthFrame != null)
                        {
                            //Debug.Log( "in here3" );
                            // get color data + texture
                            colorFrame.CopyConvertedFrameDataToArray(ColorData_full, ColorImageFormat.Rgba);

                            // get depth data
                            depthFrame.CopyFrameDataToArray(DepthData_full);

                            // Create a depth texture
                            //int index = 0;
                            //foreach (var ir in DepthData_full)
                            //{
                            //    byte intensity = (byte)(ir >> 8);
                            //    DepthRaw[index++] = intensity;
                            //    DepthRaw[index++] = intensity;
                            //    DepthRaw[index++] = intensity;
                            //    DepthRaw[index++] = 255; // Alpha
                            //}
                            //DepthTexture_full.LoadRawTextureData( DepthRaw );
                            //DepthTexture_full.Apply(); TODO fix this

                            // dispose frame
                            depthFrame.Dispose();
                            depthFrame = null;

                            // Map depth to RGBD
                            AlignRGBD();

                            // Unproject to 3D points in camera space (based on bounding box)
                            UnprojectFrom2Dto3D();

                            // Downsample all data frames if necessary
                            DownsampleAndFilterRGBDImage();

                            // Apply downsampled texture
                            ColorTexture.LoadRawTextureData(ColorData);
                            ColorTextureVisual.LoadRawTextureData(ColorData);

                            // Unproject points to 3D space
                            PreparePointCloud(state);

                            if (plotHistogram)
                            {
                                for (int i = 0; i < HistogramTexture.height; i++)
                                {
                                    for (int j = 0; j < HistogramTexture.width; j++)
                                    {
                                        int idx = i * HistogramTexture.width + j;
                                        HistogramTexture.SetPixel(j, i, new Color(histogram.posterior[idx * 256], 0, 0));
                                    }
                                }
                                HistogramTexture.Apply();
                            }

                            success = true;
                        }
                        colorFrame.Dispose();
                        colorFrame = null;
                    }
                    frame = null;
                }
            }
            return(success);
        }