Переглянути джерело

Made processing much faster.
Removed unnecessary data.

Daniel Kauth 11 роки тому
батько
коміт
d564208dbd

+ 9 - 6
bbiwarg/Detectors/Palm/PalmDetector.cs

@@ -49,12 +49,12 @@ namespace bbiwarg.Detectors.Palm
             this.edgeImage = edgeImage;
             this.palmImage = palmImage;
 
-            handImage = depthImage.Image.Convert<Byte>(delegate(short s) { return (s == depthImage.getMaxDepth()) ? (byte)0 : (byte)1; });
+            handImage = depthImage.Image.ThresholdBinaryInv(new Gray(depthImage.getMaxDepth() - 1), new Gray(1)).Convert<Gray, Byte>();
 
             fingers = getFingersWithoutThumb(detectedFingers);
             buildPointingHandMask();
             handImage = handImage.And(pointingHandMask);
-
+            
             findLongestPalmContour();
             if (palmContour != null)
             {
@@ -133,14 +133,18 @@ namespace bbiwarg.Detectors.Palm
         private void buildPointingHandMask()
         {
             pointingHandMask = new Image<Gray, byte>(width, height, new Gray(0));
+
             fillFingerSlices(pointingHandMask, 1);
             pointingHandMask = pointingHandMask.Dilate(1);
-            pointingHandMask = pointingHandMask.Or(edgeImage.getImage().Convert<Byte>(delegate(byte b) { return (b == 0) ? (byte)0 : (byte)1; }));
+            pointingHandMask = pointingHandMask.Or(edgeImage.Image);
             pointingHandMask = pointingHandMask.Dilate(1);
-
+            
             MCvConnectedComp tmp = new MCvConnectedComp();
+            // fill with value 2
             CvInvoke.cvFloodFill(pointingHandMask.Ptr, getPointInPointingHand(), new MCvScalar(2), new MCvScalar(0), new MCvScalar(0), out tmp, 0, IntPtr.Zero);
-            pointingHandMask = pointingHandMask.Convert<Byte>(delegate(byte b) { return (b == 2) ? (byte)0 : (byte)1; });
+
+            // dst = (src > 1) ? 0 : 1    (src > 1 <-> src == 2 <-> src filled by flood fill)
+            pointingHandMask = pointingHandMask.ThresholdBinaryInv(new Gray(1), new Gray(1));
             pointingHandMask = pointingHandMask.Erode(1);
             fillFingerSlices(pointingHandMask, 0);
             pointingHandMask = pointingHandMask.Erode(2);
@@ -246,7 +250,6 @@ namespace bbiwarg.Detectors.Palm
                 for (int i = 0; i < 4; ++i)
                     palmImage.drawLine(new LineSegment2DF(vertices[i], vertices[(i + 1) % 4]), PalmImageState.palmRect);
 
-
                 palmImage.drawGrid(new Vector2D(vertices[0]), new Vector2D(vertices[1]), new Vector2D(vertices[2]), new Vector2D(vertices[3]));
             }
         }

+ 20 - 26
bbiwarg/Images/DepthImage.cs

@@ -7,28 +7,32 @@ using System.Threading.Tasks;
 using Emgu.CV;
 using Emgu.CV.Structure;
 
+using System.Diagnostics;
+
 namespace bbiwarg.Images
 {
     class DepthImage
     {
         public Image<Gray, Int16> Image { get; private set; }
-        public int Width { get { return Image.Width; } }
-        public int Height { get { return Image.Height; } }
+        public int Width { get; private set; }
+        public int Height { get; private set; }
         public Int16 MinDepth { get; private set; }
         public Int16 MaxDepth { get; private set; }
 
         public DepthImage(Image<Gray, Int16> image)
         {
             this.Image = image;
+            Width = image.Width;
+            Height = image.Height;
 
             //smooth
             this.Image = image.SmoothMedian(3);
-
+            
             //threshold min&maxDepth
-            MinDepth = findMinDepth();
+            MinDepth = (Int16)findMinDepth();
             MaxDepth = (Int16)(MinDepth + 200);
-            thresholdDepth(MinDepth, MaxDepth);
 
+            thresholdDepth(MaxDepth);
         }
 
         public Int16 getDepthAt(Point point)
@@ -74,30 +78,20 @@ namespace bbiwarg.Images
 
         private Int16 findMinDepth()
         {
-            MinDepth = Int16.MaxValue;
-            for (int x = 0; x < Width; ++x)
-            {
-                for (int y = 0; y < Height; ++y)
-                {
-                    Int16 depth = getDepthAt(x, y);
-                    if (depth < MinDepth)
-                        MinDepth = depth;
-                }
-            }
-            return MinDepth;
+            // min and max values
+            double[] min, max;
+            // min and max locations
+            Point[] minLoc, maxLoc;
+
+            Image.MinMax(out min, out max, out minLoc, out maxLoc);
+            
+            return (Int16) min[0];
         }
 
-        private void thresholdDepth(Int16 min, Int16 max)
+        private void thresholdDepth(Int16 max)
         {
-            for (int x = 0; x < Width; ++x)
-            {
-                for (int y = 0; y < Height; ++y)
-                {
-                    Int16 depth = getDepthAt(x, y);
-                    if (depth > max || depth < min)
-                        setDepthAt(x, y, max);
-                }
-            }
+            // newDepth = (depth > max) ? max : depth;
+            Image = Image.ThresholdTrunc(new Gray(max));
         }
     }
 }

+ 14 - 11
bbiwarg/Images/EdgeImage.cs

@@ -6,27 +6,30 @@ using System.Threading.Tasks;
 using Emgu.CV;
 using Emgu.CV.Structure;
 
+using System.Diagnostics;
+using bbiwarg.Utility;
+
 namespace bbiwarg.Images
 {
     class EdgeImage
     {
-        private Image<Gray, Byte> image;
+        public Image<Gray, byte> Image { get; private set; }
 
-        public EdgeImage(DepthImage depthImage) {
+        public EdgeImage(DepthImage depthImage) 
+        {
             int minDepth = depthImage.getMinDepth();
             int maxDepth = depthImage.getMaxDepth();
-            Image<Gray, Int16> depthImageInt16 = depthImage.Image;
-            Image<Gray, Byte> depthImageByte = depthImageInt16.Convert<Byte>(delegate(Int16 depth) { return (byte)(((depth - minDepth) * Byte.MaxValue) / (maxDepth - minDepth)); });
-            image = depthImageByte.Canny(100, 75, 3);
-        }
 
-        public bool isEdgeAt(int x, int y) {
-            return (image.Data[y,x,0] > 0);
+            Image<Gray, Int16> depthImageInt16 = depthImage.Image.Clone();
+            depthImageInt16 = depthImageInt16.Sub(new Gray(minDepth));
+            depthImageInt16 = depthImageInt16.Mul(Byte.MaxValue / (maxDepth - minDepth));
+            Image<Gray, Byte> depthImageByte = depthImageInt16.Convert<Gray, Byte>();
+
+            Image = depthImageByte.Canny(100, 75, 3);
         }
 
-        public Image<Gray, Byte> getImage()
-        {
-            return image;
+        public bool isEdgeAt(int x, int y) {
+            return (Image.Data[y,x,0] > 0);
         }
     }
 }

+ 2 - 33
bbiwarg/InputProvider/IInputProvider.cs

@@ -7,20 +7,6 @@ using MathNet.Numerics.LinearAlgebra.Single;
 
 namespace bbiwarg.InputProviders
 {
-    public enum DetectionStatus
-    {
-        Inactive,
-        Detected,
-        Tracked
-    }
-
-    public enum HandSide
-    {
-        Unknown,
-        Left,
-        Right
-    }
-
     interface IInputProvider
     {
         void init();
@@ -30,33 +16,16 @@ namespace bbiwarg.InputProviders
         void releaseFrame();
 
         float getFrameRate();
+        int getCurrentMovieFrame();
         float getHFOV();
         float getVFOV();
         bool isActive();
 
         InputFrame getInputFrame();
 
-        /*
-         * all handIndices have to be 1 or 2
-         */
-        bool isHandOpen(uint handIndex);
-        Vector getPalmPosition3D(uint handIndex);
-        Vector getPalmPosition2D(uint handIndex);
-        Vector getTipPosition3D(uint handIndex);
-        Vector getForearmPosition3D(uint handIndex);
-        Vector getPalmNormal3D(uint handIndex);
-        DetectionStatus[] getFingerStatus(uint handIndex);
-        DetectionStatus getHandStatus(uint handIndex);
-        Vector[] getFingerTipPositions3D(uint handIndex);
-        Vector[] getFingerTipPositions2D(uint handIndex);
-        HandSide getHandSide(uint handIndex);
-
+        bool sourceIsMovie();
         void pauseMovie();
-
         void unpauseMovie();
-
-        bool sourceIsMovie();
-
         void reversePlay();
     }
 }

+ 8 - 206
bbiwarg/InputProvider/IisuInputProvider.cs

@@ -17,26 +17,13 @@ namespace bbiwarg.InputProviders
 
         //parameters
         private IParameterHandle<float> frameRate;
+        private IParameterHandle<int> currentMovieFrame;
         private IParameterHandle<float> hfov;
         private IParameterHandle<float> vfov;
         private IParameterHandle<int> playStep;
 
         //data
-        private IDataHandle<int>[] handStatus = new IDataHandle<int>[2];
-        private IDataHandle<bool>[] handOpen = new IDataHandle<bool>[2];
-        private IDataHandle<int>[] handSides = new IDataHandle<int>[2];
-        private IDataHandle<int[]>[] fingerStatus = new IDataHandle<int[]>[2];
-        private IDataHandle<Iisu.Data.Vector3>[] palmPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
-        private IDataHandle<Iisu.Data.Vector2>[] palmPositions2D = new IDataHandle<Iisu.Data.Vector2>[2];
-        private IDataHandle<Iisu.Data.Vector3>[] tipPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
-        private IDataHandle<Iisu.Data.Vector3>[] forearmPositions3D = new IDataHandle<Iisu.Data.Vector3>[2];
-        private IDataHandle<Iisu.Data.Vector3>[] palmNormals3D = new IDataHandle<Iisu.Data.Vector3>[2];
-        private IDataHandle<Iisu.Data.Vector3[]>[] fingerTipPositions3D = new IDataHandle<Iisu.Data.Vector3[]>[2];
-        private IDataHandle<Iisu.Data.Vector2[]>[] fingerTipPositions2D = new IDataHandle<Iisu.Data.Vector2[]>[2];
         private IDataHandle<Iisu.Data.IImageData> depthImage;
-        private IDataHandle<Iisu.Data.IImageData> confidenceImage;
-        private IDataHandle<Iisu.Data.IImageData> uvImage;
-        private IDataHandle<Iisu.Data.IImageData> colorImage;
 
         public IisuInputProvider(String moviePath = "") 
         {
@@ -78,6 +65,7 @@ namespace bbiwarg.InputProviders
             }
 
             frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate");
+            currentMovieFrame = device.RegisterParameterHandle<int>("SOURCE.MOVIE.CurrentFrame");
             hfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.HFOV");
             vfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.VFOV");
 
@@ -85,43 +73,7 @@ namespace bbiwarg.InputProviders
             device.EventManager.RegisterEventListener("DEVICE.Status", new Iisu.EventDelegates.Device.Status(onDeviceStatusChanged));
 
             // data
-            handStatus[0] = device.RegisterDataHandle<int>("CI.HAND1.Status");
-            handStatus[1] = device.RegisterDataHandle<int>("CI.HAND2.Status");
-
-            handOpen[0] = device.RegisterDataHandle<bool>("CI.HAND1.IsOpen");
-            handOpen[1] = device.RegisterDataHandle<bool>("CI.HAND2.IsOpen");
-
-            handSides[0] = device.RegisterDataHandle<int>("CI.HAND1.Side");
-            handSides[1] = device.RegisterDataHandle<int>("CI.HAND1.Side");
-            
-            fingerStatus[0] = device.RegisterDataHandle<int[]>("CI.HAND1.FingerStatus");
-            fingerStatus[1] = device.RegisterDataHandle<int[]>("CI.HAND2.FingerStatus");
-
-            palmPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmPosition3D");
-            palmPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.PalmPosition3D");
-
-            palmPositions2D[0] = device.RegisterDataHandle<Iisu.Data.Vector2>("CI.HAND1.PalmPosition2D");
-            palmPositions2D[1] = device.RegisterDataHandle<Iisu.Data.Vector2>("CI.HAND2.PalmPosition2D");
-
-            tipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.TipPosition3D");
-            tipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.TipPosition3D");
-
-            forearmPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.ForearmPosition3D");
-            forearmPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.ForearmPosition3D");
-
-            palmNormals3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND1.PalmNormal3D");
-            palmNormals3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3>("CI.HAND2.PalmNormal3D");
-
-            fingerTipPositions3D[0] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND1.FingerTipPositions3D");
-            fingerTipPositions3D[1] = device.RegisterDataHandle<Iisu.Data.Vector3[]>("CI.HAND2.FingerTipPositions3D");
-
-            fingerTipPositions2D[0] = device.RegisterDataHandle<Iisu.Data.Vector2[]>("CI.HAND1.FingerTipPositions2D");
-            fingerTipPositions2D[1] = device.RegisterDataHandle<Iisu.Data.Vector2[]>("CI.HAND2.FingerTipPositions2D");
-            
             depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
-            colorImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.COLOR.Image");
-            confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
-            uvImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.COLOR.REGISTRATION.UV.Image");
         }
 
         private void onDeviceStatusChanged(string eventName, DeviceStatus status)
@@ -173,172 +125,18 @@ namespace bbiwarg.InputProviders
 
 
         // Data-methodes
-        public DetectionStatus getHandStatus(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            int status = handStatus[handIndex - 1].Value;
-            DetectionStatus result = new DetectionStatus();
-            switch (status)
-            {
-                case 0:
-                    result = DetectionStatus.Inactive;
-                    break;
-                case 1:
-                    result = DetectionStatus.Detected;
-                    break;
-                case 2:
-                    result = DetectionStatus.Tracked;
-                    break;
-            }
-            return result;
-        }
-
-        public bool isHandOpen(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return handOpen[handIndex - 1].Value;
-        }
-
-        public HandSide getHandSide(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            int side = handSides[handIndex - 1].Value;
-            switch (side)
-            {
-                case 1:
-                    return HandSide.Left;
-                case 2:
-                    return HandSide.Right;
-                default:
-                    return HandSide.Unknown;
-            }
-        }
-
-        public DetectionStatus[] getFingerStatus(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            int[] status = fingerStatus[handIndex - 1].Value;
-            DetectionStatus[] result = new DetectionStatus[status.Length];
-            for (int i = 0; i < status.Length; ++i)
-            {
-                switch (status[i])
-                {
-                    case 0:
-                        result[i] = DetectionStatus.Inactive;
-                        break;
-                    case 1:
-                        result[i] = DetectionStatus.Detected;
-                        break;
-                    case 2:
-                        result[i] = DetectionStatus.Tracked;
-                        break;
-                }
-            }
-            return result;
-        }
-
-        public Vector getPalmPosition3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(swapXZYtoXYZ(palmPositions3D[handIndex - 1].Value.ToArray()));
-        }
-
-        public Vector getPalmPosition2D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(palmPositions2D[handIndex - 1].Value.ToArray());
-        }
-
-        public Vector getTipPosition3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(swapXZYtoXYZ(tipPositions3D[handIndex - 1].Value.ToArray()));
-        }
-
-        public Vector getForearmPosition3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(swapXZYtoXYZ(forearmPositions3D[handIndex - 1].Value.ToArray()));
-        }
-
-        public Vector getPalmNormal3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            return new DenseVector(swapXZYtoXYZ(palmNormals3D[handIndex - 1].Value.ToArray()));
-        }
-
-        public Vector[] getFingerTipPositions3D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            Iisu.Data.Vector3[] positions = fingerTipPositions3D[handIndex - 1].Value;
-            Vector[] results = new DenseVector[positions.Length];
-            for (int i = 0; i < positions.Length; ++i)
-                results[i] = new DenseVector(swapXZYtoXYZ(positions[i].ToArray()));
-            return results;
-        }
-
-        public Vector[] getFingerTipPositions2D(uint handIndex)
-        {
-            checkHandIndex(handIndex);
-            Iisu.Data.Vector2[] positions = fingerTipPositions2D[handIndex - 1].Value;
-            Vector[] results = new DenseVector[positions.Length];
-            for (int i = 0; i < positions.Length; ++i)
-                results[i] = new DenseVector(positions[i].ToArray());
-            return results;
-        }
-
         public InputFrame getInputFrame() {
             //depthData
             Iisu.Data.IImageInfos imageInfos = depthImage.Value.ImageInfos;
             int width = (int)imageInfos.Width;
             int height = (int)imageInfos.Height;
-            int numBytes = (int)imageInfos.BytesRaw;
-            IntPtr imageData = depthImage.Value.Raw;
-            short[] depthData = new short[width * height];
-            Marshal.Copy(imageData, depthData, 0, width * height);
-
-            //confidenceData
-            imageInfos = confidenceImage.Value.ImageInfos;
-            numBytes = (int)imageInfos.BytesRaw;
-            imageData = confidenceImage.Value.Raw;
-            short[] confidenceData = new short[width * height];
-            Marshal.Copy(imageData, confidenceData, 0, width * height);
+            IntPtr rawDepthData = depthImage.Value.Raw;
 
-            //uvData
-            imageInfos = uvImage.Value.ImageInfos;
-            numBytes = (int)imageInfos.BytesRaw;
-            imageData = uvImage.Value.Raw;
-            float[] uvData = new float[2 * width * height];
-            Marshal.Copy(imageData, uvData, 0, 2 * width * height);
-
-            //colorData
-            imageInfos = colorImage.Value.ImageInfos;
-            int widthRawColor = (int)imageInfos.Width;
-            int heightRawColor = (int)imageInfos.Height;
-            numBytes = (int)imageInfos.BytesRaw;
-            imageData = colorImage.Value.Raw;
-            byte[] colorData = new byte[numBytes];
-            Marshal.Copy(imageData, colorData, 0, numBytes);
-
-            return new InputFrame(width, height, widthRawColor, heightRawColor, depthData, confidenceData, uvData, colorData);
+            return new InputFrame(width, height, rawDepthData);
         }
 
         // other
 
-        private void checkHandIndex(uint handIndex)
-        {
-            if (handIndex < 1 || handIndex > 2)
-                throw new ArgumentOutOfRangeException("handIndex is out of range [0,1]");
-        }
-
-        private float[] swapXZYtoXYZ(float[] vector) 
-        {
-            float dummy = vector[1];
-            vector[1] = vector[2];
-            vector[2] = dummy;
-            return vector;
-        }
-
         public void pauseMovie()
         {
             if (sourceIsMovie)
@@ -351,6 +149,10 @@ namespace bbiwarg.InputProviders
                 playStep.Value = 1;
         }
 
+        public int getCurrentMovieFrame()
+        {
+            return currentMovieFrame.Value;
+        }
 
         bool IInputProvider.sourceIsMovie()
         {

+ 3 - 53
bbiwarg/InputProvider/InputFrame.cs

@@ -13,62 +13,12 @@ namespace bbiwarg.InputProviders
     {
         public int Width { get; private set; }
         public int Height { get; private set; }
-        private int widthRawColor;
-        private int heightRawColor;
-        private Int16[] depthData;
-        private Int16[] confidenceData;
-        private float[] uvData;
-        private byte[] rawColorData;
+        public IntPtr RawDepthData { get; private set; }
 
-        public InputFrame(int width, int height, int widthRawColor, int heightRawColor, Int16[] depthData, Int16[] confidenceData, float[] uvData, byte[] rawColorData) {
+        public InputFrame(int width, int height, IntPtr rawDepthData) {
             this.Width = width;
             this.Height = height;
-            this.widthRawColor = widthRawColor;
-            this.heightRawColor = heightRawColor;
-            this.depthData = depthData;
-            this.confidenceData = confidenceData;
-            this.uvData = uvData;
-            this.rawColorData = rawColorData;
-        }
-
-        public Int16 getDepthAt(int x, int y) {
-            return depthData[y * Width + x];
-        }
-
-        public Int16 getConfidenceAt(int x, int y) {
-            return confidenceData[y * Width + x];
-        }
-
-        public float getUAt(int x, int y)
-        {
-            return uvData[2 * (y * Width + x) + 0];
-        }
-
-        public float getVAt(int x, int y)
-        {
-            return uvData[2 * (y * Width + x) + 1];
-        }
-
-        public Color getColorAt(int x, int y) {
-            float u = getUAt(x, y);
-            float v = getVAt(x, y);
-
-            if (u < 0 || v < 0)
-                return Color.Black;
-
-            int xInColorImage = (int)(u * widthRawColor) % widthRawColor;
-            int yInColorImage = (int)(v * heightRawColor) % heightRawColor;
-            return getRawColorAt(x,y);
-        }
-
-        public Color getRawColorAt(int x, int y) {
-            int offset = 4 * (y * widthRawColor + x);
-            byte alpha = rawColorData[offset + 3];
-            byte red = rawColorData[offset + 2];
-            byte green = rawColorData[offset + 1];
-            byte blue = rawColorData[offset + 0];
-
-            return Color.FromArgb(alpha, red, green, blue);
+            this.RawDepthData = rawDepthData;
         }
     }
 }

+ 31 - 7
bbiwarg/VideoHandle.cs

@@ -9,6 +9,7 @@ using bbiwarg.Detectors.Palm;
 using bbiwarg.Detectors.Touch;
 using bbiwarg.Images;
 using bbiwarg.InputProviders;
+using bbiwarg.Utility;
 using Emgu.CV;
 using Emgu.CV.Structure;
 
@@ -54,6 +55,11 @@ namespace bbiwarg
             inputProvider.stop();
         }
 
+        public int getCurrentMovieFrame()
+        {
+            return inputProvider.getCurrentMovieFrame();
+        }
+
         public bool sourceIsMovie()
         {
             return inputProvider.sourceIsMovie();
@@ -76,6 +82,9 @@ namespace bbiwarg
 
         public void nextFrame()
         {
+            Stopwatch sw = new Stopwatch();
+            sw.Start();
+
             if (inputProvider.isActive())
             {
                 inputProvider.releaseFrame();
@@ -86,6 +95,9 @@ namespace bbiwarg
             {
                 inputProvider.stop();
             }
+
+            //Console.WriteLine("time for frame: {0} ms", HelperFunctions.getElapsedMilliseconds(sw));
+            //Console.WriteLine();
         }
 
         public Int16 getDepthAt(int x, int y) {
@@ -113,45 +125,57 @@ namespace bbiwarg
             return touchImage.getStateAt(x, y);
         }
 
-        public List<PalmTouchEvent> getTouchEvents()
+        public List<PalmTouchEvent> getPalmTouchEvents()
         {
             return palmTouchDetector.PalmTouchEvents;
         }
 
         private void processFrameUpdate()
         {
+            Stopwatch sw = new Stopwatch();
+            
             //read data from inputProvider
+            sw.Start();
             inputFrame = inputProvider.getInputFrame();
             Width = inputFrame.Width;
             Height = inputFrame.Height;
+            //Console.WriteLine("    time for input frame:          {0} ms", HelperFunctions.getElapsedMilliseconds(sw));
 
             //create depthImage
-            Image<Gray, Int16> image = new Image<Gray, Int16>(Width, Height);
-            for (int x = 0; x < Width; x++) {
-                for (int y = 0; y < Height; y++) {
-                    image.Data[y, x, 0] = inputFrame.getDepthAt(x, y);
-                }
-            }
+            sw.Restart();
+            Image<Gray, Int16> image = new Image<Gray, Int16>(Width, Height, Width * 2, inputFrame.RawDepthData);
+            //Console.WriteLine("    time for depth image creation: {0} ms", HelperFunctions.getElapsedMilliseconds(sw));
+
+            sw.Restart();
             depthImage = new DepthImage(image);
+            //Console.WriteLine("    time for DepthImage:           {0} ms", HelperFunctions.getElapsedMilliseconds(sw));
 
             //create images
+            sw.Restart();
             edgeImage = new EdgeImage(depthImage);
             touchImage = new TouchImage(Width, Height);
             fingerImage = new FingerImage(Width, Height);
             palmImage = new PalmImage(Width, Height);
+            //Console.WriteLine("    time for images:               {0} ms", HelperFunctions.getElapsedMilliseconds(sw));
 
             //detect+track fingers
+            sw.Restart();
             fingerDetector = new FingerDetector(depthImage, edgeImage, fingerImage);
             fingerTracker.setDetectedTouchEventsThisFrame(fingerDetector.Fingers, fingerImage);
+            //Console.WriteLine("    time for finger detection:     {0} ms", HelperFunctions.getElapsedMilliseconds(sw));
 
             //detect palm
+            sw.Restart();
             palmDetector = new PalmDetector(depthImage, edgeImage, fingerDetector.Fingers, palmImage);
+            //Console.WriteLine("    time for palm detection:       {0} ms", HelperFunctions.getElapsedMilliseconds(sw));
 
             //detect+track touchEvents
+            sw.Restart();
             touchDetector = new TouchDetector(fingerTracker.TrackedFingers, depthImage, touchImage);
             if(palmDetector.PalmQuad != null)
                 palmTouchDetector = new PalmTouchDetector(touchDetector.TouchEvents, palmDetector.PalmQuad);
             touchTracker.setDetectedTouchEventsThisFrame(touchDetector.TouchEvents, touchImage);
+            //Console.WriteLine("    time for touch detection:      {0} ms", HelperFunctions.getElapsedMilliseconds(sw));
         }
     }
 }