Guest User

Untitled

a guest
Nov 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. var depthWidth = depthFrame.FrameDescription.Width;
  2. var depthHeight = depthFrame.FrameDescription.Height;
  3. ushort[] depthData = new ushort[depthWidth * depthHeight];
  4.  
  5. var colorWidth = colorFrame.FrameDescription.Width;
  6. var colorHeight = colorFrame.FrameDescription.Height;
  7. byte[] pixels = new byte[colorWidth * colorHeight * 4];
  8.  
  9. CameraSpacePoint[] cameraSpacePoints = new CameraSpacePoint[depthData.Length];
  10. ColorSpacePoint[] colorSpacePoints = new ColorSpacePoint[depthData.Length];
  11.  
  12. depthFrame.CopyFrameDataToArray(depthData);
  13. coordinateMapper.MapDepthFrameToCameraSpace(depthData, cameraSpacePoints);
  14. coordinateMapper.MapDepthFrameToColorSpace(depthData, colorSpacePoints);
  15.  
  16. // Assuming RGBA format here
  17. colorFrame.CopyConvertedFrameDataToArray(pixels, ColorImageFormat.Rgba);
  18.  
  19. for (var index = 0; index < depthData.Length; index++)
  20. {
  21. var u = colorSpacePoints[index].X;
  22. var v = colorSpacePoints[index].Y;
  23. int pixelsBaseIndex = (int)(v * depthWidth + u);
  24.  
  25. byte red = pixels[4 * pixelsBaseIndex + 0];
  26. byte green = pixels[4 * pixelsBaseIndex + 1];
  27. byte blue = pixels[4 * pixelsBaseIndex + 2];
  28. byte alpha = pixels[4 * pixelsBaseIndex + 3];
  29. }
  30.  
  31. IndexOutOfRangeException: Index was outside the bounds of the array.
  32.  
  33. List<int> allIndex = new List<int>();
  34. for (var index = 0; index < depthData.Length; index++)
  35. {
  36. var u = colorpoints[index].X;
  37. var v = colorpoints[index].Y;
  38. int pixelsBaseIndex = (int)(v * depthWidth + u);
  39.  
  40. allIndex.Add(pixelsBaseIndex);
  41. }
  42.  
  43. var maxIndex = allIndex.Max();
  44. var minIndex = allIndex.Min();
  45. Console.WriteLine(minIndex);//Prints -2147483648
  46. Console.WriteLine((maxIndex < pixels.Length) && (minIndex >= 0));//Prints False
Add Comment
Please, Sign In to add comment