#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Brightness tracking on background image

edited March 2018

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);

}
}
``````
Tagged:

## Answers

• Answer ✓

One question: Why do you have your video constrain in a 20 by 20 pixel grid?

I was not able to put this example with brightness tracking example in processing library together

Please describe what problem you observed. In my case, if I use the whole canvas to show the video, the code works as advertised. Notice your code will always find a brighter spot in your image. If you want to uncover the image after certain brightness event, then you need to teach the program what to look for aka. what brightness should it detect to trigger showing the background. Here is where I will add a timer to show the background for certain amount of time before the code resets and waits for the next signal.

Kf

• Answer ✓

I'm not quite sure what you are trying to do -- are you trying to shine a flashlight to scrape away black and reveal a hidden image?

1. Load a hidden image `PImage hidden`
2. Create an empty mask `PGraphics mask`
3. Draw a faded circle on the mask centered on the brightest point on the camera (if it is brighter than x)
4. Apply the mask
5. Draw the masked image

Over time, this will draw more and more areas on the mask, showing more and more of the masked image.

• Hello, Yes, this is exactly what I wanted. Thank you

Sign In or Register to comment.