Project Type : window Form application
using Microsoft.Research.Kinect.Nui;
using Coding4Fun.Kinect.WinForm;
Step 1.
Initialize
------------------------------------------------------------
Runtime nui;
InLoading Event
nui = new Runtime();
nui.Initialize(RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor);
nui.VideoFrameReady += new EventHandler(nui_VideoFrameReady);
nui.SkeletonFrameReady +=new EventHandler (nui_SkeletonFrameReady);
//OpenStram
nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480,
ImageType.Color);
1.ImageStreamType :Video ,Depth,Invalid.
2.int : Depend on PC performance. 1 is batter .
3.ImageResolution: Kinect Video Resolution 640x480 can keep frame 30.
4.ImageType: Color,Depth.
1.RuntimeOption:
i.UseSkeletalTracking :Tracing Player Skeleton.
ii.UseColor : Image From Kinect.
iii.UseDepthAndPlayerIndex: Give multi player index And Depth Dector.
------------------------------------------------------------
Step 2.
Method
void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
{
//Using Coding4Fun's DLL
//picColorVideo is PictureBox
picColorVideo.Image= e.ImageFrame.ToBitmap();
//If not using Coding4Fun's DLL
//PlanerImage data = e.ImageFrame.Image;
//picColorVideo.Source = BitmapSource.Create(data.Width,data.Height,96,96,
// PixelFormats.Bgr32,null,data.Bits,data.Width*data.BytesPerPixel);
}
// Kinect coordinate Transfer Screen coordinate
Point GetDisplayPosition(Joint joint)
{
float depthX, depthY;
nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
depthX = Math.Max(0,Math.Min(depthX *320,320));
depthY = Math.Max(0, Math.Min(depthY * 240, 240));
int colorX, colorY;
nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480,
new ImageViewArea(), (int)depthX, (int)depthY, (short)0, out colorX, out colorY);
return new Point(colorX * picColorVideo.Width / 640, colorY * picColorVideo.Height / 480);
}
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
foreach (SkeletonData data in e.SkeletonFrame.Skeletons)
{
if (data.TrackingState == SkeletonTrackingState.Tracked)
{
JointsCollection jc = data.Joints;
StringBuilder sb = new StringBuilder();
foreach (JointID jid in Enum.GetValues(typeof(JointID)))
{
if (jid != JointID.Count)
{
Point p = GetDisplayPosition(jc[jid]);
sb.Append(string.Format("{0}={1},{2}\n", jid, p.X, p.Y));
}
}
//lblJoins is Labl
lblJoins.Text = sb.ToString();
}
}
}
------------------------------------------------------------
SkeletonTrackingState
Tracked - player have been detected.
PositionOnly- player have been cut,Kinect hard to detect.
NotTracked - The Joint doesn't be detect(It is hard to happen)
Joints TransformSmooth
nui.SkeletonEngine.TransformSmooth = true;
Advance
1.Use TransformSmoothParameters
nui.SkeletonEngine.SmoothParameters.
Correction
JitterRadius
MaxDeviation
Prediction
Smoothing
No comments:
Post a Comment