please format code with </> button * homework policy * asking questions
I am new to processing and I had doubts when creating a code for a project.
I want that detecting the face with the camera produces changes in the pixels of a video that I import. The camera detects my face and the brightness changes but the video is not seen. I don’t know if it can’t or I’m not applying the code well.
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
Capture video;
OpenCV opencv;
Movie film;
void setup() {
size(320, 240);
video = new Capture(this, 320, 240);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
video.start();
film= new Movie(this, "Secuencia 01.mov");
film.loop();
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
scale(2);
opencv.loadImage(video);
loadPixels();
video.loadPixels();
noFill();
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] faces = opencv.detect();
println(faces.length);
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;
float r = red (video.pixels[loc]);
float g = green(video.pixels[loc]);
float b = blue (video.pixels[loc]);
for (int i = 0; i < faces.length; i++) {
println(faces[i].x + "," + faces[i].y);
float d = dist(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
float adjustbrightness = map(d, 0, 100, 4, 0);
r *= adjustbrightness;
g *= adjustbrightness;
b *= adjustbrightness;
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
color c = color(r, g, b);
pixels[loc] = c;
}
} }
updatePixels();
}