Comment Feed for Channel 9 - Demystifying the Interaction Stream (and how to use it without WPF)http://files.channel9.msdn.com/thumbnail/0d149d5d-a674-4d9c-8821-3cc720bd6d60.pngChannel 9 - Demystifying the Interaction Stream (and how to use it without WPF)The second in our two part InteractionStream without WPF series comes from András Velvárt, where he dives into a good deal of depth, not only showing how it works, but explains the details behind it too... Kinect Interactions with(out) WPF – Part III: Demystifying the Interaction Stream In this part of my Kinect Interaction blog post series, we go deep into the rabbit hole, and examine the foundation of Kinect Interactions – the InteractionStream, upon which the entire library is built. This is a risky ride – with no official documentation, we can only count on our trusty reflector, the source code of the Kinect Interaction SDK and careful exploration. You only need to access the treasures of InteractionStream, if you want to go beyond what the KinectRegion and other controls provide. For example, you want to create your own KinectRegion, you want to zoom a map by gripping it with two hands, or want to build your entirely new interaction model, using two hands along with the press and grip gestures. Initializing the InteractionStreamInitializing the InteractionStream is much like initializing the DepthStream or the SkeletonStream. If you have a KinectSensor object, all you need are the next two lines of code: ... It seems like we are on track. Just pass an initialized KinectSensor object and this DummyInteractionClient to the constructort of the InteractionStream, and we should be all set, right? Well, not quite. The InteractionFrameReady event does not fire. Interaction Needs Skeleton and DepthIt turns out, that for the InteractionStream to work, it needs to process the data from both the depth and the skeleton streams. So, we need to initiate all three of the streams. This is what the entire OnLoaded method (which you have to wire up either in XAML or in the constructor of the page) looks like: ... It doesn’t seem so simple now, so let's walk through each line of code and see what they do. The first five lines define local variables that hold a reference to the Kinect sensor the application will use, the InteractionStream itself, the skeletons identified by the SkeletonStream, and the hand position information about the users as determined by the InteractionStream. ... Dissecting InteractionFrameReadyEventArgsSo, now that we have finally made the InteractionStream call the InteractionFrameReady event, we can start analyzing what kind of data we can get to. The first step is to get our hand on an InteractionFrame, and the interaction data it contains: SummaryI’ve shown you how you can get started with the InteractionStream and acquire information about the hands of the users, detect active hands, pressing (IsPressed and PressExtent), and open / closed hands (HandEventType and our custom LastHandEventType). What I’ve shown here does not require WPF – you can use this from any .NET application, be it XNA, Windows Forms or even Command Line. Project Information URL: http://dotneteers.net/blogs/vbandi/archive/2013/05/03/kinect-interactions-with-wpf-part-iii-demystifying-the-interaction-stream.aspx Project Source URL: Source Download private Dictionary&lt;int, InteractionHandEventType&gt; _lastLeftHandEvents = new Dictionary&lt;int, InteractionHandEventType&gt;(); private Dictionary&lt;int, InteractionHandEventType&gt; _lastRightHandEvents = new Dictionary&lt;int, InteractionHandEventType&gt;();
Dictionary&lt;int, InteractionHandEventType&gt;();
private void InteractionStreamOnInteractionFrameReady(object sender,
ctionFrameReadyEventArgs args)
{
using (var iaf = args.OpenInteractionFrame()) //dispose as soon as
le
{
if (iaf == null)
return;
iaf.CopyInteractionDataTo(_userInfos);
}
StringBuilder dump = new StringBuilder();
var hasUser = false;
foreach (var userInfo in _userInfos)
{
var userID = userInfo.SkeletonTrackingId;
if (userID == 0)
continue;
hasUser = true;
dump.AppendLine(&quot;User ID = &quot; &#43; userID);
dump.AppendLine(&quot; Hands: &quot;);
var hands = userInfo.HandPointers;
if (hands.Count == 0)
dump.AppendLine(&quot; No hands&quot;);
else
{
foreach (var hand in hands)
{
var lastHandEvents = hand.HandType ==
ctionHandType.Left
? _lastLeftHandEvents
: _lastRightHandEvents;
if (hand.HandEventType !=
ctionHandEventType.None)
lastHandEvents[userID] = hand.HandEventType;
var lastHandEvent = lastHandEvents.ContainsKey(userID)
? lastHandEvents[userID]
:
ctionHandEventType.None;
dump.AppendLine();
dump.AppendLine(&quot; HandType: &quot; &#43; hand.HandType);
dump.AppendLine(&quot; HandEventType: &quot; &#43;
andEventType);
dump.AppendLine(&quot; LastHandEventType: &quot; &#43;
ndEvent);
dump.AppendLine(&quot; IsActive: &quot; &#43; hand.IsActive);
dump.AppendLine(&quot; IsPrimaryForUser: &quot; &#43;
sPrimaryForUser);
dump.AppendLine(&quot; IsInteractive: &quot; &#43;
sInteractive);
dump.AppendLine(&quot; PressExtent: &quot; &#43;
ressExtent.ToString(&quot;N3&quot;));
dump.AppendLine(&quot; IsPressed: &quot; &#43; hand.IsPressed);
dump.AppendLine(&quot; IsTracked: &quot; &#43; hand.IsTracked);
dump.AppendLine(&quot; X: &quot; &#43; hand.X.ToString(&quot;N3&quot;));
dump.AppendLine(&quot; Y: &quot; &#43; hand.Y.ToString(&quot;N3&quot;));
dump.AppendLine(&quot; RawX: &quot; &#43;
awX.ToString(&quot;N3&quot;));
dump.AppendLine(&quot; RawY: &quot; &#43;
awY.ToString(&quot;N3&quot;));
dump.AppendLine(&quot; RawZ: &quot; &#43;
awZ.ToString(&quot;N3&quot;));
}
}
tb.Text = dump.ToString();
}
if (!hasUser)
tb.Text = &quot;No user detected.&quot;;
} Contact Information: Blog: http://dotneteers.net/blogs/vbandi/ Twitter: @vbandi enSun, 02 Aug 2015 23:00:06 GMTSun, 02 Aug 2015 23:00:06 GMTRev9Re: Demystifying the Interaction Stream (and how to use it without WPF)
posted by Ben]]>
https://channel9.msdn.com/coding4fun/kinect/Demystifying-the-Interaction-Stream-and-how-to-use-it-without-WPF#c635071173024536438
Tue, 18 Jun 2013 01:55:02 GMThttps://channel9.msdn.com/coding4fun/kinect/Demystifying-the-Interaction-Stream-and-how-to-use-it-without-WPF#c635071173024536438Ben