Browse Source

added Color to OutputImage

Alexander Hendrich 11 years ago
parent
commit
d353420eea

+ 2 - 2
bbiwarg/Detectors/Fingers/FingerDetector.cs

@@ -279,9 +279,9 @@ namespace bbiwarg.Detectors.Fingers
             FingerSliceTrail trail = finger.SliceTrail;
             for (int i = 0; i < trail.NumSlices; i++)
             {
-                outputImage.drawLineSegment(trail.Slices[i].LineSegment, 255, 0, 255);
+                outputImage.drawLineSegment(trail.Slices[i].LineSegment, Color.DeepPink);
             }
-            outputImage.drawLineSegment(finger.LineSegment, 255, 0, 0);
+            outputImage.drawLineSegment(finger.LineSegment, Color.Orange);
         }
     }
 }

+ 2 - 1
bbiwarg/Detectors/Fingers/FingerTracker.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -62,7 +63,7 @@ namespace bbiwarg.Detectors.Fingers
                 }
                 if (tracked)
                 {
-                    outputImage.drawLineSegment(finger.LineSegment, 0, 255, 0);
+                    outputImage.drawLineSegment(finger.LineSegment, Color.Yellow);
                     TrackedFingers.Add(finger);
                 }
             }

+ 5 - 5
bbiwarg/Detectors/Palm/PalmDetector.cs

@@ -243,14 +243,14 @@ namespace bbiwarg.Detectors.Palm
 
         private void draw()
         {
-            outputImage.drawContour(palmContour, 255, 0, 0);
-            outputImage.drawPoints(palmContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE), 0, 255, 0);
+            outputImage.drawContour(palmContour, Color.Red);
+            outputImage.drawPoints(palmContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE), Color.Green);
 
             if (PalmQuad != null)
             {
                 Vector2D[] vertices = PalmQuad.Vertices;
                 for (int i = 0; i < 4; ++i)
-                    outputImage.drawLineSegment(new bbiwarg.Utility.LineSegment2D(vertices[i], vertices[(i + 1) % 4]), 0, 0, 255);
+                    outputImage.drawLineSegment(new bbiwarg.Utility.LineSegment2D(vertices[i], vertices[(i + 1) % 4]), Color.Blue);
 
                 drawGrid(new Vector2D(vertices[0]), new Vector2D(vertices[1]), new Vector2D(vertices[2]), new Vector2D(vertices[3]));
             }
@@ -269,12 +269,12 @@ namespace bbiwarg.Detectors.Palm
 
             for (int i = 1; i < numRows; i++)
             {
-                outputImage.drawLineSegment(new bbiwarg.Utility.LineSegment2D(a + i * relAB, d + i * relDC), 80, 80, 255);
+                outputImage.drawLineSegment(new bbiwarg.Utility.LineSegment2D(a + i * relAB, d + i * relDC), Color.CornflowerBlue);
             }
 
             for (int i = 1; i < numColumns; i++)
             {
-                outputImage.drawLineSegment(new bbiwarg.Utility.LineSegment2D(a + i * relAD, b + i * relBC), 80, 80, 255);
+                outputImage.drawLineSegment(new bbiwarg.Utility.LineSegment2D(a + i * relAD, b + i * relBC), Color.CornflowerBlue);
             }
         }
     }

+ 5 - 4
bbiwarg/Detectors/Touch/TouchDetector.cs

@@ -43,7 +43,7 @@ namespace bbiwarg.Detectors.Touch
                     float y = HelperFunctions.thresholdRange<float>(0, depthImage.Height - 1, tipPoint.Y + directionFactor * direction.Y);
                     Vector2D tep = new Vector2D(x, y);
 
-                    outputImage.fillCircle(tep.IntX, tep.IntY, 5, 0, 127, 0);
+                    outputImage.fillCircle(tep.IntX, tep.IntY, 5, Color.Orange);
                     TouchEvent touchEvent = new TouchEvent(tep, floodValue, finger);
                     TouchEvents.Add(touchEvent);
                 }
@@ -69,11 +69,12 @@ namespace bbiwarg.Detectors.Touch
                 for (int y = minY; y < maxY; y++)
                 {
                     Int16 depth = depthImage.getDepthAt(x, y);
-                    outputImage.drawPixel(x, y, 50, 50, 50);
+                    Color color = outputImage.getColotAt(x, y);
+                    outputImage.drawPixel(x, y, Color.FromArgb(color.R / 2, color.G / 2, color.B / 2));
                     if (Math.Abs(depthAtTouch - depth) < maxDepthDifference)
                     {
                         matchedPixels++;
-                        outputImage.drawPixel(x, y, 50, 50, 255);
+                        outputImage.drawPixel(x, y, Color.FromArgb(color.R / 2, color.G / 2, color.B));
                     }
                     countedPixels++;
                 }
@@ -84,7 +85,7 @@ namespace bbiwarg.Detectors.Touch
             //status bar (% of matched pixels) -> green
             for (int x = minX; x < minX + (maxX - minX) * rel; x++)
             {
-                outputImage.drawPixel(x, maxY - 1, 0, 255, 0);
+                outputImage.drawPixel(x, maxY - 1, Color.Yellow);
             }
 
             return rel;

+ 2 - 1
bbiwarg/Detectors/Touch/TouchTracker.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -53,7 +54,7 @@ namespace bbiwarg.Detectors.Touch
                 }
                 if (tracked)
                 {
-                    outputImage.fillCircle(te.Position.IntX, te.Position.IntY, 5, 127, 0, 0);
+                    outputImage.fillCircle(te.Position.IntX, te.Position.IntY, 5, Color.Yellow);
                     TrackedTouchEvents.Add(te);
                 }
             }

+ 20 - 12
bbiwarg/Graphics/OutputImage.cs

@@ -20,31 +20,39 @@ namespace bbiwarg.Graphics
             Image = new Image<Rgb, byte>(width, height);
         }
 
-        public void drawLineSegment(bbiwarg.Utility.LineSegment2D lineSegment, byte r, byte g, byte b, int thickness = 1)
+        public Color getColotAt(int x, int y) {
+            
+            byte red = Image.Data[y, x, 0];
+            byte green = Image.Data[y, x, 1];
+            byte blue = Image.Data[y, x, 2];
+            return Color.FromArgb(red,green,blue);
+        }
+        
+        public void drawLineSegment(bbiwarg.Utility.LineSegment2D lineSegment, Color color, int thickness = 1)
         {
-            Image.Draw(new LineSegment2D(lineSegment.P1, lineSegment.P2), new Rgb(r, g, b), thickness);
+            Image.Draw(new LineSegment2D(lineSegment.P1, lineSegment.P2), new Rgb(color), thickness);
         }
 
-        public void drawContour(Contour<Point> contour, byte r, byte g, byte b, int thickness = 1)
+        public void drawContour(Contour<Point> contour, Color color, int thickness = 1)
         {
-            Image.Draw(contour, new Rgb(r, g, b), thickness);
+            Image.Draw(contour, new Rgb(color), thickness);
         }
 
-        public void drawPoints(Seq<Point> points, byte r, byte g, byte b, int thickness = 1)
+        public void drawPoints(Seq<Point> points, Color color, int thickness = 1)
         {
-            Image.Draw(points, new Rgb(r, g, b), thickness);
+            Image.Draw(points, new Rgb(color), thickness);
         }
 
-        public void drawPixel(int x, int y, byte r, byte g, byte b)
+        public void drawPixel(int x, int y, Color color)
         {
-            Image.Data[y, x, 0] = r;
-            Image.Data[y, x, 1] = g;
-            Image.Data[y, x, 2] = b;
+            Image.Data[y, x, 0] = color.R;
+            Image.Data[y, x, 1] = color.G;
+            Image.Data[y, x, 2] = color.B;
         }
 
-        public void fillCircle(int x, int y, float radius, byte r, byte g, byte b)
+        public void fillCircle(int x, int y, float radius, Color color)
         {
-            Image.Draw(new CircleF(new PointF(x, y), radius), new Rgb(r, g, b), 0);
+            Image.Draw(new CircleF(new PointF(x, y), radius), new Rgb(color), 0);
         }
     }
 }

+ 3 - 2
bbiwarg/Graphics/TouchEventVisualizer.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -72,11 +73,11 @@ namespace bbiwarg.Graphics
             {
                 for (int i = 1; i < positions.Count; ++i)
                 {
-                    OutputImage.drawLineSegment(new LineSegment2D(positions[i - 1], positions[i]), 255, 255, 255);
+                    OutputImage.drawLineSegment(new LineSegment2D(positions[i - 1], positions[i]), Color.White);
                 }
 
                 if (touchPositions.Count != 0)
-                    OutputImage.fillCircle(positions.Last<Vector2D>().IntX, positions.Last<Vector2D>().IntY, 3, 255, 0, 0);
+                    OutputImage.fillCircle(positions.Last<Vector2D>().IntX, positions.Last<Vector2D>().IntY, 3, Color.Red);
             }
         }