Browse Source

bugfix (field of view in radion not degree and not initialized while camera isn't started yet)

Alexander Hendrich 7 years ago
parent
commit
eb7f6dcf15

BIN
bbiwarg.v12.suo


+ 1 - 1
bbiwarg/Input/InputHandling/InputHandler.cs

@@ -215,7 +215,7 @@ namespace BBIWARG.Input.InputHandling
         private void initialize()
         {
             ImageSize = new ImageSize(inputProvider.ImageWidth, inputProvider.ImageHeight);
-            CoordinateConverter = new CoordinateConverter(ImageSize, inputProvider.FieldOfViewHorizontal, inputProvider.FieldOfViewVertical);
+            CoordinateConverter = new CoordinateConverter(inputProvider);
             resetFlag = false;
 
             fingerDetector = new FingerDetector(CoordinateConverter);

+ 2 - 2
bbiwarg/Input/InputProviding/InputProviderIntel.cs

@@ -86,8 +86,8 @@ namespace BBIWARG.Input.InputProviding
             }
 
             PXCMPointF32 fov = senseManager.captureManager.device.QueryDepthFieldOfView();
-            FieldOfViewHorizontal = fov.x;
-            FieldOfViewVertical = fov.y;
+            FieldOfViewHorizontal = (float) (fov.x * Math.PI / 180.0f);
+            FieldOfViewVertical = (float) (fov.y * Math.PI / 180.0f);
 
             lowConfidenceValue = senseManager.captureManager.device.QueryDepthLowConfidenceValue();
             senseManager.captureManager.device.SetDepthConfidenceThreshold((UInt16)Parameters.ConfidenceImageMinThreshold);

+ 1 - 1
bbiwarg/Parameters.cs

@@ -210,7 +210,7 @@ namespace BBIWARG
         /// <summary>
         /// maximum finger slice length (in mm)
         /// </summary>
-        public static float FingerMaxWidth3D { get { return InputSource == InputType.RS300 ? 70.0f : 35.0f; } }
+        public static readonly float FingerMaxWidth3D = 35.0f;
 
         /// <summary>
         /// the minimum number of slices a finger must have

+ 12 - 37
bbiwarg/Utility/CoordinateConverter.cs

@@ -1,4 +1,5 @@
 using System;
+using BBIWARG.Input.InputProviding;
 
 namespace BBIWARG.Utility
 {
@@ -7,30 +8,8 @@ namespace BBIWARG.Utility
     /// </summary>
     public class CoordinateConverter
     {
-        /// <summary>
-        /// the horizontal field of view angle
-        /// </summary>
-        private float fieldOfViewHorizontal;
-
-        /// <summary>
-        /// the vertical field of view angle
-        /// </summary>
-        private float fieldOfViewVertical;
-
-        /// <summary>
-        /// size of the image the coordinates are from
-        /// </summary>
-        private ImageSize imageSize;
+        private IInputProvider inputProvider;
 
-        /// <summary>
-        /// horizontal ratio relative to depth
-        /// </summary>
-        private float relativeRatioHorizontal;
-
-        /// <summary>
-        /// vertical ratio relative to depth
-        /// </summary>
-        private float relativeRatioVertical;
 
         /// <summary>
         /// Constructs a CoordinateConverter.
@@ -38,14 +17,9 @@ namespace BBIWARG.Utility
         /// <param name="imageSize">size of the image the coordinates are from</param>
         /// <param name="hfov">horizontal field of view angle</param>
         /// <param name="vfov">vertical field of view angle</param>
-        public CoordinateConverter(ImageSize imageSize, float hfov, float vfov)
+        public CoordinateConverter(IInputProvider inputProvider)
         {
-            this.imageSize = imageSize;
-            this.fieldOfViewHorizontal = hfov;
-            this.fieldOfViewVertical = vfov;
-
-            relativeRatioHorizontal = (float)Math.Tan(hfov / 2);
-            relativeRatioVertical = (float)Math.Tan(vfov / 2);
+            this.inputProvider = inputProvider;
         }
 
         /// <summary>
@@ -68,11 +42,11 @@ namespace BBIWARG.Utility
         /// <returns>the 3d position</returns>
         public Vector3D convertCoordinate2Dto3D(float x, float y, float depth)
         {
-            float deltaX = 2 * ((x / imageSize.Width) - 0.5f);
-            float deltaY = -2 * ((y / imageSize.Height) - 0.5f);
+            float deltaX = 2 * ((x / inputProvider.ImageWidth) - 0.5f);
+            float deltaY = -2 * ((y / inputProvider.ImageHeight) - 0.5f);
 
-            float tanX = deltaX * relativeRatioHorizontal;
-            float tanY = deltaY * relativeRatioVertical;
+            float tanX = deltaX * (float)Math.Tan(inputProvider.FieldOfViewHorizontal / 2);
+            float tanY = deltaY * (float)Math.Tan(inputProvider.FieldOfViewVertical / 2);
 
             float a = depth * depth;
             float b = (float)(Math.Pow(tanX, 2) + Math.Pow(tanY, 2));
@@ -92,12 +66,13 @@ namespace BBIWARG.Utility
         /// <returns>2d length of the line segment</returns>
         public float convertLength3Dto2D(float length, float depth)
         {
-            float fullLengthX = (float)(2 * Math.Cos(fieldOfViewHorizontal / 2) * depth);
-            float fullLengthY = (float)(2 * Math.Cos(fieldOfViewVertical / 2) * depth);
+            float fullLengthX = (float)(2 * Math.Cos(inputProvider.FieldOfViewHorizontal / 2) * depth);
+            float fullLengthY = (float)(2 * Math.Cos(inputProvider.FieldOfViewVertical / 2) * depth);
             float fullLengthDiagonal = (float)Math.Sqrt(Math.Pow(fullLengthX, 2) + Math.Pow(fullLengthY, 2));
 
             float ratio = length / fullLengthDiagonal;
-            return ratio * imageSize.DiagonalLength;
+            float imageSizeDiagonalLength = (float)Math.Sqrt(inputProvider.ImageWidth * inputProvider.ImageWidth + inputProvider.ImageHeight * inputProvider.ImageHeight);
+            return ratio * imageSizeDiagonalLength;
         }
     }
 }