Click here to Skip to main content
15,895,746 members
Articles / Desktop Programming / WPF

Kinect Reception

Rate me:
Please Sign up or sign in to vote.
4.94/5 (34 votes)
12 Jan 2012Ms-PL5 min read 69.1K   2K   80  
TV Screen in the Reception, When nothing happens (no one is in the reception) we can display videos on the screen but when someone enters the frame show him the Kinect Image, and if the user is doing something funny, capture his image and save it.
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using KinectReception.Enums;
using KinectReception.Managers;
using KinectReception.Objects;
using Microsoft.Research.Kinect.Nui;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;

namespace KinectReception.Controls
{
    /// <summary>
    /// Interaction logic for Settings.xaml
    /// </summary>
    public partial class KinectSettings : Window
    {
        private readonly ObservableCollection<RuleObject> _rules;
        private bool _changed = false;

        public KinectSettings()
        {
            this.InitializeComponent();

            Properties.Settings.Default.PropertyChanged += new PropertyChangedEventHandler(DefaultPropertyChanged);
            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            _rules = ConfigurationManager.Load();
            ListRules.ItemsSource = _rules;
        }

        void DefaultPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            _changed = true;
        }

        private void BtnKinectStatusClick(object sender, RoutedEventArgs e)
        {
            if (btnKinectStatus.Content.Equals(Properties.Resources.StartText))
            {
                SetKinectStop();
                KinectManager.GetInstance.Start();
            }
            else
            {
                SetKinectStart();
                KinectManager.GetInstance.Close();
            }
        }

        void SetKinectStop()
        {
            btnKinectStatus.Background = new LinearGradientBrush(Properties.Settings.Default.KinectButtonColor, Properties.Settings.Default.KinectButtonColorOffline, 1);
            btnKinectStatus.Content = Properties.Resources.StopText;

        }

        void SetKinectStart()
        {
            btnKinectStatus.Background = new LinearGradientBrush(Properties.Settings.Default.KinectButtonColor, Properties.Settings.Default.KinectButtonColorOnline, 1);
            btnKinectStatus.Content = Properties.Resources.StartText;
        }

        private void UserControlLoaded(object sender, RoutedEventArgs e)
        {
            if (KinectManager.GetInstance.IsInitialize)
            {
                SetKinectStop();
                txtCameraAngle.Text = Convert.ToString(KinectManager.GetInstance.Camera.ElevationAngle);

                btnKinectStatus.IsEnabled = true;
                expanderCamera.IsEnabled = expanderKinectSettings.IsEnabled = true;
            }
            else
            {
                btnKinectStatus.IsEnabled = false;
                expanderCamera.IsEnabled = expanderKinectSettings.IsEnabled = false;
                SetKinectStart();
            }

            
            txtStatus.Text = KinectManager.GetInstance.StatusMessage;
        }

        private void UserControlKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                var result = System.Windows.MessageBox.Show(Properties.Resources.KinectSettingsLeave, Properties.Resources.KinectSettingsTitle,
                                                            MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                    SaveClose();
                else if (result == MessageBoxResult.No)
                    ResetClose();
            }
        }

        void ResetClose()
        {
            Properties.Settings.Default.Reload();
            this.Close();
        }

        private void BtnSaveMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SaveClose();
        }

        private void BtnCloseMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ResetClose();
        }

        private void LblAddMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            _rules.Add(new RuleObject());
        }

        private void BtnDeleteClick(object sender, RoutedEventArgs e)
        {
            var a = ((System.Windows.Controls.Button)e.Source).Tag;
            _rules.Remove((RuleObject)a);
        }

        private void SaveClose()
        {
            ConfigurationManager.Save(this._rules);
            Properties.Settings.Default.Save();
            this.Close();
        }

        private void BtnBrowseVideosClick(object sender, RoutedEventArgs e)
        {
            var ofd = new FolderBrowserDialog();
            ofd.ShowDialog();

            if (string.IsNullOrEmpty(ofd.SelectedPath)) return;

            Properties.Settings.Default.VideosLibraryFolder = ofd.SelectedPath;
        }

        private void BtnBrowseVideosLeaveClick(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();
            ofd.Filter = Properties.Resources.VideoFilter;
            ofd.ShowDialog();

            if (string.IsNullOrEmpty(ofd.FileName)) return;

            Properties.Settings.Default.VideosLibraryOutFile = ofd.FileName;
        }

        private void BtnBrowseVideosEnterClick(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();
            ofd.Filter = Properties.Resources.VideoFilter;
            ofd.ShowDialog();

            if (string.IsNullOrEmpty(ofd.FileName)) return;

            Properties.Settings.Default.VideosLibraryInFile = ofd.FileName;
        }

        private void BtnBrowsePicturesClick(object sender, RoutedEventArgs e)
        {
            var ofd = new FolderBrowserDialog();
            ofd.ShowDialog();

            if (string.IsNullOrEmpty(ofd.SelectedPath)) return;

            Properties.Settings.Default.PicturesLibrary = ofd.SelectedPath;
        }

        private void BtnAngleUpMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            KinectManager.GetInstance.ChangeCameraAngle(ChangeDirection.Up);
            txtCameraAngle.Text = Convert.ToString(KinectManager.GetInstance.Camera.ElevationAngle);
        }

        private void BtnAngleDownMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            KinectManager.GetInstance.ChangeCameraAngle(ChangeDirection.Down);
            txtCameraAngle.Text = Convert.ToString(KinectManager.GetInstance.Camera.ElevationAngle);
        }

        private void LblHelpMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (this.Width == 1090)
            {
                lblHelp.Content = Properties.Resources.HelpText;
                this.Width = 600;
            }
            else
            {
                lblHelp.Content = Properties.Resources.HelpTextClose;
                this.Width = 1090;
            }
        }

        private void SourceSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (e.RemovedItems.Count == 0) return;

            var selectedJoint = ((JointID)e.AddedItems[0]);
            VitruvianMan.HighlightJoint(selectedJoint);
        }

        private void TargetSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (e.RemovedItems.Count == 0) return;

            var selectedJoint = ((JointID)e.AddedItems[0]);
            VitruvianMan.HighlightJoint(selectedJoint);
        }            
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Architect Sela
Israel Israel
Shai Raiten is VS ALM MVP, currently working for Sela Group as a ALM senior consultant and trainer specializes in Microsoft technologies especially Team System and .NET technology. He is currently consulting in various enterprises in Israel, planning and analysis Load and performance problems using Team System, building Team System customizations and adjusts ALM processes for enterprises. Shai is known as one of the top Team System experts in Israel. He conducts lectures and workshops for developers\QA and enterprises who want to specialize in Team System.

My Blog: http://blogs.microsoft.co.il/blogs/shair/

Comments and Discussions