/// <summary> /// Load saved activities from XML /// </summary> /// <param name="activities"></param> public static void Load(LinkedList <Activity> activities) { XmlDocument doc = new XmlDocument(); if (System.IO.File.Exists(@"Settings/Settings.xml")) { doc.Load(@"Settings/Settings.xml"); XmlNodeList nodeListActivity = doc.SelectNodes("//Activity"); foreach (XmlNode node in nodeListActivity) { XmlNode nodeArea = node.SelectSingleNode("Area"); Rect rect = new Rect(new Point(double.Parse(nodeArea.Attributes["X"].Value), double.Parse(nodeArea.Attributes["Y"].Value)), new Size(double.Parse(nodeArea.Attributes["Width"].Value), double.Parse(nodeArea.Attributes["Height"].Value))); XmlNodeList nodeListPos = node.SelectNodes("Posture"); LinkedList <Posture> postures = new LinkedList <Posture>(); foreach (XmlNode pos in nodeListPos) { postures.AddLast(new Posture(pos.Attributes["Name"].Value)); } XmlNodeList nodeListObject = node.SelectNodes("Object"); LinkedList <Object.Objects> objects = new LinkedList <Object.Objects>(); foreach (XmlNode obj in nodeListObject) { objects.AddLast((Object.Objects)Enum.Parse(typeof(Object.Objects), obj.Attributes["Name"].Value)); } XmlNodeList nodeListReq = node.SelectNodes("Requirement"); LinkedList <Requirement> requirements = new LinkedList <Requirement>(); foreach (XmlNode req in nodeListReq) { requirements.AddLast(Requirement.ConstructChild(req.Attributes["Name"].Value)); } Activity activity = bool.Parse(node.Attributes["Is-Dynamic-Area"].Value) ? new Activity(node.Attributes["Template-Name"].Value, BodyOrientation.ConvertIntToOrientations(int.Parse(node.Attributes["Body-Orientation"].Value)), postures, objects, requirements, node.Attributes["Name"].Value, int.Parse(node.Attributes["Minimal-People-Count"].Value)) : new Activity(rect, BodyOrientation.ConvertIntToOrientations(int.Parse(node.Attributes["Body-Orientation"].Value)), postures, objects, requirements, node.Attributes["Name"].Value, int.Parse(node.Attributes["Minimal-People-Count"].Value)); activities.AddLast(activity); } } }
private static readonly double TEMPLATE_SEARCH_INTERVAL = 1000 * 10; // Millisecond /// <summary> /// Entry /// </summary> public MainWindow() { InitializeComponent(); kinectSensor = KinectSensor.GetDefault(); bodies = new Body[kinectSensor.BodyFrameSource.BodyCount]; persons = new Person[kinectSensor.BodyFrameSource.BodyCount]; activities = new LinkedList <Activity>(); drawingGroup = new DrawingGroup(); depthSource = new DrawingImage(drawingGroup); drawingGroup_topView = new DrawingGroup(); topViewInHeight = new DrawingImage(drawingGroup_topView); DataContext = this; depthFramePixels = new ushort[kinectSensor.DepthFrameSource.FrameDescription.Width * kinectSensor.DepthFrameSource.FrameDescription.Height]; segmentedDepthFramePixels = new ushort[kinectSensor.DepthFrameSource.FrameDescription.Width * kinectSensor.DepthFrameSource.FrameDescription.Height]; Settings.Load(activities); Requirement.LoadRequirements(ListBox_Requirement); Plot.InitBackgroundCanvas(Canvas_Position_Background); TemplateDetector.loadTemplate(ListBox_Area); // Select source type needed, e.g., depth, color, body multiSourceFrameReader = kinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body | FrameSourceTypes.Depth); multiSourceFrameReader.MultiSourceFrameArrived += MultiSourceFrameReader_MultiSourceFrameArrived; kinectSensor.IsAvailableChanged += KinectSensor_IsAvailableChanged; kinectSensor.Open(); kinectConnectionCheck = new System.Timers.Timer(); kinectConnectionCheck.AutoReset = false; kinectConnectionCheck.Elapsed += kinectConnectionCheck_Elapsed; kinectConnectionCheck.Interval = KINECT_CONNECTION_CHECK_INTERVAL; kinectConnectionCheck.Enabled = true; templateSearch = new System.Timers.Timer(); templateSearch.AutoReset = true; templateSearch.Elapsed += TemplateSearch_Elaped; templateSearch.Interval = TEMPLATE_SEARCH_INTERVAL; templateSearch.Enabled = true; applicationRestart = new System.Timers.Timer(); gestureDetectorList = new List <PostureDetector>(); postures = new LinkedList <Posture>(); for (int i = 0; i < kinectSensor.BodyFrameSource.BodyCount; ++i) { PostureDetector detector = new PostureDetector(kinectSensor, i, Canvas_Position_Foreground); gestureDetectorList.Add(detector); // Init postures from trained PostureDetector.GESTURE_DB once if (i == 0) { foreach (Gesture gesture in detector.vgbFrameSource.Gestures) { postures.AddLast(new Posture(gesture.Name)); } ListBox_Posture.ItemsSource = postures; } } }