/// <summary> /// Méthode qui permet d'initialiser tout ce qui concerne kinect /// </summary> private void initKinect() { //La Kinect actuellement raccordée au PC KinectSensor kinectSensor = KinectSensor.GetDefault(); //Commence la lecture des mouvements------------------------------- //Création de la détection des bodies this.bodyReader = kinectSensor.BodyFrameSource.OpenReader(); this.bodyReader.FrameArrived += BodyReader_FrameArrived; //Tableau contenant les corps détectés this.bodies = new Body[bodyReader.BodyFrameSource.BodyCount]; //Tableau contenant les détecteurs de mouvements associés this.bodiesDetectors = new GestureDetector[this.bodies.Count]; //Crée les détecteurs de mouvement correspondants for (int i = 0; i < bodies.Count; i++) { GestureDetector handler = new GestureDetector(this.originalPath + "\\SwitchKinect.gbd"); //On récupère le fichier contenant les mouvements à partir de l'emplacement original handler.GestureFirstDetected += handler_GestureFirstDetected; //Pour chaques corps détectable, on crée un détecteur this.bodiesDetectors[i] = handler; } //---------------- //Détection de la position des mains KinectCoreWindow.GetForCurrentThread().PointerMoved += KinectPowerPoint_PointerMoved; }
void MainPage_Loaded(object sender, RoutedEventArgs e) { //Kinect Handling for drawing - auto using of default kinect sensor KinectCoreWindow kinectCore = KinectCoreWindow.GetForCurrentThread(); kinectCore.PointerMoved += kinectCore_PointerMoved; //Capture les corps pour les états des mains KinectSensor sensor = KinectSensor.GetDefault(); BodyFrameReader bodyReader = sensor.BodyFrameSource.OpenReader(); bodyReader.FrameArrived += bodyReader_FrameArrived; ///Timer qui permet de faire tourner bodyReader en continu. Workaround DispatcherTimer t = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(33) }; t.Tick += (senderTick, args) => { bodyReader.IsPaused = false; Debug.WriteLine(DateTime.Now + " - Setting Paused false --------------------------------------------------"); }; t.Start(); }
/// <summary> /// Initialization code /// </summary> /// <param name="sender">the page</param> /// <param name="e">the loaded event args</param> void KinectPointerPointSample_Loaded(object sender, RoutedEventArgs e) { // Listen to Kinect pointer events KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved; }
//########################################################### EVENEMENTS ########################################################### /// <summary> /// Evénement déclenché lorsqu'un pointeur de Kinect bougé /// </summary> /// <remarks>Fonctionne pour 1 seul personne uniquement. Kinect ne doit en détecter qu'une seule et unique</remarks> /// <param name="sender">L'objet déclenchant</param> /// <param name="args">Les arguments de l'événement contenant, notamment, la position actuel du curseur</param> void kinectCore_PointerMoved(KinectCoreWindow sender, KinectPointerEventArgs args) { //Un point selong l'axe X-Y (en %) KinectPointerPoint point = args.CurrentPoint; //Cette condition permet de contourner certain problème qui apparaissent. //En effet, cet événement est appelé 2 fois par personne, une fois pour la main droite et une fois pour la main gauche //On a donc 2 points de curseur par personne //N'utiliser que la main droite permet d'éviter que les deux mains bougent le curseur if (point.Properties.HandType == HandType.RIGHT) //On n'utilise que la main droite { //Calcule du diametre de la ligne double diameter = CURSOR_DIAMETER; diameter *= Math.Pow(point.Properties.HandReachExtent + 0.5, 3); //Traduit les positions données par Kinect (en %) en position en pixel double currentPosX = point.Position.X * this.cursorMoveCanvas.ActualWidth; double currentPosY = point.Position.Y * this.cursorMoveCanvas.ActualHeight; //Calcule la position du curseur this.cursorPosition.PosX = currentPosX - CURSOR_DIAMETER / 2; this.cursorPosition.PosY = currentPosY - CURSOR_DIAMETER / 2; if (point.Properties.HandReachExtent > 0.5) //Lorsqu'on commence à appuyer, on dessine { if (this.lastPosition != null) //Si le dernier point appuyé existe, on peut dessiner. Sinon, on attends le prochain "tour" { //Ajout la ligne entre le dernier point et le point courant Line lineToAdd = new Line() { //La position initiale de la ligne, tirée du dernier point X1 = lastPosition.Value.X, Y1 = lastPosition.Value.Y, //La position finale de la ligne, tirée du point courant X2 = currentPosX, Y2 = currentPosY, //Design de la ligne StrokeThickness = diameter, //Le diamètre de la ligne a été calculé Stroke = this.drawBrush, //La couleur stockée en local est utilisée //La ligne commence et finis par un cercle. StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round }; //On ajoute la ligne dans le canvas de dessin this.drawCanvas.Children.Add(lineToAdd); } //Met à jour la dernière position du point. La ligne à dessiner se fera à partir de ce point this.lastPosition = new Point(currentPosX, currentPosY); } else //Si on n'appuie pas/plus, on ne dessine pas { this.lastPosition = null; } } //FIN - main droite } //FIN - kinectCore_PointerMoved
void kinectCore_PointerEntered(KinectCoreWindow sender, KinectPointerEventArgs args) { KinectPointerPoint point = args.CurrentPoint; if (point.Properties.HandType == HandType.RIGHT) { } }
void AddEventHandlers() { // NB: these are POINTER events, not MOUSE events, not PEN events, etc. this.drawCanvas.PointerPressed += (s, e) => { this.TrackDown( e.Pointer.PointerId, e.Pointer.PointerDeviceType.ToString(), e.GetCurrentPoint(this.drawCanvas).Position); }; this.drawCanvas.PointerReleased += (s, e) => { this.TrackUp(e.Pointer.PointerId); }; this.drawCanvas.PointerMoved += (s, e) => { this.TrackMove( e.Pointer.PointerId, e.GetCurrentPoint(this.drawCanvas).Position, ((int)e.Pointer.PointerDeviceType + 1) * 3); }; this.drawCanvas.PointerExited += (s, e) => { this.TrackUp(e.Pointer.PointerId); }; var window = KinectCoreWindow.GetForCurrentThread(); window.PointerMoved += (s, e) => { if (this.drawCanvas.IsGripping) { var canvasPosition = new Point() { X = e.CurrentPoint.Position.X * this.drawCanvas.ActualWidth, Y = e.CurrentPoint.Position.Y * this.drawCanvas.ActualHeight }; this.TrackDown( e.CurrentPoint.PointerId, e.CurrentPoint.PointerDevice.PointerDeviceType.ToString(), canvasPosition); this.TrackMove( e.CurrentPoint.PointerId, canvasPosition, ((int)e.CurrentPoint.PointerDevice.PointerDeviceType) * 3); } else { this.TrackUp(e.CurrentPoint.PointerId); } }; window.PointerExited += (s, e) => { this.TrackUp(e.CurrentPoint.PointerId); }; }
public MainWindow() { var settings = new CefSettings(); settings.CefCommandLineArgs.Add("disable-gpu", "1"); Cef.Initialize(settings); InitializeComponent(); this.PreviewKeyDown += new KeyEventHandler(HandleEsc); sensor = KinectSensor.GetDefault(); //Mouse.OverrideCursor = Cursors.None; if (sensor != null) { sensor.Open(); reader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.Infrared | FrameSourceTypes.Body); reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived; //Initialize gestureController gestureController = new GestureController(); gestureController.Start(); gestureController.GestureRecognized += gestureController_GestureRecognized; //Initialize spyGlassController mouseController = new MouseController((int)SystemParameters.PrimaryScreenWidth / 2, (int)SystemParameters.PrimaryScreenHeight / 2); //961,600 for Display / 829,586 for local testing playersController = new PlayersController(); playersController.BodyEntered += UserReporter_BodyEntered; playersController.BodyLeft += UserReporter_BodyLeft; playersController.Start(); KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved; string folder = System.IO.Directory.GetCurrentDirectory().ToString(); for (int i = 0; i < folder.Length; i++) { if (folder[i] == '\\') { base_folder += '\\'; base_folder += '\\'; } else { base_folder += folder[i]; } } base_folder += "\\Images"; Console.WriteLine(base_folder); } }
internal HandInScreenEngagementModel(int engagedPeopleAllowed, InputPointerManager inputPointerManager) { this.EngagedPeopleAllowed = engagedPeopleAllowed; this.inputPointerManager = inputPointerManager; var kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += this.kinectCoreWindow_PointerMoved; this.handsToEngage = new List <BodyHandPair>(); this.pointerPoints = new List <KinectPointerPoint>(); }
/// <summary> /// Evénement déclenché lorsque la page a été chargée /// </summary> /// <param name="sender">L'objet déclenchant</param> /// <param name="e">Les arguments de l'événement</param> void MainPage_Loaded(object sender, RoutedEventArgs e) { //Récupération des objets Kinect nécessaires au programme this.kinect = KinectSensor.GetDefault(); this.kinectCore = KinectCoreWindow.GetForCurrentThread(); //On traite les évévenements permettant de faire bouger le curseur this.kinectCore.PointerMoved += kinectCore_PointerMoved; //On ouvre Kinect (Kinect s'allume) this.kinect.Open(); }
/// <summary> /// Uninitialization code /// </summary> /// <param name="sender">the page</param> /// <param name="e">the unloaded event args</param> private void KinectPointerPointSample_Unloaded(object sender, RoutedEventArgs e) { // Unsubscribe from mouse/pen/touch pointer events var coreWindow = CoreWindow.GetForCurrentThread(); coreWindow.PointerMoved -= coreWindow_PointerMoved; // Unsubscribe from Kinect pointer events var kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved -= kinectCoreWindow_PointerMoved; }
/// <summary> /// Execute start up tasks /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void MainWindow_Loaded(object sender, RoutedEventArgs e) { // Listen to kinect pointer events KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved; // Listen to body frames arrival if (this.bodyFrameReader != null) { this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived; } }
private void Grid_Loaded(object sender, RoutedEventArgs e) { if (sensor != null) { sensor.Open(); } reader.MultiSourceFrameArrived += reader_MultiSourceFrameArrived; var kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += this.kinectCoreWindow_PointerMoved; }
/// <summary> /// Initialise tout ce qui est relatif à Kinect /// </summary> private void InitializeKinect() { //Récupère le détecteur kinect et l'ouvre KinectSensor kinect = KinectSensor.GetDefault(); kinect.Open(); //Pointeur kinect this.kinectCore = KinectCoreWindow.GetForCurrentThread(); kinectCore.PointerMoved += MainWindow_PointerMoved; //Détection des corps kinect.BodyFrameSource.OpenReader().FrameArrived += BodyReader_BodyFrameArrived; }
protected virtual void Dispose(bool disposing) { if (!_disposedValue) { _kinectRegion = null; _inputModel = null; _interactiveElement = null; kinectCoreWindow.PointerMoved -= kinectCoreWindow_PointerMoved; _handPointerEnter = null; _handPointerLeave = null; kinectCoreWindow = null; _disposedValue = true; } }
void MainPage_Loaded(object sender, RoutedEventArgs e) { drawBrush = whiteBrush; //Création de kinect this.kinect = KinectSensor.GetDefault(); this.kinectCore = KinectCoreWindow.GetForCurrentThread(); kinectCore.PointerEntered += kinectCore_PointerEntered; kinectCore.PointerMoved += kinectCore_PointerMoved; this.kinect.Open(); }
/// <summary> /// Initializes the kinect sensor /// </summary> private static void InitilizeKinect() { kinectSensor = KinectSensor.GetDefault(); bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader(); bodyFrameReader.FrameArrived += Reader_FrameArrived; KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += KinectCoreWindow_PointerMoved; kinectSensor.Open(); #if DEBUG time.Start(); #endif }
void kinectCore_PointerMoved(KinectCoreWindow sender, KinectPointerEventArgs args) { KinectPointerPoint point = args.CurrentPoint; if (point.Properties.HandType == HandType.RIGHT) { //Diamètre du cercle double diameter = 30; diameter = diameter * Math.Pow(point.Properties.HandReachExtent + 0.5, 3); this.posX = point.Position.X * CursorMove.ActualWidth - 15; this.posY = point.Position.Y * CursorMove.ActualHeight - 15; if (point.Properties.HandReachExtent > 0.5) { //Add line if (lastPosition != null) { Line line = new Line() { X1 = lastPosition.Value.X, Y1 = lastPosition.Value.Y, X2 = posX + 15, Y2 = posY + 15, StrokeThickness = diameter, Stroke = this.drawBrush, StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round }; Debug.WriteLine(line.Y1); CursorMove.Children.Insert(0, line); } //Update the last position lastPosition = new Point(posX + 15, posY + 15); //Add ellipse --> DRAWING Lines is better //Ellipse form = new Ellipse() { Height = diameter, Width = diameter, Margin = new Thickness(posX + 15 - diameter/2, posY+15-diameter/2, 0, 0), Fill = new SolidColorBrush(Colors.Red), Opacity=1f }; //CursorMove.Children.Insert(0,form); } else { lastPosition = null; } } //INdique qu'on a traité le point args.Handled = true; }
/// <summary> /// Inicializa los parametros de la Ventana que contiene el canvas de imagenes y se definen los valores para el cursor y la deteccion de posicion del mismo respecto a la ventana. /// </summary> private void IniciatizeControls() { InitializeComponent(); WindowState = WindowState.Maximized; WindowStyle = WindowStyle.None; ventana.Background = Brushes.Black; ventana.Height = System.Windows.SystemParameters.PrimaryScreenHeight; ventana.Width = System.Windows.SystemParameters.PrimaryScreenWidth; HeightScreen = (int)ventana.Height; WidthScreen = (int)ventana.Width; imgHandLeft = new Image(); imgHandLeft.Source = new BitmapImage(Utilities.LoadUriFromResource("Cursores/manoLeft.png")); imgHandLeft.Width = 32; imgHandLeft.Height = 32; imgHandRight = new Image(); imgHandRight.Source = new BitmapImage(Utilities.LoadUriFromResource("Cursores/manoRight.png")); imgHandRight.Width = 32; imgHandRight.Height = 32; mainScreen.Children.Add(imgHandLeft); mainScreen.Children.Add(imgHandRight); sensor = KinectSensor.GetDefault(); sensor.Open(); sensor.IsAvailableChanged += AvailableChanged; this.coordinateMapper = sensor.CoordinateMapper; //para detectar si se fue el id trackeado reader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.BodyIndex | FrameSourceTypes.Color | FrameSourceTypes.Depth); reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived; //se llama cuando se mueven las manos de un body trackeado KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved; //vista360.Children.Clear(); //Limpia por completo el canvas que contiene las imagenes }
/// <summary> /// Handles kinect pointer events /// </summary> /// <param name="sender">the KinectCoreWindow</param> /// <param name="args">Kinect pointer args</param> private void kinectCoreWindow_PointerMoved(KinectCoreWindow sender, KinectPointerEventArgs args) { if (showKinect) { KinectPointerPoint kinectPointerPoint = args.CurrentPoint; if (lastTime == 0 || lastTime != kinectPointerPoint.Timestamp) { lastTime = kinectPointerPoint.Timestamp; mainScreen.Children.Clear(); } RenderPointer(kinectPointerPoint.Properties.IsEngaged, kinectPointerPoint.Position, kinectPointerPoint.Properties.UnclampedPosition, kinectPointerPoint.Properties.HandReachExtent, kinectPointerPoint.Properties.BodyTimeCounter, kinectPointerPoint.Properties.BodyTrackingId, kinectPointerPoint.Properties.HandType); } }
/// <summary> /// Initialization code /// </summary> /// <param name="sender">the page</param> /// <param name="e">the loaded event args</param> private void KinectPointerPointSample_Loaded(object sender, RoutedEventArgs e) { // Listen to mouse/pen/touch pointer events var coreWindow = CoreWindow.GetForCurrentThread(); coreWindow.PointerMoved += coreWindow_PointerMoved; // Listen to Kinect pointer events KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved; // Initialize brushes blackBrush = new SolidColorBrush(ColorHelper.FromArgb(128, 0, 0, 0)); yellowBrush = new SolidColorBrush(ColorHelper.FromArgb(255, 245, 255, 000)); greenBrush = new SolidColorBrush(ColorHelper.FromArgb(255, 0, 255, 0)); // Default to showing Kinect pointer inof this.kinect.IsChecked = true; // show Kinect data initially, not mouse/touch. }
private void initGesture() { KinectSensor kinectSensor = KinectSensor.GetDefault(); this.gestureSource = new VisualGestureBuilderFrameSource(kinectSensor, 0); //Commence la lecture des mouvements------------------------------ //Création de la base de donnée des mouvements et ajout des mouvements à la source des mouvements this.gestures = new VisualGestureBuilderDatabase("SwitchKinect.gbd"); this.gestureSource.AddGestures(gestures.AvailableGestures); //TODO déploiement automatique du dll AdaBoostTech.dll (détection de mouvement), utiliser DLLImport ? //Création de la détection des bodies this.bodyReader = kinectSensor.BodyFrameSource.OpenReader(); this.bodyReader.FrameArrived += BodyReader_FrameArrived; //Tableau contenant les corps détectés this.bodies = new Body[bodyReader.BodyFrameSource.BodyCount]; //Tableau contenant les détecteurs de mouvements associés this.bodiesDetectors = new GestureDetector[this.bodies.Count]; //Crée les détecteurs de mouvement correspondants for (int i = 0; i < bodies.Count; i++) { GestureDetector handler = new GestureDetector("SwitchKinect.gbd"); handler.GestureFirstDetected += handler_GestureFirstDetected; //Pour chaques corps détectable, on crée un détecteur this.bodiesDetectors[i] = handler; } //---------------- //Détection de la position des mains KinectCoreWindow.GetForCurrentThread().PointerMoved += ThisAddIn_PointerMoved; }
private void IniciatizeControls() { InitializeComponent(); WindowState = WindowState.Maximized; WindowStyle = WindowStyle.None; mainWindow.Height = System.Windows.SystemParameters.PrimaryScreenHeight; mainWindow.Width = System.Windows.SystemParameters.PrimaryScreenWidth; imgHandLeft = new Image(); imgHandLeft.Source = new BitmapImage(Utilities.LoadUriFromResource("Cursores/manoLeft.png")); imgHandLeft.Width = 32; imgHandLeft.Height = 32; imgHandRight = new Image(); imgHandRight.Source = new BitmapImage(Utilities.LoadUriFromResource("Cursores/manoRight.png")); imgHandRight.Width = 32; imgHandRight.Height = 32; mainScreen.Children.Add(imgHandLeft); mainScreen.Children.Add(imgHandRight); IsSidePage = SectionsPages.OUT; PageActual = 1; PagesActives = new BitmapImage[2]; FirstExecution = true; sensor = KinectSensor.GetDefault(); sensor.Open(); this.coordinateMapper = sensor.CoordinateMapper; //se llama cuando se mueven las manos de un body trackeado KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved; reader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.BodyIndex | FrameSourceTypes.Color | FrameSourceTypes.Depth); reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived; }
void MainPage_Loaded(object sender, RoutedEventArgs e) { drawBrush = blueBrush; //Création de kinect this.kinect = KinectSensor.GetDefault(); this.kinectCore = KinectCoreWindow.GetForCurrentThread(); kinectCore.PointerEntered += kinectCore_PointerEntered; kinectCore.PointerMoved += kinectCore_PointerMoved; this.kinect.Open(); //Bouton de couleur this.btnColorChoice.Background = drawBrush; this.btnColorChoice.Width = this.btnColorChoice.ActualHeight; byte[] bytColor = BitConverter.GetBytes(0xFFFFEE); Debug.WriteLine(bytColor[2]); //SocketIO ---- TEST pour joé #region connectJoe socketIO = IO.Socket("http://127.0.0.1:1337"); socketIO.On(Socket.EVENT_CONNECT, () => { Debug.WriteLine("Connected to NodeJS Server"); socketIO.On("srvCanvasClick", (data) => { Debug.WriteLine(data); }); }); #endregion }
/// <summary> /// Lorsque une main/pointeur bouge sur l'écran /// </summary> /// <param name="sender">L'appelant</param> /// <param name="args">Les arguments</param> void kinectCore_PointerMoved(KinectCoreWindow sender, KinectPointerEventArgs args) { //Le point kinect et le point déduit sur l'interface KinectPointerPoint currentPointerPoint = args.CurrentPoint; Point currentPixelPoint = new Point() { X = (int)(currentPointerPoint.Position.X * app.kinectRegion.ActualWidth), Y = (int)(currentPointerPoint.Position.Y * app.kinectRegion.ActualHeight) }; if (currentPointerPoint.Properties.IsEngaged) //Vérifie le point actuellement utilisé { //Dans le cas ou le point est dans le canvas, on peut commencer à dessiner if (isPointInCanvas(currentPixelPoint)) { //Lorsqu'on est dans le canvas, on cache la main pour pouvoir dessiner // TODO #region dessin //Diamètre du cercle changeant avec la pression double diameter = 30; diameter = diameter * Math.Pow(currentPointerPoint.Properties.HandReachExtent + 0.5, 3); //Les deux possiion à dessiner double posX = currentPixelPoint.X - getPointDrawCanvasPosition().X - 15; double posY = currentPixelPoint.Y - getPointDrawCanvasPosition().Y - 15; if (currentPointerPoint.Properties.HandReachExtent > 0.5) // Plus que 50 cm de l'épaule { //Add line if (lastPoint != null) { Line line = new Line() { X1 = this.lastPoint.Value.X, Y1 = this.lastPoint.Value.Y, X2 = posX + 15, Y2 = posY + 15, StrokeThickness = diameter, Stroke = btnColor.Background, StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round }; drawCanvas.Children.Add(line); } //Update the last position this.lastPoint = new Point(posX + 15, posY + 15); } else { //Si on est moins que 0.5cm, on met le dernier point à null pour ne plus dessiner lastPoint = null; } #endregion //----Dessin } else //Si on est hors du champ de dessin { //On affiche le pointeur } } //Indique que le point a bien été géré args.Handled = true; }
//----------------------------------- //Constructor //----------------------------------- public MainWindow() { settings = new MouseAppSettings(true); //get the kinect this.kinectSensor = KinectSensor.GetDefault(); //open the reader for color frames this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader(); //wire handler for frame arrival this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; //create the colorFrameDescription from the ColorFrameSource FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); // create the bitmap to display this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived; // get the coordinate mapper this.coordinateMapper = this.kinectSensor.CoordinateMapper; // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.colorOverlay = new DrawingImage(this.drawingGroup); // get size of color space this.displayWidth = colorFrameDescription.Width; this.displayHeight = colorFrameDescription.Height; this.deskHeight = Screen.PrimaryScreen.Bounds.Height; this.deskWidth = Screen.PrimaryScreen.Bounds.Width; handDispBuffer = new List<float>(); handDispTimes = new List<TimeSpan>(); handStates = new List<HandState>(); detectors = new List<GestureDetector>(); int maxBodies = this.kinectSensor.BodyFrameSource.BodyCount; for (int i = 0; i < maxBodies; ++i) { GestureDetector detector = new GestureDetector(this.kinectSensor, "TwistWrist"); detectors.Add(detector); } activeTime = TimeSpan.MinValue; handStateTime = TimeSpan.MinValue; driftStartTime = TimeSpan.MinValue; handStillPoint = new Point3D(); //Mouse cursor and PHIZ attributes phiz = new PHIZTracker(); kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved; // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // use the window object as the view model in this simple example this.DataContext = this; // set the status text this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText : Properties.Resources.NoSensorStatusText; handBrush = new Brush[5]; handBrush[(int)(HandState.Closed)] = handClosedBrush; handBrush[(int)(HandState.Open)] = handOpenBrush; handBrush[(int)(HandState.Lasso)] = handLassoBrush; handBrush[(int)(HandState.Unknown)] = handUnknownBrush; handBrush[(int)(HandState.NotTracked)] = handNotTrackedBrush; InitializeComponent(); this.OptionsColumn.Width = new System.Windows.GridLength(140); this.OptionsRow.Height = new System.Windows.GridLength(35); UpdateBoundaries(); sim = new InputSimulator(); }
/// <summary> /// Invoqué lorsque l'application est lancée normalement par l'utilisateur final. D'autres points d'entrée /// seront utilisés par exemple au moment du lancement de l'application pour l'ouverture d'un fichier spécifique. /// </summary> /// <param name="e">Détails concernant la requête et le processus de lancement.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Window.Current.Content as Frame; // Ne répétez pas l'initialisation de l'application lorsque la fenêtre comporte déjà du contenu, // assurez-vous juste que la fenêtre est active if (rootFrame == null) { // Créez un Frame utilisable comme contexte de navigation et naviguez jusqu'à la première page rootFrame = new Frame(); // Définir la page par défaut rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: chargez l'état de l'application précédemment suspendue } // Placez le frame dans la fenêtre active Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // Quand la pile de navigation n'est pas restaurée, accédez à la première page, // puis configurez la nouvelle page en transmettant les informations requises en tant que // paramètre rootFrame.Navigate(typeof(MainPage), e.Arguments); } //Ajout de l'intégration kinect----------- #region kinectImplementation // KinectSensor.GetDefault().Open(); //Ajout de la région kinect kinectRegion = new KinectRegion(); //Création de la région kinect cliquable à la main kinectRegion.Content = rootFrame; //La région kinect contient toute les pages principales de l'application => On peut utiliser kinect sur toute les pages par défaut //Ajout d'une grille pour le viewer et la région kinect Grid mainGrid = new Grid(); mainGrid.Children.Add(kinectRegion); Window.Current.Content = mainGrid; //La région kinect est la partie principale de la fenêtre //Ajout du kinectViewer pour pouvoir se voir KinectUserViewer kinectViewer = new KinectUserViewer() { Width = 150, Height = 130, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Right }; mainGrid.Children.Add(kinectViewer); //Ajout du kinectCore pour plus de fonctionnalité kinectCore = KinectCoreWindow.GetForCurrentThread(); #endregion // Vérifiez que la fenêtre actuelle est active Window.Current.Activate(); }
public Demo() { InitializeComponent(); // variable initialization isPointed = false; checkedButton = false; paused = false; counterFrames = 0; counterFramesBody = 0; mainHandId = 0; PointerMovedAssigned = false; MediaEndedAssigned = false; relatedBackup = null; // object initialization IdleAnimateFirstHand(); kc = new KinectController(); hue = new HueController("192.168.0.2"); hue.Connect(); hue.isBright = true; kc.bodyReader.FrameArrived += HandleFrame; idle = new DemoIdle(); this.contentControl.Content = idle; KinectRegion.SetKinectRegion(this, kinectRegion); App app = ((App)Application.Current); app.KinectRegion = kinectRegion; windowProducts = new SortedList<int, Model.Product>(); db = new DbFileManager(); state = 1; playimage = new BitmapImage(new Uri("Images\\play.png", UriKind.Relative)); pauseimage = new BitmapImage(new Uri("Images\\pause.png", UriKind.Relative)); InitProducts(); idle.label.Opacity = 0; kWin = KinectCoreWindow.GetForCurrentThread(); if (!PointerMovedAssigned) { kWin.PointerMoved += KWin_PointerMoved; kWin.PointerExited += KWin_PointerExited; kWin.PointerEntered += KWin_PointerEntered; PointerMovedAssigned = true; } /* this.MouseMove += Demo_MouseMove; currentProduct = 1; StartTrailer(windowProducts[currentProduct].GetTrailer()); isPointed = true;*/ }
private void Window_Loaded(object sender, RoutedEventArgs e) { KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += kinectCoreWindow_PointerMoved; }
private void TrackEngagedPlayersViaHandInScreen() { if (this.stopped) { return; } this.engagementPeopleHaveChanged = false; var currentlyEngagedHands = KinectCoreWindow.KinectManualEngagedHands; this.handsToEngage.Clear(); foreach (var bodyHandPair in currentlyEngagedHands) { foreach (var kinectPointerPoint in this.pointerPoints) { if (kinectPointerPoint.Properties.BodyTrackingId == bodyHandPair.BodyTrackingId && kinectPointerPoint.Properties.HandType == bodyHandPair.HandType) { bool toBeDisengaged = this.IsHandBelowScreen(kinectPointerPoint.Properties.UnclampedPosition, kinectPointerPoint.PointerId); if (toBeDisengaged) { this.engagementPeopleHaveChanged = true; } else { this.handsToEngage.Add(bodyHandPair); } } } } foreach (var kinectPointerPoint in this.pointerPoints) { if (this.handsToEngage.Count < this.engagedPeopleAllowed) { bool alreadyEngaged = false; foreach (var bodyHandPair in this.handsToEngage) { alreadyEngaged = (kinectPointerPoint.Properties.BodyTrackingId == bodyHandPair.BodyTrackingId); } if (!alreadyEngaged) { if (HandInScreenEngagementModel.IsHandInScreen(kinectPointerPoint.Properties.UnclampedPosition)) { this.handsToEngage.Add( new BodyHandPair(kinectPointerPoint.Properties.BodyTrackingId, kinectPointerPoint.Properties.HandType)); this.engagementPeopleHaveChanged = true; } } } } if (this.engagementPeopleHaveChanged) { BodyHandPair firstPersonToEngage = null; BodyHandPair secondPersonToEngage = null; Debug.Assert(this.handsToEngage.Count <= 2, "handsToEngage should be <= 2"); switch (this.handsToEngage.Count) { case 0: break; case 1: firstPersonToEngage = this.handsToEngage[0]; break; case 2: firstPersonToEngage = this.handsToEngage[0]; secondPersonToEngage = this.handsToEngage[1]; break; } switch (this.EngagedPeopleAllowed) { case 0: case 1: KinectCoreWindow.SetKinectOnePersonManualEngagement(firstPersonToEngage); break; case 2: KinectCoreWindow.SetKinectTwoPersonManualEngagement(firstPersonToEngage, secondPersonToEngage); break; } } }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow"/> class. /// </summary> public MainWindow() { this.InitializeComponent(); navService = NavigationService.GetNavigationService(this); staticNavService = navService; KinectRegion.SetKinectRegion(this, kinectRegion); App app = ((App)Application.Current); app.KinectRegion = kinectRegion; // Use the default sensor this.kinectRegion.KinectSensor = KinectSensor.GetDefault(); this.kinectSensor = KinectSensor.GetDefault(); //// open the reader for the color frames this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader(); // wire handler for frame arrival this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; // create the colorFrameDescription from the ColorFrameSource using Bgra format FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); // create the bitmap to display this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); // open the sensor this.kinectSensor.Open(); //// Add in display content var mainGridDataSource = DataSource.GetGroup("Group-1"); itemsControl.ItemsSource = mainGridDataSource; //Starts timer for clock SetClockTimer(); //Set bongo timers SetBongoGetTimer(); SetSwapTimer(); //Sets the scrolling bottom bar text event StartBottomBar(); //Sets timers and weather data SetWeatherTimer(); SetCSEventsTimer(); GetInitalApiData(); GetSlides(); SetSlideSwapTimer(); var window = KinectCoreWindow.GetForCurrentThread(); window.PointerEntered += OnKinectPointerEntered; window.PointerExited += OnKinectPointerExited; SetPageTimer(); }
public DrawingWindow() { this.kinectSensor = KinectSensor.GetDefault(); this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader(); this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; // create the colorFrameDescription from the ColorFrameSource using Bgra format FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); this.coordinateMapper = this.kinectSensor.CoordinateMapper; this.displayWidth = colorFrameDescription.Width; this.displayHeight = colorFrameDescription.Height; // create the bitmap to display this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); bodyFrameReader.FrameArrived += Reader_BodyFrameArrived; this.bodyCount = this.kinectSensor.BodyFrameSource.BodyCount; this.bodies = new Body[this.bodyCount]; //this.faceFrameSources = new FaceFrameSource[this.bodyCount]; //this.faceFrameReaders = new FaceFrameReader[this.bodyCount]; FaceFrameFeatures faceFrameFeatures = FaceFrameFeatures.BoundingBoxInColorSpace | FaceFrameFeatures.PointsInColorSpace | FaceFrameFeatures.RotationOrientation | FaceFrameFeatures.FaceEngagement | FaceFrameFeatures.Glasses | FaceFrameFeatures.Happy | FaceFrameFeatures.LeftEyeClosed | FaceFrameFeatures.RightEyeClosed | FaceFrameFeatures.LookingAway | FaceFrameFeatures.MouthMoved | FaceFrameFeatures.MouthOpen; this.faceFrameSources = new FaceFrameSource[this.bodyCount]; this.faceFrameReaders = new FaceFrameReader[this.bodyCount]; for (int i = 0; i < this.bodyCount; i++) { // create the face frame source with the required face frame features and an initial tracking Id of 0 this.faceFrameSources[i] = new FaceFrameSource(this.kinectSensor, 0, faceFrameFeatures); // open the corresponding reader this.faceFrameReaders[i] = this.faceFrameSources[i].OpenReader(); } // allocate storage to store face frame results for each face in the FOV this.faceFrameResults = new FaceFrameResult[this.bodyCount]; this.previousResults = new FaceFrameResult[this.bodyCount]; //this.Cursor = Cursors.None; this.kinectSensor.Open(); KinectCoreWindow kinectCoreWindow = KinectCoreWindow.GetForCurrentThread(); kinectCoreWindow.PointerMoved += drawArea_PointerMove; // use the window object as the view model in this simple example this.DataContext = this; // KinectRegion.SetKinectRegion(this, kinectRegion); engagement = new EngagementManager(kinectSensor); // App app = ((App)Application.Current); // app.KinectRegion = kinectRegion; this.engagement = new EngagementManager(kinectSensor); InitializeComponent(); }
private void TrackEngagedPlayersViaHandOverHead() { this.engagementPeopleHaveChanged = false; var currentlyEngagedHands = KinectCoreWindow.KinectManualEngagedHands; this.handsToEngage.Clear(); // check to see if anybody who is currently engaged should be disengaged foreach (var bodyHandPair in currentlyEngagedHands) { var bodyTrackingId = bodyHandPair.BodyTrackingId; foreach (var body in this.bodies) { if (body.TrackingId == bodyTrackingId) { // check for disengagement JointType engagedHandJoint = (bodyHandPair.HandType == HandType.LEFT) ? JointType.HandLeft : JointType.HandRight; bool toBeDisengaged = HandOverheadEngagementModel.IsHandBelowHip(engagedHandJoint, body); if (toBeDisengaged) { this.engagementPeopleHaveChanged = true; } else { this.handsToEngage.Add(bodyHandPair); } } } } // check to see if anybody should be engaged, if not already engaged foreach (var body in this.bodies) { if (this.handsToEngage.Count < this.engagedPeopleAllowed) { bool alreadyEngaged = false; foreach (var bodyHandPair in this.handsToEngage) { alreadyEngaged = (body.TrackingId == bodyHandPair.BodyTrackingId); } if (!alreadyEngaged) { // check for engagement if (HandOverheadEngagementModel.IsHandOverhead(JointType.HandLeft, body)) { // engage the left hand this.handsToEngage.Add( new BodyHandPair(body.TrackingId, HandType.LEFT)); this.engagementPeopleHaveChanged = true; } else if (HandOverheadEngagementModel.IsHandOverhead(JointType.HandRight, body)) { // engage the right hand this.handsToEngage.Add( new BodyHandPair(body.TrackingId, HandType.RIGHT)); this.engagementPeopleHaveChanged = true; } } } } if (this.engagementPeopleHaveChanged) { BodyHandPair firstPersonToEngage = null; BodyHandPair secondPersonToEngage = null; Debug.Assert(this.handsToEngage.Count <= 2, "handsToEngage should be <= 2"); switch (this.handsToEngage.Count) { case 0: break; case 1: firstPersonToEngage = this.handsToEngage[0]; break; case 2: firstPersonToEngage = this.handsToEngage[0]; secondPersonToEngage = this.handsToEngage[1]; break; } switch (this.EngagedPeopleAllowed) { case 1: KinectCoreWindow.SetKinectOnePersonManualEngagement(firstPersonToEngage); break; case 2: KinectCoreWindow.SetKinectTwoPersonManualEngagement(firstPersonToEngage, secondPersonToEngage); break; } } }