fixed button

bodyStream
lobroda 1 year ago
parent 322a3eec4f
commit f9eb86b849

@ -14,17 +14,6 @@ namespace KinectConnection
{
public class BodyImageStream : KinectStream
{
/// <summary>
/// The writeable bitmap.
/// </summary>
private WriteableBitmap bitmap = null;
// so that we can bind to it in the MainWindow.xaml
public WriteableBitmap Bitmap
{
get { return this.bitmap; }
}
private BodyFrameReader bodyFrameReader = null;
private Body[] bodies = null;
private DrawingGroup drawingGroup = new DrawingGroup();
@ -103,8 +92,6 @@ namespace KinectConnection
public override void Start()
{
this.bitmap = new WriteableBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Pbgra32, null);
if (this.KinectSensor != null)
{
this.bodyFrameReader = this.KinectSensor.BodyFrameSource.OpenReader();
@ -118,7 +105,15 @@ namespace KinectConnection
public override void Stop()
{
throw new NotImplementedException();
if (this.bodyFrameReader != null)
{
this.bodyFrameReader.FrameArrived -= this.Reader_BodyFrameArrived;
// Dispose the reader to free resources.
// If we don't dispose manualy, the gc will do it for us, but we don't know when.
this.bodyFrameReader.Dispose();
this.bodyFrameReader = null;
}
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)

@ -28,20 +28,24 @@ namespace KinectConnection
public ColorImageStream() : base()
{
// create the colorFrameDescription from the ColorFrameSource using rgba format
// the dimensions of the bitmap => match the dimensions of the color frame from the Kinect sensor.
FrameDescription colorFrameDescription = this.KinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
this.bitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
}
public override void Start()
{
// create the colorFrameDescription from the ColorFrameSource using rgba format
// the dimensions of the bitmap => match the dimensions of the color frame from the Kinect sensor.
FrameDescription colorFrameDescription = this.KinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
this.bitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
if (this.KinectSensor != null)
{
this.reader = this.KinectSensor.ColorFrameSource.OpenReader();
// open the reader for the color frames
this.reader = this.KinectSensor.ColorFrameSource.OpenReader();
// subscribe to the event
this.reader.FrameArrived += this.Reader_ColorFrameArrived;
if (this.reader != null)
{
this.reader.FrameArrived += this.Reader_ColorFrameArrived;
}
}
}
public override void Stop()

@ -57,15 +57,6 @@ namespace KinectConnection
public override void Start()
{
// get FrameDescription from DepthFrameSource
this.depthFrameDescription = this.KinectSensor.DepthFrameSource.FrameDescription;
// allocate space to put the pixels being received and converted
this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];
// create the bitmap to display
this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
if (this.KinectSensor != null)
{
// open the reader for the depth frames
@ -81,7 +72,27 @@ namespace KinectConnection
public override void Stop()
{
throw new NotImplementedException();
if (this.depthFrameReader != null)
{
this.depthFrameReader.FrameArrived -= this.Reader_FrameArrived;
// Dispose the reader to free resources.
// If we don't dispose manualy, the gc will do it for us, but we don't know when.
this.depthFrameReader.Dispose();
this.depthFrameReader = null;
}
}
public DepthImageStream() : base()
{
// get FrameDescription from DepthFrameSource
this.depthFrameDescription = this.KinectSensor.DepthFrameSource.FrameDescription;
// allocate space to put the pixels being received and converted
this.depthPixels = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height];
// create the bitmap to display
this.depthBitmap = new WriteableBitmap(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
}
/// <summary>

@ -95,13 +95,13 @@ namespace KinectConnection
{
// get FrameDescription from InfraredFrameSource
this.infraredFrameDescription = this.KinectSensor.InfraredFrameSource.FrameDescription;
}
public override void Start()
{
// create the bitmap to display
this.infraredBitmap = new WriteableBitmap(this.infraredFrameDescription.Width, this.infraredFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray32Float, null);
}
public override void Start()
{
if (this.KinectSensor != null)
{
// open the reader for the depth frames
@ -117,7 +117,15 @@ namespace KinectConnection
public override void Stop()
{
throw new NotImplementedException();
if (this.infraredFrameReader != null)
{
this.infraredFrameReader.FrameArrived -= this.Reader_InfraredFrameArrived;
// Dispose the reader to free resources.
// If we don't dispose manualy, the gc will do it for us, but we don't know when.
this.infraredFrameReader.Dispose();
this.infraredFrameReader = null;
}
}
/// <summary>

@ -70,7 +70,8 @@
<Button Content="Depth"
Width="100"
Height="30"
Grid.Column="3">
Grid.Column="3"
Command="{Binding DepthCommand}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>
@ -80,7 +81,8 @@
<Button Content="Infrared"
Width="100"
Height="30"
Grid.Column="5">
Grid.Column="5"
Command="{Binding IRCommand}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>
@ -90,7 +92,8 @@
<Button Content="Body"
Width="100"
Height="30"
Grid.Column="7">
Grid.Column="7"
Command="{Binding BodyCommand}">
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>

@ -19,6 +19,9 @@ namespace KinectSensorStreams.ViewModel
public ICommand StartCommand { get; set; }
public ICommand ColorCommand { get; set; }
public ICommand BodyCommand { get; set; }
public ICommand IRCommand { get; set; }
public ICommand DepthCommand { get; set; }
/// <summary>
/// Propriété liée à l'objet KinectManager
@ -55,12 +58,13 @@ namespace KinectSensorStreams.ViewModel
// factory
KinectStreamsFactory = new KinectStreamsFactory(new KinectManager());
// kinect stream => color stream for now
KinectStream = KinectStreamsFactory[KinectStreams.Depth];
StartCommand = new RelayCommand(Start);
// [Question] : StartCommand ici peut être mieux que BeginInit() dans MainWindow.xaml.cs ?
ColorCommand = new RelayCommand(Color);
BodyCommand = new RelayCommand(Body);
IRCommand = new RelayCommand(IR);
DepthCommand = new RelayCommand(Depth);
}
#endregion
@ -77,12 +81,47 @@ namespace KinectSensorStreams.ViewModel
// Start the kinect sensor
//KinectStream.KinectManager.StartSensor();
// Start the color stream reader
KinectStream.Start();
//KinectStream.Start();
}
private void Color()
{
//KinectStream.Start();
if(KinectStream != null)
{
KinectStream.Stop();
}
KinectStream = KinectStreamsFactory[KinectStreams.Color];
KinectStream.Start();
}
private void Body()
{
if (KinectStream != null)
{
KinectStream.Stop();
}
KinectStream = KinectStreamsFactory[KinectStreams.Body];
KinectStream.Start();
}
private void IR()
{
if (KinectStream != null)
{
KinectStream.Stop();
}
KinectStream = KinectStreamsFactory[KinectStreams.IR];
KinectStream.Start();
}
private void Depth()
{
if (KinectStream != null)
{
KinectStream.Stop();
}
KinectStream = KinectStreamsFactory[KinectStreams.Depth];
KinectStream.Start();
}
#endregion

Loading…
Cancel
Save