We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Tracking movement (Read 4215 times)
Tracking movement
Jun 11th, 2008, 4:56pm
 
Hey,

I wondered if I could get some input on the best way to realise this idea.

Basically, I want to be able to track the direction of movement of people walking in front of a webcam. I.E. whether they are walking from left to right, or right to left, and their current position.

Would the best way to do this be with frame differencing (motion detection) or with background subtraction?

Also, the lighting conditions where this is being set up might not be the most stable. Any input on this issue would be greatly appreciated. Thanks
Re: Tracking movement
Reply #1 - Jun 12th, 2008, 9:03am
 
Hi, your best bet is an optical flow method, luckily it has been implemented in java - I haven't had a chance to use it myself yet, but here's the thread
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Video;action=display;num=1211365962

Re: Tracking movement
Reply #2 - Jun 16th, 2008, 6:46pm
 
Thanks for the optical flow tip- I've found a great site explaining one method of it, and the bonus is that all the code examples are in Processing! I'm currently changing the code to fit with my needs, but it was very useful.

Here is the URL: http://sweb.cityu.edu.hk/sm3123/class12/class12.htm
Re: Tracking movement
Reply #3 - Jun 16th, 2008, 10:28pm
 
Great site! thanks for the link!
Re: Tracking movement
Reply #4 - Jul 17th, 2008, 9:46am
 
hi, I am pretty new to processing, this idea sounds very interesting.

Do you think it would be possible to trigger events depending on the position of the person? eg. If the person is standing on the right, it plays a imported video file. If the person is on the left, it plays another video file

any feed back on this idea would be great. thanks!
Re: Tracking movement
Reply #5 - Jul 17th, 2008, 12:14pm
 
HI geoffrey, thats more straightforward. You wouldn't need optical flow for that, just a simple frame difference would work. I've written a similar demo which sends OSC messages (later to be mapped to midi using OSCulator) depending on where the movement is,
http://www.memo.tv/webcam_piano_with_processing_v0_1

you could easily change the bit where the OSC message is sent (in drawGrid) to play video etc...

P.S. actually that sample is now quite old, I"ll post a more recent one up soon...
Re: Tracking movement
Reply #6 - Jul 20th, 2008, 2:18am
 
Hi Memo, GREAT SITE! your work is amazing, I love the virtual piano you have created.

I am very new to processing, and any help would be greatly appreciated.

My idea is very simple. Here is my concept...

I think tracking the left - to - right movement is not entirely important at the moment (even though it would be great!). I want the web cam to detect if a person is in front of the camera. If the person is standing in front of the camera, then a video starts to play on the screen. When they walk off the camera, then the video stops playing.

Im not sure if you can help me, but any input would be great.

Thank you!!

p.s here is a link to somthing I am trying to do. http://youtube.com/watch?v=B5mwzhUCqkA
I am going to make my animations using Adobe Aftereffects then export them as .mov files
Re: Tracking movement
Reply #7 - Jul 20th, 2008, 3:34am
 
Thanks geoffrey, to do what you are saying (if person is in front of camera play video, otherwise don't), the simplest thing to do would be take snapshot from the camera when there is no one in front of the camera - i.e. save a background image into memory. Then every frame, difference the current frame with that background image. Anything that is not black means there is something there. But for this you need a perfectly controlled environment, lighting has to not change, the camera has to not move 1mm etc. since when you saved the background image.

I'm pretty sure that adobe video you linked to  is not doing that. It is doing the same kind of motion detection as the webcam piano (frame differencing) to see where the person is. The whole billboard is not one video, when the person stops walking, the video actually stops playing (doesn't advance), but there are still loads of idle animations going on - these animations are probably sprite animations done in code - but could be separate quicktimes on loop as well..
Re: Tracking movement
Reply #8 - Jul 20th, 2008, 4:07am
 
Hi Memo, thanks for your reply!

After searching for Frame Differencing, I came across the background subtraction library here: http://processing.org/learning/libraries/backgroundsubtraction.html

It seems to go with your idea. It takes a snapshot of the web cam image, then visually shows anything which changes (or moves) in the picture.

I am sorry for all these questions, but any help would be great...

I was wondering, how to I connect the video to work with the Background subtraction library? I am currently using this code for importing a file:

import processing.video.*;
Movie myMovie;

void setup() {
 size(352, 288);
 frameRate(25);
 myMovie = new Movie(this, "comp.mp4");
 myMovie.speed(1.0);
 myMovie.loop();
}

void draw() {
 if(myMovie.available()) {
   myMovie.read();
 }
 image(myMovie, 0, 0);
}



So what I am say is - The movie comp.mp4 needs to play, when there is a background change. Any idea how this piece of code might look like?
Thank you once again, any help would be appreciated, sorry for sounding like a newb
Re: Tracking movement
Reply #9 - Jul 20th, 2008, 8:43am
 
the Frame Differencing library looks interesting, thanks Memo.

What is understand is, that it measures the difference in frames. So I guess I would set a threshold to how much movement is detected, and when the number hits that threshold, it plays a .mov file. Then when the number is lower than a threshold, the .mov file stops

I am trying to achieve this at the moment, but having difficulty understanding how to write this code. Any advice on how this might look would be greatly appreciated. Thanks
Re: Tracking movement
Reply #10 - Jul 28th, 2008, 1:52am
 
Hi Geoffrey.joe,

I have been playing around with this, and I believe that the best way to do what you want is to use optical flow and frame differencing. I have had really good results with this technique and have managed to get an average direction of movement from a webcam image. I linked to an excellent example to this earlier in the thread. I think that it is your best bet.

Alternatively, if you want to check if there is movement or not in a specific area (like memo does in his piano), I found that the best result is to put the difference image through a threshold filter and simply count the number of white pixels in a specific area.

But if you simply want to count the total amount of movement like you mentioned, then you could simply use the "presenceSum" value generated by the frame differencing example you linked, and check whether it is over a certain value.
Page Index Toggle Pages: 1