Wednesday, 15 February 2012

processing - Getting average color hue from specific spot via webcam -



processing - Getting average color hue from specific spot via webcam -

i'm trying color tracking in processing, , want grab average hue rectangle in center of screen, using webcam input. (i.e. if hold orange index card in rectangle area of webcam input, average hue orange)

i'm using illustration base of operations grabbing rectangle area, code keeps returning drab mix of gray, when hold single color in center of rectangle. can help point me in right direction here? or suggest alternative way grab selected rectangle's pixels color average?

http://www.learningprocessing.com/examples/chapter-16/example-16-11/

right i've got code:

void capturehue(){ if(cam.available()){ cam.read(); } loadpixels(); cam.loadpixels(); int numberofpixels = 125 * 90; // size of reddish rectangle for(int x = 337; x < 465; x++){ for(int y = 305; y < (400); y++){ int loc = x + y*(465); println ("loc:" + loc); color currentcolor = cam.pixels[loc]; r1 += red(currentcolor); g1 += green(currentcolor); b1 += blue(currentcolor); } } r2 = r1/numberofpixels; g2 = g1/numberofpixels; b2 = b1/numberofpixels; println("r1 : " + r1); println("g1 : " + g1); println("b1 : " + b1); coloraverage = color(r2, g2, b2); }

edit: turns out location tracking incorrect. works now.

int loc = x + y*465; should be: int loc = x + y*cam.width;

colors processing webcam video-capture webcam-capture

No comments:

Post a Comment