Video Frame Buffer Delay Motion with Difference in ofxcv

Hey guys, a major beginner here. I wanted to show the delayed movement through a live video input. (like the image below, as you can see its a delayed frame as the head moves). I got the difference video using ofxcv. However, I am not sure how to make the frames delay, or access the differenced pixels of the video, ( I’m guessing it’s a bit like a slitscan and you keep the previous frame on the screen for a while?) Sorry if it’s a super novice question, would appreciate any help!

44 AM

Hi @s.kiam,

I think you can draw in an ofFbo and clear only 90% of it each frame :

in ofApp.h class declaration :

ofFbo f;

in ofApp.cpp::setup:

f.allocate(width, height, GL_RGBA);

in ofApp.cpp::update:

float prop = 0.9 * 255;
f.begin();
ofClear(255, prop);
// draw ofxCV here
f.end();

Finally in ofApp::draw() :

f.draw(0,0);

Haven’t tested it, but should work.

Best,

P

Hi @pierre_tardif00, thank you so much for your help!
I tried it but it doesn’t quite work yet, it creates a transparent white overlay and the video frames are constant & don’t lag

this is my ofApp.H

#include “ofxCv.h”
ofVideoGrabber cam;
ofPixels previous;
ofImage diff;
ofFbo f;

and my .cpp

void ofApp::setup() {
ofSetVerticalSync(true);
cam.setup(320, 240);
f.allocate(cam.getHeight(), cam.getWidth(), GL_RGBA);
imitate(previous, cam);
imitate(diff, cam);
}

void ofApp::update() {
float prop = 0.9 * 255;
f.begin();
cam.update();
ofClear(255,prop);
if(cam.isFrameNew()) {
// take the absolute difference of prev and cam and save it inside diff
absdiff(cam, previous, diff);
diff.update();
// like ofSetPixels
copy(cam, previous);
}
f.end();
}

void ofApp::draw() {
diff.draw(0, 0);
f.draw(0,0);
}

Iet me know, thank you so much again! Really appreciate it

Hello.

Yeah it’s not workiung.

Use this instead:
main.cpp (390 Bytes) ofApp.cpp (444 Bytes) ofApp.h (258 Bytes)

It’s owkring on a vector of images, which isn’t perfect, but works ok.
Essentially, the cam difference gets stored in the current image of the array.

In the draw function, the whole array of images gets drawn on top of each others, in order of transparency - 100 % drawn first - , then decreasing to 0.
The array of images is drawn from the one processed the further out in time, to the the closest one.

Alternatively, try using the EchoTrace from ofxDotFrag, works great.

Hope this helps.

Best,

P

Hi! Maybe you sent me the wrong files because there isn’t much code in the ofApp.cpp except for the setup, thanks for putting the time to work it out tho! Will check out ofxDotFrag

ofApp.cpp (1.5 KB) ofApp.h (378 Bytes)

Yes, :sweat_smile: here it is !

++

Thank you so so much @pierre_tardif00!!! Really appreciate it! It works so well now!

Essentially, the cam difference gets stored in the current image of the array.

I’m guessing this happens in:
vector < ofImage > diffs;

Simple question, but why do you store the modulus

indexImg %= diffs.size();

Thanks again for all your help!

Hi, @s.kiam,

Glad i could help.

indexImg %= diffs.size();
is equivalent to writing :
indexImg = indexImg%diffs.size();

Best,

P