Notice: MediaWiki has been updated. Report any rough edges to marcan@marcan.st
CSharp Wrapper: Difference between revisions
From OpenKinect
Jump to navigationJump to search
LostInCake (talk | contribs) (Updated for new C# wrapper after rewrite for new API) |
|||
Line 1: | Line 1: | ||
== About == | == About == | ||
This effort will provide a wrapper to access the Kinect through C#. Instead of being a light wrapper, this aims to bring the capabilities of the low level wrapper and let it be used in a way that conforms to C# patterns. | |||
== Who is involved == | == Who is involved == | ||
Line 23: | Line 20: | ||
|- | |- | ||
| Control motor | | Control motor | ||
| Yes | |||
| | |||
|- | |||
| Get motor status | |||
| Yes | | Yes | ||
| | | | ||
Line 30: | Line 31: | ||
| | | | ||
|- | |- | ||
| | | Video streams | ||
| Yes | | Yes | ||
| | | | ||
|- | |- | ||
| Depth | | Depth streams | ||
| Yes | | Yes | ||
| | | | ||
Line 41: | Line 42: | ||
== Media == | == Media == | ||
[[File: | [[File:Csharp_kinect_demo_screenshot.png|none|thumb|400px|Screenshot of demo application.]] | ||
== Installation/Configuration == | == Installation/Configuration == | ||
===General Overview=== | |||
# Build the base library. Please refer to [http://openkinect.org/wiki/Getting_Started Getting Started] for this. | |||
# Copy libfreenect.so (linux) or libfreenect.dll (windows) to {Libfreenect Directory}/wrappers/csharp/bin | |||
# Build freenectlib and KinectDemo using the VS2008 or VS2010 solutions. | |||
# Run. Enjoy | |||
===Building C# wrapper and demo application=== | |||
The following instructions use MonoDevelop. If you have access to Visual Studio or Visual Studio Express, you can safely follow the same instructions and perform analogous steps inside the Visual Studio IDE. | |||
# Download and install [http://monodevelop.com/ MonoDevelop]. In Ubuntu, this can be found under the Software Center. | |||
# Browse to {Libfreenect Directory}/wrappers/csharp/src/lib/ and then use the solutions in either VS2008 or VS2010 depending on your version of MonoDevelop. | |||
## Once you build freenectlib, a freenect.dll should appear in {Libfreenect Directory}/wrappers/csharp/bin | |||
# Download [http://www.opentk.com/ OpenTK] binaries. Place these in a directory of your choice. | |||
# Browse to {Libfreenect Directory}/wrappers/csharp/src/test/KinectDemo and then use the solutions in either VS2008 or VS2010 depending on your version of MonoDevelop. | |||
## Fix references in the solution for the location to OpenTK binaries. | |||
## Once you build KinectDemo, a KinectDemo.exe should appear in {Libfreenect Directory}/wrappers/csharp/bin | |||
== Sample Code == | == Sample Code == | ||
The following sample code provides a basic look at how the C# wrapper is used. Full a full blown example, please look at the KinectDemo application in the repository. | |||
<source lang="csharp" border="1"> | <source lang="csharp" border="1"> | ||
using | using System; | ||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Windows.Forms; | |||
using System.Threading; | |||
using freenect; | |||
using System.Drawing; | |||
using System.Diagnostics; | |||
... | namespace KinectNetSample | ||
{ | |||
public class Sample : Form | |||
{ | |||
/// <summary> | |||
/// Constructor | |||
/// </summary> | |||
public Sample() | |||
{ | |||
// Initialize UI stuff | |||
this.InitializeComponents(); | |||
// Find device count | |||
Console.WriteLine("There are {0} Kinect Devices Connected", Kinect.DeviceCount); | |||
if(Kinect.DeviceCount > 0) | |||
{ | |||
// Connect to first device | |||
Kinect kinect = new Kinect(0); | |||
kinect.Open(); | |||
// Setup event handlers | |||
kinect.VideoCamera.DataReceived += HandleKinectVideoCameraDataReceived; | |||
kinect.DepthCamera.DataReceived += HandleKinectDepthCameraDataReceived; | |||
// Start cameras | |||
kinect.VideoCamera.Start(); | |||
kinect.DepthCamera.Start(); | |||
// | // Set LED to Yellow | ||
kinect.LED.Color = LEDColor.Yellow; | |||
// Set tilt to halfway up | |||
kinect.Motor.Tilt = 0.5; | |||
// Start update thread | |||
Thread t = new Thread(new ThreadStart(delegate() | |||
{ | |||
while(true) | |||
{ | |||
kinect.UpdateStatus(); | |||
} | |||
})); | |||
} | |||
} | |||
/// <summary> | |||
/// Handle depth data | |||
/// </summary> | |||
/// <param name="sender"> | |||
/// A <see cref="System.Object"/> | |||
/// </param> | |||
/// <param name="e"> | |||
/// A <see cref="BaseCamera.DataReceivedEventArgs"/> | |||
/// </param> | |||
private void HandleKinectDepthCameraDataReceived (object sender, BaseCamera.DataReceivedEventArgs e) | |||
{ | |||
Console.WriteLine("Depth data received at {0}", e.Timestamp); | |||
// Actual data is in e.Data | |||
} | |||
/// <summary> | |||
/// Handle video data | |||
/// </summary> | |||
/// <param name="sender"> | |||
/// A <see cref="System.Object"/> | |||
/// </param> | |||
/// <param name="e"> | |||
/// A <see cref="BaseCamera.DataReceivedEventArgs"/> | |||
/// </param> | |||
private void HandleKinectVideoCameraDataReceived (object sender, BaseCamera.DataReceivedEventArgs e) | |||
{ | |||
Console.WriteLine("Video data received at {0}", e.Timestamp); | |||
// Actual data is in e.Data | |||
} | |||
} | |||
} | } | ||
</source> | </source> | ||
[[Category:Wrappers]] | [[Category:Wrappers]] |
Revision as of 05:57, 27 May 2011
About
This effort will provide a wrapper to access the Kinect through C#. Instead of being a light wrapper, this aims to bring the capabilities of the low level wrapper and let it be used in a way that conforms to C# patterns.
Who is involved
Coordinator/Development: Aditya Gaddam (User:LostInCake)
Current Status
Feature | Supported? | Notes |
---|---|---|
Connect to Kinect (heh) | Yes | |
Control LED | Yes | 0x04 and 0x05 for the LED status seem to do the same thing - Blink Green. Seems to be something on the native lib side though. |
Control motor | Yes | |
Get motor status | Yes | |
Get accelerometer data | Yes | |
Video streams | Yes | |
Depth streams | Yes |
Media
Installation/Configuration
General Overview
- Build the base library. Please refer to Getting Started for this.
- Copy libfreenect.so (linux) or libfreenect.dll (windows) to {Libfreenect Directory}/wrappers/csharp/bin
- Build freenectlib and KinectDemo using the VS2008 or VS2010 solutions.
- Run. Enjoy
Building C# wrapper and demo application
The following instructions use MonoDevelop. If you have access to Visual Studio or Visual Studio Express, you can safely follow the same instructions and perform analogous steps inside the Visual Studio IDE.
- Download and install MonoDevelop. In Ubuntu, this can be found under the Software Center.
- Browse to {Libfreenect Directory}/wrappers/csharp/src/lib/ and then use the solutions in either VS2008 or VS2010 depending on your version of MonoDevelop.
- Once you build freenectlib, a freenect.dll should appear in {Libfreenect Directory}/wrappers/csharp/bin
- Download OpenTK binaries. Place these in a directory of your choice.
- Browse to {Libfreenect Directory}/wrappers/csharp/src/test/KinectDemo and then use the solutions in either VS2008 or VS2010 depending on your version of MonoDevelop.
- Fix references in the solution for the location to OpenTK binaries.
- Once you build KinectDemo, a KinectDemo.exe should appear in {Libfreenect Directory}/wrappers/csharp/bin
Sample Code
The following sample code provides a basic look at how the C# wrapper is used. Full a full blown example, please look at the KinectDemo application in the repository.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using freenect;
using System.Drawing;
using System.Diagnostics;
namespace KinectNetSample
{
public class Sample : Form
{
/// <summary>
/// Constructor
/// </summary>
public Sample()
{
// Initialize UI stuff
this.InitializeComponents();
// Find device count
Console.WriteLine("There are {0} Kinect Devices Connected", Kinect.DeviceCount);
if(Kinect.DeviceCount > 0)
{
// Connect to first device
Kinect kinect = new Kinect(0);
kinect.Open();
// Setup event handlers
kinect.VideoCamera.DataReceived += HandleKinectVideoCameraDataReceived;
kinect.DepthCamera.DataReceived += HandleKinectDepthCameraDataReceived;
// Start cameras
kinect.VideoCamera.Start();
kinect.DepthCamera.Start();
// Set LED to Yellow
kinect.LED.Color = LEDColor.Yellow;
// Set tilt to halfway up
kinect.Motor.Tilt = 0.5;
// Start update thread
Thread t = new Thread(new ThreadStart(delegate()
{
while(true)
{
kinect.UpdateStatus();
}
}));
}
}
/// <summary>
/// Handle depth data
/// </summary>
/// <param name="sender">
/// A <see cref="System.Object"/>
/// </param>
/// <param name="e">
/// A <see cref="BaseCamera.DataReceivedEventArgs"/>
/// </param>
private void HandleKinectDepthCameraDataReceived (object sender, BaseCamera.DataReceivedEventArgs e)
{
Console.WriteLine("Depth data received at {0}", e.Timestamp);
// Actual data is in e.Data
}
/// <summary>
/// Handle video data
/// </summary>
/// <param name="sender">
/// A <see cref="System.Object"/>
/// </param>
/// <param name="e">
/// A <see cref="BaseCamera.DataReceivedEventArgs"/>
/// </param>
private void HandleKinectVideoCameraDataReceived (object sender, BaseCamera.DataReceivedEventArgs e)
{
Console.WriteLine("Video data received at {0}", e.Timestamp);
// Actual data is in e.Data
}
}
}