private void SetTrackedSkeleton(int matchingSkeleton) { if (matchingSkeleton == _activeTID) { return; } if (matchingSkeleton != -1 && _kinect != null && _kinect.GetSensor() != null) { _kinect.GetSensor().SkeletonStream.ChooseSkeletons(matchingSkeleton); if (Strategy.Equals(TrackingEngine.CLOSEST_SKELETON) || (_activeUser != null && _activeUser.Attempts >= User.MAX_ATTEMPTS)) { Log.Info("Closest skeleton found. Starting tracking of id : " + matchingSkeleton); _kinectHandler.StartTracking(matchingSkeleton); _kinectHandler.TrackingStarted(matchingSkeleton); } _activeTID = matchingSkeleton; } else { Log.Info("No suitable skeleton found for tracking. Tracking stopped"); _kinectHandler.StopTracking(_activeTID); _kinectHandler.TrackingStopped(matchingSkeleton); _activeTID = -1; } }
void IKinect.Init() { // initialize the KinectData object if (_kinect != null && _kinect.GetSensor() == null) { Log.Error("Init cannot be completed. Kinect not active"); return; } _gestureProcessor = new GestureProcessor(this, _kinect); Log.Info("Gesture processor created"); _trackingEngine = new TrackingEngine(_kinect, this); _trackingEngine.Strategy = TrackingEngine.RECOGNIZED_FIRST; //_featureProcessor.StartProcess(); if (_vocCom != null) { _vocCom.Start(_kinect.GetSensor()); } else { Log.Error("Could not load voice commands."); } Log.Info("Voice Commands loaded."); }
public KinectHandler(KinectData kinect, Device comInterface) { if (Log == null) { return; } Log.Info("Initializing Framework"); _comInterface = comInterface; _kinect = kinect; if (_kinect != null && _kinect.GetSensor() == null) { Log.Error("Kinect not initialized, Cannot continue."); return; } _commands = FileLoader.LoadVoiceCommands(); if (_commands == null) { return; } _vocCom = new VoiceCommander(_commands); _vocCom.OrderDetected += VoiceCommandDetected; }
public TrackingEngine(KinectData kinect, KinectHandler kinectHandler) { if (Log == null) { return; } Log.Info("Starting TrackingEngine"); _kinect = kinect; _kinectHandler = kinectHandler; Strategy = RECOGNIZED_FIRST; if (_kinect != null) { Log.Info("Attaching to Kinect"); var kinectSensor = _kinect.GetSensor(); if (kinectSensor != null) { kinectSensor.AllFramesReady += TrackingEngineAllFramesReady; } _recognitionEngine = new RecognitionEngine(kinect, this); } _activeTID = -1; Log.Info("Tracking Engine Started"); LoadUsers(); Log.Info("Users loaded"); }
private void SkeletonDataReadyHandler(object sender, SkeletonFrameReadyEventArgs e) { // no active user, ignore events if (_activeUser == -1 || e == null || _kinect == null) { return; } // not recording and no context, ignore events. var sFrame = e.OpenSkeletonFrame(); if (sFrame == null) { return; } var skeletons = new Skeleton[_kinect.GetSensor().SkeletonStream.FrameSkeletonArrayLength]; sFrame.CopySkeletonDataTo(skeletons); sFrame.Dispose(); foreach (var skeleton in skeletons.Where(skeleton => skeleton != null && skeleton.TrackingId == _activeUser)) { Skeleton2DDataExtract.ProcessData(skeleton, _defaultHand); if (!_isRecording) { if (_pointer != null) { _pointer.FindContext(skeleton); } } if (_addOnGesture) { AddOnGesture(_addOnGestureType, skeleton); } } }
private Image <Bgr, byte>[] FindFace(Skeleton skel, Bitmap image) { var headPos = _kinect.GetSensor().MapSkeletonPointToColor(skel.Joints[JointType.Head].Position, ColorImageFormat.RgbResolution640x480Fps30); var shoulderL = _kinect.GetSensor().MapSkeletonPointToColor(skel.Joints[JointType.ShoulderLeft].Position, ColorImageFormat.RgbResolution640x480Fps30); var shoulderR = _kinect.GetSensor().MapSkeletonPointToColor(skel.Joints[JointType.ShoulderRight].Position, ColorImageFormat.RgbResolution640x480Fps30); var startX = shoulderL.X; var startY = Math.Max(headPos.Y - 80, 0); var width = Math.Sqrt((shoulderR.X - shoulderL.X) * (shoulderR.X - shoulderL.X)); var height = Math.Sqrt((headPos.Y - shoulderL.Y) * (headPos.Y - shoulderL.Y)) + 100; //Log.Info(startX + "," + startY + "," + width + "," + height); width = Math.Min(Math.Max(width, 0), 640); height = Math.Min(Math.Max(height, 0), 480); if (Double.IsNaN(width) || Double.IsNaN(height) || Math.Abs(width - 0) < 0.0001 || Math.Abs(height - 0) < 0.0001) { return(null); } var img = new Image <Bgr, byte>(image) { ROI = new Rectangle(startX, startY, (int)width, (int)height) }; var faces = new Image <Bgr, byte> [1]; faces[0] = img.Copy(); img.Save(FileLoader.DefaultPath + "testHeadPos.jpg"); return(faces); }
Boolean IDevice.Init() { LoadLogger(); Log.Info("Starting Kinect automation environment..."); _kinect = new KinectData(0); _kHandler = new KinectHandler(_kinect, this); _kHandler.Init(); if (_kinect.GetSensor() == null) { Log.Error("Kinect could not be instantiated. Terminating."); return(false); } return(true); }
public KinectHandler(KinectData kinect, Device comInterface) { if (Log == null) return; Log.Info("Initializing Framework"); _comInterface = comInterface; _kinect = kinect; if(_kinect != null && _kinect.GetSensor() == null) { Log.Error("Kinect not initialized, Cannot continue."); return; } _commands = FileLoader.LoadVoiceCommands(); if (_commands == null) return; _vocCom = new VoiceCommander(_commands); _vocCom.OrderDetected += VoiceCommandDetected; }
public TrackingEngine(KinectData kinect, KinectHandler kinectHandler) { if (Log == null) return; Log.Info("Starting TrackingEngine"); _kinect = kinect; _kinectHandler = kinectHandler; Strategy = RECOGNIZED_FIRST; if (_kinect != null) { Log.Info("Attaching to Kinect"); var kinectSensor = _kinect.GetSensor(); if (kinectSensor != null) kinectSensor.AllFramesReady+=TrackingEngineAllFramesReady; _recognitionEngine = new RecognitionEngine(kinect,this); } _activeTID = -1; Log.Info("Tracking Engine Started"); LoadUsers(); Log.Info("Users loaded"); }
Boolean IDevice.Init() { LoadLogger(); Log.Info("Starting Kinect automation environment..."); _kinect = new KinectData(0); _kHandler = new KinectHandler(_kinect, this); _kHandler.Init(); if(_kinect.GetSensor() == null) { Log.Error("Kinect could not be instantiated. Terminating."); return false; } return true; }