import processing.video.*;
Capture video;
PImage prevFrame;
void setup() {
size(640, 480); // Establece el tamaño de la ventana a 640x480 píxeles
video = new Capture(this, width, height, 30);// Crea una nueva instancia de 'Capture' y la asigna a la variable 'video'
video.start();
prevFrame = createImage(width, height, RGB);
}
void draw() {
if (video.available()) {
video.read();
background(0);// Establece el color de fondo de la ventana en negro.
loadPixels(); // Carga los píxeles de la ventana en un arreglo para poder manipularlos individualmente
video.loadPixels();
prevFrame.loadPixels();
for (int x = 0; x < video.width; x++) {
for (int y = 0; y < video.height; y++) { // Calcula la ubicación del píxel actual en los arreglos de píxeles
int loc = x + y * video.width;
float r1 = red(video.pixels[loc]);
float g1 = green(video.pixels[loc]);
float b1 = blue(video.pixels[loc]);
// Extrae los valores R, G y B del píxel actual de la captura de video.
float r2 = red(prevFrame.pixels[loc]);
float g2 = green(prevFrame.pixels[loc]);
float b2 = blue(prevFrame.pixels[loc]);
// Extrae los valores R, G y B del píxel correspondiente en el fotograma anterior
float r = r1 - r2 + 128;
float g = g1 - g2 + 128;
float b = b1 - b2 + 128;
// Calcula la diferencia entre los valores de los canales de color de los dos píxeles y les suma 128.
pixels[loc] = color(r, g, b); // Establece el color del píxel actual en la ventana con el valor RGB calculado
}
}
updatePixels();
prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
}
}
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Siempre activo
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.