OutputTest.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. using OpenTK;
  7. using OpenTK.Graphics.OpenGL;
  8. using MathNet.Numerics.LinearAlgebra.Single;
  9. using bbiwarg.DataSource;
  10. namespace bbiwarg.Test
  11. {
  12. class OutputTest : GameWindow
  13. {
  14. IVideoDataSource source;
  15. private List<Triangle> triangles = new List<Triangle>();
  16. private List<Pixel3D> pixel = new List<Pixel3D>();
  17. static void Main(string[] args)
  18. {
  19. OutputTest demo = new OutputTest();
  20. demo.initSource();
  21. demo.Run(30);
  22. }
  23. public void initSource()
  24. {
  25. source = new IIsuDataSource("..\\..\\videos\\10.skv");
  26. source.init();
  27. source.start();
  28. int width = 320;
  29. int height = 160;
  30. for (int x = 0; x < width; x++)
  31. {
  32. for (int y = 0; y < height; y++)
  33. {
  34. pixel.Add(new Pixel3D(x, y, width, height));
  35. }
  36. }
  37. }
  38. protected override void OnLoad(EventArgs e)
  39. {
  40. base.OnLoad(e);
  41. Title = "OutputTest";
  42. GL.ClearColor(Color.Black);
  43. }
  44. protected override void OnRenderFrame(FrameEventArgs e)
  45. {
  46. base.OnRenderFrame(e);
  47. bool isActive = source.isActive();
  48. if (isActive)
  49. {
  50. source.updateFrame();
  51. }
  52. GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  53. Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
  54. GL.MatrixMode(MatrixMode.Modelview);
  55. GL.LoadMatrix(ref modelview);
  56. GL.Color3(1.0f, 1.0f, 1.0f);
  57. DepthImage depthImage = source.getDepthImage();
  58. ConfidenceImage confidenceImage = source.getConfidenceImage();
  59. ColorImage colorImage = source.getColorImage();
  60. UVImage uvImage = source.getUVImage();
  61. ImageData imageData = new ImageData(depthImage, confidenceImage, colorImage, uvImage);
  62. int width = imageData.getWidth();
  63. int height = imageData.getHeight();
  64. for (int i = 0; i < pixel.Count; i++)
  65. {
  66. pixel[i].depth = imageData.getDepth(pixel[i].x, pixel[i].y);
  67. pixel[i].color = imageData.getColor(pixel[i].x, pixel[i].y);
  68. pixel[i].draw();
  69. }
  70. Vector palmVertex = source.getPalmPosition3D(1);
  71. Vector palmPixel = source.getPalmPosition2D(1);
  72. Pixel3D palmPosition = new Pixel3D((int)palmPixel[0], (int)palmPixel[1], width, height);
  73. palmPosition.depth = (short)(palmVertex[1] * 1000);
  74. palmPosition.color = Color.Red;
  75. palmPosition.size = 3;
  76. palmPosition.draw();
  77. //Console.WriteLine(palmPosition.toString());
  78. Console.WriteLine("Palm Position: x: " + (int)palmPixel[0] + " y: " + (int)palmPixel[1] + " 3DDepth: " + palmPosition.depth + " ImageDepth: " + imageData.getDepth((int)palmPixel[0], (int)palmPixel[1]));
  79. for (int i = 0; i < triangles.Count; i++)
  80. {
  81. triangles[i].draw();
  82. }
  83. /*
  84. GL.Begin(BeginMode.Triangles);
  85. GL.Vertex3(0.0f, 0.0f, -4.0f);
  86. GL.Vertex3(2.0f, 0.0f, -4.0f);
  87. GL.Vertex3(0.0f, 1.0f, -4.0f);
  88. GL.End();
  89. */
  90. SwapBuffers();
  91. if (isActive)
  92. {
  93. source.releaseFrame();
  94. }
  95. /*
  96. GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  97. Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
  98. GL.MatrixMode(MatrixMode.Modelview);
  99. GL.LoadMatrix(ref modelview);
  100. // triangle
  101. GL.Begin(BeginMode.Triangles);
  102. float x = palmPosition.Value._X;
  103. float y = palmPosition.Value._Y;
  104. float z = palmPosition.Value._Z;
  105. GL.Vertex3(-1.0f + x, -1.0f + z, 4.0f - 10 * y);
  106. GL.Vertex3(1.0f, -1.0f, 4.0f);
  107. GL.Vertex3(0.0f, 1.0f, 4.0f);
  108. GL.End();
  109. SwapBuffers();*/
  110. }
  111. protected override void OnResize(EventArgs e)
  112. {
  113. base.OnResize(e);
  114. GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
  115. Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, Width / (float)Height, 1.0f, 3000.0f);
  116. GL.MatrixMode(MatrixMode.Projection);
  117. GL.LoadMatrix(ref projection);
  118. }
  119. public void addSurface(Triangle triangle)
  120. {
  121. triangles.Add(triangle);
  122. }
  123. }
  124. }