atsprink

atsprink atsprink

Niner since 2012

Comments

  • Camera Fundamentals

    I am new to all of these languages and I am developing with the Kinect for my senior design so I decided to look at these videos to start out.  How come when I combine the code from 2.Setting up the Environment and 3. Camera Fundamentals, I no longer get the camera to display an image.   I have the following code which is just basically the code from video 2 and 3 combined.  If I use the bitmap and byte[] i can get the image but not if I change it like the author of the video does.  Can someone help me?

     

    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    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;
    using Coding4Fun.Kinect.Wpf;
    
    
    
    namespace Gesture_Based_Controller
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            //this is a *template* app that includes library references only. It does not do anything but use SensorChooser
            //to manage Kinect state
    
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                //SetupKinectManually(); 
                kinectSensorChooser1.KinectSensorChanged +=new DependencyPropertyChangedEventHandler(kinectSensorChooser1_KinectSensorChanged);
            }
    
            private void kinectSensorChooser1_KinectSensorChanged(object sender, DependencyPropertyChangedEventArgs e)
            {
                var oldSensor = (KinectSensor)e.OldValue;
    
                // stop old sensor
                if (oldSensor != null)
                {
                    StopKinect(oldSensor);
                }
    
               var newSensor = (KinectSensor)e.NewValue;
               if (newSensor == null)
               {
                    return;
               }
    
                // turn on features that we need
                newSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
                newSensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                newSensor.SkeletonStream.Enable();
    
    
                try
                {
                    newSensor.Start();
                }
                catch (System.IO.IOException)
                {
                    //another app is using Kinect
                    kinectSensorChooser1.AppConflictOccurred();
                }
            }
    
            // this event fires when Color/Depth/Skeleton are synchronized
           /* void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
            {
                using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                {
                    if (colorFrame == null)
                    {
                        return;
                    }
    
                    byte[] pixels = new byte[colorFrame.PixelDataLength];
                    colorFrame.CopyPixelDataTo(pixels);
    
                    // how many bytes do we need on a per row basis  bgr 32 b,g,r, empty, b, g,r, empty
                    int stride = colorFrame.Width * 4;
                    image1.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride);
    
                } 
            }*/
    
            private void StopKinect(KinectSensor sensor)
            {
                if (sensor != null)
                {
                    if (sensor.IsRunning)
                    {
                        //stop sensor 
                        sensor.Stop();
    
                        //stop audio if not null
                        if (sensor.AudioSource != null)
                        {
                            sensor.AudioSource.Stop();
                        }
    
    
                    }
                }
            }
    
            private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
            {
                StopKinect(kinectSensorChooser1.Kinect);
            }
        }
    }