public static void generateVideoForEvaluation(List <Image> Images, List <DateTime> dateTimeList, MultiObjectTrackingResult ctts, String videoName, String directory) { List <Image> imagesWithTracks = new List <Image>(); for (int i = 0; i < Images.Count; i++) { List <BoundingBox> locations = new List <BoundingBox>(); List <string> labels = new List <string>(); Dictionary <string, List <bool> > attributes = new Dictionary <string, List <bool> >(); attributes.Add("occlusion", new List <bool>()); if (ctts.tracks.Count != 0) { foreach (string key in ctts.tracks[0].booleanAttributeTracks.Keys) { if (!attributes.ContainsKey(key)) { attributes.Add(key, new List <bool>()); } } } List <int> idx = new List <int>(); for (int j = 0; j < ctts.tracks.Count; j++) { CompressedTrack ct = ctts.tracks[j]; SpaceTime st = ct.getSpaceTimeAt(dateTimeList[i]); BooleanAttribute outofview_attr = ct.getAttributeAt("outofview", dateTimeList[i]); if (st != null && outofview_attr != null && !outofview_attr.value) { BoundingBox l = st.region; locations.Add(l); labels.Add(ctts.tracks[j].label); foreach (string key in attributes.Keys) { attributes[key].Add(ct.getAttributeAt(key, dateTimeList[i]).value); } idx.Add(j); } } Image new_image = generateTrackImage(Images[i], labels, locations, attributes, idx); imagesWithTracks.Add(new_image); } Console.WriteLine("Saving " + directory + "\\" + videoName); FFMpegWrappers.generateVideoFromFrames(imagesWithTracks, videoName, directory); //Directory.CreateDirectory(directory + "\\" + videoName); //Console.WriteLine("Saving " + directory + "\\" + videoName); //for (int i = 0; i < imagesWithTracks.Count; i++) //{ // imagesWithTracks[i].Save(directory + "\\" + videoName + "\\img" + i.ToString("000") + ".jpg"); //} //Console.WriteLine("done"); }
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); }
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 IntersectionVolume = 0; for (DateTime t = commonStartTime; t <= commonEndTime; t += dt) { SpaceTime l1 = t1.getSpaceTimeAt(t); SpaceTime l2 = t2.getSpaceTimeAt(t); double overlap = BoundingBox.ComputeOverlapArea(l1.region, l2.region); IntersectionVolume += (overlap * dt.Milliseconds); } double UnionVolume = 0; for (DateTime t = startTime1; t <= endTime1; t += dt) { SpaceTime l1 = t1.getSpaceTimeAt(t); UnionVolume += (l1.region.ComputeArea() * dt.Milliseconds); } for (DateTime t = startTime2; t <= endTime2; t += dt) { SpaceTime l2 = t2.getSpaceTimeAt(t); UnionVolume += (l2.region.ComputeArea() * dt.Milliseconds); } UnionVolume -= IntersectionVolume; return(IntersectionVolume / UnionVolume); }
// if the stitched video is too long public static void generateVideoFramesForEvaluation(List <string> ImageURLs, MultiObjectTrackingResult ctts, String directory, String videoName, int fps) { if (Directory.Exists(directory + "\\" + videoName)) { return; } Directory.CreateDirectory(directory + "\\" + videoName); Console.WriteLine("Saving " + directory + "\\" + videoName); //List<Image> imageList = new List<Image>(); var wc = new WebClient(); //List<DateTime> frameTimes = new List<DateTime>(); double frameTimeSpanInMiliseconds = (double)1000 / (double)fps; //double frameTimeSpanInMiliseconds = (double)(ChunkDuration) / (double)(ImageURLs.Count) * 1000; DateTime start = ctts.VideoSegmentStartTime; for (int i = 0; i < ImageURLs.Count; i++) { DateTime t; t = start.AddMilliseconds(frameTimeSpanInMiliseconds * i); //frameTimes.Add(t); Image x = Image.FromStream(wc.OpenRead(ImageURLs[i])); //imageList.Add(x); List <BoundingBox> locations = new List <BoundingBox>(); List <string> labels = new List <string>(); Dictionary <string, List <bool> > attributes = new Dictionary <string, List <bool> >(); attributes.Add("occlusion", new List <bool>()); List <int> idx = new List <int>(); if (ctts.tracks.Count != 0) { foreach (string key in ctts.tracks[0].booleanAttributeTracks.Keys) { if (!attributes.ContainsKey(key)) { attributes.Add(key, new List <bool>()); } } } for (int j = 0; j < ctts.tracks.Count; j++) { CompressedTrack ct = ctts.tracks[j]; SpaceTime st = ct.getSpaceTimeAt(t); BooleanAttribute outofview_attr = ct.getAttributeAt("outofview", t); if (st != null && outofview_attr != null && !outofview_attr.value) { BoundingBox l = st.region; locations.Add(l); labels.Add(ctts.tracks[j].label); //attributes["occlusion"].Add(ct.getAttributeAt("occlusion", t).value); foreach (string key in attributes.Keys) { attributes[key].Add(ct.getAttributeAt(key, t).value); } idx.Add(j); } } Image new_image = generateTrackImage(x, labels, locations, attributes, idx); new_image.Save(directory + "\\" + videoName + "\\img" + i.ToString("000") + ".jpg"); } FFMpegWrappers.generateVideoFromFolderofFrames(videoName, directory + "\\" + videoName + "\\"); Console.WriteLine("done"); }