public TrackablePoint(TrackingContext context, TrackerParameters trackerParameters, PointF value) { this.context = context; this.trackerParameters = trackerParameters; this.currentValue = value; this.nonTrackingValue = value; }
public void Track(VideoFrame videoFrame) { TrackingContext context = new TrackingContext(videoFrame.Timestamp, videoFrame.Image); foreach (DrawingTracker tracker in trackers.Values) { tracker.Track(context); } }
public void UpdateContext(ITrackable drawing, VideoFrame videoFrame) { if (!SanityCheck(drawing.Id)) { return; } TrackingContext context = new TrackingContext(videoFrame.Timestamp, videoFrame.Image); trackers[drawing.Id].Track(context); }
/// <summary> /// Track the point in the current image, or use the existing data if already known. /// </summary> /// <param name="context"></param> public void Track(TrackingContext context) { this.context = context; if (!isTracking) { return; } TrackFrame closestFrame = trackTimeline.ClosestFrom(context.Time); if (closestFrame == null) { currentValue = nonTrackingValue; trackTimeline.Insert(context.Time, CreateTrackFrame(currentValue, PositionningSource.Manual)); return; } if (closestFrame.Template == null) { // We may not have the template if the timeline was imported from KVA. trackTimeline.Insert(context.Time, CreateTrackFrame(closestFrame.Location, closestFrame.PositionningSource)); currentValue = closestFrame.Location; return; } if (closestFrame.Time == context.Time) { currentValue = closestFrame.Location; return; } TrackResult result = Tracker.Track(trackerParameters.SearchWindow, closestFrame, context.Image); if (result.Similarity >= trackerParameters.SimilarityThreshold) { currentValue = result.Location; if (result.Similarity > trackerParameters.TemplateUpdateThreshold) { Bitmap template = closestFrame.Template.CloneDeep(); TrackFrame newFrame = new TrackFrame(context.Time, result.Location, template, PositionningSource.TemplateMatching); trackTimeline.Insert(context.Time, newFrame); } else { trackTimeline.Insert(context.Time, CreateTrackFrame(result.Location, PositionningSource.TemplateMatching)); } } else { currentValue = closestFrame.Location; } }
public void Add(ITrackable drawing, VideoFrame videoFrame) { if (trackers.ContainsKey(drawing.Id)) { return; } TrackingProfile profile = drawing.CustomTrackingProfile ?? PreferencesManager.PlayerPreferences.TrackingProfile; TrackerParameters parameters = new TrackerParameters(profile, imageSize); TrackingContext context = new TrackingContext(videoFrame.Timestamp, videoFrame.Image); trackers.Add(drawing.Id, new DrawingTracker(drawing, context, parameters)); }
public void AddPoint(ITrackable drawing, VideoFrame videoFrame, string key, PointF point) { if (!trackers.ContainsKey(drawing.Id)) { return; } TrackingProfile profile = drawing.CustomTrackingProfile ?? PreferencesManager.PlayerPreferences.TrackingProfile; TrackerParameters parameters = new TrackerParameters(profile, imageSize); TrackingContext context = new TrackingContext(videoFrame.Timestamp, videoFrame.Image); trackers[drawing.Id].AddPoint(context, parameters, key, point); }
public DrawingTracker(ITrackable drawing, TrackingContext context, TrackerParameters parameters) { this.drawing = drawing; this.drawingId = drawing.Id; this.parameters = parameters; foreach (KeyValuePair <string, PointF> pair in drawing.GetTrackablePoints()) { trackablePoints.Add(pair.Key, new TrackablePoint(context, parameters, pair.Value)); } drawing.TrackablePointMoved += drawing_TrackablePointMoved; assigned = true; }
public void Track(TrackingContext context) { // This is where we would spawn new threads for each tracking. // TODO: Extract the bitmapdata once and pass it to all. foreach (KeyValuePair <string, TrackablePoint> pair in trackablePoints) { pair.Value.Track(context); if (isTracking) { drawing.SetTrackablePointValue(pair.Key, pair.Value.CurrentValue); } } }
public void Track(TrackingContext context) { // This is where we would spawn new threads for each tracking. Dictionary <string, bool> insertionMap = new Dictionary <string, bool>(); bool atLeastOneInserted = false; foreach (KeyValuePair <string, TrackablePoint> pair in trackablePoints) { bool inserted = pair.Value.Track(context); drawing.SetTrackablePointValue(pair.Key, pair.Value.CurrentValue, pair.Value.TimeDifference); insertionMap[pair.Key] = inserted; if (inserted) { atLeastOneInserted = true; } } if (atLeastOneInserted) { FixTimelineSync(insertionMap); } }
public void AddPoint(TrackingContext context, TrackerParameters parameters, string key, PointF value) { // Some drawings like polyline have a dynamic list of trackable points. trackablePoints.Add(key, new TrackablePoint(context, parameters, value)); }
/// <summary> /// Track the point in the current image, or use the existing data if already known. /// We do this even if the drawing is currently not tracking, to push the existing tracked data in the object. /// Important: for drawings containing multiple trackable points, either all or none of them should have a new value. /// If some of them successfully track and some other don't, the one that didn't must insert the closest frame value. /// This way we ensure the timelines are always of the same length. /// </summary> /// <param name="context"></param> public bool Track(TrackingContext context) { bool inserted = false; this.context = context; if (!trackTimeline.HasData()) { // Not a single entry in the timeline. // This drawing has never been activated for tracking so far. currentValue = nonTrackingValue; timeDifference = -1; if (isTracking) { // Use the current user-set position as a first tracked point. trackTimeline.Insert(context.Time, CreateTrackFrame(currentValue, PositionningSource.Manual)); timeDifference = 0; } return(isTracking); } TrackFrame closestFrame = trackTimeline.ClosestFrom(context.Time); if (closestFrame.Template == null) { // This point has entries in the timeline but doesn't have the corresponding image pattern. // This happen when the timeline is imported from a KVA. currentValue = closestFrame.Location; timeDifference = Math.Abs(context.Time - closestFrame.Time); if (isTracking) { // Make sure we extract the pattern and update the entry at this time. // Note: the position we are using could come from a different time. // But since we are actively tracking we need to end up adding an entry at this time. // But since we don't have any specific template to look for, we will just create an entry at the same location. // If we are on the right time, perfect. If not, it will use the location from the closest and comit it to this time. // When the user switched tracking ON for this drawing, they saw where the point was. // If they moved it manually before changing frame, it will be handled in SetUserValue. // If not, it means they are content with the position it has and thus this insertion is correct. PositionningSource source = timeDifference == 0 ? closestFrame.PositionningSource : PositionningSource.ForcedClosest; trackTimeline.Insert(context.Time, CreateTrackFrame(closestFrame.Location, source)); timeDifference = 0; } return(isTracking); } if (closestFrame.Time == context.Time) { // We found an entry at the exact time requested. currentValue = closestFrame.Location; timeDifference = 0; return(false); } if (!isTracking) { // We did not find the exact requested time in the timeline, and we are not currently tracking. currentValue = closestFrame.Location; timeDifference = Math.Abs(context.Time - closestFrame.Time); return(false); } // We did not find the exact requested time in the timeline, but tracking is active so let's look for the pattern. TrackResult result = Tracker.Track(trackerParameters.SearchWindow, closestFrame, context.Image); if (result.Similarity >= trackerParameters.SimilarityThreshold) { currentValue = result.Location; timeDifference = 0; if (result.Similarity > trackerParameters.TemplateUpdateThreshold) { Bitmap template = BitmapHelper.Copy(closestFrame.Template); TrackFrame newFrame = new TrackFrame(context.Time, result.Location, template, PositionningSource.TemplateMatching); trackTimeline.Insert(context.Time, newFrame); } else { trackTimeline.Insert(context.Time, CreateTrackFrame(result.Location, PositionningSource.TemplateMatching)); } inserted = true; } else { // Tracking failure. currentValue = closestFrame.Location; timeDifference = Math.Abs(context.Time - closestFrame.Time); inserted = false; } return(inserted); }