Blob tracking
Now that you know how to apply a thresholding algorithm on a webcam feed, it's time to do some analysis on those pixels. We'll draw a rectangle around all white pixels in the image. This is a very basic brightness tracking algorithm and is useful when you want to create a simple interactive installation with a webcam.
How to do it...
We'll start by importing the video
library and declaring some variables. We need a Capture
object to access the webcam and an integer variable to use as a threshold value. The other integer variables are used to track the boundaries around the white pixels in the image.
import processing.video.*; Capture webcam; int threshold; int topLeftX; int topLeftY; int bottomRightX; int bottomRightY; void setup() { size( 640, 480 ); webcam = new Capture( this, width, height, 30); webcam.start(); threshold = 127; topLeftX = width; topLeftY = height; bottomRightX = 0; bottomRightY = 0; }
Inside the draw()
function, we'll apply the...