![]()
Please update your flash player
Update
Ok, you can now grab the MotionTracker source code (AS2 & AS3). Version 2 eventually will include the other methods for detecting and tracking motion which I mentioned. For now I have just included code for the technique used in the demo.
For those of you without access to a webcam (and as an example of a practical use for this class) here is a short video demonstrating the program I wrote for the installation piece.
End of update
Webcam required (obviously…)
I’m currently working on putting up a show, part of which will be a live generative piece, constructed from the movement of visitors in the gallery space. So of course I needed a method for not only detecting but tracking motion. I’ve seen some of Grant Skinner and Mario Klingemann’s incredible experiments in this field, the most accurate of which used a coloured object in the camera’s field of vision (such as a ball or glove) to track movement, however I wanted the live response of the artwork to be a surprise to the viewer, and so asking them to hold a coloured object would have detracted from the overall impact.
If you ever want to be amazed by the human mind, try recreating the tasks that it performs, particularly those which we take for granted; you will quickly realise the incredible amount of computation which must be happening just to, for example, detect movement and track an object, or to discern more than one object and their relative motions, velocities and distances. This isn’t an essay on Neuroscience though so I’ll save that for another time…
Anyway; I researched the concept of motion tracking, and made some notes on my own ideas. A few possible approaches emerged.
One of the most attractive ideas was to divide the screen into a grid, and average the colours within each segment at regular intervals. The difference in brightness within each segment (from one calculation to the next) would determine whether or not motion had occurred in this area of the screen. Using this data, clusters of segments with a high rate of change could be used to assume an object in motion. This approach is quite accurate, however it would require a lot of getPixel and setPixel, as well as converting these results into Hue, Saturation, Brightness objects; all of which would be quite processor heavy. A decent computer could handle this fairly easily, however I had to also consider the processing load of the actual generative work running over the top.
The method I used in the end was much lighter, and providing the parameters could be adjusted to suit the environment, it would yield enough accuracy to provide a quite responsive tracking point for the artwork to follow.
Here’s how it works
- After the camera object is set up, it is passed to a MotionTracker class I wrote, which extends the Point object. The MotionTracker class contains two BitmapData objects; one representing the current data from the webcam, the other is used to store the previous frame.
- When the update method is called, the new frame is drawn on top of the previous using the difference filter.
- The result then has a ColorMatrixFilter applied to it, increasing the contrast of the image and dropping the darker areas (with less movement) further into the background.
- A blur filter is then applied in order to further reduce noise and to form blobs from areas where more movement is occurring.
- The threshold method is then called in the resulting BitmapData, effectively causing all near black pixels to be ignored and all light pixels (where movement has been detected) to be set to a certain colour.
So that takes care of the motion detection, but what about the tracking?
- First we call the getColorBoundsRect method on the BitmapData object, which gives us a Rectangle object representing the area occupied by pixels of the colour we used when applying the threshold filter.
- If the rectangle has an area larger than a specified constant, then sufficient movement is occurring and it can be tracked (choosing to ignore small areas of movement helps to eradicate noise caused by background and other interferences).
- We then find the centre point of this rectangle, and then move the x and y position of the MotionTracker instance to these coordinates, applying some gentle easing to give more continuity to the movement.
I will post some source code once the MotionTracker class has been refined, and once I have build a nicer API so that, amongst other things, you can create your own UI for tweaking parameters at runtime; a useful feature if you have requirements such as mine where getting the most accuracy from a particular environment is important.
146 Responses to AS3 webcam Motion Tracking
J.Toolenaar
Jun 6th 2008
7:29 pm
Great stuff, I want to go experiment with it right away. So cant wait for some code :d.
keep it comming
Liam
Jun 10th 2008
10:47 am
So where is this show going to be? I’d like to see it. Interactive installations is a direction I’d like to head in - just don’t know where to start.
Soulwire
Jun 11th 2008
1:03 am
Hi Liam,
There’s 2 shows actually, one on the south coast (Bournemouth) and the other in London. I’m new to installations myself, though I’ll be learning Max/Msp/Jitter over summer to try and make myself more available for VJing and other live performances. Processing is also a good tool to know, though I think I’ll get more of what I need out of VVVV, though thats just a personal prefference.
Knowing where to start is always the hard part ;) There are a lot of great forums for this kind of thing, and I’ve recently read a few books which are at the very least inspiring, if not technically useful.
I’ll post the code next week once the first show opens and I’ve got the time to clean it up; I’d love to know about any use you might find for it.
vonramsey
Jun 11th 2008
9:21 am
This is amazing, can you post more information how it works with more details? Thanks!
This is a guru stuff, you can make so many thinks with it!
vonramsey
Jun 11th 2008
9:22 am
How much should it cost?
Soulwire
Jun 11th 2008
9:36 am
Hi Vonramsey,
I’ll post the code next week mate, all commented of course. I mentioned some other methods of achieving the same thing; maybe I’ll include them in the class too, if you need accuracy over speed.
Cost? It won’t cost you anything!
vonramsey
Jun 11th 2008
9:57 am
This is majestic to see such a guru stuff! What about the license when you post the code next week?
pault107
Jun 15th 2008
6:59 pm
This sounds interesting, I’d love to see it in action but I don’t have a webcam. Any chance of posting up a video?
KURT
Jun 16th 2008
10:28 am
You have to see it in action. It works realy good.
BennyB
Jun 16th 2008
3:40 pm
Is it possible to make this one in as2?
MikeM
Jun 19th 2008
12:21 pm
Hey this is realy cooool! Respect budy
Soulwire
Jun 21st 2008
11:02 am
Hi all,
I’ve been using this code now in a live generative piece, and it works well. I’ll see about uploading a video of that in action for those of you without a webcam.
BennyB; it is possible to do this in AS2. I’ll include an AS2 version in the download.
BennyB
Jun 21st 2008
11:55 am
Wow! Can’t wait. Thanks brother.
BennyB
Jun 26th 2008
7:18 am
Is it possible to make the motion (black one) like a mask? Or something like a combination with other animations that can follow the motion? Thanks.
m@
Jun 27th 2008
6:19 am
Okay, this code is ideal for a fun little personal project I am working on. I can’t wait for it to be posted! You’ll be my hero for doing so.
Soulwire
Jun 28th 2008
1:00 pm
Looking forward to hearing about the project! I had to use my webcam in the installation, it comes down on monday so I’ll tidy up the code then and release it. Sorry for the delay, it’s been mentally busy recently :)
BennyB
Jun 28th 2008
1:15 pm
Thanks again! how about the posibilities and combinations with other animations?
Soulwire
Jun 28th 2008
5:01 pm
Hi Benny. Yeah, this was in fact the original purpose of it; the motion tracking was used to influence the movement of a particle system, which in turn powered a visualisation. I’ll upload a video of the use I found for it when I add post the code. I’m sure it has many possible applications.
BennyB
Jul 1st 2008
12:25 pm
Hi,
Thanks for your reply, i see you are realy busy. Hope you can post more about your work!
Beebs
Jul 2nd 2008
7:29 am
Too bad I can’t see how it looks, but if the code is available please let me know.
Sounds exiciting!
vonramsey
Jul 2nd 2008
1:16 pm
Did i miss something?
BennyB
Jul 3rd 2008
10:35 am
When will you upload your stuff-Code-Video?
Soulwire
Jul 3rd 2008
7:15 pm
Alright chaps and chapettes, the code and demo video is now up. Sorry for the wait!
Beebs
Jul 4th 2008
2:31 am
I think you are super duper cool and generous and kind and amazing.
OMG, this opens new things that I always want to do.
Thanks a lot for sharing the code, and thanks to share the video how it looks.
Respect to you.
BennyB
Jul 4th 2008
7:22 am
Thanks a lot! I’m waiting for as2 and the other stuffs too :( Anyway your the man, thanks again.
BennyB
Jul 4th 2008
7:25 am
Stay in touch, we are watching you ;)
vonramsey
Jul 5th 2008
11:54 am
Waiting for the info and as2 too
VonRamsey
Jul 10th 2008
7:35 am
Hi there, can you please upload as2 version and more informations? I will learn how to do this, if you help-teach me. I have waiting so long for the as2 & info, i know you are busy :(
Soulwire
Jul 12th 2008
4:23 pm
Hi Benny and Vonramsey. I’ve been away in Gambia for the last 8 days, so sorry the source was rushed and that I didn’t have time to code up the AS2 version. I’ll post it asap though!
And Beebs, you’re welcome - glad it could be useful to you.
VonRamsey
Jul 14th 2008
7:45 am
Thank you for your help i realy appreciate it. I wait for new posts of you. Thank you again!
dbis interactive limited - dbis interactive communication blog » Motion Tracking in Flash
Jul 15th 2008
8:06 am
[...] is another reference of Flash based motion tracking. This entry is filed under Uncategorized. You can follow any [...]
phil wulf
Jul 18th 2008
7:55 am
Hi Windle, Great stuff. Especially like the random organic “Soul Wires” at the top of your page. Can your motion capture do multiple object tracking? I am making an interactive wall for a mall and I need a program that will allow for multiple tracking of people. I was thinking schools of fish swarming the objects, or maybe huge Banyan trees growing from people’s shadows when they stand still and twirling leaves when they walk by. The Soul Wires sped up would be cool too. Do you have any code that would facilitate this project? Would you have time to create something like this? If so, please approximate a cost range. Thank You. Great work.
Phil Wulf, Hawaii
VonRamsey
Jul 18th 2008
12:22 pm
SoulWire can do it for sure! Hope Soul finished the as2.
Soulwire
Jul 18th 2008
2:08 pm
Hi Phil,
Multiple object tracking is a different kettle of fish altogether. As you can see from the demo, this technique uses all of the image data coming in from the camera and averages it into the assumed motion of an object. If you were to track multiple objects, you would have to track each blob, which could be problematic as one object (say a person walking in front of the camera) may be comprised of multiple blobs. http://muonics.net/site_docs/work.php?id=41 is a good example of multiple object tracking, built using C++ openframeworks library - http://www.openframeworks.cc/, though it uses motion sensors, which lend themselves more to this kind of project, the webcam is a kind of poor man’s motion sensor in this instance!
That said, I have been thinking about techniques for multi-object tracking. The easiest and most accurate way would be to track coloured objects. The best way to do this would be for someone to hold an object of a specific colour, but one way of dealing with this autonomously would be to:
The first hurdle would be making sure light and shadow doesn’t adversely affect the colour tracking, which could simply be done by allowing a specific change in brightness / hue to take place.
The other problem would be that overlapping objects of similar colour could cause the motion tracker to make the wrong guess as to which object is which.
If you want to get in touch via the contact page and let me know your budget we can talk more about the project. In terms of adapting this script to track multiple objects, that is something I am keen to work on and will implement when I get the time. Mega busy at the moment!
Pitra
Jul 19th 2008
2:32 pm
wow.. it works great. love to experiment with it. thank you for the source code.
i made a quick test combining your class with flint particles class.
check it at: http://client.strategocorp.com/webcam/tes03.html
VonRamsey
Jul 19th 2008
3:22 pm
Nice but works little bit to slow imo! How about some info how you do this?
Grandy
Jul 22nd 2008
9:39 am
Hi Windle, you have realy Great skills. I’m a big newbie in Flash (i started with actionSkript2) and i will thank you for the source and for this web site with many Great informations and cool stuffs. I read that you are mega busy, I will not take your time when can you add the AS2 Version of the tracker, like i said i’m a newbie and don’t know AS3 (maybe it is easy but i will start to learn it after i learned AS2). Is there a way to make a textfield of the tracking area what gives us the x and y numbers in realtime? Maybe the area in coordinates? I just wonder if is realize-able? Thanks onemoretime. Keep the good works coming.
Golfie
Jul 22nd 2008
11:50 pm
Faaaarking great stuff dude
Grandy
Jul 30th 2008
9:29 am
Are you with us? Sorry if i bother you but i’m gone die for wondering of as2 and more infos.
Evan Grant
Jul 30th 2008
4:45 pm
Hey loving the work. We’ve just done a motion track project using OpenFrameWorks at Glastonbury http://www.vimeo.com/1315243. Be great to find out more about what you’re up to and see if we can collaborate?
Soulwire
Aug 9th 2008
6:37 pm
Just to let you know the AS2 version is now included in the download. Sorry for the wait.
It’s a little bit of a grubby conversion, but only in so far as I’ve hacked the demo to work in AS2, the MotionTracker class itself works and is coded almost identically to the AS3 version.
Vonramsey
Aug 12th 2008
4:56 pm
Thanks a lot. For the as2 version. You r the man. i will disturb you ;)
John Irving
Aug 16th 2008
4:44 pm
If been thinking that a lot of your examples here could be used for automated visualisations in clubs. I guess that all you would need to do is take in an audio signal (like you do for the motion capture script here) and process that through the flash player then send the output of the computer (laptop) screen to a projector. This would make for some easy-to-use visualisations (pre-prepared of course) which could have a simple time component and allow for fading from one visualisation to another after an elected period of time, or even just a keystroke which would start the fade manually.
Another use i’ve thought of for this motion capture code (as you described in your comment of July 18th at 2.08pm) could be to use a simple light/dark comparison of the captured image to adjust settings in the visualisations. Using it this way you could point the webcam at the crowd in the club and allow the changes in light and dark which occur due to changes in the dynamic lighting setup in the venue to adjust the visualisations settings, maybe not by much, but depending on the visualisation, this could be a nice effect.
Alternatively, you could have the webcam pointing at the DJ or VJ allowing them to manually adjust some of the visualisations settings themselves, maybe the fading i was talking about earlier or any other settings based on an X/Y axis which is the position of the image capture blob.
There are so many possibilities here that the imagination is the only true limiting factor.
Nice work mate. :)
Condor
Aug 20th 2008
1:18 pm
http://ssandler.wordpress.com/MTmini/ ???
Soulwire
Aug 20th 2008
2:25 pm
Awesome! That would work great. :)
Grandy
Aug 20th 2008
3:46 pm
Thanks for the as2, but i can’t use the motion tracker. I tried so many things but does not work, where is the error? What is wrong?
His is a simple code where i found in the Net, i tried to trace it but does nothing :(
Simple Code:
I will only that the red pointer (tracker) folows the flowers!… :(
Soulwire
Aug 20th 2008
5:13 pm
Have you modified the code so that (a) the logic for adding flowers appears within an enterFrame or timer event so that it doesn’t need mouse movement to work and (b) it uses tracker.x and tracker.y rather than _xmouse and _ymouse?
Condor
Aug 20th 2008
5:43 pm
No i don’t modified the code :( What sould i do?
Grandy
Aug 20th 2008
5:45 pm
? CONDOR what the hack Soulwire meanig me nothing to do with you. I found the flowers stuff and can’t modifie it :(
Condor
Aug 20th 2008
5:48 pm
Ups. sorry Grany. I add the link for the multiTouch stuff
Vonramsey
Aug 24th 2008
1:00 pm
What about the v2 ? U r realy bussy i see, can’t wait for more!
Vonramsey
Aug 24th 2008
1:53 pm
This is why i respect Windle, a man who has future in the Flash scene. Thumbs up.
http://labs.grinant.com/ ;)
Soulwire
Aug 24th 2008
2:56 pm
Haha, good stuff. It’s great to see it used. Yeah, I’m so eager to get V2 out as it seems it’ll be popular and of use to people. Next time a break in work comes up I’ll pick up where I left off. Cheers for the link :)
Grandy
Aug 25th 2008
3:31 pm
And how about this one? I changed the _xmouse and _ymouse in to _target._x and _target._y but does not work? Where is the error:
Soulwire
Aug 27th 2008
9:34 am
Grandy, how are you integrating the Motion Tracker? I don’t see any refference to it… Once you have the Motion Tracker running, I presume you want to replace refferences to the mouse position with trackerInstance.x / y (no underscore). Perhaps try getting the motion tracker running first, with just a dot following to get the flavour of it, then stick in your funcky fx!
Grandy
Aug 27th 2008
5:01 pm
The Motion tracker your shared works fine, the dot what you asked works too. i used directly _target._x and _target._y to track it (as2). Gona Wild, it’s bad to be a newbie, thanks anyway. I will try it one more time :(
Grandy
Aug 28th 2008
3:09 pm
Now i get it, it works good but how can i disable the mouse listener?
Vonramsey
Aug 28th 2008
4:07 pm
Like GuruWindle sayed. Delete this :
//This is the listener that listens for mouse movements
var myListener = new Object();
Mouse.addListener(myListener);
change myListener.onMouseMove this to this.onFrameEnter after this you need no more mouseDown function.
saymaad
Sep 9th 2008
6:28 am
Thank-you for a very brilliant piece of work that you have put together and you generosity of making the source public.
Due to my insuffient knowledge of actionscript may I ask someone to guide me how to attach a movie clip or even a mouse to the center point of the circle.
Any sample that could apricitiate the newbe in with the class???
Soulwire
Sep 9th 2008
9:22 am
Hi Saymaad,
All you would have to do is use the x / y values of the tracker to position a movieclip.
For example:
You can’t take control of the mouse, but one solution is to hide the mouse and use an asset which looks like a cursor and position it using the same technique.
saymaad
Sep 11th 2008
6:29 am
Thnx souldwire for the input and I m really sorry for this late reply. I didn’t checked this page because I was busy playing around with the “main.as” that I found in the AS2 folder.
I have put together a demo by editing the actual script, but the resulted detectection is not as acurate as it is in your demo (at the top of this page). Is this because of deifference in version 1 & 2 of the class?
I have uploaded a zipfile with the modification at :
http://www.megaupload.com/?d=H5KSSVMO
Can you polish the code towards better detection? I want the car to move the user but it’s responce is very slow and also not much accurate.
thank-you again for taking time reading, and helping others with this great experiment.
Reggy
Sep 11th 2008
7:41 am
Thank you for a brilliant piece of work and your generosity of making the source public.
Is there any way to bring the object position coördinates outside the computer ?
Thank you very much !
saymaad
Sep 11th 2008
7:52 am
sorry wrong file uploaded I’ll fix the link soon.
Soulwire
Sep 11th 2008
9:29 am
Saymaad - If it’s feeling a little unresponsive, you need to play with the contrast, brightness and blur settings of the MotionTracker - the aim is to get the output looking like consistent ‘blobs’ (See my demo video above in the config panel in the dark window next to me), which makes the motion easier to track. Also, have a look at the minArea setting - increasing this will stop small isolated areas of movement (like objects in the background) from tricking the tracker into moving. There shouldn’t be any difference in accuracy between the AS2 and AS3 versions.
Reggy - I think you’d need to look at interfacing flash with some external hardware. You can do the opposite (sensors to Flash / Processing etc) with things like the boards they have over at http://www.makingthings.com, though the drivers and API they have may allow Flash to send messages (such as the tracker coordinates) to physical equipment.
Good luck!
Vonramsey
Sep 11th 2008
10:33 am
Some new stuffs? Updates? Like 3D Ribbons in Papervision and motion tracking? Maybe some other stuffs made with your motion tracker?
REGGY
Sep 11th 2008
6:00 pm
Thank you for the answer and suggestions.
You are a great person !
Soulwire
Sep 12th 2008
7:53 am
Hey Von - too busy at the moment I’m afraid. I would love to be posting once or twice a week, as that’s the frequency at which I have ideas, but finding the time to code them up and write them up is another matter! I’ve been working on things like steering behaviors and Voronoi diagrams, maybe they’ll see the light of day soon. (I see bit 101 is also working on the Voronoi, so it’ll be interesting to see how we each approach it). I do have some concrete ideas about improving the motion tracker now though, and a couple of cool space filling algorithms - so I hope I can post something soon. I seem to be forever giving reasons why there’s been a delay in posting source, but I’m not the kind of blogger who posts aggregations of news or quick thoughts (perhaps I should be) so I like to refine things before they are put out there…
Reggy - You’re welcome :)
Olivier
Sep 19th 2008
2:42 pm
Ive actualy made this for adidas about a year back, good times.
At the moment im actually searching for a piece of code (not a entire class) that allows me to get the average color from a rectangle, but dont worry im sure ive seen it somewhere before. and will run into it again.
A little heads up, you dont actually have to blur, or even draw, both will make it run even better. I like your pretty growing (sprite? or graphics?) trails btw :)
Soulwire
Sep 19th 2008
2:52 pm
Hi Oliver,
Yeah, I appreciate that the blur will add CPU overheads, but it’s necessary for this approach to merge areas of colour and create blobs. V2 will work on entirely different principals though, and be much more accurate :)
If you want to get the average colour from a bitmapdata, just keep a running total of all RGB values, then average them, like so:
Would love to see your work for Adidas!
Vonramsey
Sep 20th 2008
11:06 am
Can we track colors in V2?
Soulwire
Sep 20th 2008
1:02 pm
Yep, that’ll be part of it!
Vonramsey
Sep 20th 2008
8:54 pm
A man, can’t wait have high blood pressure. How about as2? Please do it with as2, thanks for all the good stuff Windle. God bless you brother.
AS3 Colour class for extracting the color palette from a BitmapData image or photo, ColourUtils.as
Oct 11th 2008
7:56 pm
[...] AS3 webcam Motion Tracking 12% similar Tracking an object’s movement [...]
molo
Oct 15th 2008
11:17 am
Hi there,
I’d love to see a video of your live generative work in the gallery. Did you create one and upload it somewhere? Didn’t find it on youtube or vimeo…
Would also be pleased to see some photos!
Week 7: Loading External Content, Video and Sound Playback, Microphone and Camera - Advanced Flash: Actionscript
Oct 25th 2008
10:11 pm
[...] The Camera class is used to playback video that is pulled in from a web camera attached to your computer. The video can be used to build streaming web cam applications as well as computer vision projects. [...]
difercm
Nov 14th 2008
5:59 pm
How does you disable the webcam after of the enable it??
Soulwire
Nov 14th 2008
8:40 pm
Just detatch it from the video:
And also remember to kill the Motion Tracker, dispose of BitmapDatas and remove event listeners :)
vonramsey
Nov 15th 2008
4:07 pm
Are we done yet? When will you release the new version of your über tracker? Thanks
molo
Nov 18th 2008
4:53 pm
Hi! Still lookin forward to seeing a video or pics of your show in Bournemouth or London. And how did you manage it to put it on a big screen. Did you scale it? Can you scale it without losing performance?
Soulwire
Nov 19th 2008
7:12 pm
Soon my friends… soon! My list of things to play with seems to grow in an inversely proportional manner to my free time :) I’ll post my blob detection stuff asap and take it from there. Still need to try porting a few things to FP10 with Pixel Bender for that extra touch of speed.
veens
Nov 20th 2008
10:47 am
Great Stuff soulwire !!!!,
I ‘m making an interactive project with multiMotion tracking,
I Search the best method for the multitracking in as3, I found this http://andreithomaz.com/labs/?p=9.
maybe it will help you, I look forward to see your blobdetection class.
Soulwire
Nov 20th 2008
11:16 am
Hey Veens,
Yeah, I saw Andrei’s post a little while back. Great stuff! It’s a port of a set of java classes for processing, but works very well in AS3 it seems (I’ve only played with the original processing library). The edge detection is great too, it opens up some wider possibilities for face detection and more intelligent object recognition. The above experiment was designed to work for basic motion detection and be extremely fast (so that generative work could sit on top of it without impeding performance). It’s very limited though - I want to fix that soon :) The algorithm I’ve been using for blob detection is a little quicker but also simpler and less sophisticated than the library you linked to (it’s based loosely around the growing regions idea).
I think now Flash Player 10 is here with better performance and image manipulation capabilities we’re going to see some jumps in computer vision experiments from languages like C++ and Java into AS3 and who knows, even some practical uses on the web.
mianel
Nov 21st 2008
3:47 pm
Hi, Soulwire
i need you help, how i can create multiple object tracking in example as2? i can cerate a movieclip in the library and attach in main?, i learning as2, i have insuffient knowledge of actionscript, please someone help me,
bye
Soulwire
Nov 22nd 2008
3:34 pm
@Mialel - you can’t create multiple tracking instances (well you can but it’s pointless as it will be tracking the same data). You can however have as many objects as you like respond to the results of the tracking.
In the AS2 source code look for the lines in the track method:
This is easing the MovieClip ‘_target‘ to the position of the tracker. The Motion Tracker’s x and y properties are the centre of detected movement, so just use these to move your Objects. i.e.
Hope that helps get you going
molo
Nov 24th 2008
3:55 pm
Well, there’s actually another example of motion detection with multiple tracking objects online.
Watch it at: http://imm.sheridanc.on.ca/videomotion/split.swf
If you navigate back to the videomotion directory, there’s the AS2 code and examples included.
But I’d like to know how I can scale the video to fullscreen mode without losing performance. I tried it with your example and just set the camWidth and camHeight to (for example) 800×450. But this leads to a pretty bad camera display which leads to a bad motion tracking.
Is there a way to keep the video image small and just scale the tracking to the frame size?
How did you solve this for your installation and what size was it? Did you use a projector with 1024×768 or what kind of display did you use? Can you tell us more about your Hardware configuration please?
You could also post the AS-file of your installation if you want ;-)
Soulwire
Nov 24th 2008
6:57 pm
@Molo
Yeah, it’s not a great idea to make the source full screen. For a start this probably goes beyond the resolution of most generic webcams, and of course adds load to the image processing. You only need a faily small input (the size I’ve used in the source is fine). Then just scale the x and y results of the tracking to the size of your stage.
I think I’ll keep hold of the code for my installation for the time-being - I’m using the script in some generative print work, so it wouldn’t be fair to sell prints when the engine behind it is free ;)
Maybe when I get some time to work on new methods for motion detection I’ll put together some cool example of how you could use it! :)
Jettracks
Nov 25th 2008
8:30 pm
Hey Justin,
Just wanted to ask is it’s ok to use your code in a project that I’m trying to make.
I’m not a hardcore programmer such as yourself and I need all the help as of now.
vonramsey
Nov 26th 2008
9:24 am
That would be great!
RogB
Nov 27th 2008
10:55 pm
Very nice, I saw this motion detection interface article in Web Developer Vol.3 which looks a lot like this. I was developing a game with this technique. However when I put Flash Player on fullscreen to do this, there are severe frame rate issues. Any ideas on how to solve this? Works reasonably well in a smallish window.
Soulwire
Nov 28th 2008
12:16 am
Hi RogB
Are you experiencing the low framerate even though the camera is capturing at a low resolution? Could this be similar to Molo’s issue, where performing the tracking at low res and then scaling the results up to the stage size would solve it? Because the motion tracking involves performing several operations on a BitmapData, if this BitmapData has very large dimensions it will perform very badly – plus it’s not really necessary for the tracking to be done at these high resolutions.
Or are you noticing a discernable lag between, say, a 1280 x 1024 stage in normal mode and the same dimensions in fullscreen mode?
molo
Nov 28th 2008
3:50 pm
I think the question is, how can I display a silhouette or the source video with higher resolution in fullscreen mode without losing performance? This could be very useful for navigation applications. See my posted link for example: http://imm.sheridanc.on.ca/videomotion/split.swf
Even if you set the browser into fullscreen mode, there won’t be any frame rate problems.
…btw, thanks for your help, although I couldn’t get it fixed… yet ;-)
Now my tracker jumps to the end of the galaxy when I start the program.
Jonas
Dec 2nd 2008
7:12 am
I’m using the classes from your engine you built to track and have a movie clip follow it on another fla. Im not sure how exactly or what values would i pull from the class to get the x and y into my fla after importing your main class. Can you help me? I read the responses above and couldn’t understand much of it since Im learning AS3 but have to code this in AS2 grr.
Soulwire
Dec 2nd 2008
10:36 am
Hi Jonas,
have you had a look at the class called ‘Main’ in the AS2 folder of the download? It shows you how to set up the motion tracker. Basically you need to create a Video object, then attach a camera to it. From there, you can initialise the MotionTracker class and start tracking. Each time you want the MotionTracker to detect motion, call the track() method on it. You can then use the x and y properties of the MotionTracker to position your MovieClip.
It sounds like you’re having trouble actually setting it up, rather than tracking motion right?
Feel free to post some code up here showing how you’re doing it so we can see what’s missing.
Evan Fetty
Dec 16th 2008
4:51 am
Hey there,
Your work is incredible. I’m learning AS3 right now and am starting to get into Processing. I just wanted to thank you for posting your source files, I’ve learned more about clean code from these than most any other resources I have come upon.
Thanks Again! Keep Posting!
-Evan
Ag
Dec 26th 2008
4:33 pm
Hi there,
I’m newbie in AS3.
I’ve downloaded your code and wondered why I didn’t see my mirror image, even the initial value of _motionTracker.flipInput = true; ?
Somnic
Jan 15th 2009
12:11 am
Hey Soulwire.
Just found this example today while on a break from work.
I’ve been playing with something very similar to this (using a method more closely related to your color-average grid method, strangely) for a long time. Just petering around, not really thinking about application in any detail. Your solution here is elegant, and I quite like the vis you’ve done with this example.
The last thing I was working with was trying to work with 2 cameras and using the top to get xy and the side camera to get z values, matching an object in fake 3D space to those values. It works alright, but running that much calculation and trying to generate visuals at the same time was too much to handle for my machine.. lol.
I think you’ve inspired me to start from scratch, as I’ve been mucking around in this code since I started learning AS3, having to deal with all of the mistakes / misunderstood oop that I was writing when I started.
Thanks a lot for posting your code here. You’ve made another subscriber for sure, m8.
Keep fighting the good fight!
Excited to see documentation from the installation, and what your prints look like.
Cheers!
vonramsey
Jan 18th 2009
7:19 pm
Master Justin,
I’m sure you are realy bussy, when will you post a new update?
Mark
Jan 24th 2009
5:42 pm
Soulwire u’re the best!
I’m suspecting these guys got the idea from you :)
http://www.davidlindseywade.com
Is it possible to navigate through images with this source like they did?
I guess in the near future web browsing would be done by pointing a finger.
Keep up the sharp skills!
molo
Jan 27th 2009
2:15 pm
…so then you’ll like this too:
http://www.fluidtunes.com/
Mark
Jan 28th 2009
4:54 pm
That’s pretty interesting Molo, the question is how to implement something like that into web application through Flash?
andy vern
Jan 30th 2009
5:29 am
Thanks for your motion tracking class. Finally got around to playing around with it and having a lot of fun.
Here’s a link to my first experiment called Donnie Darkos Mirror
http://andyvern.com/2009/01/30/donnie-darkos-mirror/
Soulwire
Jan 30th 2009
10:37 am
@Vonramsey
I hope it will be soon! I think I was getting too involved in the accuracy and optimisations so instead will break it into segments, posting about different aspects such as extracting motion, blob detection and blob tracking - then put it all together into a new engine.
@Mark
Thanks! Yes, you could certainly adapt the source to navigate through images. A good starting point would be to subtract the previous position of the MotionTracker’s x and y coordinates from the current position. You could then use this to work out the speed of change and of course the direction and feed this into an image gallery. Maybe look at some existing scripts that use mouse dragging and apply them to the motion tracking as it would work along very similar principles. When I get around to finishing the enhanced version of this I’ll try and post a few more demo applications.
@Andy
Awesome mate! I love it - (nice reference to a great film as well). Thanks for the shout out too, I appreciate it. Keep up the good work.
Mark
Feb 3rd 2009
5:59 pm
Awesome! Trying to get it working myself, though it’ll be quite a job as i decipher more of this AS3 tongue. As I said, u truly are the best!
Hoe je webcam toevoegen aan een flashanimatie « davy blogt!
Feb 19th 2009
1:34 am
[...] http://blog.soulwire.co.uk/flash/actionscript-3/webcam-motion-detection-tracking/ [...]
Victor
Feb 20th 2009
1:06 pm
Awesome work !
I’m currently trying to build a little animation with it but I was wondering if it was possible to confine the tracking to defined area instead of the whole recod ?
vonramsey
Feb 22nd 2009
11:54 am
Wow, you will rock the web cam. Can’t wait ;)
rose
Feb 22nd 2009
5:45 pm
Wow, Soulwire, this is fantastic! IT took me a couple of evenings since I don’t know actionscript but I have the swf embedded in a Director file and am using Director’s collision-control to note when I’ve hit other sprites.
The only problem I’m having now is when I create a Director project and embed the flash inside, I cannot change the flash camera settings to the proper type of camera! If anyone has any suggestions I’d love to hear them.
Rose
Soulwire
Feb 27th 2009
8:29 pm
Hey Rose,
I really like your site - looks like you’ve worked on some great projects.
How are you getting on with the camera settings? I don’t use director so haven’t come across this problem before. Are you referring to the settings that determine which input Flash Player will look for the camera on? USB, DV, Firewire etc?
There’s a thread here: http://www.directorforum.de/showthread.php?t=56535 which links to a few articles which, at first glance look interesting!
Look forward to seeing what you come up with.
Larhart
Mar 4th 2009
7:01 pm
i send u a msg 2 days ago about how to change the circle thingy to image or movie clip…hope to hear from u soon
cheers
Soulwire
Mar 4th 2009
7:27 pm
Hey man - I emailed you back! Check your junk folder.
Here’s what I said anyway:
Hope that helps…
Larhart
Mar 9th 2009
5:25 am
i did send u another email…just wanna let u know…what i wrote is i already put the coding in the track function but still cant detect my image…i put a movie clip on the stage with the name myImage. the webcam load but the movie clip didnt follow the motion circle. hope u can help me in this.
cheers
ericsoco
Mar 13th 2009
12:39 am
awesome work! love it. inspiring.
sounds like you may already be poking around with this, but have you thought of using PixelBender to handle the pixel averaging? not entirely sure if it makes sense to run that in another thread, when you really need to have analysis happening every frame, but if there’s a way to make that work, bet it’s a pretty solid optimization.
also, BitmapData.getVector(). hell yes.
FP10 is going to blow the lid off of so many things that used to be performance bottlenecks.
been digging through FLARToolkit lately ( http://words.transmote.com/wp/20090309/flarmanager-v01/ ) and there are lots of opportunities for similar performance gains with PixelBender and FP10. if only i had time….feel your pain ;)
Soulwire
Mar 15th 2009
9:50 pm
Hey Eric,
Good work man! The FLARmanager is just the ticket. I had the same thought when playing around with it - the FLAR API can be pretty obtuse at first glance.
I have indeed been using PixelBender for the update to this script. I’ve gone down the route of using a single ‘background’ image for comparisons and then slowly blending this with the input to reduce noise from light changes etc. PixelBender was the perfect way of doing this, though I’m hoping to get some time to take this one step further and use it to do some of the number crunching involved in detecting and tracking the blobs generated by the difference technique.
I agree with your point about FP10, and with alchemy also I think there will be somewhat of a Renaissance as libraries which would previously perform too poorly in Flash can now be quite adequate in the player. Good times ahead!
I’ll be checking out your FLARmanager properly in my next spare evening.
Keep up the good work and cheers for the inspirational tips ;)
Trev
Mar 16th 2009
9:46 am
Hi Soulwire. Great program!!
Some friends and I are doing a project for our 3yd yr IT degree involving motion tracking. The client is the local town museum. We have been playing with the settings to work with Infra red light as the project is going in a low light area. We are projecting ant images onto the floor surface and they respond by movement when motion is detected.
First, I want to check that we can use your Motion Detection program?
Second, we have been playing with the settings in the control box to detect as much movement as possible, such as zero values for Blur and MinArea. And adjusting Contrast and Brightness to suit.
Any ideas on making it more sensitive to light change?
Regards
Trev.
Soulwire
Mar 16th 2009
10:03 am
Hi Trev,
Your project sounds really interesting. You should post a link up here to a video of the installation once its done!
To answer your first question - yes, please do use the script, adapt it and otherwise butcher it to suit your needs! I’m glad it’s being put to such good use.
In terms of optimising it for infrared light, I would look at the colour matrix settings. It sounds like ideally you would drop the darker areas right out and try to isolate brighter areas whilst reducing any flare the light might cause in the camera. Contrast is definitely the best place to start. Also, changing the threshold settings could be useful (in the bitmapData.threshold() method), so that any pixel with a colour value less than, say, 20% gray would be set to black and all others white.
When I was testing it for the installation I made, I took a few static screen grabs that I felt would be representative of the average frame the camera might get (light levels etc) and worked with them initially so I could focus on the settings for the image manipulation.
Good luck with the project. If you’re having any problems feel free to email me (justin ~at~ soulwire dot co dot uk) and I’ll have a look.
As you know I’ve been working on some big improvements to the code and performance, though it seems many older libraries are starting to be ported over to Flash so I don’t know whether its worth continuing to write a motion detection engine from scratch. This one is lightweight and pretty flexible though, and perhaps with some blob detection working on top to track individual areas of movement it could work well for most situations.
Webcam motion
Apr 2nd 2009
4:18 am
Good list of motion detection resources for flash developers = http://www.ugolog.com/pages/webcam-motion-detection-for-flash-flex-and-csharp, theory on background tracking is great
Mindfock - Basic (twitchy) Motion Tracking
Apr 4th 2009
2:24 am
[...] Most of the concepts are explained in detail here and there. [...]
John
Apr 4th 2009
2:30 am
very nice.. the “Here’s how it works” area was enough to get me started on my own experiment.
Very well said. :-D
John
Apr 4th 2009
2:30 am
very nice.. the “Here’s how it works” area was enough to get me started on my own experiment.
Very well said. :-D
mike
Apr 28th 2009
5:33 am
Hello again!
I have been working to figure this out and every time i try to tet my file i get an error : 2005
I want to make a drawing program that follows a laser pen and draws its movement. similar
to this:
http://www.neuroproductions.be/experiments/flash-laser-graffiti/
I have posted there and asked him for help and i got no responce, any help?
please helpppp!
thank you!
-Mike
Soulwire
Apr 28th 2009
8:58 am
Hi Mike,
Error 2005; “Parameter %1 is of the incorrect type. Should be type %2.” right?
At a glance, your problem is likely that bmd.draw(video) fails because you have not created the video object! Though this should complain of a null object reference - not sure why you’re getting the above error.
You do know you need to attach the camera to the video? You should put your function into an event handler for an enterFrame event and then in the class constructor first set up the camera:
…and then add your event listener so that at each update the video is drawn to a bitmapData and then analysed.
One word of advice though - don’t create a new BitmapData on every frame. It will stack up in memory. Just reuse the same one.
It’s not really my place to explain other people’s code, but in this case it’s actually doing a very similar thing to mine.
Basically, he’s using a matrix to amplify the red channel of the bitmapData. getColorBoundsRect will then do the rest, by isolating the areas of the image containing red (FF0000) pixels. You could do the same using my approach, which makes the image greyscale then uses threshold to drop out the background and boost what would in this instance be the areas with infared light in.
Hope that gets you started.
Mike
Apr 28th 2009
10:37 pm
Hey thanks so much man!
I will try this out asap and get back to you with updates
later tonight when i have a chance! also thanks for the
E-mail letting me know you responded!
Also I like that you elplained what i was attempting to
do, anything to help others out and inspire people to
try news things is awesome in my mind!
-Mike
Mike
Apr 29th 2009
1:39 am
Hello again!
ok so i added the camera code to call the webcam and BINGO!
I no longer get the weird error. HOWEVER! … now all i get is a blank
stage and the camera actavates but when i use my laser pointer… nothing.
any thoughts?
here is the source again :)
Thank you!
-Mike Greenwell
Mike
Apr 29th 2009
1:50 am
and another thing, Im not sure how to assign the
bitmapData to stay on a single frame… I honestly
have little knoldge of what i am trying to do at
the moment. I would love any description of what
you mean by that!
p.s : sorry for the over use of your blog!
Thanks!
-Mike
Mike
Apr 29th 2009
4:47 am
UPDATE!!! ***
I managed to get it to work now,
The problem is it dosent stop drawing when the
laser is turned off. any help with this?
Technical Overview « iDAT 203 - Negotiated Project
Apr 29th 2009
11:00 am
[...] The other day I found someone who created a tracking system entirely in flash (follow the link) I thought this was pretty cool, it uses flash and papervision 3D to produce the graphics. [...]
Mike
May 1st 2009
7:12 am
Hello again sir!
So I was wondering in as3 Like a stated before
I wanted to make a drawing program that would
detect a laser on a wall and draw that movement…
I managed to get the tacking working and the drawings
to start working, HOWEVER i cant seem to create something
similar to a “MOUSE_up and MOUSE_down” effect. I want it
to stop drawing when the laser is turned off and it no longer detects
the motion…
here is a link to my SOURCE file…
http://www.greenwellgraphics.com/final.zip
Hit me up if you get the chance, you have been
quite the swell guy thus far! thanks for all the help dudddde!
-Mike Greenwell
SOULWIRE! «
May 4th 2009
9:10 pm
[...] http://blog.soulwire.co.uk Posted by joshshard Filed in Code, Motion Tracking No Comments » [...]
molo
May 15th 2009
4:44 pm
Hi Soulwire,
just wanted to let you know that I uploaded a video on vimeo of my installation prototype here: http://vimeo.com/4653071
Actually it’s a quite old version of the application which is a simple game for collecting bubbles. But it’s the only footage I have at the moment. Again lots of props to you for uploading your code and make it possible for me to play around with this.
A little while ago I asked you about a video or photos of your installation. Is there one now somewhere on the web (youtube/ vimeo/ flickr)? Sorry for bothering again, I know how long it takes to make a video. Just asking if I missed it.
Soulwire
May 15th 2009
4:51 pm
Hey Molo,
Good work. The installation looks awesome and its a nice concept. Cheers for the mention too, thats really good of you. So where did you exhibit it?
Unfortunately the only video is the once on this page. The shots from the installation didn’t come out too well but it was basically the app above with the tentacles that followed people as they moved past.
Cheers for the update - keep up the good work :)
ashwin royan
May 16th 2009
4:41 pm
Hello again!,
amazing stuff! an idea, would it be possible to combine your music visualisation with this; ie generate the visualisation at the point this motion detector generates? that would be pretty awesome.
harry
May 17th 2009
9:54 am
Can I stop the motion webcam and take the snapshot as an image.
Thanks.
myboodesign.com
molo
May 17th 2009
10:07 pm
Actually this was part of my final thesis at uni, so it hasn’t been exhibited yet. I also know that I’m far away to what’s possible and the final app is still in progress.
My former concept included a silhouette of the user for a better usability. But as you know, flash is not (yet) hardware accelerated enough to manage full screen video with complex animations. Maybe a better programming would do it. But there’s just so much and better ways to do it (vvvv, processing, openFrameworks) so flash was a nice beginning for me I think.
I contacted an agency the other day that did kind of the same stuff with flash… and I don’t know how, but they managed it: (skip to 1:40 in the video)
http://www.moccu.com/sc/de/#/Referenzen/Digital_im_Raum/Volkswagen_-_Volkswagen_startklar/Slide_1/
jim
May 23rd 2009
3:58 am
Im attempting to make a movie clip play in my flash file, and pause whenever motion is being detected, any ideas on how to achieve this?
i assume i would be using this line:
// If there is enough movement (see the MotionTracker’s minArea property) then continue
if ( !_motionTracker.hasMovement ) return;
VonRamsey
May 23rd 2009
11:28 am
Hi Windle, i know you are very busy. I’m can’t wait for the V2? When will you surprise us ;) Have a lot of fun.
Ann
May 29th 2009
1:10 pm
Hi, this is really good.
Do you by any chance know how to tell flash to use that motion detection to control a ball? like if i moved to the left a ball on the stage will move left just like ur tracker?
MOLO
May 30th 2009
10:11 am
This question was already answered above…
just attach the coordinates of your movieclip to the x- and y-values of the tracker:
:
Soulwire
Sep 9th 2008
9:22 am
============
Hi Saymaad,
All you would have to do is use the x / y values of the tracker to position a movieclip.
For example:
// In your class members definition
public var mc:MovieClip;
// In your constructor
mc = addChild( new MovieClip ) as MovieClip;
// Then in the timer or enterFrame event where your tracker is updated…
mc.x = tracker.x;
mc.y = tracker.y;
You can’t take control of the mouse, but one solution is to hide the mouse and use an asset which looks like a cursor and position it using the same technique.
Dan
Jun 2nd 2009
2:35 pm
High five, buddy! VERY smooth!
ILP – 10 « Interactive Lasershow Project
Jun 3rd 2009
6:03 pm
[...] motion tracking / object herkenning classes en informatie: http://www.anc.ed.ac.uk/demos/tracker/ http://blog.soulwire.co.uk/flash/actionscript-3/webcam-motion-detection-tracking/ http://sourceforge.net/projects/opencvlibrary/ (meest gebruikt voor beeld herkenning) [...]
[Actionscript 3] Motion-Tracking - FlepStudio forum
Jun 13th 2009
6:34 pm
[...] Ciao, ho trovato il file as, in as3 e as2 per il motion Tracking a questo indirizzo: Flash AS3 Webcam Motion Tracking | Detecting and tracking webcam movement prova a darci un’occhiata….. volevo chiederti, ma il movimento
PeauProductions
Jun 14th 2009
11:05 pm
Hey man,
So as has been said once or twice above, I cant figure out how to mirror the image so that when the webcamera is on top of my head, it sees and moves exactly as my head does when it moves side to side.
The line:
//We flip the input as we want a mirror image
_motionTracker.flipInput = true;
does nothing to change the capture image. It may do something to the image that is usually on the right side of the screen, but I have gotten rid of that as I only needed a small flash app that showed a webcam’s view (with some adjustments like brightness). Please let me know ASAP, thanks!
-Nolan
Soulwire
Jun 14th 2009
11:38 pm
Hey Nolan,
Yeah, the image on the left is the raw input (plus filters) and won’t be flipped when you set the fipInput parameter. The flipping on the right hand side (tracking image) is done by modifying the matrix used to draw the source image to the tracking BitmapData.
If you look in Main.as, the _source Bitmap is being flipped by default - in the lines that set it’s scaleX property to -1 and then offset it’s x position. You can delete these to stop it being flipped, or flip it on the y axis by changing scaleX to scaleY and x = camW to y = camH. Is that what you meant?
PeauProductions
Jun 15th 2009
1:27 am
Awesome man :)
I had seen the scale thing and had changed it to a positive 1 but it didnt work. Got that working now.
Another thing, for future use if I need it. I have tried to change the default values for the filters, like say brightness. I have changed that values easily using the colourmatrix file default values, but when I launch the swf, the values haven’t changed, and when I use the buttons to increase/decrease, the image reverts back to what the values are (not the values I’ve changed them to). How do I make them all talk to each other?
PeauProductions
Jun 15th 2009
2:16 am
Oh and another thing, how do I show only a black and white image from the input webcam?
bert
Jun 17th 2009
1:24 pm
hi people,
how can i change this script so my webcam will play a movie on motion
like the adobe cs3 interactive wall.
im stuck here so please help me :)
greatings
bert
Kunteking
Jul 2nd 2009
6:04 pm
Hi there,
I was waiting for the v2 long time? Are you ready to share it with the world?
Leave a Reply