Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="setupFilepath"></param>
        /// <returns></returns>
        public static bool TryLoadSetup(string setupFilepath)
        {
            // TODO: validate inputs, check clients

            XDocument setupDoc = XDocument.Load(setupFilepath);
            var       root     = setupDoc.Element("Kinect2KitSetup");

            var    server          = root.Element("Server");
            string serverIPAddress = server.Element("IPAddress").Value;
            int    serverPort      = Convert.ToInt32(server.Element("Port").Value);

            if (!Kinect2Kit.TrySetServerEndPoint(serverIPAddress, serverPort))
            {
                return(false);
            }

            var kinects = root.Element("Kinects");

            foreach (var kinect in kinects.Elements("Kinect"))
            {
                string kinectName      = kinect.Element("Name").Value;
                string kinectIPAddress = kinect.Element("IPAddress").Value;
                Kinect2Kit.AddKinectClient(kinectName, kinectIPAddress);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="timestamp"></param>
        /// <param name="bodies"></param>
        /// <returns></returns>
        public static async Task <Kinect2KitSimpleResponse> StreamBodyFrame(double timestamp, Body[] bodies)
        {
            var parameters = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Bodyframe", Kinect2Kit.GetBodyFrameJSON(timestamp, bodies))
            };
            Tuple <HttpResponseMessage, JObject> resp = await Kinect2Kit.POSTAsync(Kinect2Kit.API_StreamBodyFrame, parameters);

            return(new Kinect2KitSimpleResponse(resp.Item1, (string)resp.Item2["message"]));
        }
Example #3
0
        public static async Task <Kinect2KitSimpleResponse> StartSessionAsync(string name)
        {
            string clients    = JsonConvert.SerializeObject(Kinect2Kit.KinectClients);
            var    parameters = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Name", name),
                new KeyValuePair <string, string>("Clients", clients)
            };
            Tuple <HttpResponseMessage, JObject> resp = await Kinect2Kit.POSTAsync(Kinect2Kit.API_NewSession, parameters);

            return(new Kinect2KitSimpleResponse(resp.Item1, (string)resp.Item2["message"]));
        }
Example #4
0
        public static async Task <Kinect2KitCalibrationResponse> GetCalibrationStatusAsync()
        {
            Tuple <HttpResponseMessage, JObject> resp = await Kinect2Kit.GETAsync(Kinect2Kit.API_CalibrationStatus);

            bool   acquiring      = (bool)resp.Item2["acquiring"];
            int    requiredFrames = (int)resp.Item2["required_frames"];
            int    remainedFrames = (int)resp.Item2["remained_frames"];
            bool   resolving      = (bool)resp.Item2["resolving"];
            bool   finished       = (bool)resp.Item2["finished"];
            string error          = (string)resp.Item2["error"];

            return(new Kinect2KitCalibrationResponse(resp.Item1, acquiring, requiredFrames, remainedFrames, resolving, finished, error));
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="api"></param>
        /// <returns></returns>
        private static async Task <Tuple <HttpResponseMessage, JObject> > GETAsync(string api)
        {
            string url = Kinect2Kit.URL_For(api);

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage httpMessage = await client.GetAsync(url);

                string responseText = await httpMessage.Content.ReadAsStringAsync();

                JObject responseJSON = JObject.Parse(responseText);
                return(new Tuple <HttpResponseMessage, JObject>(httpMessage, responseJSON));
            };
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="api"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private static async Task <Tuple <HttpResponseMessage, JObject> > POSTAsync(string api, List <KeyValuePair <string, string> > parameters)
        {
            string url = Kinect2Kit.URL_For(api);
            FormUrlEncodedContent data = new FormUrlEncodedContent(parameters);

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage httpMessage = await client.PostAsync(url, data);

                string responseText = await httpMessage.Content.ReadAsStringAsync();

                JObject responseJSON = JObject.Parse(responseText);
                return(new Tuple <HttpResponseMessage, JObject>(httpMessage, responseJSON));
            };
        }
Example #7
0
        public static async Task <Kinect2KitTrackingResponse> GetTrackingResultAsync()
        {
            Tuple <HttpResponseMessage, JObject> resp = await Kinect2Kit.GETAsync(Kinect2Kit.API_TrackingResult);

            JToken trackingResult = (JToken)resp.Item2["result"];

            double timestamp = (double)trackingResult["Timestamp"];
            Dictionary <string, Kinect2KitPerspective> perspectivesDict = new Dictionary <string, Kinect2KitPerspective>();

            foreach (JToken resultPerspective in trackingResult["Perspectives"].Values())
            {
                string kinectName = (string)resultPerspective["KinectName"];
                Kinect2KitPerspective perspective = await JsonConvert.DeserializeObjectAsync <Kinect2KitPerspective>(resultPerspective.ToString(), null);

                perspectivesDict[kinectName] = perspective;
            }

            return(new Kinect2KitTrackingResponse(resp.Item1, timestamp, perspectivesDict));
        }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="api"></param>
 /// <returns></returns>
 private static async Task <Tuple <HttpResponseMessage, JObject> > POSTAsync(string api)
 {
     return(await Kinect2Kit.POSTAsync(api, Kinect2Kit.EmptyParameters));
 }
Example #9
0
        public static async Task <Kinect2KitSimpleResponse> StartTrackingAsync()
        {
            Tuple <HttpResponseMessage, JObject> resp = await Kinect2Kit.POSTAsync(Kinect2Kit.API_StartTracking);

            return(new Kinect2KitSimpleResponse(resp.Item1, (string)resp.Item2["message"]));
        }