123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using OpenTK;
- using OpenTK.Graphics.OpenGL;
- using MathNet.Numerics.LinearAlgebra.Single;
- using bbiwarg.DataSource;
- namespace bbiwarg.Test
- {
- class OutputTest : GameWindow
- {
- IVideoDataSource source;
- private List<Triangle> triangles = new List<Triangle>();
- private List<Pixel3D> pixel = new List<Pixel3D>();
- static void Main(string[] args)
- {
- OutputTest demo = new OutputTest();
- demo.initSource();
- demo.Run(30);
- }
- public void initSource()
- {
- source = new IIsuDataSource("..\\..\\videos\\10.skv");
- source.init();
- source.start();
- int width = 320;
- int height = 160;
- for (int x = 0; x < width; x++)
- {
- for (int y = 0; y < height; y++)
- {
- pixel.Add(new Pixel3D(x, y, width, height));
- }
- }
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- Title = "OutputTest";
- GL.ClearColor(Color.Black);
- }
- protected override void OnRenderFrame(FrameEventArgs e)
- {
- base.OnRenderFrame(e);
- bool isActive = source.isActive();
- if (isActive)
- {
- source.updateFrame();
- }
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
- GL.MatrixMode(MatrixMode.Modelview);
- GL.LoadMatrix(ref modelview);
- GL.Color3(1.0f, 1.0f, 1.0f);
- DepthImage depthImage = source.getDepthImage();
- ConfidenceImage confidenceImage = source.getConfidenceImage();
- ColorImage colorImage = source.getColorImage();
- UVImage uvImage = source.getUVImage();
- ImageData imageData = new ImageData(depthImage, confidenceImage, colorImage, uvImage);
- int width = imageData.getWidth();
- int height = imageData.getHeight();
- for (int i = 0; i < pixel.Count; i++)
- {
- pixel[i].depth = imageData.getDepth(pixel[i].x, pixel[i].y);
- pixel[i].color = imageData.getColor(pixel[i].x, pixel[i].y);
- pixel[i].draw();
- }
- Vector palmVertex = source.getPalmPosition3D(1);
- Vector palmPixel = source.getPalmPosition2D(1);
- Pixel3D palmPosition = new Pixel3D((int)palmPixel[0], (int)palmPixel[1], width, height);
- palmPosition.depth = (short)(palmVertex[1] * 1000);
- palmPosition.color = Color.Red;
- palmPosition.size = 3;
- palmPosition.draw();
- //Console.WriteLine(palmPosition.toString());
- Console.WriteLine("Palm Position: x: " + (int)palmPixel[0] + " y: " + (int)palmPixel[1] + " 3DDepth: " + palmPosition.depth + " ImageDepth: " + imageData.getDepth((int)palmPixel[0], (int)palmPixel[1]));
- for (int i = 0; i < triangles.Count; i++)
- {
- triangles[i].draw();
- }
- /*
- GL.Begin(BeginMode.Triangles);
- GL.Vertex3(0.0f, 0.0f, -4.0f);
- GL.Vertex3(2.0f, 0.0f, -4.0f);
- GL.Vertex3(0.0f, 1.0f, -4.0f);
- GL.End();
- */
- SwapBuffers();
- if (isActive)
- {
- source.releaseFrame();
- }
- /*
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
- GL.MatrixMode(MatrixMode.Modelview);
- GL.LoadMatrix(ref modelview);
- // triangle
- GL.Begin(BeginMode.Triangles);
- float x = palmPosition.Value._X;
- float y = palmPosition.Value._Y;
- float z = palmPosition.Value._Z;
- GL.Vertex3(-1.0f + x, -1.0f + z, 4.0f - 10 * y);
- GL.Vertex3(1.0f, -1.0f, 4.0f);
- GL.Vertex3(0.0f, 1.0f, 4.0f);
- GL.End();
- 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 / 4, Width / (float)Height, 1.0f, 3000.0f);
- GL.MatrixMode(MatrixMode.Projection);
- GL.LoadMatrix(ref projection);
- }
- public void addSurface(Triangle triangle)
- {
- triangles.Add(triangle);
- }
- }
- }
|