5 Replies Latest reply on Aug 15, 2017 11:49 PM by MartyG

    Output depth data array always zero


      I'm using SR300, winds form application in C#, and trying to learn output depth value(w/projection), 3D point, .etc.

      Although there are many similar post i have reviewed, I could not find out where is wrong with the quite straight-forward code below,

      why the deptharray values are all-zero?

      When converting the depth image to RGB do shows as attached.



      private void Start_Click(object sender, EventArgs e)



                      PXCMSession session = PXCMSession.CreateInstance();

                      PXCMSenseManager sm = session.CreateSenseManager();

                      sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480, 30);

                      sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640,480, 30);



                      pxcmStatus status = sm.AcquireFrame(true);

                      PXCMCapture.Sample sample = sm.QuerySample();

                      PXCMImage image = sample.color;

                      PXCMImage dimage = sample.depth;

                      int dwidth = dimage.info.width;

                      int dheight = dimage.info.height;

                      PXCMImage.ImageData colordata;

                      PXCMImage.ImageData depthdata;

                      image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out colordata);

                      dimage.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH_RAW, out depthdata);


                      Int16[] deptharray = depthdata.ToShortArray(0, dwidth * dheight);


                     foreach (int i in deptharray)






        • 1. Re: Output depth data array always zero

          I believe that if depth values are returning as zero then there are a couple of possible causes: (a) the camera cannot perceive 3D detail from what it is looking at and so cannot generate depth coordinates, returning them as zeros.  An example of something that would be difficult for the camera to read is a flat surface such as a table top, or a sheet of paper on a table.


          Or (b) some objects may have depth coordinates in some parts of them and zeros in other parts.  This is normal, as there is simply nothing for the camera to read in the parts where there are zeros.


          If you are getting all zeros, and not just partial ones, then that would suggest that the problem is related to possibility (a), a perception issue for the camera.


          I am not an expert in the area of writing RealSense depth stream programs unfortunately, though I can read and interpret pre-made scripts quite well.    At the risk of being wrong, I suspect that this particular script is just designed to display the depth stream but not project depth coordinates onto the image.


          I would recommend a script that uses the ProjectCameraToDepth instruction to project an array of real-world coordinates onto an image.  I turned the internet upside down looking for a pre-made C# script for this instruction or for its less efficient equivalent QueryVertices, but found nothing.  I'll link RealSense stream programming expert jb455  into this discussion.  JB, do you have any pre-made C# scripts for projecting depth coordinates onto an image.


          In the meantime, I would try changing your PIXEL_FORMAT_DEPTH_RAW instruction to PIXEL_FORMAT_DEPTH and see if that gets you more refined data in your results.

          • 2. Re: Output depth data array always zero

            It may be that the values are all being truncated to zeroes. I think in PixelFormat.PIXEL_FORMAT_DEPTH_RAW, the depth data are all less than 1 so when cast as int they end up as 0. You could either use PixelFormat.PIXEL_FORMAT_DEPTH and keep it as int or use float[] and depthData.ToFloatArray() and keep it as DEPTH_RAW (or DEPTH_F32).

            • 3. Re: Output depth data array always zero

              Thanks muchly JB!

              • 4. Re: Output depth data array always zero

                Thanks MartyG and JB !


                Using PixelFormat.PIXEL_FORMAT_DEPTH with .ToShortArray works.


                The follow picture shows successfully my hand, face, and window behind me, and the point clouds' depth (z) are 360~1300 mm.

                Too small depth value indeed should not happen when the SR300 works well.


                • 5. Re: Output depth data array always zero

                  Awesome news, glad that it worked for you!  Please come back to the forum any time that you have more questions.   Good luck!