Saving raw detph-data

余生长醉 提交于 2019-12-07 21:07:57

问题


I am trying to save my kinect raw depth-data and i dont want to use the Kinect Studio, because i need the raw-data for further calculations. I am using the kinectv2 and kinect sdk!

My problem is that i just get low FPS for the saved data. Its about 15-17FPS.

Here my Framereader ( in further steps i want to save colorstream also):

frameReader = kinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Depth);
frameReader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;

Here the Event:

void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
{
   var reference = e.FrameReference.AcquireFrame();
   saveFrameTest(reference);
   frame_num++;
}

Here the saving-function:

private unsafe void saveFrameTest(Object reference)
{
  MultiSourceFrame mSF = (MultiSourceFrame)reference;

  using (var frame = mSF.DepthFrameReference.AcquireFrame())
  {
      if (frame != null)
      {
          using (Microsoft.Kinect.KinectBuffer depthBuffer = frame.LockImageBuffer())
          {
              if ((frame.FrameDescription.Width * frame.FrameDescription.Height) == (depthBuffer.Size / frame.FrameDescription.BytesPerPixel))
              {
                  ushort* frameData = (ushort*)depthBuffer.UnderlyingBuffer;
                  byte[] rawDataConverted = new byte[(int)(depthBuffer.Size / 2)];

                  for (int i = 0; i < (int)(depthBuffer.Size / 2); ++i)
                  {
                      ushort depth = frameData[i];
                      rawDataConverted[i] = (byte)(depth >= frame.DepthMinReliableDistance && depth <= frame.DepthMaxReliableDistance ? (depth) : 0);
                  }

                  String date = string.Format("{0:hh-mm-ss}", DateTime.Now);
                  String filePath = System.IO.Directory.GetCurrentDirectory() + "/test/" +date+".raw";
                  File.WriteAllBytes(filePath, rawDataConverted);
                  rawDataConverted = null;

              }
          }
      }
    }
 }

Further Infomration: I included my code in a simple Console-Application on a Intel® Xeon® Processor E5-1620 3,7GHz with 16 GB RAM.

i think the for-loop is taking to much time:

  for (int i = 0; i < (int)(depthBuffer.Size / 2); ++i)
                      {
                          ushort depth = frameData[i];
                          rawDataConverted[i] = (byte)(depth >= frame.DepthMinReliableDistance && depth <= frame.DepthMaxReliableDistance ? (depth) : 0);
                      }

I could improved my framerate. Now, i am accessing the kinectbuffer directly and resign the for-loop.

Microsoft.Kinect.KinectBuffer depthBuffer = frame.LockImageBuffer();

Marshal.Copy(depthBuffer.UnderlyingBuffer, rawData_depth, 0, (depthImageSize));

depthBuffer.Dispose();
frame.Dispose();

However i couldnt get the 30FPS-rate. Now it is about 25 FPS.


回答1:


You could try something like this to get your array. It's what I normally use.

var frame = frameReference.AcquireFrame();
var frameDescription = frame.FrameDescription;
ushort[] frameData = new ushort[frameDescription.Width * frameDescription.Height];
frame.CopyFrameDataToArray(frameData);


来源:https://stackoverflow.com/questions/32883611/saving-raw-detph-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!