|
@@ -1,144 +1,144 @@
|
|
|
-using System;
|
|
|
-using System.Collections.Generic;
|
|
|
-using System.Diagnostics;
|
|
|
-using System.Drawing;
|
|
|
-using System.Linq;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
-using OpenTK;
|
|
|
-using OpenTK.Graphics.OpenGL;
|
|
|
-using MathNet.Numerics.LinearAlgebra.Single;
|
|
|
-using bbiwarg.DataSource;
|
|
|
-using bbiwarg.Graphics.GraphicElements3D;
|
|
|
-
|
|
|
-
|
|
|
-namespace bbiwarg.Graphics
|
|
|
-{
|
|
|
- class Output : GameWindow
|
|
|
- {
|
|
|
- private IVideoHandle videoHandle;
|
|
|
-
|
|
|
- private uint imageBufferId;
|
|
|
-
|
|
|
- public Output(IVideoHandle videoHandle)
|
|
|
- {
|
|
|
- this.videoHandle = videoHandle;
|
|
|
- }
|
|
|
-
|
|
|
- protected override void OnLoad(EventArgs e)
|
|
|
- {
|
|
|
- base.OnLoad(e);
|
|
|
- Title = "OutputTest";
|
|
|
- GL.ClearColor(Color.Black);
|
|
|
-
|
|
|
- // transparency
|
|
|
- GL.Enable(EnableCap.Blend);
|
|
|
- GL.BlendEquation(BlendEquationMode.Max);
|
|
|
-
|
|
|
- //Depth Test
|
|
|
- GL.Enable(EnableCap.DepthTest);
|
|
|
-
|
|
|
-
|
|
|
- initBuffers();
|
|
|
-
|
|
|
- GL.Enable(EnableCap.Blend);
|
|
|
- GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
|
|
|
- }
|
|
|
-
|
|
|
- protected override void OnRenderFrame(FrameEventArgs e)
|
|
|
- {
|
|
|
- base.OnRenderFrame(e);
|
|
|
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
|
|
- Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
|
|
|
- GL.MatrixMode(MatrixMode.Modelview);
|
|
|
- GL.LoadMatrix(ref modelview);
|
|
|
-
|
|
|
- videoHandle.nextFrame();
|
|
|
-
|
|
|
- Stopwatch sw = new Stopwatch();
|
|
|
- sw.Start();
|
|
|
-
|
|
|
- drawDepthImage();
|
|
|
-
|
|
|
- // palm (iisu)
|
|
|
- Vector palmPosition = videoHandle.getPalmPosition3D(1);
|
|
|
- Point3D palmPoint = new Point3D(palmPosition, Color.Yellow, 0.005f);
|
|
|
- palmPoint.draw();
|
|
|
-
|
|
|
- // foreFinger
|
|
|
- Vector foreFingerPosition = videoHandle.getForeFingerPosition3D(1);
|
|
|
- Point3D foreFingerPoint = new Point3D(foreFingerPosition, Color.Red, 0.05f);
|
|
|
- foreFingerPoint.draw();
|
|
|
-
|
|
|
- //handPoints
|
|
|
- List<Vector> handPoints = videoHandle.getHandPoints();
|
|
|
- for (int i = 0; i < handPoints.Count(); i++)
|
|
|
- {
|
|
|
- new Point3D(videoHandle.pixel2VertexPosition(handPoints[i]), Color.Yellow, 0.001f).draw();
|
|
|
- }
|
|
|
-
|
|
|
- // foreArm (iisu)
|
|
|
- Vector foreArmPosition = videoHandle.getForearmPosition3D(1);
|
|
|
- Point3D foreArmPoint = new Point3D(foreArmPosition, Color.Yellow, 0.005f);
|
|
|
- foreArmPoint.draw();
|
|
|
-
|
|
|
- // finger (iisu)
|
|
|
- Vector[] fingerPositions = videoHandle.getFingerTipPositions3D(1);
|
|
|
- DetectionStatus[] fingerStatus = videoHandle.getFingerStatus(1);
|
|
|
- for (int i = 0; i < fingerStatus.Length; ++i)
|
|
|
- {
|
|
|
- if (fingerStatus[i] == DetectionStatus.Detected || fingerStatus[i] == DetectionStatus.Tracked)
|
|
|
- {
|
|
|
- Point3D fingerPoint = new Point3D(fingerPositions[i], Color.Yellow, 0.005f);
|
|
|
- fingerPoint.draw();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // palm
|
|
|
- Palm palm = videoHandle.getPalm(1);
|
|
|
- Rectangle3D palmRect = new Rectangle3D(palm.getCorners(), Color.FromArgb(128, Color.Blue));
|
|
|
- palmRect.draw();
|
|
|
-
|
|
|
- sw.Stop();
|
|
|
- Console.WriteLine(sw.ElapsedMilliseconds);
|
|
|
-
|
|
|
- SwapBuffers();
|
|
|
- }
|
|
|
-
|
|
|
- protected override void OnResize(EventArgs e)
|
|
|
- {
|
|
|
- base.OnResize(e);
|
|
|
- GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
|
|
|
- Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 3, Width / (float)Height, 0.01f, 3.0f);
|
|
|
- GL.MatrixMode(MatrixMode.Projection);
|
|
|
- GL.LoadMatrix(ref projection);
|
|
|
- }
|
|
|
-
|
|
|
- private void initBuffers()
|
|
|
- {
|
|
|
- GL.GenBuffers(1, out imageBufferId);
|
|
|
-
|
|
|
- GL.BindBuffer(BufferTarget.ArrayBuffer, imageBufferId);
|
|
|
- GL.BufferData(BufferTarget.ArrayBuffer,
|
|
|
- (IntPtr)((3 * sizeof(float) + 4 * sizeof(byte)) * videoHandle.getWidth() * videoHandle.getHeight()),
|
|
|
- IntPtr.Zero, BufferUsageHint.StreamDraw);
|
|
|
- }
|
|
|
-
|
|
|
- private void drawDepthImage()
|
|
|
- {
|
|
|
- GL.EnableClientState(ArrayCap.VertexArray);
|
|
|
- GL.EnableClientState(ArrayCap.ColorArray);
|
|
|
-
|
|
|
- GL.BindBuffer(BufferTarget.ArrayBuffer, imageBufferId);
|
|
|
- videoHandle.createVertexArray(GL.MapBuffer(BufferTarget.ArrayBuffer, BufferAccess.WriteOnly));
|
|
|
- GL.UnmapBuffer(BufferTarget.ArrayBuffer);
|
|
|
-
|
|
|
- GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float) + 4 * sizeof(byte), IntPtr.Zero);
|
|
|
- GL.ColorPointer(4, ColorPointerType.UnsignedByte, 3 * sizeof(float) + 4 * sizeof(byte), 3 * sizeof(float));
|
|
|
-
|
|
|
- GL.PointSize(2.0f);
|
|
|
- GL.DrawArrays(PrimitiveType.Points, 0, videoHandle.getWidth() * videoHandle.getHeight());
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.Drawing;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using OpenTK;
|
|
|
+using OpenTK.Graphics.OpenGL;
|
|
|
+using MathNet.Numerics.LinearAlgebra.Single;
|
|
|
+using bbiwarg.DataSource;
|
|
|
+using bbiwarg.Graphics.GraphicElements3D;
|
|
|
+
|
|
|
+
|
|
|
+namespace bbiwarg.Graphics
|
|
|
+{
|
|
|
+ class Output3D : GameWindow
|
|
|
+ {
|
|
|
+ private IVideoHandle videoHandle;
|
|
|
+
|
|
|
+ private uint imageBufferId;
|
|
|
+
|
|
|
+ public Output3D(IVideoHandle videoHandle)
|
|
|
+ {
|
|
|
+ this.videoHandle = videoHandle;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnLoad(EventArgs e)
|
|
|
+ {
|
|
|
+ base.OnLoad(e);
|
|
|
+ Title = "OutputTest";
|
|
|
+ GL.ClearColor(Color.Black);
|
|
|
+
|
|
|
+ // transparency
|
|
|
+ GL.Enable(EnableCap.Blend);
|
|
|
+ GL.BlendEquation(BlendEquationMode.Max);
|
|
|
+
|
|
|
+ //Depth Test
|
|
|
+ GL.Enable(EnableCap.DepthTest);
|
|
|
+
|
|
|
+
|
|
|
+ initBuffers();
|
|
|
+
|
|
|
+ GL.Enable(EnableCap.Blend);
|
|
|
+ GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnRenderFrame(FrameEventArgs e)
|
|
|
+ {
|
|
|
+ base.OnRenderFrame(e);
|
|
|
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
|
|
+ Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
|
|
|
+ GL.MatrixMode(MatrixMode.Modelview);
|
|
|
+ GL.LoadMatrix(ref modelview);
|
|
|
+
|
|
|
+ videoHandle.nextFrame();
|
|
|
+
|
|
|
+ Stopwatch sw = new Stopwatch();
|
|
|
+ sw.Start();
|
|
|
+
|
|
|
+ drawDepthImage();
|
|
|
+
|
|
|
+ // palm (iisu)
|
|
|
+ Vector palmPosition = videoHandle.getPalmPosition3D(1);
|
|
|
+ Point3D palmPoint = new Point3D(palmPosition, Color.Yellow, 0.005f);
|
|
|
+ palmPoint.draw();
|
|
|
+
|
|
|
+ // foreFinger
|
|
|
+ Vector foreFingerPosition = videoHandle.getForeFingerPosition3D(1);
|
|
|
+ Point3D foreFingerPoint = new Point3D(foreFingerPosition, Color.Red, 0.05f);
|
|
|
+ foreFingerPoint.draw();
|
|
|
+
|
|
|
+ //handPoints
|
|
|
+ List<Vector> handPoints = videoHandle.getHandPoints();
|
|
|
+ for (int i = 0; i < handPoints.Count(); i++)
|
|
|
+ {
|
|
|
+ new Point3D(videoHandle.pixel2VertexPosition(handPoints[i]), Color.Yellow, 0.001f).draw();
|
|
|
+ }
|
|
|
+
|
|
|
+ // foreArm (iisu)
|
|
|
+ Vector foreArmPosition = videoHandle.getForearmPosition3D(1);
|
|
|
+ Point3D foreArmPoint = new Point3D(foreArmPosition, Color.Yellow, 0.005f);
|
|
|
+ foreArmPoint.draw();
|
|
|
+
|
|
|
+ // finger (iisu)
|
|
|
+ Vector[] fingerPositions = videoHandle.getFingerTipPositions3D(1);
|
|
|
+ DetectionStatus[] fingerStatus = videoHandle.getFingerStatus(1);
|
|
|
+ for (int i = 0; i < fingerStatus.Length; ++i)
|
|
|
+ {
|
|
|
+ if (fingerStatus[i] == DetectionStatus.Detected || fingerStatus[i] == DetectionStatus.Tracked)
|
|
|
+ {
|
|
|
+ Point3D fingerPoint = new Point3D(fingerPositions[i], Color.Yellow, 0.005f);
|
|
|
+ fingerPoint.draw();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // palm
|
|
|
+ Palm palm = videoHandle.getPalm(1);
|
|
|
+ Rectangle3D palmRect = new Rectangle3D(palm.getCorners(), Color.FromArgb(128, Color.Blue));
|
|
|
+ palmRect.draw();
|
|
|
+
|
|
|
+ sw.Stop();
|
|
|
+ Console.WriteLine(sw.ElapsedMilliseconds);
|
|
|
+
|
|
|
+ SwapBuffers();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnResize(EventArgs e)
|
|
|
+ {
|
|
|
+ base.OnResize(e);
|
|
|
+ GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
|
|
|
+ Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 3, Width / (float)Height, 0.01f, 3.0f);
|
|
|
+ GL.MatrixMode(MatrixMode.Projection);
|
|
|
+ GL.LoadMatrix(ref projection);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initBuffers()
|
|
|
+ {
|
|
|
+ GL.GenBuffers(1, out imageBufferId);
|
|
|
+
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, imageBufferId);
|
|
|
+ GL.BufferData(BufferTarget.ArrayBuffer,
|
|
|
+ (IntPtr)((3 * sizeof(float) + 4 * sizeof(byte)) * videoHandle.getWidth() * videoHandle.getHeight()),
|
|
|
+ IntPtr.Zero, BufferUsageHint.StreamDraw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void drawDepthImage()
|
|
|
+ {
|
|
|
+ GL.EnableClientState(ArrayCap.VertexArray);
|
|
|
+ GL.EnableClientState(ArrayCap.ColorArray);
|
|
|
+
|
|
|
+ GL.BindBuffer(BufferTarget.ArrayBuffer, imageBufferId);
|
|
|
+ videoHandle.createVertexArray(GL.MapBuffer(BufferTarget.ArrayBuffer, BufferAccess.WriteOnly));
|
|
|
+ GL.UnmapBuffer(BufferTarget.ArrayBuffer);
|
|
|
+
|
|
|
+ GL.VertexPointer(3, VertexPointerType.Float, 3 * sizeof(float) + 4 * sizeof(byte), IntPtr.Zero);
|
|
|
+ GL.ColorPointer(4, ColorPointerType.UnsignedByte, 3 * sizeof(float) + 4 * sizeof(byte), 3 * sizeof(float));
|
|
|
+
|
|
|
+ GL.PointSize(2.0f);
|
|
|
+ GL.DrawArrays(PrimitiveType.Points, 0, videoHandle.getWidth() * videoHandle.getHeight());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|