Mathematica Asked on September 3, 2021
If I have a video at a known frame rate, and a time series of sensor readings taken at the same time. How can I play back the video and show a relevant section of the time series so the two are in sync, say the time series plot starts 1 second before the current frame and shows 2 seconds of the time series.
Use TimeSeriesShift
to adjust your time series first. I have not handled that aspect of the question below, but rather the way to get the time out of a video stream and use it for live plotting, which is kind of non-trivial and worth answering here:
This video stream player is straight out of the documentation:
stream = VideoStream["ExampleData/bullfinch.mkv"];
Panel@Column[{
Dynamic[stream["CurrentFrame"]],
Slider[
Dynamic[QuantityMagnitude[stream["Position"],
"Seconds"], (stream["Position"] = #) &], {0,
QuantityMagnitude[stream["Duration"], "Seconds"]}],
Button[
Dynamic[If[stream["Status"] === "Playing", "Pause", "Play"]],
If[stream["Status"] === "Playing", VideoPause[stream],
VideoPlay[stream]]
]
}, Alignment -> Center]
I generate a random time series:
(* example time series *)
ts = RandomFunction[WienerProcess[0, 1.5], {0, 50, .05}];
... and I create a dynamic plot. The ImagePadding
is important to stop it jumping around. I also plot only a 2 second window so that the plot scrolls horizontally:
Dynamic[
With[{t = QuantityMagnitude[stream["Position"], "Seconds"]},
DateListPlot[ts, PlotRange -> {{t - 2, t}, {-10, 10}},
AspectRatio -> 1, ImagePadding -> 20
]]]
Answered by flinty on September 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP