Detecting hands with a webcam
in
Programming Questions
•
1 year ago
Hey, I'm trying to make an interactive sketch where the user can pop bubbles with their hands on screen using the imported webcam feed. I can detect different colour and saturation pixels but I was wondering whether it was possible to detect just a hand without making the user wear anything special?
This is what I use to detect motion at the moment:
- for (int x = 0; x < video.width; x ++ ) {
- for (int y = 0; y < video.height; y ++ ) {
- int loc = x + y*video.width; // Step 1, what is the 1D pixel location
- color current = video.pixels[loc]; // Step 2, what is the current color
- color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color
- // Step 4, compare colors (previous vs. current)
- float r1 = red(current);
- float g1 = green(current);
- float b1 = blue(current);
- float r2 = red(previous);
- float g2 = green(previous);
- float b2 = blue(previous);
- float diff = dist(r1, g1, b1, r2, g2, b2);
- // Step 5, How different are the colors?
- // If the color at that pixel has changed, then there is motion at that pixel.
- if (diff > threshold) {
- // If motion, display black
- pixels[loc] = color(0);
- soundCount--;
- }
- else {
- // If not, display white
- pixels[loc] = color(255);
- }
- }
- }
- updatePixels();
- float freq = map(soundCount, 0, height, 3000, 60);
- sine.setFreq(freq);
- float pan = map(soundCount, 0, width, -1, 1);
- sine.setPan(pan);
- }
I use that to detect if something's moving and then output a sine wave using values from that.
Thanks
1