Ejemplo n.º 1
0
        public static void stitchImage2Video()
        {
            string videoname = "Video_VIRAT_S_010005_02_000177_000203";
            string dir       = @"C:\research\MSRDVA\temp\0efdc91e-62e2-4a70-b5fd-18720c170e03\AggregatedStitched\Video_VIRAT_S_010005_02_000177_000203\";

            FFMpegWrappers.generateVideoFromFolderofFrames(videoname, dir);
        }
        // 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");
        }