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
project to be done -HELP (Read 888 times)
project to be done -HELP
Dec 3rd, 2006, 9:30pm
 
The basic concept is, when somebody enters a black room, the camera(which will be connected to the computer) will recognize the figure, and then with the processing analyzing/understanding it, according to the height of the person, a musical instrument will be generated and be projected on the wall.

For example when a short man enters the room, a violin will appear on the wall, but if a tall man enters, a guitar or another musical instrument will be generated and projected.

I have searched the libraries and i have found ones that will probably help me but the main question, is how will the program in the processing understand the figure and how can I make a grid on the picture from the camera and give the program to understand where the person is and what instrument will be projected.

Can anybody help me to set up the code in the processing, or give ideas I can use to search alone and make it?I know it is difficult and the problem is that I have just started, as I mentioned in the previous topic, so I do not know much to develop my idea.

Thanks in advance.
Re: project to be done -HELP
Reply #1 - Dec 4th, 2006, 1:04pm
 
I've done this before. And it doesn't use any libraries, it's quite simple.

First off you need a specific color for your background. One which is guaranteed to clash with all visitors. Then you need to examine the change in color of the pixels and draw a line at the highest point. The following code illustrates this principle but examines the pixels on screen. You're going to have to modify it to work with a camera.

To use it with a camera you need to be checking "myCapture.pixels" as opposed to pixels.
Code:

int threshold = 100; // set this higher to make it less sensitive

void setup() {
size(640, 480);
loadPixels();
stroke(255);
}

void draw(){
background(0);
ellipse(mouseX, mouseY, 50, 50);
int y = diffMountain();
line(0, y, width, y);
}

// This method uses XOR to find the difference between two colors
// (At least I think it does)
int diffMountain(){
int peak = height;
int speed = 16;
int [] oldPixels = new int[pixels.length];
arraycopy(pixels, oldPixels);
loadPixels();
for(int y = 0; y < height; y++){
int diff = 0;
for(int x = 0; x < width; x+=speed){
diff += oldPixels[x + y * width]^pixels[x + y * width];
}
if(diff > threshold){
peak = y;
// println(diff); // This line can help you judge what threshold you should be using
break;
}
}
return peak;
}

Notice how the horizontal line only appears when you move the mouse.

Try experimenting with different threshold values, those will help counter the auto-adjust on most webcams.

If you get stuck just ask again.
Page Index Toggle Pages: 1