/// <summary> /// Constructor for VisualKinectUnit /// </summary> /// <param name="sensor">LocatedSensor class kinect sensor</param> /// <param name="skeletonDrawingImage">Image that we'll draw the skeleton on</param> /// <param name="colorImage">Image we'll use to push the color camera video to</param> public VisualKinectUnit(LocatedSensor locatedSensor, System.Windows.Controls.Image skeletonDrawingImage = null, System.Windows.Controls.Image colorImage = null, KinectViewport viewport = null) { // Get in some parameters this.locatedSensor = locatedSensor; this.skeletonDrawingImage = skeletonDrawingImage; this.colorImage = colorImage; this.viewport = viewport; // Set up the basics for drawing a skeleton this.showGlobalSkeletons = false; // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Turn on the skeleton stream to receive skeleton frames locatedSensor.sensor.SkeletonStream.Enable(); // Turn on the color stream to receive color frames locatedSensor.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); // This is the bitmap we'll display on-screen colorBitmap = (new WriteableBitmap(locatedSensor.sensor.ColorStream.FrameWidth, locatedSensor.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null)); // Add an event handler to be called whenever there is new color frame data if (colorImage != null) { locatedSensor.sensor.ColorFrameReady += this.refreshColorImage; } // Add an event handler to be called whenever there is new color frame data if (skeletonDrawingImage != null) { locatedSensor.sensor.SkeletonFrameReady += this.refreshSkeletonDrawing; this.skeletonDrawingImage.Source = imageSource; } // If we've got a viewport, then let's attach the generic update value function to // the text changed handlers if (viewport != null) { viewport.AttachVisualKinect(this); viewport.xOffset.TextChanged += updateValues; viewport.yOffset.TextChanged += updateValues; viewport.zOffset.TextChanged += updateValues; viewport.pitchAngle.TextChanged += updateValues; viewport.rollAngle.TextChanged += updateValues; viewport.yawAngle.TextChanged += updateValues; viewport.showGlobalSkeletons.Checked += setGlobalSkeletons; viewport.showGlobalSkeletons.Unchecked += clearGlobalSkeletons; } }
public VisualKinectUnit(LocatedSensor sensor, KinectViewport viewport) { new VisualKinectUnit(sensor, viewport.skeletonDrawingImage, viewport.colorImage, viewport); }