Beispiel #1
0
            public double getMetric(CompressedTrack t1, CompressedTrack t2, int fps)
            {
                TimeSpan dt = new TimeSpan(0, 0, 0, 0, (int)Math.Floor(1000.0 / fps));

                DateTime startTime1 = t1.startTime;
                DateTime startTime2 = t2.startTime;

                DateTime endTime1 = t1.endTime;
                DateTime endTime2 = t2.endTime;

                //is there any overlap at all?
                if (startTime1 > endTime2 || startTime2 > endTime1)
                {
                    return(0);
                }

                //find overlap times

                DateTime commonStartTime = startTime1;

                if (startTime2 > startTime1)
                {
                    commonStartTime = startTime2;
                }
                DateTime commonEndTime = endTime1;

                if (endTime2 < endTime1)
                {
                    commonEndTime = endTime2;
                }

                if (commonEndTime - commonStartTime < dt)
                {
                    return(0);
                }

                //now compute the integral

                double sum = 0;

                for (DateTime t = commonStartTime; t <= commonEndTime; t += dt)
                {
                    SpaceTime l1      = t1.getSpaceTimeAt(t);
                    SpaceTime l2      = t2.getSpaceTimeAt(t);
                    double    overlap = BoundingBox.ComputeOverlapAreaFraction(l1.region, l2.region);
                    sum += (overlap * dt.Milliseconds); //pixel-sec
                }
                TimeSpan deltat1 = endTime1 - startTime1;
                TimeSpan deltat2 = endTime2 - startTime2;
                double   max_ms  = Math.Max((double)deltat1.TotalMilliseconds, (double)deltat2.TotalMilliseconds);

                return(sum / max_ms);
            }