Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

SilverLight 5 and Kinect, via the magic of P-Invoke

Kinect and the Kinect for Windows SDK and SilverLight 5? Impossible, you say? Not so my friends, not so. Not only is it possible, but here's someone that's done it AND sharing their code too!

Silverlight 5 P-Invoke: Using Kinect SDK from Silverlight

...The Silverlight 5 RC contains the previously announced P-Invoke feature which enables you to call Win32 style APIs from a trusted Silverlight application.

There are some attempts to use Kinect from Silverlight (here) but this was before MS released the official SDK. we will use Silverlight 5 P-Invoke feature to call the Kinect SDK APIs.

P-Invoke in Silverlight works just like P-Invoke on the desktop. you use the DllImport attribute to import the APIs and you declare in your code the dependent types (Enums, structs, etc.)

image

I tried to keep the classes and methods in library identical to the ones in the official SDK. I implemented only a couple of the available APIs (with the help of the Coding4Fun Kinect Toolkit and Reflector).

...

Project Information URL: http://mosalem.blogspot.com/2011/09/silverlight-5-p-invoke-using-kinect-sdk.html

Project Source URL: https://skydrive.live.com/?cid=cbb3c32611bc50d4&sc=documents&id=CBB3C32611BC50D4%21588 (and select and download "Silverlight 5 Library for Kinect")

image

image

image

image

private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
   Runtime runtime = (App.Current as App).KinectRuntime;
   runtime.VideoStream.OpenStream(ImageType.Color, ImageResolution.Resolution640x480);
  runtime.DepthStream.OpenStream(ImageType.Depth, ImageResolution.Resolution320x240);
runtime.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(runtime_VideoFrameReady);
   runtime.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(runtime_DepthFrameReady);
}
    
void runtime_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
{
    Dispatcher.BeginInvoke(() => {
        image1.Source = e.ImageFrame.ToBitmapSource();
    });
}
void runtime_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
{
    Dispatcher.BeginInvoke(() =>
    {
        image2.Source = e.ImageFrame.ToBitmapSource();
    });

}

Contact Information:

Follow the Discussion

  • Will this method or just using the managed dlls from the SDK work in a Metro (Windows 8) application?  I know it wouldn't get approved since it's not part of the WinRT, but I'd like to see if I can write a full screen Metro style app with Kinect.  Though I'm not sure that the drivers and SDK even work on Win 8.  I really hope we can get a WinRT version of the Kinect SDK as this would be very cook for when I have my tablet connected to my HD TV.

    Thanks,
    Mike

  • GeneGene

    Cool =) You can also use Kinect (wii motes and lot more) starting from Silverlight 2 and up using MIRIA SDK (http://miria.codeplex.com) .
    See video here : http://www.youtube.com/watch?v=IfY2jKlfvns

    G.

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.