Browse Source

performance improvements

Alexander Hendrich 11 years ago
parent
commit
cc98e05776
4 changed files with 30 additions and 15 deletions
  1. 3 2
      bbiwarg/Constants.cs
  2. 21 6
      bbiwarg/Graphics/OutputImage.cs
  3. 2 3
      bbiwarg/Images/EdgeImage.cs
  4. 4 4
      bbiwarg/InputHandler.cs

+ 3 - 2
bbiwarg/Constants.cs

@@ -12,7 +12,7 @@ namespace bbiwarg
     class Constants
     {
         // Logger
-        public static readonly LogSubject LogLevel = LogSubject.None;
+        public static readonly LogSubject LogLevel = LogSubject.Timer;
         public static readonly int ConsoleWidth = 90;
         public static readonly int ConsoleHeight = 30;
         
@@ -30,7 +30,8 @@ namespace bbiwarg
         public static readonly int TuioPort = 3333;
 
         // image
-        public static readonly float ImageDiagonalLength = new Vector2D(319,239).Length;
+        public static readonly Vector2D MaxPixel = new Vector2D(319, 239);
+        public static readonly float ImageDiagonalLength = MaxPixel.Length;
 
         // confidence image
         public static readonly int ConfidenceImageMinThreshold = 500;

+ 21 - 6
bbiwarg/Graphics/OutputImage.cs

@@ -68,12 +68,27 @@ namespace bbiwarg.Graphics
 
         public void drawImage(Image<Gray, byte> image, Color color)
         {
-            if(color.R != 0)
-                Image[0] = image.Mul((float)color.R / byte.MaxValue);
-            if(color.G != 0)
-                Image[1] = image.Mul((float)color.G / byte.MaxValue);
-            if(color.B != 0)
-                Image[2] = image.Mul((float)color.B / byte.MaxValue);
+            if (color.R != 0)
+            {
+                if (color.R != byte.MaxValue)
+                    Image[0] = image.Mul((float)color.R / byte.MaxValue);
+                else
+                    Image[0] = image;
+            }
+            if (color.G != 0)
+            {
+                if (color.G != byte.MaxValue)
+                    Image[1] = image.Mul((float)color.G / byte.MaxValue);
+                else
+                    Image[1] = image;
+            }
+            if (color.B != 0)
+            {
+                if (color.B != byte.MaxValue)
+                    Image[2] = image.Mul((float)color.B / byte.MaxValue);
+                else
+                    Image[2] = image;
+            }
         }
 
         public void drawQuadrangleGrid(Quadrangle quad, Color borderColor, Color gridColor, int numRows, int numCols) {

+ 2 - 3
bbiwarg/Images/EdgeImage.cs

@@ -25,7 +25,7 @@ namespace bbiwarg.Images
         {
             Width = depthImage.Width;
             Height = depthImage.Height;
-            Image = (depthImage.Image * (255.0f / (float)(depthImage.MaxDepth - depthImage.MinDepth))).Canny(Constants.EdgeImageCannyStartThreshold, Constants.EdgeImageCannyLinkingThreshold, Constants.EdgeImageCannySize).ThresholdBinary(new Gray(0), new Gray(1));
+            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);
         }
 
@@ -63,8 +63,7 @@ namespace bbiwarg.Images
 
         public Vector2D findNextEdge(Vector2D start, Vector2D direction, int maxSearchSize = 0, bool roughEdge=true, bool returnNullIfNoEdgeFound=true)
         {
-            Vector2D max = new Vector2D(Image.Width-1, Image.Height-1);
-            Vector2D maxGrow = (max - start) / direction;
+            Vector2D maxGrow = (Constants.MaxPixel - start) / direction;
             Vector2D maxDecline = start / direction.getAbsolute();
 
             int maxStepsX;

+ 4 - 4
bbiwarg/InputHandler.cs

@@ -241,7 +241,7 @@ namespace bbiwarg
             }
 
             //image1
-            OutputImages[1].drawImage(edgeImage.Image.Mul(255), Constants.EdgeImageColor);
+            OutputImages[1].drawImage(edgeImage.Image.ThresholdBinary(new Gray(0), new Gray(255)), Constants.EdgeImageColor);
             foreach (Finger f in fingerTracker.Fingers)
             {
                 for (int i = 0; i < f.SliceTrail.NumSlices; i++)
@@ -255,13 +255,13 @@ namespace bbiwarg
             foreach (Hand h in handDetector.Hands)
             {
                 if (h.Side == Hand.HandSide.Right)
-                    OutputImages[2].drawImage(h.Mask.Mul(255), Constants.HandRightColor);
+                    OutputImages[2].drawImage(h.Mask.ThresholdBinary(new Gray(0), new Gray(255)), Constants.HandRightColor);
                 else
-                    OutputImages[2].drawImage(h.Mask.Mul(255), Constants.HandLeftColor);
+                    OutputImages[2].drawImage(h.Mask.ThresholdBinary(new Gray(0), new Gray(255)), Constants.HandLeftColor);
             }
 
             //image3
-            OutputImages[3].drawImage((depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image.Or(255 - handDetector.HandMask.Mul(255)), Constants.DepthImageColor);
+            OutputImages[3].drawImage((depthImage.MaxDepth - depthImage.MinDepth) - depthImage.Image.Or(255 - handDetector.HandMask.ThresholdBinary(new Gray(0), new Gray(255))), Constants.DepthImageColor);
             foreach (TouchEvent te in touchTracker.TouchEvents)
                 OutputImages[3].fillCircle(te.Position.IntX, te.Position.IntY, 5, Constants.TouchEventTrackedColor);
             if (palmDetector.PalmContour != null && palmDetector.PalmContour.Count<Point>() > 0)