本文整理汇总了C#中Microsoft.Kinect.Skeleton.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Skeleton.Where方法的具体用法?C# Skeleton.Where怎么用?C# Skeleton.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Kinect.Skeleton
的用法示例。
在下文中一共展示了Skeleton.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSkeletonForPlayer
private Skeleton GetSkeletonForPlayer(int player)
{
Skeleton[] skeletons;
using (SkeletonFrame skeletonFrame = this._skeletonFrameEventArgs.OpenSkeletonFrame())
{
if (skeletonFrame == null)
{
throw new SkeletonFrameDataNotAvailableException();
}
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(skeletons);
}
var tracked = skeletons
.Where(skeleton => skeleton.TrackingState == SkeletonTrackingState.Tracked);
if (!tracked.Any())
{
throw new Exception("No players found!");
}
return tracked.ElementAtOrDefault(player);
}
示例2: ObterEsqueletoUsuario
public static Skeleton ObterEsqueletoUsuario(this SkeletonFrame quadro)
{
Skeleton esqueletoUsuario = null;
Skeleton[] esqueletos = new Skeleton[quadro.SkeletonArrayLength];
quadro.CopySkeletonDataTo(esqueletos);
IEnumerable<Skeleton> esqueletosRastreados = esqueletos.Where(esqueleto => esqueleto.TrackingState == SkeletonTrackingState.Tracked);
if (esqueletosRastreados.Count() > 0)
esqueletoUsuario = esqueletosRastreados.First();
return esqueletoUsuario;
}
示例3: Main
static void Main(string[] args)
{
var sensor = Microsoft.Kinect.KinectSensor.KinectSensors.FirstOrDefault(sens => sens.Status == KinectStatus.Connected);
if (sensor == null)
return;
sensor.SkeletonStream.Enable();
var skeletonData = new Skeleton[sensor.SkeletonStream.FrameSkeletonArrayLength];
sensor.SkeletonFrameReady += (o, arg) =>
{
using (SkeletonFrame frame = arg.OpenSkeletonFrame())
{
if (frame == null || skeletonData == null)
return;
frame.CopySkeletonDataTo(skeletonData);
foreach (var skeleton in skeletonData)
{
}
}
};
sensor.Start();
sensor.ElevationAngle = 0;
sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Default;
Vector<double> p0 = null, p1 = null, p2 = null;
Func<Vector<double>, Vector<double>> transform = null;
Func<Vector<double>> readRightHand = () => skeletonData.Where(row => row.TrackingState == SkeletonTrackingState.Tracked).Select(row => row.Joints[JointType.HandRight]).Select(row => new DenseVector(new double[] { row.Position.X, row.Position.Y, row.Position.Z })).FirstOrDefault();
while (true)
{
var key = Console.ReadKey();
if (key.Key == ConsoleKey.D0)
p0 = readRightHand();
if (key.Key == ConsoleKey.D1)
p1 = readRightHand();
if (key.Key == ConsoleKey.D2)
p2 = readRightHand();
if (p0 != null && p1 != null && p2 != null)
{
transform = WorldTransform.GenerateTransform(p0, p1, p2);
}
if (transform != null)
{
var transformed = transform(readRightHand());
Console.Clear();
Console.WriteLine("Transformed: " + PosToString(transformed));
}
else
{
Console.Clear();
Console.WriteLine("Untransformed: " + PosToString(readRightHand()));
}
}
}
示例4: DrawSkeleton
/// <summary>
/// Creates skeleton models for each of the tracked skeleton in the array
/// </summary>
/// <param name="skeletons">Array of all found skeletons</param>
/// <param name="brush">Color of the skeleton</param>
/// <param name="sensor">The sensor.</param>
/// <param name="width">The width of the canvas.</param>
/// <param name="height">The height of the canvas.</param>
public void DrawSkeleton(Skeleton[] skeletons, Brush brush, KinectSensor sensor, double width, double height)
{
var skeletonModels = new ObservableCollection<Polyline>();
foreach (var skeleton in skeletons.Where(skeleton => skeleton.TrackingState != SkeletonTrackingState.NotTracked))
{
skeletonModels.Add(CreateFigure(skeleton, brush, CreateBody(), sensor, width, height));
skeletonModels.Add(CreateFigure(skeleton, brush, CreateLeftHand(), sensor, width, height));
skeletonModels.Add(CreateFigure(skeleton, brush, CreateRightHand(), sensor, width, height));
skeletonModels.Add(CreateFigure(skeleton, brush, CreateLeftLeg(), sensor, width, height));
skeletonModels.Add(CreateFigure(skeleton, brush, CreateRightLeg(), sensor, width, height));
}
SkeletonParts = skeletonModels;
}
示例5: onSkeletonFrameReady
protected void onSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
Skeleton[] squelettes = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(squelettes);
if (canvas.Children.Count > 2)
canvas.Children.RemoveRange(1, canvas.Children.Count - 1);
foreach (Skeleton squelette in squelettes.Where(skel => skel.TrackingState == SkeletonTrackingState.Tracked))
{
drawBone(squelette, canvas, JointType.Head, JointType.ShoulderCenter, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.ShoulderCenter, JointType.ShoulderLeft, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.ShoulderCenter, JointType.ShoulderRight, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.ShoulderCenter, JointType.Spine, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.Spine, JointType.HipCenter, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.HipCenter, JointType.HipLeft, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.HipCenter, JointType.HipRight, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.ShoulderLeft, JointType.ElbowLeft, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.ElbowLeft, JointType.WristLeft, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.WristLeft, JointType.HandLeft, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.ShoulderRight, JointType.ElbowRight, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.ElbowRight, JointType.WristRight, Brushes.AliceBlue);
drawBone(squelette, canvas, JointType.WristRight, JointType.HandRight, Brushes.AliceBlue);
// Left Leg
this.drawBone(squelette, canvas, JointType.HipLeft, JointType.KneeLeft, Brushes.AliceBlue);
this.drawBone(squelette, canvas, JointType.KneeLeft, JointType.AnkleLeft, Brushes.AliceBlue);
this.drawBone(squelette, canvas, JointType.AnkleLeft, JointType.FootLeft, Brushes.AliceBlue);
// Right Leg
this.drawBone(squelette, canvas, JointType.HipRight, JointType.KneeRight, Brushes.AliceBlue);
this.drawBone(squelette, canvas, JointType.KneeRight, JointType.AnkleRight, Brushes.AliceBlue);
this.drawBone(squelette, canvas, JointType.AnkleRight, JointType.FootRight, Brushes.AliceBlue);
}
}
}
}
示例6: DesenharEsqueletoUsuario
private void DesenharEsqueletoUsuario(SkeletonFrame quadro)
{
if (quadro == null) return;
using (quadro)
{
Skeleton[] esqueletos = new Skeleton[quadro.SkeletonArrayLength];
quadro.CopySkeletonDataTo(esqueletos);
IEnumerable<Skeleton> esqueletosRastreados = esqueletos.Where(esqueleto => esqueleto.TrackingState == SkeletonTrackingState.Tracked);
if (esqueletosRastreados.Count() > 0)
{
Skeleton esqueleto = esqueletosRastreados.First();
EsqueletoUsuarioAuxiliar funcoesEsqueletos = new EsqueletoUsuarioAuxiliar(kinect);
funcoesEsqueletos.DesenharArticulacao(esqueleto.Joints[JointType.HandRight], canvasKinect);
funcoesEsqueletos.DesenharArticulacao(esqueleto.Joints[JointType.HandLeft], canvasKinect);
}
}
}
开发者ID:gilgaljunior,项目名称:CrieAplicacoesInterativascomoMicrosoftKinect,代码行数:18,代码来源:MainWindow.xaml.cs
示例7: SensorSkeletonFrameReady
// Process the new skeleton data
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
// Copy the skeleton data to the "skeletons" array.
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(skeletons);
// Cull off the non tracked skeletons.
skeletons = skeletons.Where(x => x.TrackingState == SkeletonTrackingState.Tracked).ToArray();
// Detect high fives between pairs of skeletons.
detectHighFives(skeletons);
}
}
}
示例8: Sensor_SkeletonFrameReady
static void Sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (var frame = e.OpenSkeletonFrame())
{
if (frame != null)
{
Skeleton[] skeletons = new Skeleton[frame.SkeletonArrayLength];
frame.CopySkeletonDataTo(skeletons);
if (skeletons.Length > 0)
{
var user = skeletons.Where(u => u.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault();
if (user != null)
{
//_gesture.Update(user);
}
}
}
}
}
示例9: FindClosestSkeleton
private Skeleton FindClosestSkeleton(Skeleton[] skeletons)
{
var seed = new
{
Distance = float.PositiveInfinity,
Skeleton = new Skeleton()
};
var result = skeletons.Where(skeleton => skeleton.TrackingState != SkeletonTrackingState.NotTracked)
.Aggregate(seed, (running, cur) =>
{
if (cur.Position.Z >= running.Distance)
return running;
return new
{
Distance = cur.Position.Z,
Skeleton = cur
};
});
return result.Skeleton;
}
示例10: SkeletonFramesReady
private static void SkeletonFramesReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
{
if (skeletonFrameData != null)
{
var allSkeletons = new Skeleton[skeletonFrameData.SkeletonArrayLength];
skeletonFrameData.CopySkeletonDataTo(allSkeletons);
List<Skeleton> tracked =
allSkeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked).ToList();
if (tracked.Any())
{
// Find the closest skeleton
Skeleton closest = tracked.OrderBy(t => t.Position.Z).First();
// Get the head x position
float headX = closest.Joints
.Where(j => j.JointType == JointType.Head)
.Select(h => h.Position.X)
.FirstOrDefault();
// Broadcast to subject
HeadXSubject.OnNext(headX);
}
}
}
}
示例11: ExtractValidSkeletons
private void ExtractValidSkeletons(Skeleton[] rawSkeletons)
{
var validSkeletons = rawSkeletons.Where(
skeleton => skeleton.TrackingState == SkeletonTrackingState.Tracked &&
skeleton.Joints.Count(joint => joint.TrackingState == JointTrackingState.Tracked) > Constants.MINIMUM_JOINT_THRESHOLD
);
foreach (Skeleton skeleton in validSkeletons)
{
if (currentVisitors.ContainsKey(skeleton.TrackingId))
currentVisitors[skeleton.TrackingId].Update(skeleton);
else
currentVisitors.Add(skeleton.TrackingId, new WagSkeleton(skeleton));
WagFaceTracker wagFaceTracker = wagFaceTrackers.SingleOrDefault(tracker => tracker.SkeletonId == skeleton.TrackingId);
if (wagFaceTracker == null)
{
wagFaceTracker = wagFaceTrackers.FirstOrDefault(tracker => tracker.IsUsing == false);
wagFaceTracker.SkeletonId = skeleton.TrackingId;
wagFaceTracker.IsUsing = true;
}
currentVisitors[skeleton.TrackingId].LastFrameSeen = currentFrame;
Calibration.ApplyTransformations(currentVisitors[skeleton.TrackingId]);
}
foreach (WagSkeleton wagSkeleton in currentVisitors.Values)
{
wagSkeleton.FramesNotSeen = currentFrame - wagSkeleton.LastFrameSeen;
}
OnPropertyChanged("ClosestVisitor");
}
示例12: SkeletonDataReadyHandler
private void SkeletonDataReadyHandler(object sender, SkeletonFrameReadyEventArgs e)
{
// no active user, ignore events
if (_activeUser == -1 || e == null || _kinect == null) return;
// not recording and no context, ignore events.
var sFrame = e.OpenSkeletonFrame();
if (sFrame == null) return;
var skeletons = new Skeleton[_kinect.GetSensor().SkeletonStream.FrameSkeletonArrayLength];
sFrame.CopySkeletonDataTo(skeletons);
sFrame.Dispose();
foreach (var skeleton in skeletons.Where(skeleton => skeleton != null && skeleton.TrackingId == _activeUser))
{
Skeleton2DDataExtract.ProcessData(skeleton, _defaultHand);
if (!_isRecording)
if (_pointer != null) _pointer.FindContext(skeleton);
if (_addOnGesture)
{
AddOnGesture(_addOnGestureType, skeleton);
}
}
}
示例13: GetPrimarySkeleton
/// <summary>
/// Looks for the closest skeleton
/// </summary>
/// <param name="skeletons">All skeletons recognised by Kinect</param>
/// <returns>The skeleton closestto the sensor</returns>
public static Skeleton GetPrimarySkeleton(Skeleton[] skeletons)
{
Skeleton skeleton = null;
if (skeletons != null)
foreach (Skeleton skelet in skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked))
if (skeleton == null || skelet.Position.Z < skeleton.Position.Z)
skeleton = skelet;
return skeleton;
}
示例14: NewSensor_SkeletonFrameReady
void NewSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs args)
{
var colors = new Dictionary<int, Color>();
Skeleton[] skeletons;
using (var frame = args.OpenSkeletonFrame())
{
if (frame == null)
return;
skeletons = new Skeleton[frame.SkeletonArrayLength];
frame.CopySkeletonDataTo(skeletons);
}
foreach (var skeleton in skeletons.Where(s => SkeletonTrackingState.Tracked.Equals(s.TrackingState)))
{
Random _rnd = new Random();
var userId = skeleton.TrackingId;
var crazyColors = Color.FromRgb((byte)_rnd.Next(255), (byte)_rnd.Next(255), (byte)_rnd.Next(255));
colors.Add(userId, KinectRegion.PrimaryUserTrackingId == userId ?
crazyColors :
Colors.Blue);
}
this.KinectUserViewer.UserColors = colors;
}
示例15: SensorSkeletonFrameReady
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
Skeleton[] skeletons = new Skeleton[0];
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
skeletonFrame.CopySkeletonDataTo(skeletons);
if (skeletons.Length > 0)
{
var user = skeletons.Where(u => u.TrackingState == SkeletonTrackingState.Tracked).FirstOrDefault();
if (user != null)
{
_gestureRight.Update(user);
_gestureLeft.Update(user);
}
}
}
}
}