We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
getting color from adjusted video (Read 335 times)
getting color from adjusted video
Mar 23rd, 2008, 12:39am
 
i did this to get the color of a point in the webcam capture. It works well, but when i use the imageadjuster lib. it does not.
You can define the color by clicking on the video.
I split the video in two parts. the left part is adjusted, the right is not.
The selected color will be shown as a black overlay.

I hope you can help me to fix the problem.

Code:

import processing.video.*;
import imageadjuster.*;

ImageAdjuster adjust = new ImageAdjuster(this);
Capture video;
float RED=400;
float GREEN=400;
float BLUE=400;
color a1;
float threshold=5;

void setup() {
size(320,240);
video = new Capture(this, width, height, 30);
}

void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height); // Draw the webcam video onto the screen
video.loadPixels();

//Problem starts here:
adjust.contrast(g, 0, 0, width/2, height, 3.0f);


for(int j=0; j<video.height; j++){
for(int i=0; i<video.width; i++){
int num = (j*video.width)+i;
if( (abs(red(video.pixels[num]) - RED) <=threshold) && (abs(green(video.pixels[num]) - GREEN) <=threshold) && (abs(blue(video.pixels[num]) - BLUE)<=threshold)){
stroke(0);
point(i,j);
}
}
}
}
}

void mousePressed() {
a1=get(mouseX, mouseY);
RED=red(a1);
GREEN=green(a1);
BLUE=blue(a1);

}

void keyPressed()
{
if (key == 'A' || key == 'a') {
threshold++;
}
else if ((key == 'y' || key == 'Y')&& threshold>0) {
threshold--;
}
println("threshold= "+threshold);
}

Page Index Toggle Pages: 1