Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Brightness tracking on background image

$
0
0

Hello, I wanted to make interactive brightness tracking - same as here https://processing.org/examples/brightness.html, but use video to track brightness (so I can shine on the camera to reveal the image). I was not able to put this example with brightness tracking example in processing library together. Or just make an ellipse with blurred edges and the rest of the image black?

/** * Brightness Tracking * by Golan Levin. * * Tracks the brightest pixel in a live video signal. */

PImage bg;
int y;
import processing.video.*;

Capture video;

void setup() {
  size(640, 480);
  video = new Capture(this, width, height);
  video.start();  
  bg = loadImage("02.jpg");
  noStroke();
  smooth();
}

void draw() {

  if (video.available()) {
    video.read();
    background(bg);
    image(video, 0, 0, 20, 20); 
    int brightestX = 0; 
    int brightestY = 0; 
    float brightestValue = 0;
    video.loadPixels();
    int index = 0;
    for (int y = 0; y < video.height; y++) {
      for (int x = 0; x < video.width; x++) {
        int pixelValue = video.pixels[index];
        float pixelBrightness = brightness(pixelValue);

        if (pixelBrightness > brightestValue) {
          brightestValue = pixelBrightness;
          brightestY = y;
          brightestX = x;
        }
        index++;
      }

    }
    fill(255, 204, 0, 80);
    ellipse(brightestX, brightestY, 250, 250);

  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles