基本上我有一个摄像机流,我试图在摄像机流的顶部覆盖一个Skeleton,我可以成功地做到这一点,如何骨架没有正确地映射到流的顶部。 / p>
我尝试使用坐标贴图并将深度空间点更改为ColorSpacePoint,但这会使骨架完全消失。
#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>``
如果您提前感谢
,可以获得更多信息答案 0 :(得分:0)
好的,所以我看到你正在为你的相机和骨架使用单独的Image
;我利用DrawingGroup
让骨架和相机对齐。另外,我通常不会依赖Grid
来放置Image
- 我将所有内容放在Canvas
上,或者如果您确实需要Grid
,请同时放置Image
{1}}位于Grid
的同一单元格中。
请使用DrawingGroup
查看this question示例。