Drawing with webcam impossbile?
in
Core Library Questions
•
3 years ago
I've tried to make something similar to the BrightnessTracking example. My goal is that you could draw silly faces on your webcam image (and finally the image would track your face). But it seems that drawing on a webcam video with ellipses doesn't work. It works when the webcam video is not drawn on the screen. Is there a workaround so that the webcam wouldn't update the whole screen?
- import processing.video.*;
- Capture video;
- void setup() {
- size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
- // Uses the default video input, see the reference if this causes an error
- video = new Capture(this, width, height, 30);
- noStroke();
- smooth();
- }
- void draw() {
- if (video.available()) {
- video.read();
- //image(video, 0, 0, width, height); Draw the webcam video onto the screen
- int brightestX = 0; // X-coordinate of the brightest video pixel
- int brightestY = 0; // Y-coordinate of the brightest video pixel
- float brightestValue = 0; // Brightness of the brightest video pixel
- // Search for the brightest pixel: For each row of pixels in the video image and
- // for each pixel in the yth row, compute each pixel's index in the video
- video.loadPixels();
- int index = 0;
- for (int y = 0; y < video.height; y++) {
- for (int x = 0; x < video.width; x++) {
- // Get the color stored in the pixel
- int pixelValue = video.pixels[index];
- // Determine the brightness of the pixel
- float pixelBrightness = brightness(pixelValue);
- // If that value is brighter than any previous, then store the
- // brightness of that pixel, as well as its (x,y) location
- if (pixelBrightness > brightestValue) {
- brightestValue = pixelBrightness;
- brightestY = y;
- brightestX = x;
- }
- index++;
- }
- }
- // Draw a large, yellow circle at the brightest pixel
- translate(width,0);
- scale(-1,1);
- fill(0, 0, 0, 255);
- ellipse(brightestX, brightestY, 20, 20);
- }
- }
2