C# Kinect SDK 2.0,将骨架映射到图像覆盖?
基本上,我有一个摄影机流,我试图在摄影机流的顶部覆盖一个骨架,我可以成功地做到这一点,因为骨架没有正确地映射到流的顶部 我尝试使用坐标映射器,将深度空间点更改为颜色空间点,但这会使骨架完全消失C# Kinect SDK 2.0,将骨架映射到图像覆盖?,c#,xaml,visual-studio-2013,kinect,C#,Xaml,Visual Studio 2013,Kinect,基本上,我有一个摄影机流,我试图在摄影机流的顶部覆盖一个骨架,我可以成功地做到这一点,因为骨架没有正确地映射到流的顶部 我尝试使用坐标映射器,将深度空间点更改为颜色空间点,但这会使骨架完全消失 #region Handling the body frame data arriving from the Sensor for Skeleton /// Handles the body frame data arriving from the sensor /// <
#region Handling the body frame data arriving from the Sensor for Skeleton
/// Handles the body frame data arriving from the sensor
/// </summary>
/// <param name="sender">object sending the event</param>
/// <param name="e">event arguments</param>
private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
// Normal Boolean
bool dataReceived = false;
//Using = Provides a convenient syntax that ensures the correct use of IDisposable objects.
using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
{
//If from is not Null
if (bodyFrame != null)
{
//If body is not null
if (this.bodies == null)
{
//New body in array number of bodies
this.bodies = new Body[bodyFrame.BodyCount];
}
// The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
// As long as those body objects are not disposed and not set to null in the array,
// those body objects will be re-used.
bodyFrame.GetAndRefreshBodyData(this.bodies);
dataReceived = true;
}
}
//if Data has been recieved
if (dataReceived)
{
//Use Drawing Group
using (DrawingContext dc = this.drawingGroup.Open())
{
// Draw a transparent background to set the render size
dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
//Set the index of the Pen to 0
int penIndex = 0;
//For each body
foreach (Body body in this.bodies)
{
//This is the colour of the Pen, It goes in array order for each body.
Pen drawPen = this.bodyColors[penIndex++];
//If body is tracked
if (body.IsTracked)
{
this.DrawClippedEdges(body, dc);
IReadOnlyDictionary<JointType, Joint> joints = body.Joints;
// convert the joint points to depth (display) space
Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>();
foreach (JointType jointType in joints.Keys)
{
// sometimes the depth(Z) of an inferred joint may show as negative
// clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
CameraSpacePoint SkeletonPosition = joints[jointType].Position;
if (SkeletonPosition.Z < 0)
{
SkeletonPosition.Z = InferredZPositionClamp;
}
ColorSpacePoint colorSpacePoint = this.coordinateMapper.MapCameraPointToColorSpace(SkeletonPosition);
jointPoints[jointType] = new Point(colorSpacePoint.X / 3.75, colorSpacePoint.Y / 3.75); //Divide Positions by 3.8 to correctly map skeleton to canvas
}
//Draw the bodies with the Pen Colour selected on amount of bodies available
this.DrawBody(joints, jointPoints, dc, drawPen);
//Draw the Left Hand, Feeding in the State and type of Joint
this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
//Draw the right Hand, Feeding in the state and type of Joint
this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);
this.test(joints, jointPoints, dc, drawPen, ElbowAngle);
}
}
// prevent drawing outside of our render area
this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
}
}
正如你所见,我正试图使用ColorSpacePoint将关节正确映射到颜色流,但由于某些原因,它不起作用,有人能解释一下我做错了什么吗
下面是我的XAML的外观:
<Window x:Class="MedicalKinectWPF.FreeFormSkeleton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:k="http://schemas.microsoft.com/kinect/2014"
WindowState="Maximized"
Loaded="FreeFormSkeletonWindow_Loaded"
Closing="FreeFormSkeletonWindow_Closing"
Title="MainWindow" Height="1920" Width="1080" Background="#FF381E1E">
<Window.Resources>
<SolidColorBrush x:Key="MediumGreyBrush" Color="#ff6e6e6e" />
<SolidColorBrush x:Key="KinectPurpleBrush" Color="#ff52318f" />
<SolidColorBrush x:Key="KinectBlueBrush" Color="#ff00BCF2" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120px" />
<RowDefinition Height="2" />
<RowDefinition Height="*" />
<RowDefinition Height="2" />
<RowDefinition Height="100px" />
</Grid.RowDefinitions>
<!-- Free Form Skeleton Title Label (HEADER)-->
<Label x:Name="Title" Content = "Free Form Skeleton Demonstration" TextElement.Foreground="Snow"
HorizontalAlignment="Center"
Margin="318,10,247,0"
VerticalAlignment="Top"
Height="44" Width="427"
FontSize="25" FontWeight="Bold"/>
<!-- Seperator -->
<Rectangle Grid.Row="1" Grid.ColumnSpan="2" Fill="LightBlue" />
<!-- Kinect Output-->
<Grid Grid.Row="2">
<Grid x:Name="CameraSkeletonGrid">
<!-- Camera image -->
<Image x:Name="CameraImage" Width="1920" Height="1080" />
<!--Skeleton Image-->
<Image Source="{Binding ImageSource}" Stretch="UniformToFill" Width="1920" Height="1080" />
</Grid>
<!-- Skeletal Tracking Only -->
<Grid x:Name="Skeleton" Margin="20" Visibility="Collapsed">
<Viewbox>
<Image Source="{Binding ImageSource}" Stretch="UniformToFill" Width="1920" Height="1080"/>
</Viewbox>
</Grid>
</Grid>
<!-- Seperator -->
<Rectangle Grid.Row="3" Fill="AliceBlue" />
<!-- Navigation -->
<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- Switch to camera & body -->
<Button x:Name = "ToggleRGBSkeleton" FontSize="25" FontFamily="Segoe UI Semibold" TextElement.Foreground="Snow" Background="{x:Null}" BorderBrush="White" Click="OnToggleCamera" Cursor="Hand" >
<TextBlock Text="RGB Camera With 
 Skeleton Overlay"/>
</Button>
<!-- Switch to Skeleton Only Mode -->
<Button x:Name="ToggleSkeleton" Grid.Column="1" FontSize="25" FontFamily="Segoe UI Semibold" TextElement.Foreground="Snow" Background="{x:Null}" BorderBrush="White" Click="OnToggleSkeleton" Cursor="Hand">
<TextBlock Text="Skeleton Only"/>
</Button>
</Grid>
</Grid>
</Window>``
如果您需要更多信息,请提前感谢好的,我看到您正在为您的相机和骨骼使用单独的图像;我利用一个绘图组将骨架和相机对齐。此外,我通常不依赖网格来放置图像-我将所有内容都放在画布上,或者如果您确实需要网格,请将两个图像放在网格的同一单元格中
请查看使用DrawingGroup的示例。您的XAML是什么样子的?问题的一部分可能是视觉元素没有排列好给我5分钟时间,我会编辑帖子,并为你输入我的Xaml编码。同时,这个链接可能会有所帮助:Xaml发布了,我多次查看,我看不出我做错了什么。我如何将两张图片放在网格的同一单元格上?