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.
IndexProgramming Questions & HelpOther Libraries › imageadjuster & Video
Page Index Toggle Pages: 1
imageadjuster & Video (Read 668 times)
imageadjuster & Video
Mar 25th, 2008, 9:53am
 
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);
}

Re: imageadjuster & Video
Reply #1 - Mar 25th, 2008, 9:18pm
 
It's not entirely clear what isn't working, is it "when I click a color on the adjusted side, it no longer matches and masks any colors"?  If so, and this is just a guess, but...

 When you click the mouse, you're get()'ing the color from the screen (not the video).  But when you look for the color you're looking in the original video pixels.  So if you were to click on the left side of the screen and pick a high-contrast color, you might not find that color in the video pixels.  If that is the problem, then you should either get() the original color from the video, or match the pixels from the adjusted screen - do one or the other, not both, so that the two sources match.  (or, a third option, pass your video as the argument to adjust.contrast() and have the video pixels themselves updated, you'd then probably want to move it so that it occurs before image()'ing it to the screen, doing it this way you'll have the same adjusted pixels in your video AND screen, avoiding the problem entirely)
Re: imageadjuster & Video
Reply #2 - Mar 26th, 2008, 12:53pm
 
@davbol: thank you for your answer!

I now understand my mistake.

I give you a short explanation why i adjust the contrast: i want to track a specified color in the image from the cam, but as you know an object not just had ONE color it have gradients, i increase the contrast to compress the gradients to nearly one color. So i want to click on the adjusted image and mark that color in the image.

Your third options sounds good, but how can i update the video pixels themselves? I thought the lib update just the image on the screen.
Re: imageadjuster & Video
Reply #3 - Mar 26th, 2008, 3:26pm
 
the Movie/Capture classes extends PIMage and are a perfect "fit" for the adjuster routines (in fact, that library was mainly targeted for video-related uses)  So something like this at the top of draw:

video.read();
adjust.contrast(video, ..whatever..); // adjust video directly
image(video,0,0); // show adjusted video
// video AND screen now both have adjusted pixels[]
Re: imageadjuster & Video
Reply #4 - Mar 26th, 2008, 3:40pm
 
It works nice and smooth! Thank you again davbol!
Page Index Toggle Pages: 1