Browse Source

imported project from other git-repo

Alexander Hendrich 10 years ago
parent
commit
1e14b5154b

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+bbiwarg/bin/
+bbiwarg/obj/
+*.skv

+ 0 - 1
README

@@ -1 +0,0 @@
-TODO :)

+ 20 - 0
bbiwarg.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bbiwarg", "bbiwarg\bbiwarg.csproj", "{12271049-82D6-436D-A51E-E6614C8E9C50}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{12271049-82D6-436D-A51E-E6614C8E9C50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{12271049-82D6-436D-A51E-E6614C8E9C50}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{12271049-82D6-436D-A51E-E6614C8E9C50}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{12271049-82D6-436D-A51E-E6614C8E9C50}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 13 - 0
bbiwarg.userprefs

@@ -0,0 +1,13 @@
+<Properties>
+  <MonoDevelop.Ide.Workspace />
+  <MonoDevelop.Ide.Workbench ActiveDocument="..\..\..\..\..\..\Documents\iisuSDK\UnityHandMeshSample\Source\Assets\Scripts\iisu\DepthImage.cs">
+    <Files>
+      <File FileName="..\..\..\..\..\..\Documents\iisuSDK\UnityHandMeshSample\Source\Assets\Scripts\iisu\IisuInputProvider.cs" Line="50" Column="43" />
+      <File FileName="..\..\..\..\..\..\Documents\iisuSDK\UnityHandMeshSample\Source\Assets\Scripts\iisu\DepthImage.cs" Line="1" Column="1" />
+    </Files>
+  </MonoDevelop.Ide.Workbench>
+  <MonoDevelop.Ide.DebuggingService.Breakpoints>
+    <BreakpointStore />
+  </MonoDevelop.Ide.DebuggingService.Breakpoints>
+  <MonoDevelop.Ide.DebuggingService.PinnedWatches />
+</Properties>

BIN
bbiwarg.v11.suo


+ 6 - 0
bbiwarg/App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+    </startup>
+</configuration>

+ 36 - 0
bbiwarg/DepthImage.cs

@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bbiwarg
+{
+    class DepthImage
+    {
+        private int width, height;
+        private ushort[] data;
+
+        public DepthImage(int width, int height, ushort[] data)
+        {
+            this.width = width;
+            this.height = height;
+            this.data = data;
+        }
+
+        public int getWidth()
+        {
+            return width;
+        }
+
+        public int getHeight()
+        {
+            return height;
+        }
+
+        public ushort getDepth(int x, int y)
+        {
+            return data[y * width + x];
+        }
+    }
+}

+ 71 - 0
bbiwarg/IVideoDataSource.cs

@@ -0,0 +1,71 @@
+using System;
+
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg
+{
+    public enum FingerStatus
+    {
+        Inactive,
+        Detected,
+        Tracked
+    }
+
+    public enum HandSide
+    {
+        Unknown,
+        Left,
+        Right
+    }
+
+    /*
+     * Interface get data from a camera or a video file.
+     * Completely independent of iisu.
+     */
+    interface IVideoDataSource
+    {
+        /*
+         * Initializes the data source.
+         */
+        void init();
+
+        /*
+         * Starts the recording of data.
+         */
+        void start();
+        /*
+         * Stops the recording of data.
+         */
+        void stop();
+
+        /*
+         * Updates the data for the current frame.
+         * Needs to be called before any method to read data.
+         */
+        void updateFrame();
+        /*
+         * Lets the data source process the next frame.
+         */
+        void releaseFrame();
+
+        /*
+         * Returns true iff new data is generated.
+         * (e.g camera is running or video hasn't ended)
+         */
+        bool isActive();
+        int getFrameRate();
+        DepthImage getDepthImage();
+
+        /*
+         * all handIndices have to be 1 or 2
+         */
+        bool isHandOpen(uint handIndex);
+        Vector getPalmPosition3D(uint handIndex);
+        Vector getTipPosition3D(uint handIndex);
+        Vector getForearmPosition3D(uint handIndex);
+        Vector getPalmNormal3D(uint handIndex);
+        FingerStatus[] getFingerStatus(uint handIndex);
+        Vector[] getFingerTipPositions3D(uint handIndex);
+        HandSide getHandSide(uint handIndex);
+    }
+}

+ 224 - 0
bbiwarg/IisuDataSource.cs

@@ -0,0 +1,224 @@
+using System;
+using System.Runtime.InteropServices;
+
+using Iisu;
+using MathNet.Numerics.LinearAlgebra.Single;
+
+namespace bbiwarg
+{
+    class IIsuDataSource: IVideoDataSource
+    {
+        private IHandle handle;
+        private IDevice device;
+        private string moviePath;
+        bool active;
+
+        // parameters
+        private IParameterHandle<float> frameRate;
+
+        // data
+        private IDataHandle<bool>[] handOpen = new IDataHandle<bool>[2];
+        private IDataHandle<Iisu.Data.Vector3>[] palmPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
+        private IDataHandle<Iisu.Data.Vector3>[] tipPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
+        private IDataHandle<Iisu.Data.Vector3>[] forearmPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
+        private IDataHandle<Iisu.Data.Vector3>[] palmNormals3D = new IDataHandle<Iisu.Data.Vector3>[2];
+        private IDataHandle<int[]>[] fingerStatus = new IDataHandle<int[]>[2];
+        private IDataHandle<Iisu.Data.Vector3[]>[] fingerTipPositions3D = new IDataHandle<Iisu.Data.Vector3[]>[2];
+        private IDataHandle<int>[] handSides = new IDataHandle<int>[2];
+        private IDataHandle<Iisu.Data.IImageData> depthImage;
+
+        /*
+         * Creates an Iisu data source.
+         * params:
+         *  moviePath: path to movie to be used as source
+         *             if empty the camera is used
+         */
+        public IIsuDataSource(string moviePath = "")
+        {
+            this.moviePath = moviePath;
+            active = false;
+        }
+
+        public void init()
+        {
+            handle = Iisu.Iisu.Context.CreateHandle();
+            
+            IDeviceConfiguration conf = handle.CreateDeviceConfiguration();
+            if (moviePath.Length != 0)
+                conf.MoviePath = moviePath;
+            
+            device = handle.InitializeDevice(conf);
+            
+            // parameters
+            device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 0; // playMode = once
+            frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate"); 
+
+            // events
+            device.EventManager.RegisterEventListener("DEVICE.Status", new Iisu.EventDelegates.Device.Status(onDeviceStatusChanged));
+            
+            // data
+            depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
+            
+            handOpen[0] = device.RegisterDataHandle<bool>("CI.HAND1.IsOpen");
+            handOpen[1] = device.RegisterDataHandle<bool>("CI.HAND2.IsOpen");
+
+            palmPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmPosition3D");
+            palmPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.PalmPosition3D");
+
+            tipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.TipPosition3D");
+            tipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.TipPosition3D");
+
+            forearmPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.ForearmPosition3D");
+            forearmPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.ForearmPosition3D");
+
+            palmNormals3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmNormal3D");
+            palmNormals3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.PalmNormal3D");
+
+            fingerStatus[0] = device.RegisterDataHandle<int[]>("CI.HAND1.FingerStatus");
+            fingerStatus[1] = device.RegisterDataHandle<int[]>("CI.HAND2.FingerStatus");
+
+            fingerTipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND1.FingerTipPositions3D");
+            fingerTipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND2.FingerTipPositions3D");
+
+            handSides[0] = device.RegisterDataHandle<int>("CI.HAND1.Side");
+            handSides[1] = device.RegisterDataHandle<int>("CI.HAND1.Side");
+        }
+
+        private void onDeviceStatusChanged(string eventName, DeviceStatus status)
+        {
+            active = status.HasFlag(Iisu.DeviceStatus.Playing);
+        }
+
+        public void start()
+        {
+            device.Start();
+        }
+
+        public void stop()
+        {
+            device.Stop(true);
+        }
+
+        public void updateFrame()
+        {
+            device.UpdateFrame(true);
+        }
+
+        public void releaseFrame()
+        {
+            device.ReleaseFrame();
+        }
+
+        public bool isActive()
+        {
+            return active;
+        }
+
+        public int getFrameRate()
+        {
+            return (int) frameRate.Value;
+        }
+
+        public DepthImage getDepthImage()
+        {
+            Iisu.Data.IImageInfos imageInfos = depthImage.Value.ImageInfos;
+            int width = (int) imageInfos.Width;
+            int height = (int) imageInfos.Height;
+            int numBytes = (int) imageInfos.BytesRaw;
+
+            IntPtr imageData = depthImage.Value.Raw;
+            
+            short[] tmp = new short[width * height];
+            Marshal.Copy(imageData, tmp, 0, width * height);
+
+            ushort[] data = new ushort[width * height];
+            Buffer.BlockCopy(tmp, 0, data, 0, numBytes);
+
+            return new DepthImage(width, height, data);
+        }
+
+        private void checkHandIndex(uint handIndex) 
+        {
+            if (handIndex < 1 || handIndex > 2)
+                throw new ArgumentOutOfRangeException("handIndex is out of range [0,1]");
+        }
+
+        public bool isHandOpen(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return handOpen[handIndex - 1].Value;
+        }
+
+        public Vector getPalmPosition3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(palmPositions3D[handIndex - 1].Value.ToArray());
+        }
+
+        public Vector getTipPosition3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(tipPositions3D[handIndex - 1].Value.ToArray());
+        }
+
+        public Vector getForearmPosition3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(forearmPositions3D[handIndex - 1].Value.ToArray());
+        }
+
+        public Vector getPalmNormal3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            return new DenseVector(palmNormals3D[handIndex - 1].Value.ToArray());
+        }
+
+        public FingerStatus[] getFingerStatus(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            int[] status = fingerStatus[handIndex - 1].Value;
+            FingerStatus[] result = new FingerStatus[status.Length];
+            for (int i = 0; i < status.Length; ++i)
+            {
+                switch (status[i])
+                {
+                    case 0:
+                        result[i] = FingerStatus.Inactive;
+                        break;
+                    case 1:
+                        result[i] = FingerStatus.Detected;
+                        break;
+                    case 2:
+                        result[i] = FingerStatus.Tracked;
+                        break;
+                }
+            }
+            return result;
+        }
+
+        public Vector[] getFingerTipPositions3D(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            Iisu.Data.Vector3[] positions = fingerTipPositions3D[handIndex - 1].Value;
+            Vector[] results = new DenseVector[positions.Length];
+            for (int i = 0; i < positions.Length; ++i)
+                results[i] = new DenseVector(positions[i].ToArray());
+            return results;
+        }
+
+        public HandSide getHandSide(uint handIndex)
+        {
+            checkHandIndex(handIndex);
+            int side = handSides[handIndex - 1].Value;
+            switch (side) 
+            {
+                case 1:
+                    return HandSide.Left;
+                case 2:
+                    return HandSide.Right;
+                default:
+                    return HandSide.Unknown;
+            }
+        }
+    }
+}

+ 88 - 0
bbiwarg/Program.cs

@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Drawing;
+using OpenTK;
+using OpenTK.Graphics.OpenGL;
+using Iisu;
+
+namespace bbiwarg
+{
+    class Program : GameWindow
+    {
+
+        static void Main(string[] args)
+        {
+            Program demo = new Program();
+            demo.init();
+            demo.Run(30);
+        }
+
+        protected override void OnLoad(EventArgs e)
+        {
+            base.OnLoad(e);
+            Title = "Hello OpenTK!";
+            GL.ClearColor(Color.CornflowerBlue);
+        }
+
+        protected override void OnRenderFrame(FrameEventArgs e)
+        {
+            base.OnRenderFrame(e);
+
+           device.UpdateFrame(true);
+           
+
+            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();
+            device.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, 64.0f);
+
+            GL.MatrixMode(MatrixMode.Projection);
+
+            GL.LoadMatrix(ref projection);
+        }
+
+        private IHandle handle;
+        private IDevice device;
+        private IDataHandle<Iisu.Data.Vector3> palmPosition;
+
+        public void init()
+        {
+            handle = Iisu.Iisu.Context.CreateHandle();
+            device = handle.InitializeDevice();
+            IEventManager em = handle.EventManager;
+
+            palmPosition = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmPosition3D");
+
+            device.Start();
+        }
+
+    }
+}

+ 36 - 0
bbiwarg/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("bbiwarg")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("bbiwarg")]
+[assembly: AssemblyCopyright("Copyright ©  2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("9a4fbb46-15f2-4c9a-a443-000e282b3ba5")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 47 - 0
bbiwarg/TestDataSource.cs

@@ -0,0 +1,47 @@
+using System;
+
+using System.Drawing;
+
+namespace bbiwarg
+{
+    class TestDataSource
+    {
+        static void Main(string[] args)
+        {
+            IVideoDataSource source = new IIsuDataSource("..\\..\\videos\\1.skv");
+
+            source.init();
+            source.start();
+
+            int i = 0;
+            int j = 0;
+            while (source.isActive())
+            {
+                source.updateFrame();
+
+                if ((i % 30) == 0)
+                {
+                    DepthImage image = source.getDepthImage();
+
+                    Bitmap bm = new Bitmap(image.getWidth(), image.getHeight());
+                    for (int x = 0; x < image.getWidth(); ++x)
+                    {
+                        for (int y = 0; y < image.getHeight(); ++y) 
+                        {
+                            int value = (image.getDepth(x, y) / 4) % 256; // / 4 because most values are small (< 1024)
+                            bm.SetPixel(x, y, Color.FromArgb(255, value, value, value));
+                        }
+                    }
+
+                    bm.Save("test." + j + ".png");
+                    j++;
+                }
+
+                source.releaseFrame();
+                ++i;
+            }
+
+            source.stop();
+        }
+    }
+}

+ 73 - 0
bbiwarg/bbiwarg.csproj

@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{12271049-82D6-436D-A51E-E6614C8E9C50}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>bbiwarg</RootNamespace>
+    <AssemblyName>bbiwarg</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="iisuNet, Version=3.0.0.0, Culture=neutral, processorArchitecture=x86">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>lib\iisuNet.dll</HintPath>
+    </Reference>
+    <Reference Include="MathNet.Numerics">
+      <HintPath>lib\MathNet.Numerics.dll</HintPath>
+    </Reference>
+    <Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>lib\OpenTK.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="DepthImage.cs" />
+    <Compile Include="IisuDataSource.cs" />
+    <Compile Include="IVideoDataSource.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="TestDataSource.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

BIN
bbiwarg/lib/MathNet.Numerics.dll


BIN
bbiwarg/lib/OpenTK.dll


BIN
bbiwarg/lib/iisuNet.dll