using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
namespace 深度數據捕捉
{
/// ide
} else if (depth > 900 && depth < 2000) { pixels[colorIndex + BlueIndex] = 0; pixels[colorIndex + GreenIndex] = 255; pixels[colorIndex + RedIndex] = 0; } else if (depth > 2000) { pixels[colorIndex + BlueIndex] = 0; pixels[colorIndex + GreenIndex] = 0; pixels[colorIndex + RedIndex] = 255; } byte intensity = CalculateIntensityFromDepth(depth); pixels[colorIndex + BlueIndex] = intensity; pixels[colorIndex + GreenIndex] = intensity; pixels[colorIndex + RedIndex] = intensity; if (player > 0) { pixels[colorIndex + BlueIndex] = Colors.LightGreen.B; pixels[colorIndex + GreenIndex] = Colors.LightGreen.G; pixels[colorIndex + RedIndex] = Colors.LightGreen.R; } } return pixels; } private void Window_Loaded(object sender, RoutedEventArgs e) { if(KinectSensor.KinectSensors.Count>0){ _kinect=KinectSensor.KinectSensors[0]; _kinect.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); _kinect.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); _kinect.SkeletonStream.Enable(); _kinect.AllFramesReady+=_kinect_AllFramesReady; _kinect.Start(); } else{ Console.WriteLine("There's not Kinect!"); } }
void _kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame != null)
{
byte[] pixels = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(pixels);
int stride = colorFrame.Width * 4;
imageCamera.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride);spa
} } using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame != null) { byte[] pixelss = convertDepthFrameToColorFrame(depthFrame); int strides = depthFrame.Width * 4; imageDepth.Source = BitmapSource.Create(depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixelss, strides); } }
}code
private void Window_UnLoaded(object sender, RoutedEventArgs e)
{
_kinect.Stop();orm
}xml
}
}it
</Grid>