moving objects with optical flow

My knowledge of oF and C++ is basic and I am trying to set an object in a space where it is subject to movement captured by the use of optical flow.

first: how do i set a designated area of action, one that i can later make into a fullscreen, project and have interactions with
second: how do I make the position of the object (a picture for example), subject to motion?

something similar to this,

http://forum.openframeworks.cc/t/making-an-object-e.g.-ofimage-draggable/1637/0

except no mouse usage,

alot like this

http://www.youtube.com/v/MIYt1yNwoZU">http://www.youtube.com/v/MIYt1yNwoZU" type=“application/x-shockwave-flash” allowscriptaccess=“always” allowfullscreen=“true” width=“320” height=“265”>

And I am wondering if anyone can provide me with insight or tutorial on how that can be accomplished?

thank you very much in advance :smiley:

check this example out… http://forum.openframeworks.cc/t/motion-controlled-pong-demo/1991/0

It includes an ofxMotionTracer add-on I put together based on my own Frame Differencing classes and the Optical Flow code from Memo Akten. I structured everything into three main classes that build off each other:
Frame Differencer - the basic frame differencer
Motion Tracker - adds optical flow to the frame differencer
Motion Trigger - adds vector triggers to Motion Tracker that fire when the average optical flow is within their angle and magnitude bounds

The latest version of this add-on is attached to this post.

it uses Optical Flow - well an average of the vectors to detect overall motion… but you can definitely still access the regional optical flow vectors, and then just apply them as forces on your objects…

ofxMotionTracker_beta2.zip

Thanks plong0! I had been looking at your example, but every time I tried to run it i found an error and was unable to see it.

:oops: could you point me in a direction where I can learn to access the regional optical flow vectors and to apply them as forces? And what must I do to have several objects move around all subject to being moved?

I apologize but my knowledge of C++ is minimal
thank you!

Progress has been made!! However, when compiling, FrameDifferencer.cpp has some error and says that: tiStrToLower/mapPoint/mapX/mapY/normalizeX/normalizeY are all undeclared in the scope. How do i fix that?

Thank you

hmm… sounds like you’re missing the ofxTI_Utils add-on … should be included in the original addonPack I posted in the linked thread. If not, here it is.

Ok… well, the MotionTracker offers the getVelAtPixel(int x, int y, float *u, float *v) and getVelAtNorm(float x, float y, float *u, float *v) methods for retrieving regional vectors.

They both store the vector into the u and v parameters.

getValAtPixel takes x,y co-ordinates within the optical flow tracker’s local co-ordinate system. So for example, if your opticalFlowResolution is 640x480 … x is between 0 and 640 and y is between 0 and 480.

getValAtNorm takes x,y co-ordinates as normalized co-ordinates (ie. a percentage of the co-ordinate system). These values are between 0.0 and 1.0.

To get you started on applying them as forces to objects, here is a bit of pseudo-code…

  
  
foreach(object as cObject){  
  float forceX, forceY;  
  float cX = cObject->getX() / ofGetWidth(); // normalize the x position to the screen  
  float cY = cObject->getY() / ofGetHeight(); // normalize the y position to the screen  
  
  motionTracker.getVelAtNorm(cX, cY, forceX, forceY);  
  
  cObject->applyForce(forceX, forceY);  
}  
  

I should mention that I have an ofxBox2dMotion add-on and example that I intend to release in the near future (along with a bundle of other add-ons and examples) that combines the ofxMotionTracker addon with the ofxBox2d addon… basically gives you a box2d world where objects interact with the camera feed. This should be ready for release within the next month or so… I am just swamped at the moment and need to take the time to clean all the code up.

ofxTI_Utils_beta1.zip

missing #include in the TI_Utils.h file?

The FrameDifferencer errors persists and i cannot find their source.

it is unable to find

tiStrToLower/mapPoint/mapX/mapY/normalizeX/normalizeY

declared in their scopes, which all have to do with calibration.