public bool validateFaceFrame(FaceFrame faceFrame)
 {
     // check if this matchFaceWithBody frame has valid matchFaceWithBody frame results
     return ValidateFaceBoxAndPoints(faceFrame.FaceFrameResult);
 }
        private void RecordData(RectI faceRegion, FaceFrame faceFrame)
        {
            //record the R, G, B, IR values from the Face Region pixels
            using (var irFrame = faceFrame.InfraredFrameReference.AcquireFrame())
            {
                using (var depthFrame = faceFrame.DepthFrameReference.AcquireFrame())
                {
                    using (var colorFrame = faceFrame.ColorFrameReference.AcquireFrame())
                    {
                        if ((null == irFrame) || (null == colorFrame) || (null == depthFrame)) return;

                        DepthSpacePoint[] depthSpacePoints = new DepthSpacePoint[colorFrame.FrameDescription.Height * colorFrame.FrameDescription.Width];

                        FrameDescription depthFrameDescription = depthFrame.FrameDescription;

                        // Access the depth frame data directly via LockImageBuffer to avoid making a copy
                        using (KinectBuffer depthFrameData = depthFrame.LockImageBuffer())
                        {
                            this.m_CoordMapper.MapColorFrameToDepthSpaceUsingIntPtr(
                                depthFrameData.UnderlyingBuffer,
                                depthFrameData.Size,
                                depthSpacePoints);
                        }

                        //Get the pixels
                        m_colorBitmap.Lock();
                        unsafe
                        {
                            byte* pixels = (byte*)m_colorBitmap.BackBuffer;

                            var startPixel = faceRegion.Left * faceRegion.Top;
                            var endPixel = faceRegion.Right * faceRegion.Bottom;

                            float alpha = 0;
                            float red = 0;
                            float green = 0;
                            float blue = 0;
                            float ir = 0;

                            ushort[] irFrameData = new ushort[irFrame.FrameDescription.Height * irFrame.FrameDescription.Width];
                            irFrame.CopyFrameDataToArray(irFrameData);

                            //Now get the Red, Green, Blue Pixels for the region
                            for (int i = startPixel; i < endPixel; i += 4)
                            {
                                //var pixel = pixels[i];
                                int irIndex = (int)depthSpacePoints[i].X * (int)depthSpacePoints[i].Y;

                                blue += pixels[i]; // << 24;
                                green += pixels[i + 1]; // << 16;
                                red += pixels[i + 2];// << 8;
                                alpha += pixels[i + 3];
                                if (irIndex < irFrameData.Length)
                                    ir += irFrameData[irIndex];
                                else
                                    ir += 0;
                            }
                            float size = Math.Abs(startPixel - endPixel);

                            float avg_alpha = alpha / size;
                            float avg_red = red / size;
                            float avg_green = green / size;
                            float avg_blue = blue / size;
                            float avg_ir = ir / size;

                            double std_alpha = 0;
                            double std_red = 0;
                            double std_green = 0;
                            double std_blue = 0;
                            double std_ir = 0;

                            double var_alpha = 0;
                            double var_red = 0;
                            double var_green = 0;
                            double var_blue = 0;
                            double var_ir = 0;

                            //Now calculate standard deviation
                            for (int i = startPixel; i < endPixel; i += 4)
                            {
                                //var pixel = pixels[i];
                                var_blue = (double)(pixels[i] - avg_blue);
                                std_blue += Math.Pow(var_blue, 2.0);

                                var_green = (pixels[i + 1] - avg_green);
                                std_green += Math.Pow(var_green, 2);

                                var_red = (pixels[i + 2] - avg_red);
                                std_red += Math.Pow(var_red, 2);

                                var_alpha = (pixels[i + 3] - avg_alpha);
                                std_alpha += Math.Pow(var_alpha, 2);

                                int irIndex = (int)depthSpacePoints[i].X * (int)depthSpacePoints[i].Y;
                                if (irIndex < irFrameData.Length)
                                    var_ir = irFrameData[irIndex] - avg_ir;
                                else
                                    var_ir = avg_ir;

                                std_ir += Math.Pow(var_ir, 2);

                            }

                            std_alpha = Math.Sqrt(std_alpha / size);
                            std_red = Math.Sqrt(std_red / size);
                            std_green = Math.Sqrt(std_green / size);
                            std_blue = Math.Sqrt(std_blue / size);
                            std_ir = Math.Sqrt(std_ir / size);

                            double prime_alpha = 0;
                            double prime_red = 0;
                            double prime_green = 0;
                            double prime_blue = 0;
                            double prime_ir = 0;

                            //Now calculate standard deviation
                            for (int i = startPixel; i < endPixel; i += 4)
                            {
                                //var pixel = pixels[i];
                                var_blue = (double)(pixels[i] - avg_blue);
                                prime_blue += var_blue / std_blue;

                                var_green = (pixels[i + 1] - avg_green);
                                prime_green += var_green / std_green;

                                var_red = (pixels[i + 2] - avg_red);
                                prime_red += var_red / std_red;

                                var_alpha = (pixels[i + 3] - avg_alpha);
                                prime_alpha += var_alpha / std_alpha;

                                int irIndex = (int)depthSpacePoints[i].X * (int)depthSpacePoints[i].Y;
                                if (irIndex < irFrameData.Length)
                                    var_ir = irFrameData[irIndex] - avg_ir;
                                else
                                    var_ir = avg_ir;

                                prime_ir += var_ir / std_ir;
                            }

                            double norm_alpha = prime_alpha / size;
                            double norm_red = prime_red / size;
                            double norm_blue = prime_blue / size;
                            double norm_green = prime_green / size;
                            double norm_ir = prime_ir / size;

                            Plot(norm_red, norm_green, norm_blue, norm_ir);

                            jadeCalculation.Write(
                                m_secondsElapsed.ElapsedMilliseconds,
                                norm_alpha, norm_red, norm_green, norm_blue, norm_ir);

                        }
                        m_colorBitmap.Unlock();
                    }
                }
            }
        }