Jelajahi Sumber

homography export

Alexander Hendrich 10 tahun lalu
induk
melakukan
0def7ca51b
2 mengubah file dengan 23 tambahan dan 9 penghapusan
  1. 3 0
      bbiwarg/Parameters.cs
  2. 20 9
      bbiwarg/Utility/Projection2DTo2D.cs

+ 3 - 0
bbiwarg/Parameters.cs

@@ -147,6 +147,9 @@ namespace bbiwarg
         // touchEventVisualizer
         public static readonly int TouchEventVisualizerFadeOutTime = 1500;
 
+        // homographyExport
+        public static readonly String HomographyFileName = "homography.txt";
+
         // colors
         public static readonly Color ColorDetected = Color.Turquoise;
         public static readonly Color ColorTracked = Color.Yellow;

+ 20 - 9
bbiwarg/Utility/Projection2DTo2D.cs

@@ -36,32 +36,43 @@ namespace bbiwarg.Utility
         }
 
         public void addCalibrationPoints(Vector2D pointA, Vector2D pointB) {
-            calibrationPointsA.Add(pointA);
-            calibrationPointsB.Add(pointB);
+            calibrationPointsA.Add(sizeA.getRelativePoint(pointA));
+            calibrationPointsB.Add(sizeB.getRelativePoint(pointB));
 
             if (calibrationPointsA.Count == numPointsForCalibration)
                 calibrate();
         }
 
         public Vector2D projectPoint(Vector2D pointA) {
-            PointF[] pointfsB = new PointF[1] {pointA};
+            PointF[] pointfsB = new PointF[1] {sizeA.getRelativePoint(pointA)};
             homography.ProjectPoints(pointfsB);
-            return new Vector2D(pointfsB[0]);
+            return sizeB.getAbsolutePoint(new Vector2D(pointfsB[0]));
         }
 
         private void calibrate() {
             homography = CameraCalibration.FindHomography(calibrationPointsA.ToArray(), calibrationPointsB.ToArray(), Emgu.CV.CvEnum.HOMOGRAPHY_METHOD.DEFAULT, 0.995);
+            
             calibrationPointsA.Clear();
             calibrationPointsB.Clear();
             IsCalibrated = true;
 
-            Console.WriteLine("HOMOGRAPHY:");
-            for (int r = 0; r < homography.Size.Height; r++) {
-                for (int c = 0; c < homography.Size.Width; c++) {
-                    Console.Write(homography.Data[r, c] + "\t");
+            exportHomography();
+        }
+
+        private void exportHomography() {
+            String[] fileData = new String[homography.Size.Height];
+            StringBuilder sb = new StringBuilder();
+            for (int r = 0; r < homography.Size.Height; r++)
+            {
+                for (int c = 0; c < homography.Size.Width; c++)
+                {
+                    sb.Append(homography.Data[r, c]);
+                    sb.Append(" ");
                 }
-                Console.WriteLine();
+                fileData[r] = sb.ToString();
+                sb.Clear();
             }
+            System.IO.File.WriteAllLines(Parameters.HomographyFileName, fileData);
         }
     }
 }