本文整理汇总了C#中KinectSensor类的典型用法代码示例。如果您正苦于以下问题:C# KinectSensor类的具体用法?C# KinectSensor怎么用?C# KinectSensor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KinectSensor类属于命名空间,在下文中一共展示了KinectSensor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
void Start()
{
// set up kinect connection
sensor = KinectSensor.GetDefault();
if (sensor != null)
{
bodyReader = sensor.BodyFrameSource.OpenReader();
// faceFrameSources = new FaceFrameSource[bodyCount];
// faceFrameReaders = new FaceFrameReader[bodyCount];
//
// for(int i = 0; i < bodyCount; ++i)
// {
// faceFrameSources[i] = FaceFrameSource.Create(sensor, 0, FaceFrameFeatures.LookingAway);
// faceFrameReaders[i] = faceFrameSources[i].OpenReader();
// }
//
// faceFrameResults = new FaceFrameResult[bodyCount];
if (!sensor.IsOpen)
sensor.Open ();
}
else
Debug.Log ("No Kinect Sensor found. Check connections / power");
}
示例2: Start
// Use this for initialization
void Start()
{
// Find a Kinect sensor
KinectSensorCollection kinectSensors = KinectSensor.KinectSensors;
if(kinectSensors.Count == 0)
{
this.sensor = null;
throw new UnityException("Could not find a Kinect sensor.");
}
// Enable the skeleton stream
this.sensor = kinectSensors[0];
this.sensor.SkeletonStream.Enable();
if(!this.sensor.SkeletonStream.IsEnabled)
{
throw new UnityException("Sensor could not be enabled.");
}
// Create the input processor
this.inputProcessor = new SeatedInfoProcessor();
//inputProcessor = new InputProcessor(this.sensor.CoordinateMapper, DepthImageFormat.Resolution320x240Fps30);
this.InputInfo = null;
Debug.Log("Hello");
return;
}
示例3: kinect_IsAvailableChanged
void kinect_IsAvailableChanged( KinectSensor sender, IsAvailableChangedEventArgs args )
{
// Kinectが接続された
if ( args.IsAvailable ) {
// カラーを設定する
if ( colorFrameReader == null ) {
// カラー画像の情報を作成する(BGRAフォーマット)
colorFrameDesc = kinect.ColorFrameSource.CreateFrameDescription( ColorImageFormat.Bgra );
colorBitmap = new WriteableBitmap( colorFrameDesc.Width, colorFrameDesc.Height );
ImageColor.Source = colorBitmap;
colorBuffer = new byte[colorFrameDesc.Width * colorFrameDesc.Height * colorFrameDesc.BytesPerPixel];
// カラーリーダーを開く
colorFrameReader = kinect.ColorFrameSource.OpenReader();
colorFrameReader.FrameArrived += colorFrameReader_FrameArrived;
}
ImageColor.Source = colorBitmap;
TextStatus.Text = "Kinectが接続されました";
}
// Kinectが外された
else {
// イメージを初期化する
ImageColor.Source = null;
TextStatus.Text = "Kinectが外されました";
}
}
示例4: OnNavigatedTo
protected override void OnNavigatedTo( NavigationEventArgs e )
{
base.OnNavigatedTo( e );
try {
// Kinectを開く
kinect = KinectSensor.GetDefault();
if ( kinect == null ) {
throw new Exception( "Kinectを開けません" );
}
kinect.Open();
// カラー画像の情報を作成する(BGRAフォーマット)
colorFrameDesc = kinect.ColorFrameSource.CreateFrameDescription( ColorImageFormat.Bgra );
colorBitmap = new WriteableBitmap( colorFrameDesc.Width, colorFrameDesc.Height );
ImageColor.Source = colorBitmap;
colorBuffer = new byte[colorFrameDesc.Width * colorFrameDesc.Height * colorFrameDesc.BytesPerPixel];
// カラーリーダーを開く
colorFrameReader = kinect.ColorFrameSource.OpenReader();
colorFrameReader.FrameArrived += colorFrameReader_FrameArrived;
}
catch ( Exception ex ) {
MessageDialog dlg = new MessageDialog( ex.Message );
dlg.ShowAsync();
}
}
示例5: MainPage
public MainPage()
{
InitializeComponent();
_sensor = KinectSensor.GetDefault();
if (_sensor != null)
{
_sensor.Open();
_bodies = new Body[_sensor.BodyFrameSource.BodyCount];
_colorReader = _sensor.ColorFrameSource.OpenReader();
_colorReader.FrameArrived += ColorReader_FrameArrived;
_bodyReader = _sensor.BodyFrameSource.OpenReader();
_bodyReader.FrameArrived += BodyReader_FrameArrived;
// 2) Initialize the face source with the desired features
_faceSource = new FaceFrameSource(_sensor, 0, FaceFrameFeatures.BoundingBoxInColorSpace |
FaceFrameFeatures.FaceEngagement |
FaceFrameFeatures.Glasses |
FaceFrameFeatures.Happy |
FaceFrameFeatures.LeftEyeClosed |
FaceFrameFeatures.MouthOpen |
FaceFrameFeatures.PointsInColorSpace |
FaceFrameFeatures.RightEyeClosed);
_faceReader = _faceSource.OpenReader();
_faceReader.FrameArrived += FaceReader_FrameArrived;
}
}
示例6: MainPage
public MainPage()
{
InitializeComponent();
_navigationHelper = new NavigationHelper(this);
_sensor = KinectSensor.GetDefault();
if (_sensor != null)
{
_sensor.Open();
_reader = _sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.Infrared | FrameSourceTypes.Body);
_reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
_gestureController = new GestureController();
_gestureController.GestureRecognized += GestureController_GestureRecognized;
}
// Initialize the gesture detection objects for our gestures
this.gestureDetectorList = new List<GestureDetector>();
// Create a gesture detector for each body (6 bodies => 6 detectors)
int maxBodies = this._sensor.BodyFrameSource.BodyCount;
for (int i = 0; i < maxBodies; ++i)
{
GestureResultView result =
new GestureResultView(i, false, false, 0.0f);
GestureDetector detector =
new GestureDetector(this._sensor, result);
result.PropertyChanged += GestureResult_PropertyChanged;
this.gestureDetectorList.Add(detector);
}
}
示例7: Start
void Start ()
{
_Sensor = KinectSensor.GetDefault();
if (_Sensor != null)
{
_Reader = _Sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth);
var colorFrameDesc = _Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
ColorWidth = colorFrameDesc.Width;
ColorHeight = colorFrameDesc.Height;
_ColorTexture = new Texture2D(colorFrameDesc.Width, colorFrameDesc.Height, TextureFormat.RGBA32, false);
_ColorData = new byte[colorFrameDesc.BytesPerPixel * colorFrameDesc.LengthInPixels];
var depthFrameDesc = _Sensor.DepthFrameSource.FrameDescription;
_DepthData = new ushort[depthFrameDesc.LengthInPixels];
_DepthTexture = new Texture2D( depthFrameDesc.Width, depthFrameDesc.Height, TextureFormat.ARGB32, false );
if (!_Sensor.IsOpen)
{
_Sensor.Open();
}
}
}
示例8: GestureDetector
/// <summary>
/// Initializes a new instance of the GestureDetector class along with the gesture frame source and reader
/// </summary>
/// <param name="kinectSensor">Active sensor to initialize the VisualGestureBuilderFrameSource object with</param>
/// <param name="gestureResultView">GestureResultView object to store gesture results of a single body to</param>
public GestureDetector(KinectSensor kinectSensor, KinectManager kinectManager)
{
if (kinectSensor == null)
{
throw new ArgumentNullException("kinectSensor");
}
// create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor.
this.vgbFrameSource = VisualGestureBuilderFrameSource.Create(kinectSensor, 0);
this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost;
// open the reader for the vgb frames
this.vgbFrameReader = this.vgbFrameSource.OpenReader();
if (this.vgbFrameReader != null)
{
this.vgbFrameReader.IsPaused = true;
this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived;
}
// load the 'Seated' gesture from the gesture database
using (VisualGestureBuilderDatabase database = VisualGestureBuilderDatabase.Create(this.gestureDatabase))
{
// we could load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures),
// but for this program, we only want to track one discrete gesture from the database, so we'll load it by name
foreach (Gesture gesture in database.AvailableGestures)
{
if (gesture.Name.Equals(this.shootingGestureName))
{
this.vgbFrameSource.AddGesture(gesture);
}
}
}
}
示例9: OnNavigatedTo
protected override void OnNavigatedTo( NavigationEventArgs e )
{
base.OnNavigatedTo( e );
try {
// Kinectを開く
kinect = KinectSensor.GetDefault();
if ( kinect == null ) {
throw new Exception( "Kinectを開けません" );
}
kinect.Open();
// 赤外線画像の情報を取得する
infraredFrameDesc = kinect.InfraredFrameSource.FrameDescription;
// 画像化のためのバッファを作成する
infraredBitmapBuffer = new byte[infraredFrameDesc.LengthInPixels * 4];
infraredBitmap = new WriteableBitmap(
infraredFrameDesc.Width, infraredFrameDesc.Height );
ImageInfrared.Source = infraredBitmap;
infraredBuffer = new ushort[infraredFrameDesc.LengthInPixels];
// 赤外線画像リーダーを開く
infraredFrameReader = kinect.InfraredFrameSource.OpenReader();
infraredFrameReader.FrameArrived += infraredFrameReader_FrameArrived;
}
catch ( Exception ex ) {
MessageDialog dlg = new MessageDialog( ex.Message );
dlg.ShowAsync();
}
}
示例10: OnNavigatedTo
protected override void OnNavigatedTo( NavigationEventArgs e )
{
base.OnNavigatedTo( e );
try {
// Kinectを開く
kinect = KinectSensor.GetDefault();
kinect.Open();
// 表示のためのデータを作成
depthFrameDesc = kinect.DepthFrameSource.FrameDescription;
// Depthリーダーを開く
depthFrameReader = kinect.DepthFrameSource.OpenReader();
depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
// 表示のためのデータ
depthBitmap = new WriteableBitmap( depthFrameDesc.Width,
depthFrameDesc.Height );
ImageDepth.Source = depthBitmap;
depthBuffer = new ushort[depthFrameDesc.LengthInPixels];
depthBitmapBuffer = new byte[depthFrameDesc.LengthInPixels * 4];
depthPoint = new Point( depthFrameDesc.Width / 2,
depthFrameDesc.Height / 2 );
}
catch ( Exception ex ) {
MessageDialog dlg = new MessageDialog(ex.Message);
dlg.ShowAsync();
}
}
示例11: Start
// Use this for initialization
void Start () {
print("START");
/*Get Kinect Sensor and start reading data*/
//Get Default Kinect Sensor
sensor = null;
sensor = KinectSensor.GetDefault();
if( sensor != null )
{
//We have a sensor connected
print("SENSOR CONNECTED");
//Open the connection/Start reading the data
reader = sensor.BodyFrameSource.OpenReader();
if( !sensor.IsOpen )
{
sensor.Open();
}
} else
{
print("NO KINECT CONNECTED");
}
print(sensor);
}
示例12: MainPage
public MainPage()
{
// one sensor is currently supported
this.kinectSensor = KinectSensor.GetDefault();
SetupCurrentDisplay(DEFAULT_DISPLAYFRAMETYPE);
this.multiSourceFrameReader =
this.kinectSensor.OpenMultiSourceFrameReader(
FrameSourceTypes.Infrared
| FrameSourceTypes.Color
| FrameSourceTypes.Depth);
this.multiSourceFrameReader.MultiSourceFrameArrived +=
this.Reader_MultiSourceFrameArrived;
// set IsAvailableChanged event notifier
this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;
// use the window object as the view model in this simple example
this.DataContext = this;
// open the sensor
this.kinectSensor.Open();
this.InitializeComponent();
}
示例13: Start
// Use this for initialization
void Start () {
mySensor = KinectSensor.GetDefault();
if (mySensor != null)
{
// Total array of data representing a single rendered frame
colorFrameData = new byte[colorWidth * colorHeight * bytes_per_pixel];
backgroundTex = new Texture2D(colorWidth, colorHeight, TextureFormat.BGRA32, false);
if (!mySensor.IsOpen)
{
mySensor.Open();
}
msFrameReader = mySensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color);
//Rendering user as part of the Unity Scene background via Main Camera
Rect cameraRect = Camera.main.pixelRect;
float rectHeight = cameraRect.height;
float rectWidth = cameraRect.width;
if (rectWidth > rectHeight)
rectWidth = rectHeight * colorWidth / colorHeight;
else
rectHeight = rectWidth * colorHeight / colorWidth;
float foregroundOfsX = (cameraRect.width - rectWidth) / 2;
float foregroundOfsY = (cameraRect.height - rectHeight) / 2;
foregroundImgRect = new Rect(foregroundOfsX, foregroundOfsY, rectWidth, rectHeight);
foregroundGuiRect = new Rect(foregroundOfsX, cameraRect.height - foregroundOfsY, rectWidth, -rectHeight);
}
} //End of Start()
示例14: FaceTracker
/// <summary>
/// Initializes a new instance of the FaceTracker class from a reference of the Kinect device.
/// <param name="sensor">Reference to kinect sensor instance</param>
/// </summary>
public FaceTracker(KinectSensor sensor)
{
if (sensor == null) {
throw new ArgumentNullException("sensor");
}
if (!sensor.ColorStream.IsEnabled) {
throw new InvalidOperationException("Color stream is not enabled yet.");
}
if (!sensor.DepthStream.IsEnabled) {
throw new InvalidOperationException("Depth stream is not enabled yet.");
}
this.operationMode = OperationMode.Kinect;
this.coordinateMapper = sensor.CoordinateMapper;
this.initializationColorImageFormat = sensor.ColorStream.Format;
this.initializationDepthImageFormat = sensor.DepthStream.Format;
var newColorCameraConfig = new CameraConfig(
(uint)sensor.ColorStream.FrameWidth,
(uint)sensor.ColorStream.FrameHeight,
sensor.ColorStream.NominalFocalLengthInPixels,
FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_B8G8R8X8);
var newDepthCameraConfig = new CameraConfig(
(uint)sensor.DepthStream.FrameWidth,
(uint)sensor.DepthStream.FrameHeight,
sensor.DepthStream.NominalFocalLengthInPixels,
FaceTrackingImageFormat.FTIMAGEFORMAT_UINT16_D13P3);
this.Initialize(newColorCameraConfig, newDepthCameraConfig, IntPtr.Zero, IntPtr.Zero, this.DepthToColorCallback);
}
示例15: MainPage
public MainPage()
{
// one sensor is currently supported
this.kinectSensor = KinectSensor.GetDefault();
// get the infraredFrameDescription from the InfraredFrameSource
FrameDescription infraredFrameDescription = this.kinectSensor.InfraredFrameSource.FrameDescription;
// open the reader for the infrared frames
this.infraredFrameReader = this.kinectSensor.InfraredFrameSource.OpenReader();
// wire handler for frame arrival
this.infraredFrameReader.FrameArrived += this.Reader_InfraredFrameArrived;
// allocate space to put the pixels being received and converted
this.infraredFrameData = new ushort[infraredFrameDescription.Width * infraredFrameDescription.Height];
this.infraredPixels = new byte[infraredFrameDescription.Width * infraredFrameDescription.Height * BytesPerPixel];
// create the bitmap to display
this.bitmap = new WriteableBitmap(infraredFrameDescription.Width, infraredFrameDescription.Height);
this.CurrentFrameDescription = infraredFrameDescription;
// set IsAvailableChanged event notifier
this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;
// use the window object as the view model in this simple example
this.DataContext = this;
// open the sensor
this.kinectSensor.Open();
this.InitializeComponent();
}