public KeypointN(Keypoint kp) { if (kp.HasFV != true) { throw (new ArgumentException("While trying to generate integer " + "vector: source keypoint has no feature vector yet")); } x = kp.X; y = kp.Y; scale = kp.Scale; orientation = kp.Orientation; dim = kp.FVLinearDim; descriptor = new int[kp.FVLinearDim]; for (int d = 0; d < kp.FVLinearDim; ++d) { descriptor[d] = (int)(255.0 * kp.FVLinearGet(d)); if (descriptor[d] < 0 || descriptor[d] > 255) { throw (new ArgumentOutOfRangeException ("Resulting integer descriptor k is not 0 <= k <= 255")); } } }
private void CapAndNormalizeFV(Keypoint kp, double fvGradHicap) { double norm = 0.0; for (int n = 0; n < kp.FVLinearDim; ++n) { norm += Math.Pow(kp.FVLinearGet(n), 2.0); } norm = Math.Sqrt(norm); if (norm == 0.0) { throw (new InvalidOperationException ("CapAndNormalizeFV cannot normalize with norm = 0.0")); } for (int n = 0; n < kp.FVLinearDim; ++n) { kp.FVLinearSet(n, kp.FVLinearGet(n) / norm); } for (int n = 0; n < kp.FVLinearDim; ++n) { if (kp.FVLinearGet(n) > fvGradHicap) { kp.FVLinearSet(n, fvGradHicap); } } norm = 0.0; for (int n = 0; n < kp.FVLinearDim; ++n) { norm += Math.Pow(kp.FVLinearGet(n), 2.0); } norm = Math.Sqrt(norm); for (int n = 0; n < kp.FVLinearDim; ++n) { kp.FVLinearSet(n, kp.FVLinearGet(n) / norm); } }