How to Mask an Image of a Live Capture

Hi everyone, I'm a beginner with Processing, and I am trying to make a code that involves facial capture through a webcam on my laptop. The camera feed is being fed into an image at the end of my code, but is there any way I could apply a mask to this image? Any help would be really appreciated, thanks!

import gab.opencv.*; import java.awt.Rectangle; import processing.video.*; OpenCV opencv; Rectangle[] faces; Capture video; PImage img, mask;

void setup() {

size(640, 360); background(0);

video = new Capture(this, width, height); video.start();
noStroke(); smooth(); opencv = new OpenCV(this, width, height); opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);

}

void draw() {

if (video.available()) {

video.read();
PImage mask = loadImage("radial1.png");
opencv.loadImage(video);
video.loadPixels();
noFill();
stroke(0, 255, 0);
strokeWeight(3);
faces = opencv.detect();
video.mask(mask); //<--Recieves NullPointerException error
for (int i = 0; i < faces.length; i++) { //facedraw
  image(video, 200, 200, 150, 150, (faces[+i].x)+1, faces[+i].y+1, (faces[i].width)+faces[i].x, (faces[+i].height)+faces[i].y);
}

} }

Answers

  • Does your .png image have the same image dimension as your video?

    Kf

  • I believe so, I set width and height of the video to be equal to the size of the window (640,360). The .png has those same dimensions

Sign In or Register to comment.