Guest User

Untitled

a guest
Oct 21st, 2016
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 23.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Kinect;
  7. using Microsoft.Kinect.Fusion;
  8.  
  9. namespace KinectConnectionTest
  10. {
  11.     public class KinectFusionizer
  12.     {
  13.         public bool CaptureCurrent = false;
  14.         private KinectSensor sensor;
  15.  
  16.         private object volumeLock = new object();
  17.         private object rawDataLock = new object();
  18.  
  19.         private float voxelsPerMeter = 384;
  20.         private int voxelsX = 384;
  21.         private int voxelsY = 384;
  22.         private int voxelsZ = 256;
  23.  
  24.         private float minDepthClip = 0.5f;
  25.         private float maxDepthClip = 1f;
  26.  
  27.         private int depthWidth = 512;
  28.         private int depthHeight = 424;
  29.         private int downsampledWidth;
  30.         private int downsampledHeight;
  31.         private int depthVisibilityTestMapWidth = 0;
  32.         private int depthVisibilityTestMapHeight = 0;
  33.         private int colorWidth = 1920;
  34.         private int colorHeight = 1080;
  35.  
  36.         #region Constants
  37.         private const int DownsampleFactor = 2;
  38.         private const int ColorDownsampleFactor = 4;
  39.         private const ushort DepthVisibilityTestThreshold = 50; // 50mm
  40.         #endregion
  41.  
  42.         #region Matrixes
  43.         private Matrix4 worldToCameraTransform;
  44.         private Matrix4 defaultWorldToVolumeTransform;
  45.         private Matrix4 worldToBGRTransform; //TODO: needed?
  46.         #endregion
  47.  
  48.         /// <summary>
  49.         /// The coordinate mapper to convert between depth and color frames of reference
  50.         /// </summary>
  51.         private CoordinateMapper mapper;
  52.  
  53.         #region Arrays
  54.         private int[] resampledColorImagePixelsAlignedToDepth;
  55.         private ushort[] depthImagePixels;
  56.         private float[] downsampledDepthImagePixels;
  57.         private int[] downsampledDeltaFromReferenceColorPixels;
  58.         private int[] deltaFromReferenceFramePixelsArgb;
  59.         private ColorSpacePoint[] colorCoordinates;
  60.         private ushort[] depthVisibilityTestMap;
  61.         private byte[] colorImagePixels;
  62.         #endregion
  63.  
  64.         #region Frames
  65.         private FusionColorImageFrame resampledColorFrameDepthAligned;
  66.         private FusionFloatImageFrame depthFloatFrame;
  67.         private FusionFloatImageFrame downsampledDepthFloatFrame;
  68.         private FusionFloatImageFrame downsampledSmoothDepthFloatFrame;
  69.         private FusionPointCloudImageFrame downsampledDepthPointCloudFrame;
  70.         private FusionPointCloudImageFrame downsampledRaycastPointCloudFrame;
  71.         private FusionColorImageFrame downsampledDeltaFromReferenceFrameColorFrame;
  72.         #endregion
  73.  
  74.         ColorReconstruction volume;
  75.         private MultiSourceFrameReader reader;
  76.  
  77.         public KinectFusionizer()
  78.         {
  79.             SetUpKinectVariables();
  80.             SetupVariables();
  81.         }
  82.  
  83.         public void SetUpKinectVariables()
  84.         {
  85.             sensor = KinectSensor.GetDefault();
  86.             if (sensor == null)
  87.             {
  88.                 throw new Exception("The Kinect could not be found");
  89.             }
  90.             sensor.Open();
  91.             FrameDescription depthFrameDescription = sensor.DepthFrameSource.FrameDescription;
  92.             depthWidth = depthFrameDescription.Width;
  93.             depthHeight = depthFrameDescription.Height;
  94.  
  95.             FrameDescription colorFrameDescription = sensor.ColorFrameSource.FrameDescription;
  96.             colorWidth = colorFrameDescription.Width;
  97.             colorHeight = colorFrameDescription.Height;
  98.  
  99.             reader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Depth | FrameSourceTypes.Color);
  100.             reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
  101.         }
  102.  
  103.         private void SetupVariables()
  104.         {
  105.             mapper = sensor.CoordinateMapper;
  106.  
  107.             //Calculate integers used for allocation
  108.             int depthImageSize = depthWidth * depthHeight;
  109.             downsampledWidth = depthWidth / DownsampleFactor;
  110.             downsampledHeight = depthHeight / DownsampleFactor;
  111.             int colorImageByteSize = colorWidth * colorHeight * sizeof(int);
  112.             int downsampledDepthImageSize = downsampledWidth * downsampledHeight;
  113.  
  114.             //Allocate frames
  115.             resampledColorFrameDepthAligned = new FusionColorImageFrame(depthWidth, depthHeight);
  116.             depthFloatFrame = new FusionFloatImageFrame(depthWidth, depthHeight);
  117.             downsampledDepthFloatFrame = new FusionFloatImageFrame(downsampledWidth, downsampledHeight);
  118.             downsampledSmoothDepthFloatFrame = new FusionFloatImageFrame(downsampledWidth, downsampledHeight);
  119.             downsampledDepthPointCloudFrame = new FusionPointCloudImageFrame(downsampledWidth, downsampledHeight);
  120.             downsampledRaycastPointCloudFrame = new FusionPointCloudImageFrame(downsampledWidth, downsampledHeight);
  121.             downsampledDeltaFromReferenceFrameColorFrame = new FusionColorImageFrame(downsampledWidth, downsampledHeight);
  122.  
  123.             //Allocate arrays
  124.             depthImagePixels = new ushort[depthImageSize];
  125.             downsampledDepthImagePixels = new float[downsampledDepthImageSize];
  126.             downsampledDeltaFromReferenceColorPixels = new int[downsampledDepthImageSize];
  127.             deltaFromReferenceFramePixelsArgb = new int[depthImageSize];
  128.             colorCoordinates = new ColorSpacePoint[depthImageSize];
  129.             resampledColorImagePixelsAlignedToDepth = new int[depthImageSize];
  130.             depthVisibilityTestMapWidth = colorWidth / ColorDownsampleFactor;
  131.             depthVisibilityTestMapHeight = colorHeight / ColorDownsampleFactor;
  132.             depthVisibilityTestMap = new ushort[depthVisibilityTestMapWidth * depthVisibilityTestMapHeight];
  133.             colorImagePixels = new byte[colorImageByteSize];
  134.         }
  135.  
  136.         private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
  137.         {
  138.             if (CaptureCurrent)
  139.             {
  140.                 ProcessFrameData(e);
  141.                 Process();
  142.             }
  143.         }
  144.  
  145.         private void ProcessFrameData(MultiSourceFrameArrivedEventArgs e)
  146.         {
  147.             MultiSourceFrameReference frameReference = e.FrameReference;
  148.             MultiSourceFrame multiSourceFrame = null;
  149.             DepthFrame depthFrame = null;
  150.             ColorFrame colorFrame = null;
  151.             try
  152.             {
  153.                 multiSourceFrame = frameReference.AcquireFrame();
  154.                 if (multiSourceFrame != null)
  155.                 {
  156.                     lock (rawDataLock)
  157.                     {
  158.                         ColorFrameReference colorFrameReference = multiSourceFrame.ColorFrameReference;
  159.                         DepthFrameReference depthFrameReference = multiSourceFrame.DepthFrameReference;
  160.                         colorFrame = colorFrameReference.AcquireFrame();
  161.                         depthFrame = depthFrameReference.AcquireFrame();
  162.  
  163.                         if ((depthFrame != null) && (colorFrame != null))
  164.                         {
  165.                             FrameDescription colorFrameDescription = colorFrame.FrameDescription;
  166.                             int colorWidth = colorFrameDescription.Width;
  167.                             int colorHeight = colorFrameDescription.Height;
  168.                             if ((colorWidth * colorHeight * sizeof(int)) == colorImagePixels.Length)
  169.                                 colorFrame.CopyConvertedFrameDataToArray(colorImagePixels, ColorImageFormat.Bgra);
  170.  
  171.                             FrameDescription depthFrameDescription = depthFrame.FrameDescription;
  172.                             int depthWidth = depthFrameDescription.Width;
  173.                             int depthHeight = depthFrameDescription.Height;
  174.  
  175.                             if ((depthWidth * depthHeight) == depthImagePixels.Length)
  176.                                 depthFrame.CopyFrameDataToArray(depthImagePixels);
  177.                         }
  178.                     }
  179.                 }
  180.                 CaptureCurrent = false; //We got both color and depth, everything went ok, stop trying to capture this image
  181.             }
  182.             catch (Exception)
  183.             {
  184.                 // ignore if the frame is no longer available
  185.             }
  186.             finally
  187.             {
  188.                 // MultiSourceFrame, DepthFrame, ColorFrame, BodyIndexFrame are IDispoable
  189.                 if (depthFrame != null)
  190.                 {
  191.                     depthFrame.Dispose();
  192.                     depthFrame = null;
  193.                 }
  194.                 if (colorFrame != null)
  195.                 {
  196.                     colorFrame.Dispose();
  197.                     colorFrame = null;
  198.                 }
  199.                 if (multiSourceFrame != null)
  200.                 {
  201.                     multiSourceFrame = null;
  202.                 }
  203.             }
  204.         }
  205.  
  206.         private void Process()
  207.         {
  208.             lock (volumeLock)
  209.             {
  210.                 RecreateReconstruction();
  211.             }
  212.             ResetReconstruction();
  213.             ProcessDepthData();
  214.             TrackCamera();
  215.             IntegrateData();
  216.             RenderReconstruction();
  217.             WriteToMemory();
  218.         }
  219.  
  220.         /// <summary>
  221.         /// Constructs and prepares the ColorReconstruction for data input
  222.         /// </summary>
  223.         private void RecreateReconstruction()
  224.         {
  225.             ReconstructionParameters volParam = new ReconstructionParameters(voxelsPerMeter, voxelsX, voxelsY, voxelsZ);
  226.             worldToCameraTransform = Matrix4.Identity;
  227.             ReconstructionProcessor ProcessorType = ReconstructionProcessor.Amp;
  228.             volume = ColorReconstruction.FusionCreateReconstruction(volParam, ProcessorType, -1, worldToCameraTransform);
  229.             defaultWorldToVolumeTransform = volume.GetCurrentWorldToVolumeTransform();
  230.             ResetReconstruction();
  231.  
  232.             worldToBGRTransform = Matrix4.Identity;
  233.             worldToBGRTransform.M11 = voxelsPerMeter / voxelsX;
  234.             worldToBGRTransform.M22 = voxelsPerMeter / voxelsY;
  235.             worldToBGRTransform.M33 = voxelsPerMeter / voxelsZ;
  236.             worldToBGRTransform.M41 = 0.5f;
  237.             worldToBGRTransform.M42 = 0.5f;
  238.             worldToBGRTransform.M44 = 1.0f;
  239.         }
  240.  
  241.         private void ResetReconstruction()
  242.         {
  243.             worldToCameraTransform = Matrix4.Identity;
  244.             Matrix4 worldToVolumeTransform = defaultWorldToVolumeTransform;
  245.             float minDist = (minDepthClip < maxDepthClip) ? minDepthClip : maxDepthClip;
  246.             worldToVolumeTransform.M43 -= minDist * voxelsPerMeter;
  247.             volume.ResetReconstruction(worldToCameraTransform, worldToVolumeTransform);
  248.             ResetColorImage();
  249.         }
  250.  
  251.         private void ResetColorImage()
  252.         {
  253.             Array.Clear(resampledColorImagePixelsAlignedToDepth, 0, resampledColorImagePixelsAlignedToDepth.Length);
  254.             resampledColorFrameDepthAligned.CopyPixelDataFrom(resampledColorImagePixelsAlignedToDepth);
  255.         }
  256.  
  257.         private void ProcessDepthData()
  258.         {
  259.             volume.DepthToDepthFloatFrame(depthImagePixels, depthFloatFrame, minDepthClip, maxDepthClip, false);
  260.         }
  261.  
  262.         private void TrackCamera()
  263.         {
  264.             Matrix4 calculatedCameraPos = worldToCameraTransform; //copy
  265.             TrackCamera_AlignPointClouds(ref calculatedCameraPos); //manipulate
  266.             worldToCameraTransform = calculatedCameraPos; //set to new
  267.         }
  268.  
  269.         private void TrackCamera_AlignPointClouds(ref Matrix4 calculatedCameraPose)
  270.         {
  271.             DownsampleDepthFrameNearestNeighbor(downsampledDepthFloatFrame, DownsampleFactor);
  272.             volume.SmoothDepthFloatFrame(downsampledDepthFloatFrame, downsampledSmoothDepthFloatFrame, 1, 0.04f); //TODO: Magic numbers
  273.             FusionDepthProcessor.DepthFloatFrameToPointCloud(downsampledSmoothDepthFloatFrame, downsampledDepthPointCloudFrame);
  274.             volume.CalculatePointCloud(downsampledRaycastPointCloudFrame, calculatedCameraPose);
  275.             Matrix4 initialPose = calculatedCameraPose;
  276.             FusionDepthProcessor.AlignPointClouds(downsampledRaycastPointCloudFrame, downsampledDepthPointCloudFrame, FusionDepthProcessor.DefaultAlignIterationCount, downsampledDeltaFromReferenceFrameColorFrame, ref calculatedCameraPose);
  277.             UpsampleColorDeltasFrameNearestNeighbor(DownsampleFactor);
  278.             //UpdateAlignDeltas(); //TODO: Necessary?
  279.         }
  280.  
  281.         /// <summary>
  282.         /// Downsample depth pixels with nearest neighbor
  283.         /// </summary>
  284.         /// <param name="dest">The destination depth image.</param>
  285.         /// <param name="factor">The downsample factor (2=x/2,y/2, 4=x/4,y/4, 8=x/8,y/8, 16=x/16,y/16).</param>
  286.         private unsafe void DownsampleDepthFrameNearestNeighbor(FusionFloatImageFrame dest, int factor)
  287.         {
  288.             #region ErrorHandling
  289.             if (null == dest || null == downsampledDepthImagePixels)
  290.                 throw new ArgumentException("inputs null");
  291.             if (false == (2 == factor || 4 == factor || 8 == factor || 16 == factor))
  292.                 throw new ArgumentException("factor != 2, 4, 8 or 16");
  293.             int downsampleWidth = depthWidth / factor;
  294.             int downsampleHeight = depthHeight / factor;
  295.             if (dest.Width != downsampleWidth || dest.Height != downsampleHeight)
  296.                 throw new ArgumentException("dest != downsampled image size");
  297.             #endregion
  298.             fixed (ushort* rawDepthPixelPtr = depthImagePixels)
  299.             {
  300.                 ushort* rawDepthPixels = (ushort*)rawDepthPixelPtr;
  301.  
  302.                 // Horizontal flip the color image as the standard depth image is flipped internally in Kinect Fusion
  303.                 // to give a viewpoint as though from behind the Kinect looking forward by default.
  304.                 Parallel.For(
  305.                     0,
  306.                     downsampleHeight,
  307.                     y =>
  308.                     {
  309.                         int flippedDestIndex = (y * downsampleWidth) + (downsampleWidth - 1);
  310.                         int sourceIndex = y * depthWidth * factor;
  311.  
  312.                         for (int x = 0; x < downsampleWidth; ++x, --flippedDestIndex, sourceIndex += factor)
  313.                         {
  314.                             // Copy depth value
  315.                             downsampledDepthImagePixels[flippedDestIndex] = (float)rawDepthPixels[sourceIndex] * 0.001f;
  316.                         }
  317.                     });
  318.             }
  319.  
  320.             dest.CopyPixelDataFrom(downsampledDepthImagePixels);
  321.         }
  322.  
  323.         /// <summary>
  324.         /// Up sample color delta from reference frame with nearest neighbor - replicates pixels
  325.         /// </summary>
  326.         /// <param name="factor">The up sample factor (2=x*2,y*2, 4=x*4,y*4, 8=x*8,y*8, 16=x*16,y*16).</param>
  327.         private unsafe void UpsampleColorDeltasFrameNearestNeighbor(int factor)
  328.         {
  329.             #region ErrorHandling
  330.             if (null == downsampledDeltaFromReferenceFrameColorFrame || null == downsampledDeltaFromReferenceColorPixels || null == deltaFromReferenceFramePixelsArgb)
  331.                 throw new ArgumentException("inputs null");
  332.             if (false == (2 == factor || 4 == factor || 8 == factor || 16 == factor))
  333.                 throw new ArgumentException("factor != 2, 4, 8 or 16");
  334.             int upsampleWidth = downsampledWidth * factor;
  335.             int upsampleHeight = downsampledHeight * factor;
  336.             if (depthWidth != upsampleWidth || depthHeight != upsampleHeight)
  337.                 throw new ArgumentException("upsampled image size != depth size");
  338.             #endregion
  339.             downsampledDeltaFromReferenceFrameColorFrame.CopyPixelDataTo(downsampledDeltaFromReferenceColorPixels);
  340.  
  341.             // Here we make use of unsafe code to just copy the whole pixel as an int for performance reasons, as we do
  342.             // not need access to the individual rgba components.
  343.             fixed (int* rawColorPixelPtr = downsampledDeltaFromReferenceColorPixels)
  344.             {
  345.                 int* rawColorPixels = (int*)rawColorPixelPtr;
  346.  
  347.                 // Note we run this only for the source image height pixels to sparsely fill the destination with rows
  348.                 Parallel.For(
  349.                     0,
  350.                     downsampledHeight,
  351.                     y =>
  352.                     {
  353.                         int destIndex = y * upsampleWidth * factor;
  354.                         int sourceColorIndex = y * downsampledWidth;
  355.  
  356.                         for (int x = 0; x < downsampledWidth; ++x, ++sourceColorIndex)
  357.                         {
  358.                             int color = rawColorPixels[sourceColorIndex];
  359.  
  360.                             // Replicate pixels horizontally
  361.                             for (int colFactorIndex = 0; colFactorIndex < factor; ++colFactorIndex, ++destIndex)
  362.                             {
  363.                                 // Replicate pixels vertically
  364.                                 for (int rowFactorIndex = 0; rowFactorIndex < factor; ++rowFactorIndex)
  365.                                 {
  366.                                     // Copy color pixel
  367.                                     deltaFromReferenceFramePixelsArgb[destIndex + (rowFactorIndex * upsampleWidth)] = color;
  368.                                 }
  369.                             }
  370.                         }
  371.                     });
  372.             }
  373.  
  374.             int sizeOfInt = sizeof(int);
  375.             int rowByteSize = downsampledHeight * sizeOfInt;
  376.  
  377.             // Duplicate the remaining rows with memcpy
  378.             for (int y = 0; y < downsampledHeight; ++y)
  379.             {
  380.                 // iterate only for the smaller number of rows
  381.                 int srcRowIndex = upsampleWidth * factor * y;
  382.  
  383.                 // Duplicate lines
  384.                 for (int r = 1; r < factor; ++r)
  385.                 {
  386.                     int index = upsampleWidth * ((y * factor) + r);
  387.  
  388.                     System.Buffer.BlockCopy(
  389.                         deltaFromReferenceFramePixelsArgb, srcRowIndex * sizeOfInt, deltaFromReferenceFramePixelsArgb, index * sizeOfInt, rowByteSize);
  390.                 }
  391.             }
  392.         }
  393.  
  394.         private void IntegrateData()
  395.         {
  396.             MapColorToDepth();
  397.             volume.IntegrateFrame(depthFloatFrame, resampledColorFrameDepthAligned, FusionDepthProcessor.DefaultIntegrationWeight, FusionDepthProcessor.DefaultColorIntegrationOfAllAngles, worldToCameraTransform);
  398.             RenderReconstruction();
  399.         }
  400.  
  401.         /// <summary>
  402.         /// Process the color and depth inputs, converting the color into the depth space
  403.         /// </summary>
  404.         private unsafe void MapColorToDepth()
  405.         {
  406.             mapper.MapDepthFrameToColorSpace(depthImagePixels, colorCoordinates);
  407.  
  408.             lock (rawDataLock)
  409.             {
  410.                 // Fill in the visibility depth map.
  411.                 Array.Clear(depthVisibilityTestMap, 0, depthVisibilityTestMap.Length);
  412.                 fixed (ushort* ptrDepthVisibilityPixels = depthVisibilityTestMap, ptrDepthPixels = depthImagePixels)
  413.                 {
  414.                     for (int index = 0; index < depthImagePixels.Length; ++index)
  415.                     {
  416.                         if (!float.IsInfinity(colorCoordinates[index].X) && !float.IsInfinity(colorCoordinates[index].Y))
  417.                         {
  418.                             int x = (int)(Math.Floor(colorCoordinates[index].X + 0.5f) / ColorDownsampleFactor);
  419.                             int y = (int)(Math.Floor(colorCoordinates[index].Y + 0.5f) / ColorDownsampleFactor);
  420.  
  421.                             if ((x >= 0) && (x < depthVisibilityTestMapWidth) &&
  422.                                 (y >= 0) && (y < depthVisibilityTestMapHeight))
  423.                             {
  424.                                 int depthVisibilityTestIndex = (y * depthVisibilityTestMapWidth) + x;
  425.                                 if ((ptrDepthVisibilityPixels[depthVisibilityTestIndex] == 0) ||
  426.                                     (ptrDepthVisibilityPixels[depthVisibilityTestIndex] > ptrDepthPixels[index]))
  427.                                 {
  428.                                     ptrDepthVisibilityPixels[depthVisibilityTestIndex] = ptrDepthPixels[index];
  429.                                 }
  430.                             }
  431.                         }
  432.                     }
  433.                 }
  434.  
  435.                 // Here we make use of unsafe code to just copy the whole pixel as an int for performance reasons, as we do
  436.                 // not need access to the individual rgba components.
  437.                 fixed (byte* ptrColorPixels = colorImagePixels)
  438.                 {
  439.                     int* rawColorPixels = (int*)ptrColorPixels;
  440.  
  441.                     // Horizontal flip the color image as the standard depth image is flipped internally in Kinect Fusion
  442.                     // to give a viewpoint as though from behind the Kinect looking forward by default.
  443.                     Parallel.For(
  444.                         0,
  445.                         depthHeight,
  446.                         y =>
  447.                         {
  448.                             int destIndex = y * depthWidth;
  449.                             int flippedDestIndex = destIndex + (depthWidth - 1); // horizontally mirrored
  450.  
  451.                                 for (int x = 0; x < depthWidth; ++x, ++destIndex, --flippedDestIndex)
  452.                             {
  453.                                     // calculate index into depth array
  454.                                     int colorInDepthX = (int)Math.Floor(colorCoordinates[destIndex].X + 0.5);
  455.                                 int colorInDepthY = (int)Math.Floor(colorCoordinates[destIndex].Y + 0.5);
  456.                                 int depthVisibilityTestX = (int)(colorInDepthX / ColorDownsampleFactor);
  457.                                 int depthVisibilityTestY = (int)(colorInDepthY / ColorDownsampleFactor);
  458.                                 int depthVisibilityTestIndex = (depthVisibilityTestY * depthVisibilityTestMapWidth) + depthVisibilityTestX;
  459.  
  460.                                     // make sure the depth pixel maps to a valid point in color space
  461.                                     if (colorInDepthX >= 0 && colorInDepthX < colorWidth && colorInDepthY >= 0
  462.                                     && colorInDepthY < colorHeight && depthImagePixels[destIndex] != 0)
  463.                                 {
  464.                                     ushort depthTestValue = depthVisibilityTestMap[depthVisibilityTestIndex];
  465.  
  466.                                     if ((depthImagePixels[destIndex] - depthTestValue) < DepthVisibilityTestThreshold)
  467.                                     {
  468.                                             // Calculate index into color array- this will perform a horizontal flip as well
  469.                                             int sourceColorIndex = colorInDepthX + (colorInDepthY * colorWidth);
  470.  
  471.                                             // Copy color pixel
  472.                                             resampledColorImagePixelsAlignedToDepth[flippedDestIndex] = rawColorPixels[sourceColorIndex];
  473.                                     }
  474.                                     else
  475.                                     {
  476.                                         resampledColorImagePixelsAlignedToDepth[flippedDestIndex] = 0;
  477.                                     }
  478.                                 }
  479.                                 else
  480.                                 {
  481.                                     resampledColorImagePixelsAlignedToDepth[flippedDestIndex] = 0;
  482.                                 }
  483.                             }
  484.                         });
  485.                 }
  486.             }
  487.  
  488.             resampledColorFrameDepthAligned.CopyPixelDataFrom(resampledColorImagePixelsAlignedToDepth);
  489.         }
  490.  
  491.         private void RenderReconstruction()
  492.         {
  493.  
  494.         }
  495.  
  496.         private void WriteToMemory()
  497.         {
  498.             ColorMesh m = volume.CalculateMesh(1);
  499.             //PCDExporter.Output(m); //output your mesh somehow
  500.         }
  501.     }
  502. }
Add Comment
Please, Sign In to add comment