Quellcode durchsuchen

WIP: add homography calculator

Nick Steyer vor 2 Jahren
Ursprung
Commit
c94e778151

+ 1 - 0
Assembly-CSharp.csproj

@@ -120,6 +120,7 @@
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\MR\ZEDMirror.cs" />
     <Compile Include="Assets\ZED\Examples\Object Detection\Scripts\BBox2DHandler.cs" />
     <Compile Include="Assets\ZED\SDK\NativeInterface\ZEDCommon.cs" />
+    <Compile Include="Assets\StreetLight\HomographyCalculator.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\Utilities\ZEDSVOManager.cs" />
     <Compile Include="Assets\ZED\Tools\Mixed Reality Calibration\Scripts\ToggleGroup3D.cs" />
     <Compile Include="Assets\ZED\SDK\Helpers\Scripts\SkeletonTracking\RigBone.cs" />

+ 44 - 0
Assets/StreetLight/HomographyCalculator.cs

@@ -0,0 +1,44 @@
+using MathNet.Numerics.LinearAlgebra;
+using MathNet.Numerics.LinearAlgebra.Complex;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Assets.StreetLight
+{
+    internal class HomographyCalculator
+    {
+        internal Matrix<double> InverseMatrix(Matrix<double> matrix)
+        {
+            ProcessStartInfo start = new ProcessStartInfo
+            {
+                FileName = "cmd.exe",
+                //Arguments = "conda run -n HomographyCalculator python C:\\Users\\nick.steyer\\SmartStreetLight\\HomographyCalculator\\main.py",
+                UseShellExecute = false,// Do not use OS shell
+                CreateNoWindow = true, // We don't need new window
+                RedirectStandardInput = true,
+                RedirectStandardOutput = true,// Any output, generated by application will be redirected back
+                RedirectStandardError = true // Any error in standard output will be redirected back (for example exceptions)
+            };
+
+            using (Process process = Process.Start(start))
+            {
+                using (var input = process.StandardInput)
+                {
+                    input.WriteLine("C:\\Users\\nick.steyer\\Anaconda3\\Scripts\\activate.bat");
+                    input.WriteLine("conda run -n HomographyCalculator python C:\\Users\\nick.steyer\\SmartStreetLight\\HomographyCalculator\\main.py");
+                }
+
+                using StreamReader reader = process.StandardOutput;
+                string stderr = process.StandardError.ReadToEnd(); // Here are the exceptions from our Python script
+                string result = reader.ReadToEnd(); // Here is the result of StdOut(for example: print "test")
+            }
+
+            return null;
+        }
+    }
+}

+ 11 - 0
Assets/StreetLight/HomographyCalculator.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 2f5bb6d09ed31674eb8430f10fa5b527
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/StreetLight/Scripts/PositionCalculator.cs

@@ -3,6 +3,8 @@ using Assets.StreetLight.Poco;
 using MathNet.Numerics.LinearAlgebra;
 using MathNet.Numerics.LinearAlgebra.Double;
 using MathNet.Numerics.Statistics;
+using Newtonsoft.Json;
+using Numpy;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
@@ -130,6 +132,12 @@ namespace Assets.StreetLight.Scripts
             currentH.MapInplace(q => Math.Round(q, 15));
             var inverseH = currentH.Inverse();
 
+            var matrixString = string.Join(Environment.NewLine, currentH.EnumerateRows().Select(row => string.Join(" ", row.Enumerate().Select(number => number.ToString("0." + new string('#', 50), CultureInfo.InvariantCulture)))));
+            File.WriteAllText(@"C:\Users\nick.steyer\Desktop\currentH.csv", matrixString);
+
+            var calc = new HomographyCalculator();
+            //var foo = calc.InverseMatrix(currentH);
+
             foreach (var correspondence in correspondences)
             {
                 var x1 = correspondence.WorldPosition;