private void ParseKeyframes(XmlReader r)
        {
            // TODO: catch empty tag <Keyframes/>.

            // Note: unlike chrono and tracks, keyframes are "merged" into existing keyframes if one already exists at the same position.
            // This has an impact on how we add drawings.
            // We keep the drawings internally to the keyframe during the parse, and only perform the post-drawing init at the end,
            // when the keyframe is merge-inserted into the collection.
            // For chrono and tracks on the other hand, we perform the post-drawing init on the fly during the parse.

            r.ReadStartElement();

            while (r.NodeType == XmlNodeType.Element)
            {
                if (r.Name == "Keyframe")
                {
                    Keyframe keyframe = KeyframeSerializer.Deserialize(r, GetScaling(), RemapTimestamp, metadata);
                    if (keyframe != null)
                    {
                        metadata.MergeInsertKeyframe(keyframe);
                    }
                }
                else
                {
                    string unparsed = r.ReadOuterXml();
                    log.DebugFormat("Unparsed content in KVA XML: {0}", unparsed);
                }
            }

            r.ReadEndElement();
        }
        /// <summary>
        /// Create a keyframe and a label to host the subtitle.
        /// </summary>
        private static void AddSubtitle(Metadata metadata, int start, int end, string content)
        {
            long startTs = (long)(start * metadata.AverageTimeStampsPerSecond / 1000.0f);
            long endTs   = (long)(end * metadata.AverageTimeStampsPerSecond / 1000.0f);

            // Make sure the keyframe timestamps corresponds to an actual video frame.
            long startFrame = (long)Math.Round((float)startTs / metadata.AverageTimeStampsPerFrame);

            startTs = startFrame * metadata.AverageTimeStampsPerFrame;
            long endFrame = (long)Math.Round((float)endTs / metadata.AverageTimeStampsPerFrame);

            endTs = endFrame * metadata.AverageTimeStampsPerFrame;

            Guid   id       = Guid.NewGuid();
            long   position = startTs;
            string title    = null;
            string timecode = start.ToString();
            string comments = "";
            List <AbstractDrawing> drawings = new List <AbstractDrawing>();

            // Create a label object.
            float  top      = metadata.ImageSize.Height * 0.75f;
            PointF location = new PointF(200, top);

            DrawingText drawing = new DrawingText(location, startTs, metadata.AverageTimeStampsPerFrame, content);

            drawing.Name = "Subtitle";

            drawing.InfosFading.UseDefault                = false;
            drawing.InfosFading.ReferenceTimestamp        = position;
            drawing.InfosFading.AverageTimeStampsPerFrame = metadata.AverageTimeStampsPerFrame;
            drawing.InfosFading.AlwaysVisible             = false;
            drawing.InfosFading.OpaqueFrames              = (int)((endTs - startTs) / (float)metadata.AverageTimeStampsPerFrame);
            drawing.InfosFading.FadingFrames              = 10;

            // FIXME: there seems to be an issue with style element .Value modification.
            //StyleElementFontSize styleElement = label.DrawingStyle.Elements["font size"] as StyleElementFontSize;
            //if (styleElement != null)
            //{
            //    styleElement.Value = 24;
            //    label.DrawingStyle.RaiseValueChanged();
            //}

            drawings.Add(drawing);
            Keyframe keyframe = new Keyframe(id, position, title, timecode, comments, drawings, metadata);

            metadata.MergeInsertKeyframe(keyframe);
        }
Beispiel #3
0
        private static void ParseFile(string source, Metadata metadata, int frameNumber)
        {
            string        json = File.ReadAllText(source);
            OpenPoseFrame frame;

            try
            {
                frame = JsonConvert.DeserializeObject <OpenPoseFrame>(json);
            }
            catch (Exception e)
            {
                log.ErrorFormat(e.Message);
                return;
            }

            long timestamp = metadata.FirstTimeStamp + (frameNumber * metadata.AverageTimeStampsPerFrame);

            List <AbstractDrawing> drawings = new List <AbstractDrawing>();

            foreach (OpenPosePerson person in frame.people)
            {
                AbstractDrawing drawing = CreateDrawing(metadata, timestamp, person);
                if (drawing != null)
                {
                    drawings.Add(drawing);
                }
            }

            // Create a keyframe and add the drawings to it.
            Guid     id       = Guid.NewGuid();
            long     position = timestamp;
            string   title    = null;
            string   timecode = null;
            string   comments = "";
            Keyframe keyframe = new Keyframe(id, position, title, timecode, comments, drawings, metadata);

            metadata.MergeInsertKeyframe(keyframe);
        }