Beispiel #1
0
        private void sliderTILT_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            int val = (int)sliderTILT.Value;

            CLNUIDevice.SetMotorPosition(motor, (short)val);
            textBoxTILT.Text = val.ToString();
        }
Beispiel #2
0
 void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (errquit == false)
     {
         if (campaused == true)
         {
             captureThread.Resume();
         }
         if (accpaused == false)
         {
             accelerometerTimer.Stop();
         }
         CLNUIDevice.SetMotorLED(motor, 0);
         if (motor != IntPtr.Zero)
         {
             CLNUIDevice.DestroyMotor(motor);
         }
         running = false;
         captureThread.Join();
         if (camera != IntPtr.Zero)
         {
             CLNUIDevice.StopCamera(camera);
             CLNUIDevice.DestroyCamera(camera);
         }
     }
 }
Beispiel #3
0
 void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (running == true)
     {
         running = false;
         captureThread.Join();
         if (camera != IntPtr.Zero)
         {
             CLNUIDevice.StopCamera(camera);
             CLNUIDevice.DestroyCamera(camera);
         }
         camera = CLNUIDevice.CreateCamera(devSerial);
     }
     if (comboFEED.SelectedIndex == 0)
     {
         colorImage    = new NUIImage(640, 480);
         feed.Source   = colorImage.BitmapSource;
         running       = true;
         captureThread = new Thread(delegate()
         {
             CLNUIDevice.StartCamera(camera);
             while (running)
             {
                 CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 500);
                 Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate()
                 {
                     colorImage.Invalidate();
                 });
             }
             CLNUIDevice.StopCamera(camera);
         });
         captureThread.IsBackground = true;
         captureThread.Start();
     }
     else
     {
         colorImage    = new NUIImage(640, 480);
         feed.Source   = colorImage.BitmapSource;
         running       = true;
         captureThread = new Thread(delegate()
         {
             CLNUIDevice.StartCamera(camera);
             while (running)
             {
                 CLNUIDevice.GetCameraDepthFrameRGB32(camera, colorImage.ImageData, 500);
                 Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate()
                 {
                     colorImage.Invalidate();
                 });
             }
             CLNUIDevice.StopCamera(camera);
         });
         captureThread.IsBackground = true;
         captureThread.Start();
     }
 }
Beispiel #4
0
 void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     accelerometerTimer.Stop();
     CLNUIDevice.SetMotorLED(motor, 0);
     if (motor != IntPtr.Zero)
     {
         CLNUIDevice.DestroyMotor(motor);
     }
     if (captureThread != null)
     {
         running = false;
         captureThread.Join(100);
     }
     if (camera != IntPtr.Zero)
     {
         CLNUIDevice.DestroyCamera(camera);
     }
 }
Beispiel #5
0
        public MainWindow()
        {
            InitializeComponent();
            Closing += new System.ComponentModel.CancelEventHandler(OnClosing);

            if (CLNUIDevice.GetDeviceCount() < 1)
            {
                MessageBox.Show("Is the Kinect plugged in?");
                Environment.Exit(0);
            }

            string serialString = CLNUIDevice.GetDeviceSerial(0);

            camera = CLNUIDevice.CreateCamera(serialString);

            colorImage = new NUIImage(640, 480);
            depthImage = new NUIImage(640, 480);
            rawImage   = new NUIImage(640, 480);

            color.Source = colorImage.BitmapSource;
            depth.Source = depthImage.BitmapSource;

            running       = true;
            captureThread = new Thread(delegate()
            {
                if (CLNUIDevice.StartCamera(camera))
                {
                    while (running)
                    {
                        CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 0);
                        CLNUIDevice.GetCameraDepthFrameRGB32(camera, depthImage.ImageData, 0);
                        CLNUIDevice.GetCameraDepthFrameRAW(camera, rawImage.ImageData, 0);
                        Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate()
                        {
                            colorImage.Invalidate();
                            depthImage.Invalidate();
                        });
                    }
                }
            });
            captureThread.IsBackground = true;
            captureThread.Start();
        }
Beispiel #6
0
 public MainWindow()
 {
     InitializeComponent();
     Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
     try
     {
         _devCount = CLNUIDevice.GetDeviceCount();
         if (_devCount == 0)
         {
             Environment.Exit(0);
         }
         for (int i = 0; i < _devCount; i++)
         {
             string devSerial = CLNUIDevice.GetDeviceSerial(i);
             cameras.Items.Add(string.Format("Kinect Serial: {0}", devSerial));
             cameraWindows[i] = new CameraWindow(devSerial);
             cameraWindows[i].Show();
         }
     }
     catch { }
 }
Beispiel #7
0
        public CameraWindow(string devSerial)
        {
            InitializeComponent();
            Closing += new System.ComponentModel.CancelEventHandler(OnClosing);

            xp.Minimum = -981;
            xp.Maximum = 981;
            yp.Minimum = -981;
            yp.Maximum = 981;
            zp.Minimum = -981;
            zp.Maximum = 981;

            try
            {
                motor  = CLNUIDevice.CreateMotor(devSerial);
                camera = CLNUIDevice.CreateCamera(devSerial);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                Environment.Exit(0);
            }

            CLNUIDevice.SetMotorPosition(motor, 0);

            serial.Content     = string.Format("Serial Number: {0}", devSerial);
            accelerometerTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Normal, (EventHandler) delegate(object sender, EventArgs e)
            {
                short _x = 0, _y = 0, _z = 0;
                CLNUIDevice.GetMotorAccelerometer(motor, ref _x, ref _y, ref _z);
                x.Content = _x.ToString();
                xp.Value  = _x;
                y.Content = _y.ToString();
                yp.Value  = _y;
                z.Content = _z.ToString();
                zp.Value  = _z;
            }, Dispatcher);
            accelerometerTimer.Start();

            led.SelectionChanged += new SelectionChangedEventHandler(led_SelectionChanged);
            led.SelectedIndex     = 0;

            colorImage   = new NUIImage(640, 480);
            color.Source = colorImage.BitmapSource;

            depthImage   = new NUIImage(640, 480);
            depth.Source = depthImage.BitmapSource;

            running       = true;
            captureThread = new Thread(delegate()
            {
//                 Trace.WriteLine(string.Format("Camera {0:X}", camera.ToInt32()));
                if (CLNUIDevice.StartCamera(camera))
                {
                    while (running)
                    {
                        CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 500);
                        CLNUIDevice.GetCameraDepthFrameRGB32(camera, depthImage.ImageData, 0);
                        Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate()
                        {
                            colorImage.Invalidate();
                            depthImage.Invalidate();
                        });
                    }
                    CLNUIDevice.StopCamera(camera);
                }
            });
            captureThread.IsBackground = true;
            captureThread.Start();
        }
Beispiel #8
0
 private void down_Click(object sender, RoutedEventArgs e)
 {
     CLNUIDevice.SetMotorPosition(motor, -8000);
 }
Beispiel #9
0
 void led_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     CLNUIDevice.SetMotorLED(motor, (byte)led.SelectedIndex);
 }
Beispiel #10
0
 private void comboLED_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     CLNUIDevice.SetMotorLED(motor, (byte)comboLED.SelectedIndex);
 }
Beispiel #11
0
        public CameraWindow(string devSerial)
        {
            this.devSerial = devSerial;
            InitializeComponent();
            Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
            try
            {
                motor  = CLNUIDevice.CreateMotor(devSerial);
                camera = CLNUIDevice.CreateCamera(devSerial);
                labelSERIAL.Content = string.Format("Serial Number: {0}", devSerial);
            }
            catch
            {
                MessageBox.Show("Is your device connected! Drivers installed?", "Kinect Not Found!");
                errquit = true;
                this.Close();
            }
            DataContext        = this;
            TheCharacter       = "█";
            FromLeft           = 526;
            FromTop            = 136;
            TheFontSize        = 5;
            accelerometerTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Normal, (EventHandler) delegate(object sender, EventArgs e)
            {
                short _x = 0, _y = 0, _z = 0;
                CLNUIDevice.GetMotorAccelerometer(motor, ref _x, ref _y, ref _z);
                double gx = 0;
                double gy = 0;
                _x        = (short)(_x - _xCal);
                _y        = (short)(_y - _yCal);
                _z        = (short)(_z - _zCal);
                if (comboXAXIS.SelectedIndex == 0)
                {
                    gx = _x + 1000;
                }
                else if (comboXAXIS.SelectedIndex == 1)
                {
                    gx = _y + 1000;
                }
                else if (comboXAXIS.SelectedIndex == 2)
                {
                    gx = _z + 1000;
                }
                if (comboYAXIS.SelectedIndex == 0)
                {
                    gy = _x + 1000;
                }
                else if (comboYAXIS.SelectedIndex == 1)
                {
                    gy = _y + 1000;
                }
                else if (comboYAXIS.SelectedIndex == 2)
                {
                    gy = _z + 1000;
                }
                FromLeft        = 389 + (int)(gx / 9.661835748792271);
                FromTop         = 34 + (int)(gy / 9.661835748792271);
                labelX.Content  = "X: " + (_x).ToString();
                progressX.Value = _x;
                labelY.Content  = "Y: " + (_y).ToString();
                progressY.Value = _y;
                labelZ.Content  = "Z: " + (_z).ToString();
                progressZ.Value = _z;
            }, Dispatcher);
            accelerometerTimer.Start();

            comboLED.SelectionChanged     += new SelectionChangedEventHandler(comboLED_SelectionChanged);
            comboLED.SelectedIndex         = 0;
            comboFEED.SelectionChanged    += new SelectionChangedEventHandler(comboBox1_SelectionChanged);
            comboFEED.SelectedIndex        = 0;
            comboXAXIS.SelectedIndex       = 0;
            comboYAXIS.SelectedIndex       = 1;
            comboTheSize.SelectionChanged += new SelectionChangedEventHandler(comboBox1_SelectionChanged_1);
            comboTheSize.SelectedIndex     = 5;
            sliderTILT.Maximum             = 8000;
            sliderTILT.Minimum             = -8000;
            sliderTILT.Value = 0;
            CLNUIDevice.SetMotorPosition(motor, 0);
        }