UPDATE(AllStreamsWork): AllStreamsWork but the code is ugly

pull/17/head
Johan LACHENAL 1 year ago
parent 6834f13942
commit 74faaf065f

@ -44,6 +44,7 @@ namespace Lib
Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
reader = kinectmanager.Sensor.BodyFrameSource.OpenReader();
reader.FrameArrived += Reader_BodyFrameArrived;
// initialiser le tableau des corps
this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount];
Canvas = skeletonCanvas;

@ -18,10 +18,14 @@ namespace Lib
public BodyFrameReader Reader
{
get { return reader; }
set { reader = value; }
private set { reader = value; }
}
//private ColorFrameReader colorReader;
private ColorFrameReader _colorReader;
public ColorFrameReader ColorReader {
get { return _colorReader; }
private set { _colorReader = value; }
}
private Body[] bodies;
public Body[] Bodies
@ -36,6 +40,11 @@ namespace Lib
Reader.Dispose();
Reader = null;
}
if(ColorReader != null)
{
ColorReader.Dispose();
ColorReader = null;
}
}
@ -45,6 +54,8 @@ namespace Lib
Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
reader = kinectmanager.Sensor.BodyFrameSource.OpenReader();
reader.FrameArrived += Reader_BodyFrameArrived;
ColorReader = KinectManager.Sensor.ColorFrameSource.OpenReader();
ColorReader.FrameArrived += Reader_ColorFrameArrived;
// initialiser le tableau des corps
this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount];
Canvas = skeletonCanvas;
@ -167,5 +178,36 @@ namespace Lib
}
}
}
private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
{
if (colorFrame != null)
{
// ... Logique existante pour traiter la frame
//Debug.WriteLine("Traitement de la frame de couleur.");
FrameDescription colorFrameDescription = colorFrame.FrameDescription;
using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
{
this.Bitmap.Lock();
// Vérifier si la taille de l'image a changé
if ((colorFrameDescription.Width == this.Bitmap.PixelWidth) && (colorFrameDescription.Height == this.Bitmap.PixelHeight))
{
colorFrame.CopyConvertedFrameDataToIntPtr(
this.Bitmap.BackBuffer,
(uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
ColorImageFormat.Bgra);
this.Bitmap.AddDirtyRect(new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight));
}
this.Bitmap.Unlock();
}
//Debug.WriteLine("Frame de couleur traitée.");
}
}
}
}
}

@ -12,6 +12,7 @@ namespace Lib
Color,
Depth,
IR,
Body,
ColorAndBody
}
}

@ -31,7 +31,8 @@ namespace Lib
{ KinectStreams.Color, () => new ColorImageStream(KinectManager) },
{ KinectStreams.Depth, () => new DepthImageStream(KinectManager) },
{ KinectStreams.IR, () => new InfraredImageStream(KinectManager) },
{ KinectStreams.ColorAndBody, () => new BodyImageStream(KinectManager,SkeletonCanvas) }
{ KinectStreams.Body, () => new BodyImageStream(KinectManager,SkeletonCanvas) },
{ KinectStreams.ColorAndBody, () => new ColorAndBodyImageStream(KinectManager,SkeletonCanvas) }
};
}

@ -22,12 +22,15 @@
<Button Content="Filtre 1" Margin="5" Click="ToColorImageStream"/>
<Button Content="Filtre 2" Margin="5" Click="ToDepthImageStream"/>
<Button Content="Filtre 3" Margin="5" Click="ToInfraredImageStream"/>
<Button Content="Filtre 4" Margin="5" Click="ToColorAndBodyImageStream"/>
<Button Content="Filtre 5" Margin="5"/>
<Button Content="Filtre 4" Margin="5" Click="ToBodyImageStream"/>
<Button Content="Filtre 5" Margin="5" Click="ToColorAndBodyImageStream"/>
</StackPanel>
<Image Grid.Row="2" Source="{Binding CurrentKinectStream.Bitmap}" />
<Canvas Grid.Row="2" x:Name="skeletonCanvas" />
<Viewbox Grid.Row="2" Stretch="Uniform">
<Grid>
<Image Grid.Row="2" Source="{Binding CurrentKinectStream.Bitmap}" />
<Canvas Grid.Row="2" x:Name="skeletonCanvas" />
</Grid>
</Viewbox>
</Grid>
</Window>

@ -97,6 +97,13 @@ namespace WpfApp
CurrentKinectStream.Start();
}
private void ToBodyImageStream(object sender, RoutedEventArgs e)
{
CurrentKinectStream.Stop();
CurrentKinectStream = Factory[KinectStreams.Body];
Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start();
}
private void ToColorAndBodyImageStream(object sender, RoutedEventArgs e)
{
CurrentKinectStream.Stop();

Loading…
Cancel
Save