Is there a possibility to count/catch/control the Pixels from a webcamvideo?
in
Core Library Questions
•
1 year ago
Hi everyone,
I would like to know if there is a way to count, catch or control the pixels (in this example). The example already distinguishes
the bright pixels and set them into white and the darker pixels and put them into black.
For my purpose It would suffice to set the background to black an only let the program put the white pixels (but that makes my sketch flicker),
and eventually count/catch/control only the white pixels for further use.
My Plan is to further work with my pixels like in the following sketch:
I want the white pixels to be able to move around and be pushed with e.g. a key and then find their original position again.
I don´t know if my idea to control the pixels is the right way or I have to start totally different.
I would be happy about any little clue, idea, experience or link that might help me.
Thanks! :)
This is the Brightness Thresholding Example (only making white pixels)
import processing.video.*;
color black = color(0);
color white = color(255);
int numPixels;
Capture video;
void setup() {
size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
strokeWeight(5);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height, 24);
numPixels = video.width * video.height;
noCursor();
smooth();
}
void draw() {
background(0);
if (video.available()) {
video.read();
video.loadPixels();
int threshold = 127; // Set the threshold value
float pixelBrightness; // Declare variable to store a pixel's color
// Turn each pixel in the video frame black or white depending on its brightness
loadPixels();
for (int i = 0; i < numPixels; i++) {
pixelBrightness = brightness(video.pixels[i]);
if (pixelBrightness > threshold) { // If the pixel is brighter than the
pixels[i] = white; // threshold value, make it white
}
// else { // Otherwise,
// pixels[i] = black; // make it black
// }
}
updatePixels();
}
}
1