Exemplo n.º 1
0
 public void AddFilteredTrajectory(List <Vector> _filtered)
 {
     for (int i = 0; i < _filtered.Count; i++)
     {
         FilteredTrajectory.Add(_filtered[i].Clone() as Vector);
     }
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            // 1. Import data.
            string       inputPath = "/home/xavier/Documents/chronojump-no-git/kinoveafiltering-cb3bafc0f6f2/Data/sample-signal.txt";
            List <float> values    = ParseInput(inputPath);

            // 2. Convert values to a list of timed points.
            // In this example, time is implicit in the input and interval between data point is given.
            // Kinovea's code is tailored for 2D values, since we are dealing with a 1D series we'll just set the Y component to 0 for all points.
            // Convert the relative displacements into absolute coordinates on the fly.
            long              intervalMilliseconds = 1;
            long              time    = 0;
            float             coord   = 0;
            List <TimedPoint> samples = new List <TimedPoint>();

            foreach (float value in values)
            {
                coord += value;
                samples.Add(new TimedPoint(coord, 0, time));
                time += intervalMilliseconds;
            }

            // 3. Filter the data.
            // In Kinovea this also takes a calibration helper to convert positions and times between video space and real world space.
            // Here we assume the data is already in real world space so the function was slightly simplified.
            double             framerate = 1000.0 / intervalMilliseconds;
            FilteredTrajectory traj      = new FilteredTrajectory();

            traj.Initialize(samples, framerate);

            // 4. Compute linear kinematics on the data.
            // At this point `traj` contains a list of raw positions, a list of filtered positions at various cutoff frequencies, and the best-guess cutoff frequency.
            // The LinearKinematics class was simplified a lot compared to the Kinovea code to focus on 1D and only compute speed and acceleration.
            // A second pass of filtering is possible, this was for high speed video sources which tend to create extra noisy values at the digitization step, it shouldn't be needed here.
            bool                 enableSecondPassFiltering = false;
            LinearKinematics     linearKinematics          = new LinearKinematics();
            TimeSeriesCollection tsc = linearKinematics.BuildKinematics(traj, intervalMilliseconds, enableSecondPassFiltering);

            // 5. Export the result.
            // At this point the speed and acceleration are expressed in ms⁻¹ and ms⁻².
            string outputFilename = string.Format("{0}-output.csv", Path.GetFileNameWithoutExtension(inputPath));
            string outputPath     = Path.Combine(Path.GetDirectoryName(inputPath), outputFilename);

            ExportCSV(outputPath, tsc);

            Console.WriteLine("Done. Press any key.");
            Console.ReadKey();
        }