We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, mates. I am kinda really new in Processing, but some things I already know and try to use it. Recently found an example
of changing brightness of camera's pixels (it's like a flashlight). The code works, all fine and nice. But when I try to change the size of window(not camera), it ruins evething (photo).
And don't know what to do. And one more thing what i saw. First we load all pixels, then cam.pixels. And in (loop in loop) we work with camera's pixels, but when we update Pixels, we update all pixels, not only from camera. And when i try to write cam.pixels[loc] = c; or cam.updatePixels();
it doesn't work, just gray screen. Could you help me or if know( i didn't found) links with similar problems. Thanks in advance.
import processing.video.*;
// Step 2. Declare a Capture object
Capture video;
void setup() {
size(500, 500);
video = new Capture(this, 320, 240,30);
video.start();
}
// An event for when a new frame is available
void captureEvent(Capture video) {
// Step 4. Read the image from the camera.
video.read();
}
void draw() {
loadPixels();
video.loadPixels();
for (int x = 0; x < video.width; x++) {
for (int y = 0; y < video.height; y++) {
// Calculate the 1D location from a 2D grid
int loc = x + y*video.width;
// Get the R,G,B values from image
float r, g, b;
r = red (video.pixels[loc]);
g = green(video.pixels[loc]);
b = blue (video.pixels[loc]);
// Calculate an amount to change brightness based on proximity to the mouse
float d = dist(x, y, mouseX, mouseY);
float adjustbrightness = map(d, 0, 100, 4, 0);
r *= adjustbrightness;
g *= adjustbrightness;
b *= adjustbrightness;
// Constrain RGB to make sure they are within 0-255 color range
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
// Make a new color and set pixel in the window
color c = color(r, g, b);
pixels[loc] = c;
}
} updatePixels();
}
Answers
you are reading from the camera which is 320 pixels wide but writing to the screen which is 500 pixels wide
input
output
etc
But how (I beg your pardon) use only camera's pixels on the screen? I tried to write
video.pixels[loc] = c
but nothing. So....I guess I need to create a new canvas withcreateGraphics
on the screen and write it there? Or not?what you have is fine. you just need to ensure your output wraps where your input does. try replacing line 49 with:
(untested)
Dear savior, Thank you a lot ;;)