ofxFlowTools: optical flow, fluid dynamics and particles in GLSL


Does anyone have any tips for applying and drawing a force at a location which is not attached to mouse dragging/movement?


hello @moostrik and all,
How I can use your OpticalFlow to get the vector forces in a determined image area. I’m looking for directional changes in vector forces.
I’ve seen you had in mind ( branch 0.98 ) to make a function to return such values:

//ofVec2f* getFlowVectors();

but finally not present in the master branch. Is there any other way to do it?


did you take a look at the averageFlow class?
It takes all velocity (or another force) in a certain part of a texture and returns the average value.

I updated the extended example today to give a better insight into its workings


F.Y.I. recently I did a complete cleanup and refactor of ofxFlowTools. Please let me know if everything still works as expected.


Thank you @m.oostrik, that class looks very ad-hoc. I’m checking how does it work.
So if for now what I look for is the average direction of an specific area of the image

My first attempt would be:

  • setup: set resolution + ROI
	averageFlow.setup(32, 32, FT_VELOCITY);
	averageFlow.setRoi(.2, .2, .6, .6);
  • update all + update the main image texture input
    averageFlow.setInput(opticalFlow.getVelocity()); averageFlow.update();

Then get desired direction inside that ROI:
averageFlow.getDirection(int index)

One question, How is index working at getDirection? I’ve to check the RGB channels? so 0, 1, 2?


Thank you so much again. Shining code there :slight_smile:

Compiles in Release mode, but In Debug mode I’ve got 1 error. I’ve checked project properties but no idea why is this error there…

Any way, since your addon for OF0.10 I’m not able to see any more Fluid or Particles, Just the OpticalFlow visualization mode.

Do you know what I’m doing wrong here? May be my discrete card configuration?

For this reason I guess I’m not able to see the averageFlow visible results too (the Extended Example)

My setup:
Nvidia1060 + win10.

Can anyone else try it too? Just to check if fluid works for others in windows.



Your approach is right.
Although your probably not looking for getDirection(int index) but getComponent(int index)

Average flow is made for ‘Flows’ of up to four components.
FT_VELOCITY has two components (x and y)
So if you want these both you could do getComponent(0) and getComponent(1)
or getComponents() witch returns a vector<float>

getDirection() is similar to getComponent(), and should return the normalised direction, but right now it does not work properly.


Any way, since your addon for OF0.10 I’m not able to see any more Fluid or Particles, Just the OpticalFlow visualization mode.

Have you tried it in opengl 2?
(Just remove #define USE_PROGRAMMABLE_GL )


I’ve tried it and no differences there. In 098 branch I use OpenGl 4.1 and It works.


Unfortunately i have no windows machine setup for OF right now


There is no visible errors there, that might be some windows shader errors over there, right? Any way to debug this?

Can anyone else try it in windows? Just to check if fluid draws work for some of you.


Hi there,

I’m trying to create a force from a pre-existing image that moves around on screen (using the ofXAnimatable addon), so that it will look just like what happens with camera or mouse flows, but where the “force” is the pre-existing figure moving around. Seems like I would create a new type of ftFlow or ftFlowForceType, and update the positions according to my animated figure positions. Anyone tried this before or have any input? @m.oostrik


you could try to set your animation as the input for the opticalFlow


One question about the averageFlow extension:
What’s the difference between averageFlow.setInput and averageFlow.addInput ?


setInput(texure) clears the existing input and, sets the texture to the input
addInput(texture) adds the texture to the existing input