Kinect彩色和紅外圖像數據的處理

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 KinectColorViewer
{
/// 函數


/// MainWindow.xaml 的交互邏輯
///

public partial class MainWindow : Window
{
KinectSensor kinectSensor;
private byte[] pixelData;

public MainWindow()
    {
        InitializeComponent();
    }

    //在Loaded事件的處理函數中添加KinectSensor對象的初始化代碼
    private void Grid_Loaded(object sender, RoutedEventArgs e)
    {
        kinectSensor = (from sensor in KinectSensor.KinectSensors
                        where sensor.Status == KinectStatus.Connected
                        select sensor).FirstOrDefault();
        kinectSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
        kinectSensor.Start();//啓動Kinect設備
        kinectSensor.ColorFrameReady += kinectSensor_ColorFrameReady;
    }

    //獲取視頻數據,並將獲取到的數據顯示出來 
    void kinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
    {
        using (ColorImageFrame imageFrame = e.OpenColorImageFrame())
        {
            if(imageFrame != null)
            {
                this.pixelData = new byte[imageFrame.PixelDataLength];
                imageFrame.CopyPixelDataTo(this.pixelData);
                this.ColorImage.Source = BitmapSource.Create(imageFrame.Width,
                    imageFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixelData,
                    imageFrame.Width * imageFrame.BytesPerPixel);
            }
        }
    }

    private void Grid_Unloaded(object sender, RoutedEventArgs e)
    {
        kinectSensor.Stop();//關閉Kinect設備
    }
}

}this


ColorImageFormat 的枚舉項:
// 摘要:
// Image formats for the Color Image Stream. It represents Image Data format,
// Framerate, and Resolution.
public enum ColorImageFormat
{

// 摘要:
// The image format is undefined.
Undefined = 0,
//
// 摘要:
// RGB data (32 bits per pixel, layout corresponding to PixelFormats.Bgr32).
// Resolution of 640 by 480 at 30 Frames per second.
RgbResolution640x480Fps30 = 1,
//
// 摘要:
// RGB data (32 bits per pixel, layout corresponding to PixelFormats.Bgr32).
// Resolution of 1280 by 960 at 12 Frames per second.
RgbResolution1280x960Fps12 = 2,
//
// 摘要:
// The data is collected from the Kinect as YUV, but it is translated to: RGB
// data (32 bits per pixel, layout corresponding to PixelFormats.Bgr32). Resolution
// of 640 by 480 at 15 Frames per second.
YuvResolution640x480Fps15 = 3,
//
// 摘要:
// YUV data (32 bits per pixel, layout corresponding to D3DFMT_LIN_UYVY). Resolution
// of 640 by 480 at 15 Frames per second.
RawYuvResolution640x480Fps15 = 4,
//
// 摘要:
// Infrared data (16 bits per pxel) Resolution of 640 by 480 at 30 Frames per
// second.
InfraredResolution640x480Fps30 = 5,
//
// 摘要:
// Bayer data (8 bits per pixel, layout in alternating pixels of red, green
// and blue). Resolution of 640 by 480 at 30 Frames per second.
RawBayerResolution640x480Fps30 = 6,
//
// 摘要:
// Bayer data (8 bits per pixel, layout in alternating pixels of red, green
// and blue). Resolution of 1280 by 960 at 12 Frames per second.
RawBayerResolution1280x960Fps12 = 7,
}
spa

我只想說:操蛋!上次安裝的Kinect For Window SDK 的運行環境出錯。。。害得我覺得本身的程序出錯糾結了兩天!!!最後卸載從新下載安裝完果真沒錯。接下來就簡單了。。。code

相關文章
相關標籤/搜索