how to make running average of 5 frames of video?

    Apr 06 2010 | 9:19 pm
    I'd like to calculate a running average of the last 5 frames of video from a live stream, in order to control noise.
    I've looked at jit.slide (and it's shader cousin), it seems to mostly do what I need, but I really don't understand the two parameters and what they do.

    • Apr 07 2010 | 12:08 am
      maybe [jit.op @op +]
      send the first frame through the jit.op, then the output wraps back around to the right inlet. next frame comes through, gets added, wraps back around again, repeat. After 5, bang out the stored matrix into [jit.op @op * @val 0.2] to take the average. However, you'll go over the maximum matrix values in a lot of places, so I'm not sure about the method...
      maybe jit.matrixset could also be used, but it would be more clunky probably. jit.3m? Possibly you'll need to calculate the average using every frame instead of sets of 5.
      Depending on what you want, jit.slide might "shmorph" something close enough to an "average", and will work fine.
    • Apr 07 2010 | 9:15 am
      Jit.slide could probably produce accurate enough results, as you can only deal with very small amounts of noise this way anyway. Slide_up and slide_down specify the amount of frames it would take to fully get to an input image if you were to input it that many times (which will normally never happen). That sounds tricky, but if you have a slide of 30 that means when you input a frame, only 1/30 of the difference between the current image and the input is added to the current frame.
      But you could also make a buffer of 5 frames (5 matrices), each multiplied by .2 and add together. Use a counter to rotate through them with a gate (or [jit.cycle]). There may be an easier way, I can't think of it now.
    • Apr 07 2010 | 4:24 pm
      cv.jit.ravg is another option.