
the older openCV library is not as fast or advanced as newer version but it is much easier to get started with and works fine for basic motion tracking. download from here: http://ubaa.net/shared/processing/opencv/index.html
note the website is old so it shows the libraries folder in a different place; the correct place is in the “libraries” folder inside your “processing” sketch folder (create it if necessary).
download the examples and run the Blob example. hopefully it will work. if it does, yay. read about openCV if you haven’t already so you understand the functions in that example, more or less (one of many tutorials, google for more – http://createdigitalmotion.com/2009/02/processing-tutorials-getting-started-with-video-processing-via-opencv/). most importantly how you need a background reference frame to compare video to so it can figure out what has changed, i.e. who or what has moved. in this example, the upper left video is raw video, the upper right is greyscale version (which speeds up calculations – although on some machines this might display as color anyway), the lower left is the background reference image, and the lower right is the Difference (live video compared to reference).
note the code tells you that hitting spacebar will record a new background image, which you should do with nothing visible in the frame, in other words, move your head out of the way and then hit space to re-calibrate. you will need to do this if anything changes in the video frame, the ambient light changes, the camera moves, anything.
once you understand the basics of code and how it makes an array of blobs, you need to get the center of the blob. if the threshold is not tuned correctly, or more than person or object is in the frame, you’ll have multiple blobs and need to decide which to pay attention to, e.g. the biggest. note you can set maximum number of blobs to 1 and it will only give you the biggest blob. the threshold is ideal when empty camera view gives you a totally black Difference, and something moving is one distinct blob. use blob.centroid to get coordinates, then you can control whatever you want using, for example, map().
getting tracking to work consistently requires experimentation with ambient lighting, timing of capturing background reference frame, blob minimum and maximum, and threshold settings. trial and error is often the most effective way to get it right. consider adding more keyboard commands to adjust parameters.







