Group Abstract Group Abstract

Message Boards Message Boards

Overlay graphic on video

GROUPS:
I would like to overlay a simple graphic such as a small circle, line or cross hairs (say no more that 50 pixels in width) on a video stream. Is there a more efficient way of doing this rather than manipualting the matrix data for the live stream images?

Thanks.
POSTED BY: M Edwards
Answer
1 year ago
This demonstrates an approach you could probably adapt. Basically, you could Inset a dynamic object showing your sequence of video frames into a Graphics expression that shows your desired overlay:
 frames = Import["ExampleData/cellularautomaton.gif"];
 
 (* One way to do a simple overlay on a sequence of frames that doesn't have various animator controls stuck around it *)
 (* You'll probably want to heavily modify this to suit your actual application *)
 Graphics[
  {Inset[
    DynamicModule[{i = 1},
     Dynamic[
      Refresh[
      frames[[i = Mod[i, Length@frames] + 1]],
      UpdateInterval -> .25
      ],
     TrackedSymbols -> {}
     ]
    ],
   Center,
   Center,
   16
   ],
  Thick, Red,
  Circle[],
  Line@{{{-1, 0}, {1, 0}}, {{0, -1}, {0, 1}}}},
PlotRange -> {{-8, 8}, {-8, 8}}
]
(* A nice Graphics expression with dynamically updating frames should now appear in your notebook... *)

(* If you did want to modify frames for Export... *)
newFrames =
  Table[
   Rasterize[
    Graphics@
     {Inset[frames[[i]], Center, Center, 2],
      Circle[],
      Line@{{{-1, 0}, {1, 0}}, {{0, -1}, {0, 1}}}},
    "Image"
    ],
   {i, Length@frames}
   ];

Export["test.gif", newFrames];

(* To demo the result of the Export *)
Import["test.gif", "Animation"]

Since I can't really show a Dynamic object in a post here (not yet, at least to my knowledge), here's the GIF from the Export to demonstrate what the Graphics expression with embedded Dynamic looks like:
POSTED BY: William Rummler
Answer
1 year ago
Thank you for taking the time to teach me this, I really appreciate it.

Also, very nice idea using the cellular automata for overlaying the cross-hairs.

Regards,

Marc
POSTED BY: M Edwards
Answer
1 year ago