public override Frame Process(Frame frame, FrameSource frameSource, FramesReleaser releaser)
 {
     lock (_lock)
     {
         using (var frameset = FrameSet.FromFrame(frame))
         {
             using (var depth = frameset.DepthFrame)
             {
                 using (var texture = frameset.FirstOrDefault <VideoFrame>(_textureStream))
                 {
                     _videoStreamFilter[depth.Profile.Stream].CopyProfile(depth);
                     _videoStreamFilter[texture.Profile.Stream].CopyProfile(texture);
                     if (_currVideoStreamFilter.Count == 0 ||
                         !_currVideoStreamFilter[depth.Profile.Stream].Equals(_videoStreamFilter[depth.Profile.Stream]) ||
                         !_currVideoStreamFilter[texture.Profile.Stream].Equals(_videoStreamFilter[texture.Profile.Stream]))
                     {
                         ResetProcessingBlock();
                         _currVideoStreamFilter[depth.Profile.Stream]   = new RsVideoStreamRequest(depth);
                         _currVideoStreamFilter[texture.Profile.Stream] = new RsVideoStreamRequest(texture);
                     }
                     var points = _pb.Calculate(depth, releaser);
                     _pb.MapTexture(texture);
                     return(frameSource.AllocateCompositeFrame(releaser, depth, points).AsFrame());
                 }
             }
         }
     }
 }
    //object l = new object();
    private void OnFrames(FrameSet frames)
    {
        using (var aligned = aligner.Process(frames))
        {
            using (var colorFrame = aligned.ColorFrame)
                using (var depthFrame = aligned.DepthFrame)
                {
                    if (depthFrame == null)
                    {
                        Debug.Log("No depth frame in frameset, can't create point cloud");
                        return;
                    }

                    if (!UpdateParticleParams(depthFrame.Width, depthFrame.Height))
                    {
                        Debug.Log("Unable to craete point cloud");
                        return;
                    }

                    using (var points = pc.Calculate(depthFrame))
                    {
                        setParticals(points, colorFrame);
                    }
                }
        }
    }
Esempio n. 3
0
 /// <summary>
 /// 將深度與彩色影像直接轉換成點雲並輸出.ply檔
 /// </summary>
 internal void DepthToPLY(VideoFrame color, DepthFrame depth)
 {
     using (PointCloud pc = new PointCloud())
     {
         pc.MapTexture(color);                       // Tell pointcloud object to map to this color frame
         using (Points points = pc.Calculate(depth)) // Generate the pointcloud and texture mappings
             points.ExportToPLY("C:/Users/EL125/Desktop/testest.ply", color);
     }
 }
    private void OnFrame(Frame frame)
    {
        if (frame.Profile.Stream != Stream.Depth)
        {
            return;
        }
        var depthFrame = frame as DepthFrame;

        if (!UpdateParticleParams(depthFrame.Width, depthFrame.Height))
        {
            Debug.Log("Unable to craete point cloud");
            return;
        }

        using (var points = pc.Calculate(depthFrame))
        {
            setParticals(points, null);
        }
    }
    private void OnFrame(FrameSet frameset)
    {
        //Align depth frame to color frame
        using (FrameSet aligned = aligner.Process(frameset))
        {
            //DepthFrame
            depthFrame = aligned.Where(f => f.Profile.Stream == Stream.Depth).First() as DepthFrame;

            if (depthFrame == null)
            {
                Debug.Log("depth frame is null");
                return;
            }

            //ColorFrame
            vidFrame = aligned.Where(f => f.Profile.Stream == Stream.Color).First() as VideoFrame;

            if (vidFrame == null)
            {
                Debug.Log("color frame is null");
                return;
            }

            UpdateParticleParams(depthFrame.Width, depthFrame.Height, depthFrame.Profile.Format);

            //CoordinateData
            var points = pc.Calculate(depthFrame);
            vertices = vertices ?? new Points.Vertex[points.Count];
            points.CopyTo(vertices);

            //ColorData
            colorData = colorData ?? new byte[vidFrame.Stride * vidFrame.Height];
            vidFrame.CopyTo(colorData);

            for (int index = 0; index < particleSize; index += skipParticles)
            {
                var v = vertices[index];

                if (v.z > 0)
                {
                    particles[index].position   = new Vector3(v.x, v.y, v.z);
                    particles[index].startSize  = pointsSize;
                    particles[index].startColor = new Color32(colorData[index * 3], colorData[index * 3 + 1], colorData[index * 3 + 2], 255);
                }

                else
                {
                    particles[index].position   = new Vector3(0, 0, 0);
                    particles[index].startSize  = (float)0.0;
                    particles[index].startColor = new Color32(0, 0, 0, 0);
                }
            }
        }
    }
    private void OnFrame(FrameSet frameset)
    {
        using (FrameSet aligned = aligner.Process(frameset))
        {
            //Depth
            depthFrame = aligned.Where(f => f.Profile.Stream == Stream.Depth).First() as DepthFrame;

            //Color
            vidFrame = aligned.Where(f => f.Profile.Stream == Stream.Color).First() as VideoFrame;


            if (depthFrame == null || vidFrame == null)
            {
                // Debug.Log("Frame is not a depth frame");
                return;
            }

            UpdateParticleParams(depthFrame.Width, depthFrame.Height, depthFrame.Profile.Format);

            var points = pc.Calculate(depthFrame);

            //Depth
            vertices = vertices ?? new Points.Vertex[points.Count];
            points.CopyTo(vertices);

            //Color
            byteColorData = byteColorData ?? new byte[vidFrame.Stride * vidFrame.Height];
            vidFrame.CopyTo(byteColorData);

            for (int index = 0; index < particleSize; index += skipParticles)
            {
                var v = vertices[index];

                if (v.z > 0)
                {
                    particles[index].position  = new Vector3(v.x, v.y, v.z);
                    particles[index].startSize = pointsSize;
                    //particles[index].startColor = gradient.Evaluate(v.z);
                    particles[index].startColor = new Color32(byteColorData[index * 3], byteColorData[index * 3 + 1], byteColorData[index * 3 + 2], 255);
                }

                /*
                 * else
                 * {
                 *  particles[index].position = new Vector3(0, 0, 0);
                 *  particles[index].startSize = (float)0.0;
                 *  particles[index].startColor = new Color32(0, 0, 0, 0);
                 * }
                 */
            }
        }
    }
Esempio n. 7
0
    void onNewSampleSetThreading(FrameSet frameSet)
    {
        using (FrameSet aligned = aligner.Process(frameSet)){
            VideoFrame vidFrame   = aligned.Where(x => x.Profile.Stream == Stream.Color).First() as VideoFrame;
            Frame      depthFrame = aligned.Where(x => x.Profile.Stream == Stream.Depth).First();


            byteColorData = byteColorData ?? new byte[vidFrame.Stride * vidFrame.Height];
            vidFrame.CopyTo(byteColorData);
            uintColorData = Array.ConvertAll(byteColorData, x => (uint)x);

            var points = pointCloud.Calculate(depthFrame);
            vertices = vertices ?? new Points.Vertex[dataLength];
            points.CopyTo(vertices);
        }
    }
Esempio n. 8
0
    private void OnFrames(FrameSet frames)
    {
        using (var depthFrame =
                   holeFilling.ApplyFilter(
                       temporal.ApplyFilter(
                           spatial.ApplyFilter(
                               frames.DepthFrame))))
            using (var points = pc.Calculate(depthFrame))
                using (var f = frames.FirstOrDefault <VideoFrame>(stream))
                {
                    pc.MapTexture(f);
                    memcpy(verticesPtr, points.VertexData, points.Count * 3 * sizeof(float));

                    e.Set();
                }
    }
Esempio n. 9
0
    private void OnFrames(FrameSet frames)
    {
        using (var depthFrame = frames.DepthFrame)
            using (var points = pc.Calculate(depthFrame))
                using (var f = frames.FirstOrDefault <VideoFrame>(stream))
                {
                    pc.MapTexture(f);

                    memcpy(verticesPtr, points.VertexData, points.Count * 3 * sizeof(float));

                    frameSize = depthFrame.Width * depthFrame.Height * 2 * sizeof(float);
                    if (frameData == IntPtr.Zero)
                    {
                        frameData = Marshal.AllocHGlobal(frameSize);
                    }
                    memcpy(frameData, points.TextureData, frameSize);

                    e.Set();
                }
    }
Esempio n. 10
0
    private void OnFrame(Frame frame)
    {
        if (frame.Profile.Stream == Intel.RealSense.Stream.Depth)
        {
            var depthFrame = frame as DepthFrame;
            if (depthFrame == null)
            {
                Debug.Log("Frame is not a depth frame");
                return;
            }

            UpdateParticleParams(depthFrame.Width, depthFrame.Height, depthFrame.Profile.Format);

            var points = pc.Calculate(frame);

            Points.Vertex[] vertices = new Points.Vertex[points.Count];
            points.CopyTo(vertices);
            for (int index = 0; index < vertices.Length; index += skipParticles)
            {
                var v = vertices[index];
                if (v.z > 0)
                {
                    particles[index].position   = new Vector3(v.x, v.y, v.z);
                    particles[index].startSize  = pointsSize;
                    particles[index].startColor = gradient.Evaluate(v.z);
                }
                else
                {
                    particles[index].position   = new Vector3(0, 0, 0);
                    particles[index].startSize  = (float)0.0;
                    particles[index].startColor = new Color32(0, 0, 0, 0);
                }
            }
        }
        else if (frame.Profile.Stream == Intel.RealSense.Stream.Color)
        {
            //pc.MapTexture(frame);
        }
    }
    private void OnFrames(FrameSet frames)
    {
        if (frames.DepthFrame == null)
        {
            Debug.Log("No depth frame in frameset, can't create point cloud");
            return;
        }

        if (!UpdateParticleParams(frames.DepthFrame.Width, frames.DepthFrame.Height))
        {
            Debug.Log("Unable to craete point cloud");
            return;
        }

        using (var points = pc.Calculate(frames.DepthFrame))
        {
            if (frames.ColorFrame != null)
            {
                if (frames.ColorFrame.BitsPerPixel == 24)
                {
                    pc.MapTexture(frames.ColorFrame);
                    colorFrameWidth  = frames.ColorFrame.Width;
                    colorFrameHeight = frames.ColorFrame.Height;
                    var newSize = frames.ColorFrame.Stride * colorFrameHeight;
                    lock (l)
                    {
                        if (lastColorImage == null || lastColorImage.Length != newSize)
                        {
                            lastColorImage = new byte[newSize];
                        }

                        frames.ColorFrame.CopyTo(lastColorImage);
                    }
                }
            }
            pointsQueue.Enqueue(points);
        }
    }