User Tools

Site Tools

<Tutorial Program 6>

Due Date: 10/29/2009

THESE SKETCHES DO NOT WORK AS APPLETS because they utilize the user's video camera. Sorry.

Problem: Key in each of the four Processing examples at the end of the chapter and experiment with them. Understand the basic idea behind:

  • Frame differencing:

  • Background subtraction:

  • Brightness thresholding:

  • Brightness tracking (a penlight does nicely here):

You can experiment with these as much as you like, but focus on one algorithm and provide a writeup describing what you tried and the results. Be prepared to demonstrate in class.

Writeup: Brightness tracking

     In fiddling around with the four different algorithms, none seemed to me more entertaining than brightness tracking. Copying the code directly from p. 560 of the Reas and Fry Processing textbook, the program works by going through the pixels array and comparing each pixel to the previous, specifically, its brightness. If one pixel has a greater brightness value than a pixel before it, then a variable int brightestValue is assigned the brightness value of this new, brighter pixel. The program continues in this fashion until the end of the pixels array has been met. At this point, the pixel with the highest brightness value has been found for the first sweep through the pixels array. Since these pixels are obtained from a video camera, each sweep through the pixels array is actually just going through one still of the video. As the video is updated and refreshed per the frame rate, the sketch will need to work its way through the pixels array once for each frame, rediscovering the brightest pixel each time. It is very unlikely in a video shot involving the tiniest bit of motion (e.g. one with living, breathing people in the frame) that the brightest pixel will remain the same between frames. A yellow, semi-transparent circle is drawn to the screen, to mark the location of the brightest pixel.

     I modified the sketch to track not the brightest pixel, but the pixels with the greatest amounts of red, green, and blue. The sketch tracked these using an almost identical method as was used for brightness: whereas before, the method was to go through the pixels array and compare the brightness of each pixel to the one previous to it using brightness(), the new method used approximations of red(), green(), and blue(). Specifically, it used the shift right logical (>>) and bitwise-AND (&) operators to manipulate the binary representations of the pixels' colors more directly, and thus more quickly. Red, green, and blue semi-transparent circles are drawn to represent the pixels with the highest red, green, and blue values, respectively. The sketch also draws a white, semi-transparent triangle. The x- and y-coordinates of its corners are determined by the x and y values of the reddest, greenest, and bluest pixels.

</Tutorial Program 6>

cs276/ · Last modified: 2009/10/27 01:26 by wikiwikwik