|
@@ -0,0 +1,85 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+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;
|
|
|
+
|
|
|
+
|
|
|
+namespace bbiwarg.Graphics
|
|
|
+{
|
|
|
+ class Output : GameWindow
|
|
|
+ {
|
|
|
+ private IVideoDataSource source;
|
|
|
+
|
|
|
+ public Output(IVideoDataSource source)
|
|
|
+ {
|
|
|
+ this.source = source;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnLoad(EventArgs e)
|
|
|
+ {
|
|
|
+ base.OnLoad(e);
|
|
|
+ Title = "OutputTest";
|
|
|
+ GL.ClearColor(Color.Black);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ source.updateFrame();
|
|
|
+
|
|
|
+ ImageData image = source.getImageData();
|
|
|
+ int width = image.getWidth();
|
|
|
+ int height = image.getHeight();
|
|
|
+
|
|
|
+ for (int x = 0; x < width; x++) {
|
|
|
+ for (int y = 0; y < height; y++) {
|
|
|
+ if (image.getConfidence(x, y) > 100) {
|
|
|
+ int depth = image.getDepth(x, y);
|
|
|
+ Vertex vertex = new Vertex(x-width/2, height/2-y, depth);
|
|
|
+ Color color = image.getColor(x, y);
|
|
|
+ float size = 0.5f;
|
|
|
+
|
|
|
+ Point pixel = new Point(vertex, color, size);
|
|
|
+ pixel.draw();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Vector palmPosition2D = source.getPalmPosition2D(1);
|
|
|
+ int palmX = (int) palmPosition2D[0];
|
|
|
+ int palmY = (int) palmPosition2D[1];
|
|
|
+ int palmDepth = image.getDepth(palmX, palmY);
|
|
|
+ Vertex palmVertex = new Vertex(palmX - width / 2, height / 2 - palmY, palmDepth);
|
|
|
+ Color palmColor = Color.Yellow;
|
|
|
+ float palmSize = 5.0f;
|
|
|
+
|
|
|
+ Point palmPixel = new Point(palmVertex, palmColor, palmSize);
|
|
|
+ palmPixel.draw();
|
|
|
+
|
|
|
+
|
|
|
+ SwapBuffers();
|
|
|
+ source.releaseFrame();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 / 4, Width / (float)Height, 1.0f, 3000.0f);
|
|
|
+ GL.MatrixMode(MatrixMode.Projection);
|
|
|
+ GL.LoadMatrix(ref projection);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|