<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using D435 sensor : Mapping coordinates from color to depth  after aligning frames in Items with no label</title>
    <link>https://community.intel.com/t5/Items-with-no-label/Using-D435-sensor-Mapping-coordinates-from-color-to-depth-after/m-p/687085#M16147</link>
    <description>&lt;P&gt;Camera: D435 &lt;/P&gt;&lt;P&gt;OS: Windows 10 &lt;/P&gt;&lt;P&gt;language: C# &lt;/P&gt;&lt;P&gt;I had been successfully using a program with SR300 which I'm now migrating to support D435 sensor only with latest SDK. The older SDK had some methods to map coordinates from optical to depth which I cant find in the new SDK. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However with the limited C# samples available I can see there is a way of aligning color and depth frames. However the aligned frame seems to be a VideoFrame and not DepthFrame. With DepthFrame I could do use the CopyTo function to access depth values by iterating through the pixels. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering how can I similarly access depth values from a the aligned Videoframe. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My progressing code is below - which works fine without aligning frames, but then I cant find a way to map a pixel from color to its depth equivalent. Also for some reason if I use the align filter, the frames just freeze ) guess one of the native calls throw an error ) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note Q1 &amp;amp; Q2 in commented code below. Any help will be greatly appreciated. Thank you. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;CODE&gt;var token = tokenSource.Token;
        ushort[] depthdata = new ushort[640 * 480];
        var t = Task.Factory.StartNew(() =&amp;gt;
        {
            while (!token.IsCancellationRequested)
            {
                //// We use the frames that are captured from live camera as the input data for the SW device
                using (var frames = pipeline.WaitForFrames())
                {
                    var depthFrame = frames.DepthFrame.DisposeWith(frames);
                    var colorFrame = frames.ColorFrame.DisposeWith(frames);
                    sync.SubmitFrame(depthFrame);
                    sync.SubmitFrame(colorFrame);
                }
                // Dispaly the frames that come from the SW device after synchronization
                using (var new_frames = sync.WaitForFrames())
                {
                    if (new_frames.Count == 2)
                    {
                        new_frames.ApplyFilter(align); // Q1: This results in freeze after few seconds. 
                        var depthFrame = new_frames.DepthFrame.DisposeWith(new_frames);
                        var colorFrame = new_frames.ColorFrame.DisposeWith(new_frames);
                        // VideoFrame colorizedDepth = colorizer.Process(depthFrame).As&amp;lt;VideoFrame&amp;gt;().DisposeWith(new_frames);
                        depthFrame.CopyTo(depthdata);
                        //  var colorizedDepth = frames[Intel.RealSense.Stream.Depth, Format.Rgb8].As&amp;lt;VideoFrame&amp;gt;().DisposeWith(frames);
                        // colorizedDepth.CopyTo(depthdata);  // Q2: What should be size of depthdata array here ( Stride * Height ?) OR ( Width * height ) and how can i iterate through it to access z values ? 
                        WriteableBitmap colorizedDepthImage;
                        unsafe
                        {
                            //D435 - get access to data and then see the followin convertion to dataptr
                            _calibrationData.angleCameraTorsoRadians = 0.43;
                            fixed (ushort* dataptr = depthdata)
                            {
                                // MAIN OPERATION On DEPTH Data here ..// 
                                //measurer.Measure(dataptr, regions, _calibrationData);
                            }
                            fixed (ushort* dataptr = depthdata)
                            {
                                // Colorize Depth Image for Display ( this is for SR300 where I programmed the colors myself for depth ) 
                                colorizedDepthImage = _colorizer.GetColorizedBitmap(dataptr);
                                var depthStream = GetPngStream(colorizedDepthImage);
                            }
                            //For capturing Color stream as well 
                            var bytes = new byte[colorFrame.Stride * colorFrame.Height];
                            colorFrame.CopyTo(bytes);
                            // .... Mode code here // 
                            //Raise events to notify UI
                            RaiseFrameProcessedEvent(new ProcessedFrame(depthStream, regions, _calibrationData));
                            RaiseColorFrameAvailableEvent(new ColorFrame(colorStream));
                            depthStream.Dispose();
                        }
                    }
                }
            }
        }, token);&lt;/CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2019 13:53:56 GMT</pubDate>
    <dc:creator>MCC001</dc:creator>
    <dc:date>2019-03-21T13:53:56Z</dc:date>
    <item>
      <title>Using D435 sensor : Mapping coordinates from color to depth  after aligning frames</title>
      <link>https://community.intel.com/t5/Items-with-no-label/Using-D435-sensor-Mapping-coordinates-from-color-to-depth-after/m-p/687085#M16147</link>
      <description>&lt;P&gt;Camera: D435 &lt;/P&gt;&lt;P&gt;OS: Windows 10 &lt;/P&gt;&lt;P&gt;language: C# &lt;/P&gt;&lt;P&gt;I had been successfully using a program with SR300 which I'm now migrating to support D435 sensor only with latest SDK. The older SDK had some methods to map coordinates from optical to depth which I cant find in the new SDK. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However with the limited C# samples available I can see there is a way of aligning color and depth frames. However the aligned frame seems to be a VideoFrame and not DepthFrame. With DepthFrame I could do use the CopyTo function to access depth values by iterating through the pixels. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering how can I similarly access depth values from a the aligned Videoframe. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My progressing code is below - which works fine without aligning frames, but then I cant find a way to map a pixel from color to its depth equivalent. Also for some reason if I use the align filter, the frames just freeze ) guess one of the native calls throw an error ) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note Q1 &amp;amp; Q2 in commented code below. Any help will be greatly appreciated. Thank you. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;CODE&gt;var token = tokenSource.Token;
        ushort[] depthdata = new ushort[640 * 480];
        var t = Task.Factory.StartNew(() =&amp;gt;
        {
            while (!token.IsCancellationRequested)
            {
                //// We use the frames that are captured from live camera as the input data for the SW device
                using (var frames = pipeline.WaitForFrames())
                {
                    var depthFrame = frames.DepthFrame.DisposeWith(frames);
                    var colorFrame = frames.ColorFrame.DisposeWith(frames);
                    sync.SubmitFrame(depthFrame);
                    sync.SubmitFrame(colorFrame);
                }
                // Dispaly the frames that come from the SW device after synchronization
                using (var new_frames = sync.WaitForFrames())
                {
                    if (new_frames.Count == 2)
                    {
                        new_frames.ApplyFilter(align); // Q1: This results in freeze after few seconds. 
                        var depthFrame = new_frames.DepthFrame.DisposeWith(new_frames);
                        var colorFrame = new_frames.ColorFrame.DisposeWith(new_frames);
                        // VideoFrame colorizedDepth = colorizer.Process(depthFrame).As&amp;lt;VideoFrame&amp;gt;().DisposeWith(new_frames);
                        depthFrame.CopyTo(depthdata);
                        //  var colorizedDepth = frames[Intel.RealSense.Stream.Depth, Format.Rgb8].As&amp;lt;VideoFrame&amp;gt;().DisposeWith(frames);
                        // colorizedDepth.CopyTo(depthdata);  // Q2: What should be size of depthdata array here ( Stride * Height ?) OR ( Width * height ) and how can i iterate through it to access z values ? 
                        WriteableBitmap colorizedDepthImage;
                        unsafe
                        {
                            //D435 - get access to data and then see the followin convertion to dataptr
                            _calibrationData.angleCameraTorsoRadians = 0.43;
                            fixed (ushort* dataptr = depthdata)
                            {
                                // MAIN OPERATION On DEPTH Data here ..// 
                                //measurer.Measure(dataptr, regions, _calibrationData);
                            }
                            fixed (ushort* dataptr = depthdata)
                            {
                                // Colorize Depth Image for Display ( this is for SR300 where I programmed the colors myself for depth ) 
                                colorizedDepthImage = _colorizer.GetColorizedBitmap(dataptr);
                                var depthStream = GetPngStream(colorizedDepthImage);
                            }
                            //For capturing Color stream as well 
                            var bytes = new byte[colorFrame.Stride * colorFrame.Height];
                            colorFrame.CopyTo(bytes);
                            // .... Mode code here // 
                            //Raise events to notify UI
                            RaiseFrameProcessedEvent(new ProcessedFrame(depthStream, regions, _calibrationData));
                            RaiseColorFrameAvailableEvent(new ColorFrame(colorStream));
                            depthStream.Dispose();
                        }
                    }
                }
            }
        }, token);&lt;/CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 13:53:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Items-with-no-label/Using-D435-sensor-Mapping-coordinates-from-color-to-depth-after/m-p/687085#M16147</guid>
      <dc:creator>MCC001</dc:creator>
      <dc:date>2019-03-21T13:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using D435 sensor : Mapping coordinates from color to depth  after aligning frames</title>
      <link>https://community.intel.com/t5/Items-with-no-label/Using-D435-sensor-Mapping-coordinates-from-color-to-depth-after/m-p/687086#M16148</link>
      <description>&lt;P&gt;An alternative to using Align in the RealSense SDK 2.0 is an instruction called &lt;B&gt;rs2_project_color_pixel_to_depth_pixel&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It maps a pixel in the color image to a pixel in the depth image. An example use of the instruction can be found in the link below, starting on line 116 of the script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/IntelRealSense/librealsense/blob/development/include/librealsense2/rsutil.h#L116" target="_self" alt="https://github.com/IntelRealSense/librealsense/blob/development/include/librealsense2/rsutil.h#L116"&gt;&lt;/A&gt;&lt;A href="https://github.com/IntelRealSense/librealsense/blob/development/include/librealsense2/rsutil.h#L116"&gt;https://github.com/IntelRealSense/librealsense/blob/development/include/librealsense2/rsutil.h#L116&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 14:43:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Items-with-no-label/Using-D435-sensor-Mapping-coordinates-from-color-to-depth-after/m-p/687086#M16148</guid>
      <dc:creator>MartyG</dc:creator>
      <dc:date>2019-03-21T14:43:32Z</dc:date>
    </item>
  </channel>
</rss>

