3 Replies Latest reply on Dec 13, 2017 4:18 PM by Intel Corporation

    Most effecient way to get depth data & edit display image

    David__

      I'm modifying the DF_RawStreams C# example project and I have two goals:

      1. Get the depth data in the most efficient way possible

      2. Edit the image displayed on the fly in the most efficient way possible.

       

      I've hobbled together some working code for getting the depth in mm:

                              if (MainPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                              {
                                  image = sample[MainPanel];
                                  image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH, out imageData);
                                  var dwidth = image.info.width;
                                  var dheight = image.info.height;
                                  var dPixels = imageData.ToShortArray(0, dwidth * dheight);
                                  for (int y = 0; y < dheight; y++)
                                  {
                                      for (int x = 0; x < dwidth; x++)
                                      {
                                          var depth = dPixels[y * dwidth + x];
                                          if (depth < avgDepth) {
                                              avgDepth--;
                                          } else if (depth > avgDepth) {
                                              avgDepth++;
                                          }
                                      }
                                  }
                                  image.ReleaseAccess(imageData);
                                  render(this, new RenderFrameEventArgs(0, image));
                                  SetStatus(avgDepth.ToString());
                              }
      

       

      That is from about line 123 in raw_streams.cs. Given this as a starting point, how would I also draw on top of the image being rendered in the most memory and CPU efficient way possible? Ideally I'd love to be able to use System.Drawing.Graphics, like this where image is a Bitmap:

       

      using (Graphics graphics = Graphics.FromImage(image))
      {
          graphics.FillRectangle(new SolidBrush(Color.Black),
                              Width / 2 - 150,
                              Height / 2 - 21,
                              300,
                              41);
      
      }
      

      How could I get from what I currently have, to also being able to efficiently draw on the rendered depth image?