ADD : début BodyStream (not working yet)

bodyStream
lobroda 1 year ago
parent 4366d32d52
commit 0a7c3c9a24

@ -1,4 +1,5 @@
using System;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -11,15 +12,68 @@ namespace KinectConnection
{
public class BodyImageStream : KinectStream
{
private BodyFrameReader reader;
private Body[] bodies = null;
public Body[] Bodies
{
get { return bodies; }
set { SetProperty(ref bodies, value); }
}
public BodyImageStream() : base()
{
// Initialize the bodies array
this.bodies = new Body[this.KinectSensor.BodyFrameSource.BodyCount];
}
public override void Start()
{
throw new NotImplementedException();
// Open the reader for the body frames
this.reader = this.KinectSensor.BodyFrameSource.OpenReader();
// Subscribe to the event
this.reader.FrameArrived += this.Reader_BodyFrameArrived;
}
public override void Stop()
{
throw new NotImplementedException();
if (this.reader != null)
{
// Unsubscribe from the event
this.reader.FrameArrived -= this.Reader_BodyFrameArrived;
// Dispose the reader to free resources
this.reader.Dispose();
this.reader = null;
}
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
bodyFrame.GetAndRefreshBodyData(this.bodies);
}
}
// Process the body data
foreach (Body body in this.bodies)
{
if (body.IsTracked)
{
// Get the right hand joint
Joint rightHand = body.Joints[JointType.HandRight];
// Check the tracking state of the joint
if (rightHand.TrackingState == TrackingState.Tracked)
{
CameraSpacePoint position = rightHand.Position;
}
}
}
}
}
}

@ -20,6 +20,7 @@ namespace KinectConnection
streamFactory = new Dictionary<KinectStreams, Func<KinectStream>>
{
{ KinectStreams.Color, () => new ColorImageStream() },
{ KinectStreams.Body, () => new BodyImageStream() },
// Other streams ...
};
}

@ -8,6 +8,7 @@
None,
Color,
Depth,
IR
IR,
Body
}
}

@ -110,8 +110,30 @@
</Grid>
<Grid Grid.Row="4">
<Viewbox Grid.Row="1" HorizontalAlignment="Center">
<Image Source="{Binding KinectStream.Bitmap}"/>
<Viewbox Grid.Row="1"
HorizontalAlignment="Center"
Height="400"
Width="400">
<!--<Image Source="{Binding KinectStream.Bitmap}"/>-->
<ItemsControl ItemsSource="{Binding KinectStream.Bodies}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Canvas>
<ItemsControl ItemsSource="{Binding Joints.Values}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Ellipse Width="10" Height="10" Fill="Red">
<Ellipse.RenderTransform>
<TranslateTransform X="{Binding Position.X}" Y="{Binding Position.Y}" />
</Ellipse.RenderTransform>
</Ellipse>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Canvas>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Viewbox>
</Grid>
</Grid>

@ -1,12 +1,16 @@
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using KinectConnection;
using KinectConnection.enums;
using System.Net.NetworkInformation;
using System.Windows.Input;
namespace KinectSensorStreams.ViewModel
{
public class MainWindowVM
public class MainWindowVM : ObservableObject
{
private KinectStream kinectStream;
#region Properties
/// <summary>
@ -31,7 +35,11 @@ namespace KinectSensorStreams.ViewModel
/// <summary>
/// The Kinect stream property.
/// </summary>
public KinectStream KinectStream { get; set; }
public KinectStream KinectStream
{
get { return kinectStream; }
set { SetProperty(ref kinectStream, value); }
}
#endregion
@ -48,7 +56,7 @@ namespace KinectSensorStreams.ViewModel
// factory
KinectStreamsFactory = new KinectStreamsFactory(new KinectManager());
// kinect stream => color stream for now
KinectStream = KinectStreamsFactory[KinectStreams.Color];
KinectStream = KinectStreamsFactory[KinectStreams.Body];
StartCommand = new RelayCommand(Start);
@ -75,7 +83,7 @@ namespace KinectSensorStreams.ViewModel
private void Color()
{
KinectStream.Start();
//KinectStream.Start();
}
#endregion

Loading…
Cancel
Save