public override void ProcessRequest(JToken casJSON) { KinectSensor kinectSensor = SensorHandler.GetSensor(); this.coordinateMapper = kinectSensor.CoordinateMapper; this.colorFrameDescription = kinectSensor.ColorFrameSource.FrameDescription; int time_slept = 0; while (!kinectSensor.IsAvailable) { Thread.Sleep(5); time_slept += 5; if (time_slept > TIMEOUT_MS) { System.Environment.Exit(-2); } } bool dataReceived = false; while (!dataReceived) { this.currColorFrame = SensorHandler.GetColorFrame(); if (this.currColorFrame != null) { dataReceived = true; } } dataReceived = false; while (!dataReceived) { this.currDepthFrame = SensorHandler.GetDepthFrame(); if (this.currDepthFrame != null) { dataReceived = true; } } this.aggregatedData = this.ProcessBlocksFromFrames(); this.currColorFrame = null; this.currDepthFrame = null; }
public override void ProcessRequest(JToken allAnnotations) { KinectSensor kinectSensor = SensorHandler.GetSensor(); int ms_slept = 0; while (!kinectSensor.IsAvailable) { Thread.Sleep(500); ms_slept += 500; System.Diagnostics.Debug.WriteLine("Waiting on sensor..."); if (ms_slept >= CONNECT_TIMEOUT_MS) { System.Environment.Exit(-1); } } CoordinateMapper coordinateMapper = kinectSensor.CoordinateMapper; FrameDescription frameDescription = kinectSensor.DepthFrameSource.FrameDescription; List <Tuple <JointType, JointType> > bones = new List <Tuple <JointType, JointType> >(); bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); bool dataReceived = false; Body[] bodies = null; Body body = null; ms_slept = 0; while (!dataReceived) { BodyFrame bodyFrame = null; System.Diagnostics.Debug.WriteLine("Waiting on body frame..."); while (bodyFrame == null) { bodyFrame = SensorHandler.GetBodyFrame(); } bodies = new Body[bodyFrame.BodyCount]; bodyFrame.GetAndRefreshBodyData(bodies); System.Diagnostics.Debug.WriteLine("Checking if body is detected in frame..."); System.Diagnostics.Debug.WriteLine(bodyFrame.BodyCount + " bodies detected"); int count = 0; if (bodyFrame.BodyCount > 0) { foreach (Body b in bodies) { if (b.IsTracked) { System.Diagnostics.Debug.WriteLine("Found body frame."); body = b; dataReceived = true; count++; } } } System.Diagnostics.Debug.WriteLine(count + " bodies tracked"); Thread.Sleep(100); ms_slept += 100; if (ms_slept >= POINTING_TIMEOUT_MS) { System.Environment.Exit(-1); } bodyFrame.Dispose(); } //// convert the joint points to depth (display) space /// IReadOnlyDictionary <JointType, Joint> joints = body.Joints; Dictionary <JointType, CameraSpacePoint> jointPoints = new Dictionary <JointType, CameraSpacePoint>(); foreach (JointType jointType in joints.Keys) { // sometimes the depth(Z) of an inferred joint may show as negative // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity) CameraSpacePoint position = joints[jointType].Position; if (position.Z < 0) { position.Z = 0.1f; } DepthSpacePoint depthSpacePoint = coordinateMapper.MapCameraPointToDepthSpace(position); jointPoints[jointType] = position; } Tuple <JointType, JointType> bone = bones.First(); List <BlockData> blocks = this.GetBlocks(allAnnotations); this.ComputeConfidenceScores(bone, jointPoints, blocks); }