Browse Source

-renamed Constants to Parameters
-rewritten Vector2D isInbound() and moveInBound()
-ImageWidth and ImageHeight are now stored in Parameters

Alexander Hendrich 10 years ago
parent
commit
10686b604f

+ 14 - 18
bbiwarg/Graphics/OutputWindow.cs

@@ -26,8 +26,8 @@ namespace bbiwarg.Graphics
         private uint textureID;
 
         public OutputWindow(InputProvider inputProvider, InputHandler inputHandler)
-            : base((int)(Constants.OutputScaleFactor * Math.Max(1, Math.Min(Constants.OutputNumImagesPerRow, Constants.OutputNumImages)) * inputProvider.ImageWidth),
-                   (int)(Constants.OutputScaleFactor * (1 + (Constants.OutputNumImages - 1) / Constants.OutputNumImagesPerRow) * inputProvider.ImageHeight))
+            : base((int)(Parameters.OutputScaleFactor * Math.Max(1, Math.Min(Parameters.OutputNumImagesPerRow, Parameters.OutputNumImages)) * Parameters.ImageWidth),
+                   (int)(Parameters.OutputScaleFactor * (1 + (Parameters.OutputNumImages - 1) / Parameters.OutputNumImagesPerRow) * Parameters.ImageHeight))
         {
             this.inputProvider = inputProvider;
             this.inputHandler = inputHandler;
@@ -36,7 +36,7 @@ namespace bbiwarg.Graphics
         protected override void OnLoad(EventArgs e)
         {
             base.OnLoad(e);
-            Title = Constants.OutputTitle;
+            Title = Parameters.OutputTitle;
             GL.ClearColor(Color.Black);
 
             // transparency
@@ -68,13 +68,9 @@ namespace bbiwarg.Graphics
             int screenWidth = ClientRectangle.Width;
             int screenHeight = ClientRectangle.Height;
 
-            int imageWidth = inputProvider.ImageWidth;
-            int imageHeight = inputProvider.ImageHeight;
-            float imageAspectRatio = (float)imageWidth / (float)imageHeight;
-
-            int numRows = 1 + (Constants.OutputNumImages - 1) / Constants.OutputNumImagesPerRow;
-            int numCols = Math.Min(Constants.OutputNumImages, Constants.OutputNumImagesPerRow);
-            int heightForWidth = (int)((float)screenWidth / ((float)numCols * imageAspectRatio) * (float)numRows);
+            int numRows = 1 + (Parameters.OutputNumImages - 1) / Parameters.OutputNumImagesPerRow;
+            int numCols = Math.Min(Parameters.OutputNumImages, Parameters.OutputNumImagesPerRow);
+            int heightForWidth = (int)((float)screenWidth / ((float)numCols * Parameters.ImageAspectRatio) * (float)numRows);
 
             GL.Viewport(0, (screenHeight - heightForWidth) / 2, screenWidth, heightForWidth);
 
@@ -96,7 +92,7 @@ namespace bbiwarg.Graphics
 
             inputHandler.updateFrame();
 
-            Title = Constants.OutputTitle + " (Frame: " + inputProvider.CurrentFrameID + ")";
+            Title = Parameters.OutputTitle + " (Frame: " + inputProvider.CurrentFrameID + ")";
 
             Timer.start("buildTextures");
             GL.Enable(EnableCap.Texture2D);
@@ -104,10 +100,10 @@ namespace bbiwarg.Graphics
             int imageIndex = 0;
             foreach (OutputImage image in inputHandler.OutputImages)
             {
-                int x = imageIndex % Constants.OutputNumImagesPerRow;
-                int y = imageIndex / Constants.OutputNumImagesPerRow;
+                int x = imageIndex % Parameters.OutputNumImagesPerRow;
+                int y = imageIndex / Parameters.OutputNumImagesPerRow;
                 GL.BindTexture(TextureTarget.Texture2D, textureID);
-                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, inputProvider.ImageWidth, inputProvider.ImageHeight, 0, PixelFormat.Rgb, PixelType.UnsignedByte, image.Image.MIplImage.imageData);
+                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, Parameters.ImageWidth, Parameters.ImageHeight, 0, PixelFormat.Rgb, PixelType.UnsignedByte, image.Image.MIplImage.imageData);
                 GL.Begin(PrimitiveType.Quads);
                 GL.Color3(1.0, 1.0, 1.0);
                 GL.TexCoord2(0, 0); GL.Vertex3(0 + x, 0 + y, -1);
@@ -172,17 +168,17 @@ namespace bbiwarg.Graphics
                 case Key.KeypadPlus:
                 case Key.BracketRight: //fix
                     if (palmGridControlFocus == PalmGridControlFocus.Rows)
-                        Constants.PalmGridNumRows++;
+                        Parameters.PalmGridNumRows++;
                     else
-                        Constants.PalmGridNumColumns++;
+                        Parameters.PalmGridNumColumns++;
                     break;
                 case Key.Minus:
                 case Key.KeypadMinus:
                 case Key.Slash: //fix
                     if (palmGridControlFocus == PalmGridControlFocus.Rows)
-                        Constants.PalmGridNumRows = Math.Max(1, Constants.PalmGridNumRows - 1);
+                        Parameters.PalmGridNumRows = Math.Max(1, Parameters.PalmGridNumRows - 1);
                     else
-                        Constants.PalmGridNumColumns = Math.Max(1, Constants.PalmGridNumColumns-1);
+                        Parameters.PalmGridNumColumns = Math.Max(1, Parameters.PalmGridNumColumns-1);
                     break;
             }
         }

+ 10 - 10
bbiwarg/Graphics/TouchEventVisualizer.cs

@@ -79,7 +79,7 @@ namespace bbiwarg.Graphics
             List<int> ids = new List<int>(lastUpdates.Keys);
             for (int i = ids.Count - 1; i >= 0; i--) {
                 int id = ids[i];
-                if (currentTime - lastUpdates[id] > Constants.TouchEventVisualizerFadeOutTime) {
+                if (currentTime - lastUpdates[id] > Parameters.TouchEventVisualizerFadeOutTime) {
                     positions.Remove(id);
                     lastUpdates.Remove(id);
                 }
@@ -88,42 +88,42 @@ namespace bbiwarg.Graphics
             OutputImage = new OutputImage(width, height);
 
             //border
-            OutputImage.drawRectangle(0, 0, width - 1, height - 1, Constants.TouchEventVisualizerGridColor);
+            OutputImage.drawRectangle(0, 0, width - 1, height - 1, Parameters.TouchEventVisualizerGridColor);
 
             //draw grid
-            int numRows = Constants.PalmGridNumRows;
-            int numColumns = Constants.PalmGridNumColumns;
+            int numRows = Parameters.PalmGridNumRows;
+            int numColumns = Parameters.PalmGridNumColumns;
             int widthPerColumn = width / numColumns;
             int heightPerRow = height / numRows;
 
             for (int i = 0; i <= numColumns; i++)
             {
-                OutputImage.drawLineSegment(new LineSegment2D(new Vector2D(i * widthPerColumn, 0), new Vector2D(i * widthPerColumn, height - 1)), Constants.TouchEventVisualizerGridColor);
+                OutputImage.drawLineSegment(new LineSegment2D(new Vector2D(i * widthPerColumn, 0), new Vector2D(i * widthPerColumn, height - 1)), Parameters.TouchEventVisualizerGridColor);
             }
 
             for (int i = 0; i <= numRows; i++)
             {
-                OutputImage.drawLineSegment(new LineSegment2D(new Vector2D(0, i * heightPerRow), new Vector2D(width - 1, i * heightPerRow)), Constants.TouchEventVisualizerGridColor);
+                OutputImage.drawLineSegment(new LineSegment2D(new Vector2D(0, i * heightPerRow), new Vector2D(width - 1, i * heightPerRow)), Parameters.TouchEventVisualizerGridColor);
             }
                         
             for (int row = 0; row < numRows; row++) {
                 for (int col = 0; col < numColumns; col++) {
                     int x = (int)((col+0.5f)*widthPerColumn)-5;
                     int y = (int)((row+0.5f)*heightPerRow)+5;
-                    OutputImage.drawText(x,y,(1+row*numColumns+col).ToString(),Constants.TouchEventVisualizerTextColor);
+                    OutputImage.drawText(x,y,(1+row*numColumns+col).ToString(),Parameters.TouchEventVisualizerTextColor);
                 }
             }
 
             foreach (int id in positions.Keys)
-                drawTouchGesture(positions[id], 1 - ((currentTime - lastUpdates[id]) / (float)Constants.TouchEventVisualizerFadeOutTime));
+                drawTouchGesture(positions[id], 1 - ((currentTime - lastUpdates[id]) / (float)Parameters.TouchEventVisualizerFadeOutTime));
         }
 
         public void drawTouchGesture(List<Vector2D> positions, float opacity)
         {
             Vector2D maxPixel = new Vector2D(width - 1, height - 1);
             int numPositions = positions.Count;
-            Color lineColor = Constants.TouchEventVisualizerLineColor;
-            Color pointColor = Constants.TouchEventVisualizerPointColor;
+            Color lineColor = Parameters.TouchEventVisualizerLineColor;
+            Color pointColor = Parameters.TouchEventVisualizerPointColor;
             Color lineColorFaded = Color.FromArgb((int)(opacity * lineColor.R), (int)(opacity * lineColor.G), (int)(opacity * lineColor.B));
             Color pointColorFaded = Color.FromArgb((int)(opacity * pointColor.R), (int)(opacity * pointColor.G), (int)(opacity * pointColor.B));
             for (int i = 1; i < numPositions; i++)

+ 1 - 1
bbiwarg/Images/ConfidenceImage.cs

@@ -19,7 +19,7 @@ namespace bbiwarg.Images
         {
             Image = image;
 
-            Mask = (Image.ThresholdBinary(new Gray(Constants.ConfidenceImageMinThreshold), new Gray(1))).Convert<Gray, byte>();
+            Mask = (Image.ThresholdBinary(new Gray(Parameters.ConfidenceImageMinThreshold), new Gray(1))).Convert<Gray, byte>();
         }
     }
 }

+ 3 - 10
bbiwarg/Images/DepthImage.cs

@@ -18,30 +18,23 @@ namespace bbiwarg.Images
     {
         public Image<Gray, byte> Image { get; private set; }
         public Image<Gray, byte> BackgroundMask { get; private set; }
-        public int Width { get; private set; }
-        public int Height { get; private set; }
-        public Vector2D BottomRight { get; private set; }
         public Int16 MinDepth { get; private set; }
         public Int16 MaxDepth { get; private set; }
 
         public DepthImage(Image<Gray, Int16> image)
         {
-            Width = image.Width;
-            Height = image.Height;
-            BottomRight = new Vector2D(Width - 1, Height - 1);
-
             //image = image.SmoothBlur(3,3,true);
-            image = image.SmoothMedian(Constants.DepthImageMedianSize);
+            image = image.SmoothMedian(Parameters.DepthImageMedianSize);
             
             //threshold min&maxDepth
             MinDepth = findMinDepth(image);
-            MaxDepth = (Int16)(MinDepth + Constants.DepthImageDepthRange);
+            MaxDepth = (Int16)(MinDepth + Parameters.DepthImageDepthRange);
 
             //smooth+threshold (dst = (src > (MaxDepth - MinDepth)) ? MaxDepth - MinDepth : src)
             Image = (image - MinDepth).ThresholdTrunc(new Gray(MaxDepth - MinDepth)).Convert<Gray, byte>();
             
             //Image = Image.SmoothBlur(3,3, true);
-            Image = Image.SmoothMedian(Constants.DepthImageMedianSize);
+            Image = Image.SmoothMedian(Parameters.DepthImageMedianSize);
         }
 
         public Int16 getDepthAt(Point point)

+ 3 - 7
bbiwarg/Images/EdgeImage.cs

@@ -18,15 +18,11 @@ namespace bbiwarg.Images
     {
         public Image<Gray, Byte> Image { get; private set; }
         public Image<Gray, byte> RoughImage { get; private set; }
-        public int Width { get; private set; }
-        public int Height { get; private set; }
 
         public EdgeImage(DepthImage depthImage)
         {
-            Width = depthImage.Width;
-            Height = depthImage.Height;
-            Image = depthImage.Image.ConvertScale<byte>(255f / (depthImage.MaxDepth - depthImage.MinDepth), 0).Canny(Constants.EdgeImageCannyStartThreshold, Constants.EdgeImageCannyLinkingThreshold, Constants.EdgeImageCannySize).ThresholdBinary(new Gray(0), new Gray(1));
-            RoughImage = Image.Dilate(Constants.EdgeImageRoughNumDilationIterations);
+            Image = depthImage.Image.ConvertScale<byte>(255f / (depthImage.MaxDepth - depthImage.MinDepth), 0).Canny(Parameters.EdgeImageCannyStartThreshold, Parameters.EdgeImageCannyLinkingThreshold, Parameters.EdgeImageCannySize).ThresholdBinary(new Gray(0), new Gray(1));
+            RoughImage = Image.Dilate(Parameters.EdgeImageRoughNumDilationIterations);
         }
 
         public EdgeImage(Image<Gray, Byte> edgeImage, Image<Gray, Byte> roughEdgeImage)
@@ -63,7 +59,7 @@ namespace bbiwarg.Images
 
         public Vector2D findNextEdge(Vector2D start, Vector2D direction, int maxSearchSize = 0, bool roughEdge = true, bool returnNullIfNoEdgeFound = true)
         {
-            Vector2D maxGrow = (Constants.MaxPixel - start) / direction;
+            Vector2D maxGrow = (Parameters.ImageMaxPixel - start) / direction;
             Vector2D maxDecline = start / direction.getAbsolute();
 
             int maxStepsX;

+ 27 - 31
bbiwarg/InputHandler.cs

@@ -25,8 +25,6 @@ namespace bbiwarg
 
         private InputProvider inputProvider;
         private InputFrame currentInputFrame;
-        private int imageWidth;
-        private int imageHeight;
         private int currentFrameID;
         private int lastFrameID;
 
@@ -50,8 +48,6 @@ namespace bbiwarg
         public InputHandler(InputProvider inputProvider)
         {
             this.inputProvider = inputProvider;
-            this.imageWidth = inputProvider.ImageWidth;
-            this.imageHeight = inputProvider.ImageHeight;
             this.currentFrameID = inputProvider.CurrentFrameID;
             this.lastFrameID = this.currentFrameID - 1;
 
@@ -65,15 +61,15 @@ namespace bbiwarg
             palmTracker = new PalmTracker();
             touchTracker = new TouchTracker();
 
-            touchEventVisualizer = new TouchEventVisualizer(imageWidth, imageHeight);
+            touchEventVisualizer = new TouchEventVisualizer(Parameters.ImageWidth, Parameters.ImageHeight);
             touchTracker.TouchDown += touchEventVisualizer.touchDown;
             touchTracker.TouchMove += touchEventVisualizer.touchMove;
             touchTracker.TouchUp += touchEventVisualizer.touchUp;
 
 
-            if (Constants.TuioEnabled)
+            if (Parameters.TuioEnabled)
             {
-                tuioCommunicator = new TuioCommunicator(Constants.TuioIP.ToString(), Constants.TuioPort);
+                tuioCommunicator = new TuioCommunicator(Parameters.TuioIP.ToString(), Parameters.TuioPort);
                 touchTracker.TouchDown += tuioCommunicator.touchDown;
                 touchTracker.TouchMove += tuioCommunicator.touchMove;
                 touchTracker.TouchUp += tuioCommunicator.touchUp;
@@ -89,7 +85,7 @@ namespace bbiwarg
 
             touchEventVisualizer.reset();
 
-            if (Constants.TuioEnabled)
+            if (Parameters.TuioEnabled)
                 tuioCommunicator.reset();
         }
 
@@ -136,7 +132,7 @@ namespace bbiwarg
             currentFrameID = currentInputFrame.FrameID;
             Logger.CurrentFrame = currentFrameID;
 
-            if (Constants.TuioEnabled)
+            if (Parameters.TuioEnabled)
                 tuioCommunicator.initFrame();
 
             Timer.stop("beforeUpdateFrame");
@@ -146,7 +142,7 @@ namespace bbiwarg
         {
             Timer.start("afterUpdateFrame");
 
-            if (Constants.TuioEnabled)
+            if (Parameters.TuioEnabled)
                 tuioCommunicator.commitFrame();
 
             createOutputImages();
@@ -157,7 +153,7 @@ namespace bbiwarg
         private void createConfidenceImage()
         {
             Timer.start("createCnfdncImg");
-            Image<Gray, Int16> rawConfidenceImage = new Image<Gray, Int16>(imageWidth, imageHeight, imageWidth * 2, currentInputFrame.RawConfidenceData);
+            Image<Gray, Int16> rawConfidenceImage = new Image<Gray, Int16>(Parameters.ImageWidth, Parameters.ImageHeight, Parameters.ImageWidth * 2, currentInputFrame.RawConfidenceData);
             confidenceImage = new ConfidenceImage(rawConfidenceImage);
             Timer.stop("createCnfdncImg");
         }
@@ -165,7 +161,7 @@ namespace bbiwarg
         private void createDepthImage()
         {
             Timer.start("createDepthImage");
-            Image<Gray, Int16> rawDepthImage = new Image<Gray, Int16>(imageWidth, imageHeight, imageWidth * 2, currentInputFrame.RawDepthData);
+            Image<Gray, Int16> rawDepthImage = new Image<Gray, Int16>(Parameters.ImageWidth, Parameters.ImageHeight, Parameters.ImageWidth * 2, currentInputFrame.RawDepthData);
             rawDepthImage = rawDepthImage.Or((1 - confidenceImage.Mask).Convert<Gray, Int16>().Mul(Int16.MaxValue));
             depthImage = new DepthImage(rawDepthImage);
             Timer.stop("createDepthImage");
@@ -237,61 +233,61 @@ namespace bbiwarg
         private void createOutputImages()
         {
             Timer.start("createOutputImages");
-            int numImages = Constants.OutputNumImages;
+            int numImages = Parameters.OutputNumImages;
             OutputImages = new OutputImage[numImages];
             for (int i = 0; i < numImages; i++)
             {
-                OutputImages[i] = new OutputImage(imageWidth, imageHeight);
+                OutputImages[i] = new OutputImage(Parameters.ImageWidth, Parameters.ImageHeight);
             }
 
             //image0
-            OutputImages[0].drawImage((depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image, Constants.DepthImageColor);
+            OutputImages[0].drawImage((depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image, Parameters.DepthImageColor);
             foreach (Finger f in fingerTracker.Fingers)
             {
-                OutputImages[0].fillCircle(f.TipPoint.IntX, f.TipPoint.IntY, 4, Constants.FingerTipColor);
+                OutputImages[0].fillCircle(f.TipPoint.IntX, f.TipPoint.IntY, 4, Parameters.FingerTipColor);
             }
 
             foreach (TrackedFinger tf in fingerTracker.TrackedObjects)
             {
                 if (tf.CurrentState == TrackingState.Tracked)
                 {
-                    OutputImages[0].fillCircle(tf.TipPointPrediction.IntX, tf.TipPointPrediction.IntY, 3, Constants.FingerPointsPredictionColor);
-                    OutputImages[0].fillCircle(tf.HandPointPrediction.IntX, tf.HandPointPrediction.IntY, 3, Constants.FingerPointsPredictionColor);
+                    OutputImages[0].fillCircle(tf.TipPointPrediction.IntX, tf.TipPointPrediction.IntY, 3, Parameters.FingerPointsPredictionColor);
+                    OutputImages[0].fillCircle(tf.HandPointPrediction.IntX, tf.HandPointPrediction.IntY, 3, Parameters.FingerPointsPredictionColor);
                 }
             }
 
             //image1
-            OutputImages[1].drawImage(edgeImage.Image.ThresholdBinary(new Gray(0), new Gray(255)), Constants.EdgeImageColor);
+            OutputImages[1].drawImage(edgeImage.Image.ThresholdBinary(new Gray(0), new Gray(255)), Parameters.EdgeImageColor);
             foreach (Finger f in fingerTracker.Fingers)
             {
                 for (int i = 0; i < f.SliceTrail.NumSlices; i++)
-                    OutputImages[1].drawLineSegment(f.SliceTrail[i].LineSegment, Constants.FingerSliceColor);
-                OutputImages[1].drawContour(f.Contour, Constants.FingerContourColor);
-                OutputImages[1].drawLineSegment(f.LineSegment, Constants.FingerTrackedColor);
-                OutputImages[1].drawText(f.MidPoint.IntX, f.MidPoint.IntY, f.TrackID.ToString(), Constants.FingerIDColor);
+                    OutputImages[1].drawLineSegment(f.SliceTrail[i].LineSegment, Parameters.FingerSliceColor);
+                OutputImages[1].drawContour(f.Contour, Parameters.FingerContourColor);
+                OutputImages[1].drawLineSegment(f.LineSegment, Parameters.FingerTrackedColor);
+                OutputImages[1].drawText(f.MidPoint.IntX, f.MidPoint.IntY, f.TrackID.ToString(), Parameters.FingerIDColor);
             }
 
             //image2
             foreach (Hand h in handTracker.Hands)
             {
-                OutputImages[2].drawImage(h.Mask.ThresholdBinary(new Gray(0), new Gray(255)), Constants.HandColor[h.ZIndex % Constants.HandNumColors]);
-                OutputImages[2].fillCircle(h.Centroid.IntX, h.Centroid.IntY, 5, Constants.HandCentroidColor);
-                OutputImages[2].drawText(h.Centroid.IntX, h.Centroid.IntY, h.TrackID.ToString(), Constants.HandIDColor);
+                OutputImages[2].drawImage(h.Mask.ThresholdBinary(new Gray(0), new Gray(255)), Parameters.HandColor[h.ZIndex % Parameters.HandNumColors]);
+                OutputImages[2].fillCircle(h.Centroid.IntX, h.Centroid.IntY, 5, Parameters.HandCentroidColor);
+                OutputImages[2].drawText(h.Centroid.IntX, h.Centroid.IntY, h.TrackID.ToString(), Parameters.HandIDColor);
 
                 if (h.ThumbDefect != null)
-                    OutputImages[2].drawDefect(h.ThumbDefect, Color.CornflowerBlue, Color.Yellow);
+                    OutputImages[2].drawDefect(h.ThumbDefect, Parameters.HandThumbDefectPointColor, Parameters.HandThumbDefectLineColor);
             }
 
             //image3
-            OutputImages[3].drawImage((depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image.Or(255 - handDetector.HandMask.ThresholdBinary(new Gray(0), new Gray(255))), Constants.DepthImageColor);
+            OutputImages[3].drawImage((depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image.Or(255 - handDetector.HandMask.ThresholdBinary(new Gray(0), new Gray(255))), Parameters.DepthImageColor);
             foreach (TrackedTouchEvent tte in touchTracker.TrackedObjects)
             {
                 Vector2D position = tte.AbsolutePositionPrediction;
-                OutputImages[3].fillCircle(position.IntX, position.IntY, 5, Constants.TouchEventTrackedColor);
+                OutputImages[3].fillCircle(position.IntX, position.IntY, 5, Parameters.TouchEventTrackedColor);
             }
             foreach (Palm p in palmTracker.OptimizedPalms)
             {
-                OutputImages[3].drawQuadrangleGrid(p.Quad, Constants.PalmQuadColor, Constants.PalmGridColor, Constants.PalmGridNumRows, Constants.PalmGridNumColumns);
+                OutputImages[3].drawQuadrangleGrid(p.Quad, Parameters.PalmQuadColor, Parameters.PalmGridColor, Parameters.PalmGridNumRows, Parameters.PalmGridNumColumns);
             }
 
             //image4
@@ -302,7 +298,7 @@ namespace bbiwarg
             //borders
             for (int i = 0; i < numImages; i++)
             {
-                OutputImages[i].drawRectangle(0, 0, imageWidth - 1, imageHeight - 1, Constants.OutputImageBorderColor);
+                OutputImages[i].drawRectangle(0, 0, Parameters.ImageWidth - 1, Parameters.ImageHeight - 1, Parameters.OutputImageBorderColor);
             }
 
             Timer.stop("createOutputImages");

+ 9 - 10
bbiwarg/MainBBWIWARG.cs

@@ -16,16 +16,15 @@ namespace bbiwarg
     {
         static void Main(string[] args)
         {
+            Console.SetWindowSize(Parameters.ConsoleWidth, Parameters.ConsoleHeight);
             if (args.Length > 0)
             {
                 handleArgs(args);     
             }
 
-            Console.SetWindowSize(Constants.ConsoleWidth, Constants.ConsoleHeight);
-            
             InputProvider inputProvider;
-            if (Constants.InputSource == InputType.Movie)
-                inputProvider = new VideoInputProvider(Constants.InputMoviePath);
+            if (Parameters.InputSource == InputType.Movie)
+                inputProvider = new VideoInputProvider(Parameters.InputMoviePath);
             else
                 inputProvider = new InputProvider();
 
@@ -34,7 +33,7 @@ namespace bbiwarg
             InputHandler inputHandler = new InputHandler(inputProvider);
 
             OutputWindow outputWindow = new OutputWindow(inputProvider, inputHandler);
-            outputWindow.Run(Constants.OutputUpdateRate, Constants.OutputRenderRate);
+            outputWindow.Run(Parameters.OutputUpdateRate, Parameters.OutputRenderRate);
 
             inputProvider.stop();
         }
@@ -56,21 +55,21 @@ namespace bbiwarg
                     portString = parts[1];
             }
 
-            while (!TuioCommunicator.tryParseIPAddress(ipString, out Constants.TuioIP))
+            while (!TuioCommunicator.tryParseIPAddress(ipString, out Parameters.TuioIP))
             {
                 Console.WriteLine("Please insert the TUIO-Client's IP (Default is 127.0.0.1):");
                 ipString = Console.ReadLine();
             }
-            Console.WriteLine("TUIO-IP is set to:" + Constants.TuioIP.ToString());
+            Console.WriteLine("TUIO-IP is set to:" + Parameters.TuioIP.ToString());
 
-            while (!TuioCommunicator.tryParsePort(portString, out Constants.TuioPort))
+            while (!TuioCommunicator.tryParsePort(portString, out Parameters.TuioPort))
             {
                 Console.WriteLine("Please insert the TUIO-Client's Port (Default is 3333):");
                 portString = Console.ReadLine();
             }
-            Console.WriteLine("TUIO-PORT is set to:" + Constants.TuioPort);
+            Console.WriteLine("TUIO-PORT is set to:" + Parameters.TuioPort);
 
-            Constants.TuioEnabled = true;
+            Parameters.TuioEnabled = true;
         }
     }
 }

+ 11 - 7
bbiwarg/Constants.cs → bbiwarg/Parameters.cs

@@ -16,7 +16,7 @@ namespace bbiwarg
         Movie = 1
     }
 
-    class Constants
+    class Parameters
     {
         // input
         public static readonly InputType InputSource = InputType.Camera;
@@ -37,12 +37,16 @@ namespace bbiwarg
 
         // TUIO
         public static bool TuioEnabled = false;
-        public static IPAddress TuioIP = new IPAddress(new byte[4]{127,0,0,1});
+        public static IPAddress TuioIP = new IPAddress(new byte[4] { 127, 0, 0, 1 });
         public static Int16 TuioPort = 3333;
 
         // image
-        public static readonly Vector2D MaxPixel = new Vector2D(319, 239);
-        public static readonly float ImageDiagonalLength = MaxPixel.Length;
+        public static readonly int ImageWidth = 320;
+        public static readonly int ImageHeight = 240;
+        public static readonly int ImageNumPixels = ImageWidth * ImageHeight;
+        public static readonly Vector2D ImageMaxPixel = new Vector2D(ImageWidth - 1, ImageHeight - 1);
+        public static readonly float ImageDiagonalLength = ImageMaxPixel.Length;
+        public static readonly float ImageAspectRatio = (float)ImageWidth / (float)ImageHeight;
 
         // confidence image
         public static readonly int ConfidenceImageMinThreshold = 500;
@@ -86,6 +90,7 @@ namespace bbiwarg
         public static readonly int HandFloodFillUpDiff = 2;
         public static readonly float HandMaxSize = 0.6f;
         public static readonly float HandMinSize = 0.01f;
+        public static readonly float HandExtensionMaxSize = 0.5f * HandMaxSize;
         public static readonly float HandThumbDefectMaxDistanceToThumb = FingerMaxWidth;
         public static readonly float HandThumbDefectMinThumbShortLengthRatio = 0.75f;
         public static readonly float HandThumbDefectMaxThumbShortLengthRatio = 1.1f;
@@ -164,12 +169,11 @@ namespace bbiwarg
 
         public static readonly Color PalmQuadColor = Color.Blue;
         public static readonly Color PalmGridColor = Color.CornflowerBlue;
-        public static readonly Color PalmConturColor = Color.Red;
-        public static readonly Color PalmConvexHullColor = Color.Green;
-        public static readonly Color PalmThumbDefectColor = Color.Lime;
 
         public static readonly Color[] HandColor = new Color[3] { Color.Red, Color.Blue, Color.Green };
         public static readonly Color HandCentroidColor = Color.Yellow;
         public static readonly Color HandIDColor = Color.White;
+        public static readonly Color HandThumbDefectPointColor = Color.Lime;
+        public static readonly Color HandThumbDefectLineColor = Color.CornflowerBlue;
     }
 }

+ 19 - 18
bbiwarg/Recognition/FingerRecognition/FingerDetector.cs

@@ -31,8 +31,9 @@ namespace bbiwarg.Recognition.FingerRecognition
 
         private void detectFingers()
         {
-            int maxX = depthImage.BottomRight.IntX;
-            int maxY = depthImage.BottomRight.IntY;
+            Vector2D maxPixel = Parameters.ImageMaxPixel;
+            int maxX = maxPixel.IntX;
+            int maxY = maxPixel.IntY;
 
             Fingers = new List<Finger>();
 
@@ -54,7 +55,7 @@ namespace bbiwarg.Recognition.FingerRecognition
                             if (slice != null)
                             {
                                 FingerSliceTrail trail = findFingerSliceTrail(slice, edgeDirection);
-                                if (trail != null && trail.NumSlices > Constants.FingerMinNumSlices)
+                                if (trail != null && trail.NumSlices > Parameters.FingerMinNumSlices)
                                 {
                                     createFingerFromTrail(trail);
                                 }
@@ -82,9 +83,9 @@ namespace bbiwarg.Recognition.FingerRecognition
             FingerSliceTrail trail = new FingerSliceTrail(startSlice);
 
             Vector2D direction = startDirection;
-            Vector2D position = startSlice.Mid + Constants.FingerStepSize * direction;
+            Vector2D position = startSlice.Mid + Parameters.FingerStepSize * direction;
 
-            if (position.isInBound(Vector2D.Zero, depthImage.BottomRight))
+            if (position.isInBound())
             {
                 FingerSlice nextSlice = findFingerSliceFromMid(position, direction);
                 if (nextSlice != null)
@@ -92,9 +93,9 @@ namespace bbiwarg.Recognition.FingerRecognition
                     trail.addSlice(nextSlice);
                     trail = expandTrail(trail);
 
-                    if (trail.NumSlices > Constants.FingerMinNumSlices / 2)
+                    if (trail.NumSlices > Parameters.FingerMinNumSlices / 2)
                     {
-                        trail.removeFirstSlices(Constants.FingerRemoveNumSlicesForCorrection);
+                        trail.removeFirstSlices(Parameters.FingerRemoveNumSlicesForCorrection);
                         trail.reverse();
                         trail = expandTrail(trail, true);
                         trail.reverse();
@@ -110,7 +111,7 @@ namespace bbiwarg.Recognition.FingerRecognition
         private FingerSliceTrail expandTrail(FingerSliceTrail trail, bool reversed = false)
         {
             Vector2D currentDirection = trail.getEndDirection();
-            Vector2D currentPosition = trail.EndSlice.Mid + Constants.FingerStepSize * currentDirection;
+            Vector2D currentPosition = trail.EndSlice.Mid + Parameters.FingerStepSize * currentDirection;
 
             int gapCounter = 0;
             int numSlices = trail.NumSlices;
@@ -118,18 +119,18 @@ namespace bbiwarg.Recognition.FingerRecognition
             FingerSlice lastSlice = trail.EndSlice;
             FingerSlice nextSlice;
 
-            while (currentPosition.isInBound(Vector2D.Zero, depthImage.BottomRight) && gapCounter <= Math.Min(numSlices, Constants.FingerMaxGapCounter))
+            while (currentPosition.isInBound() && gapCounter <= Math.Min(numSlices, Parameters.FingerMaxGapCounter))
             {
                 Vector2D direction = (reversed) ? currentDirection.getInverse() : currentDirection;
                 nextSlice = findFingerSliceFromMid(currentPosition, direction);
 
-                if (nextSlice != null && Math.Abs(nextSlice.Length - lastSlice.Length) <= Constants.FingerMaxSliceDifferencePerStep)
+                if (nextSlice != null && Math.Abs(nextSlice.Length - lastSlice.Length) <= Parameters.FingerMaxSliceDifferencePerStep)
                 {
                     gapCounter = 0;
                     numSlices++;
                     trail.addSlice(nextSlice);
                     currentDirection = trail.getEndDirection();
-                    currentPosition = nextSlice.Mid + Constants.FingerStepSize * currentDirection;
+                    currentPosition = nextSlice.Mid + Parameters.FingerStepSize * currentDirection;
 
                     lastSlice = nextSlice;
                 }
@@ -150,18 +151,18 @@ namespace bbiwarg.Recognition.FingerRecognition
             Vector2D dirStart = direction.getOrthogonal(true);
             Vector2D dirEnd = direction.getOrthogonal(false);
 
-            Vector2D start = edgeImageAdapted.findNextEdge(position, dirStart, Constants.FingerMaxWidth);
+            Vector2D start = edgeImageAdapted.findNextEdge(position, dirStart, Parameters.FingerMaxWidth);
             if (start == null) return null;
 
-            Vector2D end = edgeImageAdapted.findNextEdge(position, dirEnd, Constants.FingerMaxWidth);
+            Vector2D end = edgeImageAdapted.findNextEdge(position, dirEnd, Parameters.FingerMaxWidth);
             if (end == null) return null;
 
             return getFingerSlice(start, end);
         }
         private FingerSlice findFingerSliceFromStartEdge(Vector2D start, Vector2D direction)
         {
-            Vector2D searchStart = start + Constants.FingerContourMargin * direction;
-            Vector2D end = edgeImageAdapted.findNextEdge(searchStart, direction, Constants.FingerMaxWidth);
+            Vector2D searchStart = start + Parameters.FingerContourMargin * direction;
+            Vector2D end = edgeImageAdapted.findNextEdge(searchStart, direction, Parameters.FingerMaxWidth);
             if (end == null) 
                 return null;
 
@@ -171,7 +172,7 @@ namespace bbiwarg.Recognition.FingerRecognition
         private FingerSlice getFingerSlice(Vector2D start, Vector2D end)
         {
             FingerSlice slice = new FingerSlice(start, end);
-            if (slice.Length >= Constants.FingerMinWidth && slice.Length <= Constants.FingerMaxWidth && fingerSliceDepthTest(slice))
+            if (slice.Length >= Parameters.FingerMinWidth && slice.Length <= Parameters.FingerMaxWidth && fingerSliceDepthTest(slice))
                 return slice;
 
             return null;
@@ -208,13 +209,13 @@ namespace bbiwarg.Recognition.FingerRecognition
             Int16 depthAtOut2 = depthImage.getDepthAt(finger.SliceTrail.MidSlice.OutEnd);
             int minDepthDifference = Math.Min(Math.Abs(depthAtFinger - depthAtOut1), Math.Abs(depthAtFinger - depthAtOut2));
 
-            return (minDepthDifference < Constants.FingerCrippleMinDifference);
+            return (minDepthDifference < Parameters.FingerCrippleMinDifference);
         }
 
 
         private FingerSliceTrail orderTrailTipToHand(FingerSliceTrail trail)
         {
-            int numSlicesForDirectionDetection = Constants.FingerNumSlicesForDirectionDetection;
+            int numSlicesForDirectionDetection = Parameters.FingerNumSlicesForDirectionDetection;
             int maxIndex = trail.NumSlices - 1;
             float sumStart = 0;
             float sumEnd = 0;

+ 4 - 4
bbiwarg/Recognition/FingerRecognition/FingerSlice.cs

@@ -29,10 +29,10 @@ namespace bbiwarg.Recognition.FingerRecognition
             End = end;
             Mid = (start + end) / 2;
             updateLineSegment();
-            ContourStart = (Start + Constants.FingerContourMargin * Direction.getInverse()).moveInBound(Vector2D.Zero, Constants.MaxPixel, Direction);
-            ContourEnd = (End + Constants.FingerContourMargin * Direction).moveInBound(Vector2D.Zero, Constants.MaxPixel, Direction.getInverse());
-            OutStart = (Start + Constants.FingerOutMargin * Direction.getInverse()).moveInBound(Vector2D.Zero, Constants.MaxPixel, Direction);
-            OutEnd = (End + Constants.FingerOutMargin * Direction).moveInBound(Vector2D.Zero, Constants.MaxPixel, Direction.getInverse());
+            ContourStart = (Start + Parameters.FingerContourMargin * Direction.getInverse()).moveInBound(Direction);
+            ContourEnd = (End + Parameters.FingerContourMargin * Direction).moveInBound(Direction.getInverse());
+            OutStart = (Start + Parameters.FingerOutMargin * Direction.getInverse()).moveInBound(Direction);
+            OutEnd = (End + Parameters.FingerOutMargin * Direction).moveInBound(Direction.getInverse());
         }
 
         private void updateLineSegment()

+ 2 - 2
bbiwarg/Recognition/FingerRecognition/FingerSliceTrail.cs

@@ -53,13 +53,13 @@ namespace bbiwarg.Recognition.FingerRecognition
 
         public Vector2D getStartDirection()
         {
-            int innerStartIndex = Math.Min(NumSlices, Constants.FingerNumSlicesForRelativeDirection);
+            int innerStartIndex = Math.Min(NumSlices, Parameters.FingerNumSlicesForRelativeDirection);
             return (StartSlice.Mid - Slices[innerStartIndex].Mid).normalize();
         }
 
         public Vector2D getEndDirection()
         {
-            int innerEndIndex = Math.Max(0, NumSlices - Constants.FingerNumSlicesForRelativeDirection);
+            int innerEndIndex = Math.Max(0, NumSlices - Parameters.FingerNumSlicesForRelativeDirection);
             return (EndSlice.Mid - Slices[innerEndIndex].Mid).normalize();
         }
 

+ 2 - 2
bbiwarg/Recognition/FingerRecognition/FingerTracker.cs

@@ -15,13 +15,13 @@ namespace bbiwarg.Recognition.FingerRecognition
         public List<Finger> Fingers { get { return getCurrentObjectsWithState(TrackingState.Tracked); } }
 
         public FingerTracker()
-            : base(Constants.FingerTrackerMinSimilarityForTracking)
+            : base(Parameters.FingerTrackerMinSimilarityForTracking)
         {
         }
 
         protected override TrackedFinger createTrackedObject(Finger detectedObject)
         {
-            return new TrackedFinger(idPool.getNextUnusedID(), detectedObject, Constants.FingerTrackerNumFramesDetectedUntilTracked, Constants.FingerTrackerNumFramesLostUntilDeleted);
+            return new TrackedFinger(idPool.getNextUnusedID(), detectedObject, Parameters.FingerTrackerNumFramesDetectedUntilTracked, Parameters.FingerTrackerNumFramesLostUntilDeleted);
         }
     }
 }

+ 5 - 5
bbiwarg/Recognition/FingerRecognition/TrackedFinger.cs

@@ -20,9 +20,9 @@ namespace bbiwarg.Recognition.FingerRecognition
         public TrackedFinger(int id, Finger detectedFinger, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
             : base(id, detectedFinger, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
         {
-            tipPointKalman = new Kalman2DPositionFilter(Constants.FingermXX, Constants.FingermXY, Constants.FingermYY);
+            tipPointKalman = new Kalman2DPositionFilter(Parameters.FingermXX, Parameters.FingermXY, Parameters.FingermYY);
             tipPointKalman.setInitialPosition(detectedFinger.TipPoint);
-            handPointKalman = new Kalman2DPositionFilter(Constants.FingermXX, Constants.FingermXY, Constants.FingermYY);
+            handPointKalman = new Kalman2DPositionFilter(Parameters.FingermXX, Parameters.FingermXY, Parameters.FingermYY);
             handPointKalman.setInitialPosition(detectedFinger.HandPoint);
             lastRawDirections = new List<Vector2D>();
 
@@ -45,7 +45,7 @@ namespace bbiwarg.Recognition.FingerRecognition
                 tipPointKalman.getCorrectedPosition(detectedFinger.TipPoint);
                 handPointKalman.getCorrectedPosition(detectedFinger.HandPoint);
                 lastRawDirections.Add(rawDirection);
-                if (lastRawDirections.Count == Constants.FingerTrackerNumDirectionsForReverseCheck)
+                if (lastRawDirections.Count == Parameters.FingerTrackerNumDirectionsForReverseCheck)
                     lastRawDirections.RemoveAt(0);
             }
         }
@@ -65,11 +65,11 @@ namespace bbiwarg.Recognition.FingerRecognition
 
             //tip position
             float tipPointDistance = tip.getDistanceTo(TipPointPrediction);
-            float tipPointSimilarity = Math.Max(0, 1 - tipPointDistance / Constants.ImageDiagonalLength);
+            float tipPointSimilarity = Math.Max(0, 1 - tipPointDistance / Parameters.ImageDiagonalLength);
 
             //hand position
             float handPointDistance = hand.getDistanceTo(HandPointPrediction);
-            float handPointSimilarity = Math.Max(0, 1 - handPointDistance / Constants.ImageDiagonalLength);
+            float handPointSimilarity = Math.Max(0, 1 - handPointDistance / Parameters.ImageDiagonalLength);
 
             return tipPointSimilarity * handPointSimilarity;
         }

+ 9 - 18
bbiwarg/Recognition/HandRecognition/HandDetector.cs

@@ -52,9 +52,6 @@ namespace bbiwarg.Recognition.HandRecognition
 
         private void findHands()
         {
-            int width = edgeImage.Width;
-            int height = edgeImage.Height;
-            int maxArea = width * height;
             Hands = new List<Hand>();
 
             foreach (Finger finger in fingers)
@@ -74,8 +71,8 @@ namespace bbiwarg.Recognition.HandRecognition
                 if (newHand)
                 {
                     Image<Gray, byte> handMask = getHandMask(finger.HandPoint);
-                    int area = handMask.CountNonzero()[0];
-                    if (area < maxArea * Constants.HandMaxSize && area > maxArea * Constants.HandMinSize)
+                    int numPixels = handMask.CountNonzero()[0];
+                    if (numPixels < Parameters.HandMaxSize * Parameters.ImageNumPixels && numPixels > Parameters.HandMinSize * Parameters.ImageNumPixels)
                     {
                         Hand hand = new Hand(handMask, finger);
                         Hands.Add(hand);
@@ -87,12 +84,10 @@ namespace bbiwarg.Recognition.HandRecognition
 
         private Image<Gray, byte> getHandMask(Vector2D p)
         {
-            int width = edgeImage.Width;
-            int height = edgeImage.Height;
-            Image<Gray, byte> mask = new Image<Gray, byte>(width + 2, height + 2);
+            Image<Gray, byte> mask = new Image<Gray, byte>(Parameters.ImageWidth + 2, Parameters.ImageHeight + 2);
             MCvConnectedComp comp = new MCvConnectedComp();
-            CvInvoke.cvFloodFill(modifiedHandDepthImage, p, new MCvScalar(255), new MCvScalar(Constants.HandFloodFillDownDiff), new MCvScalar(Constants.HandFloodFillUpDiff), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, mask);
-            return mask.Copy(new Rectangle(1, 1, width, height));
+            CvInvoke.cvFloodFill(modifiedHandDepthImage, p, new MCvScalar(255), new MCvScalar(Parameters.HandFloodFillDownDiff), new MCvScalar(Parameters.HandFloodFillUpDiff), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, mask);
+            return mask.Copy(new Rectangle(1, 1, Parameters.ImageWidth, Parameters.ImageHeight));
         }
 
         private void setZIndexes()
@@ -118,7 +113,7 @@ namespace bbiwarg.Recognition.HandRecognition
 
         private void createHandMask()
         {
-            HandMask = new Image<Gray, byte>(depthImage.Width, depthImage.Height);
+            HandMask = new Image<Gray, byte>(Parameters.ImageWidth, Parameters.ImageHeight);
             foreach (Hand hand in Hands)
                 HandMask = HandMask.Or(hand.Mask);
         }
@@ -145,7 +140,7 @@ namespace bbiwarg.Recognition.HandRecognition
                             bool midOut2InHand = underlyingHand.isInside(midOut2);
 
                             Int16 maxDepth = depthImage.MaxDepth;
-                            if (midOut1InHand != midOut2InHand && depthAtMidOut1 != maxDepth && depthAtMidOut2 != maxDepth && Math.Abs(depthAtMidOut1 - depthAtMidOut2) < Constants.HandExtendMaxDifference)
+                            if (midOut1InHand != midOut2InHand && depthAtMidOut1 != maxDepth && depthAtMidOut2 != maxDepth && Math.Abs(depthAtMidOut1 - depthAtMidOut2) < Parameters.HandExtendMaxDifference)
                             {
                                 Vector2D p1, p2;
                                 if (midOut1InHand)
@@ -188,14 +183,10 @@ namespace bbiwarg.Recognition.HandRecognition
         }
 
         private void extendHand(Hand hand, Vector2D p) {
-            int width = edgeImage.Width;
-            int height = edgeImage.Height;
-            int maxArea = width * height;
-            
             Image<Gray, byte> extendMask = getHandMask(p);
-            int area = extendMask.CountNonzero()[0];
+            int numPixels = extendMask.CountNonzero()[0];
 
-            if(area <= 0.5f*Constants.HandMaxSize * maxArea)
+            if(numPixels <= Parameters.HandExtensionMaxSize * Parameters.ImageNumPixels)
                 hand.extendMask(extendMask);
         }
 

+ 2 - 2
bbiwarg/Recognition/HandRecognition/HandTracker.cs

@@ -13,13 +13,13 @@ namespace bbiwarg.Recognition.HandRecognition
 
 
         public HandTracker()
-            : base(Constants.HandTrackerMinSimilarity)
+            : base(Parameters.HandTrackerMinSimilarity)
         {
         }
 
         protected override TrackedHand createTrackedObject(Hand detectedObject)
         {
-            return new TrackedHand(idPool.getNextUnusedID(), detectedObject, Constants.HandTrackerNumFramesDetectedUntilTracked, Constants.HandTrackerNumFramesLostUntilDeleted);
+            return new TrackedHand(idPool.getNextUnusedID(), detectedObject, Parameters.HandTrackerNumFramesDetectedUntilTracked, Parameters.HandTrackerNumFramesLostUntilDeleted);
         }
     }
 }

+ 2 - 2
bbiwarg/Recognition/HandRecognition/TrackedHand.cs

@@ -17,7 +17,7 @@ namespace bbiwarg.Recognition.HandRecognition
         public TrackedHand(int id, Hand detectedHand, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
             : base(id, detectedHand, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
         {
-            centroidKalman = new Kalman2DPositionFilter(Constants.HandmXX, Constants.HandmXY, Constants.HandmYY);
+            centroidKalman = new Kalman2DPositionFilter(Parameters.HandmXX, Parameters.HandmXY, Parameters.HandmYY);
             centroidKalman.setInitialPosition(detectedHand.Centroid);
 
             logStateChange();
@@ -38,7 +38,7 @@ namespace bbiwarg.Recognition.HandRecognition
         {
             //centroid position
             float centroidDistance = CentroidPrediction.getDistanceTo(detectedHand.Centroid);
-            float centroidSimilarity = Math.Max(0, 1 - centroidDistance / Constants.ImageDiagonalLength);
+            float centroidSimilarity = Math.Max(0, 1 - centroidDistance / Parameters.ImageDiagonalLength);
 
             return centroidSimilarity;
         }

+ 4 - 4
bbiwarg/Recognition/PalmRecognition/PalmDetector.cs

@@ -63,12 +63,12 @@ namespace bbiwarg.Recognition.PalmRecognition
                 //fingersUpper
                 Vector2D fingersUpper = thumbDefect.OuterLong;
                 bool handBelow = true;
-                while (handBelow && fingersUpper.isInBound(Vector2D.Zero, Constants.MaxPixel))
+                while (handBelow && fingersUpper.isInBound())
                 {
                     fingersUpper += directionWristFinger;
                     Vector2D below = fingersUpper.copy();
                     bool handBelowFound = false;
-                    while (!handBelowFound && below.getDistanceTo(fingersUpper) < 2*Constants.FingerMaxWidth && below.isInBound(Vector2D.Zero, Constants.MaxPixel))
+                    while (!handBelowFound && below.getDistanceTo(fingersUpper) < 2*Parameters.FingerMaxWidth && below.isInBound())
                     {
                         below += directionUpperLower;
                         handBelowFound = palmHand.isInside(below);
@@ -78,12 +78,12 @@ namespace bbiwarg.Recognition.PalmRecognition
 
                 //wristUpper
                 Vector2D wristUpper = thumbDefect.Inner;
-                while (wristUpper.isInBound(Vector2D.Zero, Constants.MaxPixel) && palmHand.isInside(wristUpper))
+                while (wristUpper.isInBound() && palmHand.isInside(wristUpper))
                     wristUpper += directionFingerWrist;
 
                 //handWidth
                 Vector2D lower = thumbDefect.Inner + 10 * directionUpperLower;
-                while (lower.isInBound(Vector2D.Zero, Constants.MaxPixel) && palmHand.isInside(lower))
+                while (lower.isInBound() && palmHand.isInside(lower))
                     lower += directionUpperLower;
                 Vector2D handWidth = (lower - thumbDefect.Inner);
 

+ 2 - 2
bbiwarg/Recognition/PalmRecognition/PalmTracker.cs

@@ -13,13 +13,13 @@ namespace bbiwarg.Recognition.PalmRecognition
         public List<Palm> OptimizedPalms { get { return getOptimizedPalms(); } }
 
         public PalmTracker()
-            : base(Constants.PalmTrackerMinSimilarity)
+            : base(Parameters.PalmTrackerMinSimilarity)
         {
         }
 
         protected override TrackedPalm createTrackedObject(Palm detectedPalm)
         {
-            return new TrackedPalm(idPool.getNextUnusedID(), detectedPalm, Constants.PalmTrackerNumFramesDetectedUntilTracked, Constants.PalmTrackerNumFramesLostUntilDeleted);
+            return new TrackedPalm(idPool.getNextUnusedID(), detectedPalm, Parameters.PalmTrackerNumFramesDetectedUntilTracked, Parameters.PalmTrackerNumFramesLostUntilDeleted);
         }
 
         private List<Palm> getOptimizedPalms() {

+ 8 - 8
bbiwarg/Recognition/PalmRecognition/TrackedPalm.cs

@@ -25,10 +25,10 @@ namespace bbiwarg.Recognition.PalmRecognition
         public TrackedPalm(int id, Palm detectedPalm, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
             : base(id, detectedPalm, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
         {
-            wristUpperKalman = new Kalman2DPositionFilter(Constants.PalmmXX, Constants.PalmmXY, Constants.PalmmYY);
-            wristLowerKalman = new Kalman2DPositionFilter(Constants.PalmmXX, Constants.PalmmXY, Constants.PalmmYY);
-            fingersUpperKalman = new Kalman2DPositionFilter(Constants.PalmmXX, Constants.PalmmXY, Constants.PalmmYY);
-            fingersLowerKalman = new Kalman2DPositionFilter(Constants.PalmmXX, Constants.PalmmXY, Constants.PalmmYY);
+            wristUpperKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
+            wristLowerKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
+            fingersUpperKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
+            fingersLowerKalman = new Kalman2DPositionFilter(Parameters.PalmmXX, Parameters.PalmmXY, Parameters.PalmmYY);
             wristUpperKalman.setInitialPosition(detectedPalm.WristUpper);
             wristLowerKalman.setInitialPosition(detectedPalm.WristLower);
             fingersUpperKalman.setInitialPosition(detectedPalm.FingersUpper);
@@ -67,19 +67,19 @@ namespace bbiwarg.Recognition.PalmRecognition
 
             //wristUpper
             float wristUpperDistance = WristUpperPrediction.getDistanceTo(detectedPalm.WristUpper);
-            float wristUpperSimilarity = Math.Max(0, 1 - wristUpperDistance / Constants.ImageDiagonalLength);
+            float wristUpperSimilarity = Math.Max(0, 1 - wristUpperDistance / Parameters.ImageDiagonalLength);
 
             //wristLower
             float wristLowerDistance = WristLowerPrediction.getDistanceTo(detectedPalm.WristLower);
-            float wristLowerSimilarity = Math.Max(0, 1 - wristLowerDistance / Constants.ImageDiagonalLength);
+            float wristLowerSimilarity = Math.Max(0, 1 - wristLowerDistance / Parameters.ImageDiagonalLength);
 
             //fingersUpper
             float fingersUpperDistance = FingersUpperPrediction.getDistanceTo(detectedPalm.FingersUpper);
-            float fingersUpperSimilarity = Math.Max(0, 1 - fingersUpperDistance / Constants.ImageDiagonalLength);
+            float fingersUpperSimilarity = Math.Max(0, 1 - fingersUpperDistance / Parameters.ImageDiagonalLength);
 
             //fingersLower
             float fingersLowerDistance = FingersLowerPrediction.getDistanceTo(detectedPalm.FingersLower);
-            float fingersLowerSimilarity = Math.Max(0, 1 - fingersLowerDistance / Constants.ImageDiagonalLength);
+            float fingersLowerSimilarity = Math.Max(0, 1 - fingersLowerDistance / Parameters.ImageDiagonalLength);
 
             float similarity = handSimilarity * wristUpperSimilarity * wristLowerSimilarity * fingersUpperSimilarity * fingersLowerSimilarity;
 

+ 8 - 8
bbiwarg/Recognition/TouchRecognition/TouchDetector.cs

@@ -39,8 +39,8 @@ namespace bbiwarg.Recognition.TouchRecognition
                 Vector2D tipPoint = finger.TipPoint;
                 Vector2D direction = finger.Direction;
                 Vector2D directionInv = direction.getInverse();
-                Vector2D tipPointInside = (tipPoint + Constants.TouchTipInsideFactor * directionInv).moveInBound(Vector2D.Zero, depthImage.BottomRight, direction);
-                Vector2D tipPointOutside = (tipPoint + Constants.TouchTipOutsideFactor * direction).moveInBound(Vector2D.Zero, depthImage.BottomRight, directionInv);
+                Vector2D tipPointInside = (tipPoint + Parameters.TouchTipInsideFactor * directionInv).moveInBound(direction);
+                Vector2D tipPointOutside = (tipPoint + Parameters.TouchTipOutsideFactor * direction).moveInBound(directionInv);
 
                 foreach (Palm palm in palms)
                 {
@@ -53,7 +53,7 @@ namespace bbiwarg.Recognition.TouchRecognition
                         int numPixels = touchMask.Width * touchMask.Height;
                         float touchValue = touchPixels / (float)numPixels;
 
-                        if (touchValue > Constants.TouchMinTouchValue)
+                        if (touchValue > Parameters.TouchMinTouchValue)
                         {
                             TouchEvent touchEvent = new TouchEvent(tipPointOutside, touchMask, finger, palm);
                             TouchEvents.Add(touchEvent);
@@ -67,10 +67,10 @@ namespace bbiwarg.Recognition.TouchRecognition
         private Image<Gray, byte> getTouchMask(Vector2D touchPoint)
         {
 
-            int minX = Math.Max(touchPoint.IntX - 2 * Constants.TouchAreaSize / 3, 0);
-            int maxX = Math.Min(touchPoint.IntX + Constants.TouchAreaSize / 3, depthImage.Width - 1);
-            int minY = Math.Max(touchPoint.IntY - 2 * Constants.TouchAreaSize / 3, 0);
-            int maxY = Math.Min(touchPoint.IntY + Constants.TouchAreaSize / 3, depthImage.Height - 1);
+            int minX = Math.Max(touchPoint.IntX - 2 * Parameters.TouchAreaSize / 3, 0);
+            int maxX = Math.Min(touchPoint.IntX + Parameters.TouchAreaSize / 3, Parameters.ImageWidth - 1);
+            int minY = Math.Max(touchPoint.IntY - 2 * Parameters.TouchAreaSize / 3, 0);
+            int maxY = Math.Min(touchPoint.IntY + Parameters.TouchAreaSize / 3, Parameters.ImageHeight - 1);
 
             Vector2D relTouchPoint = new Vector2D(touchPoint.IntX - minX, touchPoint.IntY - minY);
             Rectangle rect = new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1);
@@ -78,7 +78,7 @@ namespace bbiwarg.Recognition.TouchRecognition
             Image<Gray, byte> touchMask = new Image<Gray, byte>(rect.Width + 2, rect.Height + 2);
 
             MCvConnectedComp comp = new MCvConnectedComp();
-            CvInvoke.cvFloodFill(touchArea, relTouchPoint, new MCvScalar(255), new MCvScalar(Constants.TouchFloodfillDownDiff), new MCvScalar(Constants.TouchFloodfillUpDiff), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, touchMask);
+            CvInvoke.cvFloodFill(touchArea, relTouchPoint, new MCvScalar(255), new MCvScalar(Parameters.TouchFloodfillDownDiff), new MCvScalar(Parameters.TouchFloodfillUpDiff), out comp, Emgu.CV.CvEnum.CONNECTIVITY.EIGHT_CONNECTED, Emgu.CV.CvEnum.FLOODFILL_FLAG.DEFAULT, touchMask);
 
             Rectangle cropRect = new Rectangle(1, 1, rect.Width, rect.Height);
             return touchMask.Copy(cropRect);

+ 2 - 2
bbiwarg/Recognition/TouchRecognition/TouchTracker.cs

@@ -20,13 +20,13 @@ namespace bbiwarg.Recognition.TouchRecognition
         public event TouchEventHandler TouchUp;
 
         public TouchTracker()
-            : base(Constants.TouchTrackerMinSimilarity)
+            : base(Parameters.TouchTrackerMinSimilarity)
         {
         }
 
         protected override TrackedTouchEvent createTrackedObject(TouchEvent detectedObject)
         {
-            TrackedTouchEvent tte = new TrackedTouchEvent(idPool.getNextUnusedID(), detectedObject, Constants.TouchTrackerNumFramesDetectedUntilTracked, Constants.TouchTrackerNumFramesLostUntilDeleted);
+            TrackedTouchEvent tte = new TrackedTouchEvent(idPool.getNextUnusedID(), detectedObject, Parameters.TouchTrackerNumFramesDetectedUntilTracked, Parameters.TouchTrackerNumFramesLostUntilDeleted);
             tte.TouchDown += TouchDown;
             tte.TouchMove += TouchMove;
             tte.TouchUp += TouchUp;

+ 3 - 3
bbiwarg/Recognition/TouchRecognition/TrackedTouchEvent.cs

@@ -40,10 +40,10 @@ namespace bbiwarg.Recognition.TouchRecognition
         public TrackedTouchEvent(int id, TouchEvent detectedTouchEvent, int numFramesDetectedUntilTracked, int numFramesLostUntilDeleted)
             : base(id, detectedTouchEvent, numFramesDetectedUntilTracked, numFramesLostUntilDeleted)
         {
-            absolutePositionKalman = new Kalman2DPositionFilter(Constants.TouchmXX, Constants.TouchmXY, Constants.TouchmYY);
+            absolutePositionKalman = new Kalman2DPositionFilter(Parameters.TouchmXX, Parameters.TouchmXY, Parameters.TouchmYY);
             absolutePositionKalman.setInitialPosition(detectedTouchEvent.AbsolutePosition);
 
-            relativePositionKalman = new Kalman2DPositionFilter(Constants.TouchmXX, Constants.TouchmXY, Constants.TouchmYY);
+            relativePositionKalman = new Kalman2DPositionFilter(Parameters.TouchmXX, Parameters.TouchmXY, Parameters.TouchmYY);
             relativePositionKalman.setInitialPosition(detectedTouchEvent.RelativePosition);
 
             fingerID = detectedTouchEvent.Finger.TrackID;
@@ -84,7 +84,7 @@ namespace bbiwarg.Recognition.TouchRecognition
 
             //absolute position similarity
             float absoluteDistance = detectedTouchEvent.AbsolutePosition.getDistanceTo(AbsolutePositionPrediction);
-            float absoluteSimilarity = Math.Max(0, 1 - absoluteDistance / Constants.ImageDiagonalLength);
+            float absoluteSimilarity = Math.Max(0, 1 - absoluteDistance / Parameters.ImageDiagonalLength);
 
             //relative position similarity
             float relativeDistance = detectedTouchEvent.RelativePosition.getDistanceTo(RelativePositionPrediction);

+ 4 - 4
bbiwarg/Utility/ConvexityDefect.cs

@@ -45,10 +45,10 @@ namespace bbiwarg.Utility
             float thumbShortLengthRatio = thumb.LineSegment.Length / VectorShort.Length;
             float shortLongLengthRatio = VectorShort.Length / VectorLong.Length;
 
-            return (tipDistance <= Constants.HandThumbDefectMaxDistanceToThumb &&
-                    handDistance <= Constants.HandThumbDefectMaxDistanceToThumb &&
-                    thumbShortLengthRatio <= Constants.HandThumbDefectMaxThumbShortLengthRatio && thumbShortLengthRatio >= Constants.HandThumbDefectMinThumbShortLengthRatio &&
-                    shortLongLengthRatio <= Constants.HandThumbDefectMaxShortLongLengthRatio && shortLongLengthRatio >= Constants.HandThumbDefectMinShortLongLengthRatio);
+            return (tipDistance <= Parameters.HandThumbDefectMaxDistanceToThumb &&
+                    handDistance <= Parameters.HandThumbDefectMaxDistanceToThumb &&
+                    thumbShortLengthRatio <= Parameters.HandThumbDefectMaxThumbShortLengthRatio && thumbShortLengthRatio >= Parameters.HandThumbDefectMinThumbShortLengthRatio &&
+                    shortLongLengthRatio <= Parameters.HandThumbDefectMaxShortLongLengthRatio && shortLongLengthRatio >= Parameters.HandThumbDefectMinShortLongLengthRatio);
         }
 
         public bool isCausedByFinger(Finger finger) {

+ 2 - 2
bbiwarg/Utility/Logger.cs

@@ -28,13 +28,13 @@ namespace bbiwarg.Utility
 
         public static void log(string message, LogSubject subject)
         {
-            if (Constants.LogLevel.HasFlag(subject))
+            if (Parameters.LogLevel.HasFlag(subject))
                 Console.WriteLine("Frame: " + CurrentFrame + "\t" + message);
         }
 
         public static void clear(LogSubject subject)
         {
-            if (Constants.LogLevel.HasFlag(subject))
+            if (Parameters.LogLevel.HasFlag(subject))
                 Console.Clear();
         }
     }

+ 8 - 0
bbiwarg/Utility/Vector2D.cs

@@ -74,11 +74,19 @@ namespace bbiwarg.Utility
             return (minX <= X && X <= maxX && minY <= Y && Y <= maxY);
         }
 
+        public bool isInBound() {
+            return isInBound(Vector2D.Zero, Parameters.ImageMaxPixel);
+        }
+
         public bool isInBound(Vector2D topLeft, Vector2D bottomRight)
         {
             return (X >= topLeft.X && X <= bottomRight.X && Y >= topLeft.Y && Y <= bottomRight.Y);
         }
 
+        public Vector2D moveInBound(Vector2D inBoundDirection) {
+            return moveInBound(Vector2D.Zero, Parameters.ImageMaxPixel, inBoundDirection);
+        }
+
         public Vector2D moveInBound(Vector2D topLeft, Vector2D bottomRight, Vector2D inBoundDirection)
         {
             Vector2D pos = new Vector2D(X, Y);

+ 1 - 1
bbiwarg/bbiwarg.csproj

@@ -81,7 +81,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Constants.cs" />
+    <Compile Include="Parameters.cs" />
     <Compile Include="Graphics\OutputWindow.cs" />
     <Compile Include="InputHandler.cs" />
     <Compile Include="InputProviders\InputFrame.cs" />

+ 2 - 1
bbiwarg/bbiwarg.csproj.user

@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
-    <StartArguments>127.0.0.1:3333</StartArguments>
+    <StartArguments>
+    </StartArguments>
   </PropertyGroup>
   <PropertyGroup>
     <PublishUrlHistory>publish\</PublishUrlHistory>