How to easily replace image with video?

edited December 2015 in Library Questions

Hi

I m a beginner to processing, and i would like to know if it would be possible to change img1 with a new movie"BD,mov". I want that move as the mask1.

Thanks for your help!!

PImage img1; PImage mask1; PImage img2; PImage mask2; import processing.video.*; Movie movie;

int threshold = 127;

color black = color(0); color white = color(255); int numPixels; Capture video;

void setup() { //size(1920,1280); size(1000, 800); strokeWeight(5);

//img1 = loadImage("bd2.jpg");

movie = new Movie(this, "bd.mov"); movie.loop(); img2 = loadImage("nagitive.jpg");

// imageMode(CENTER);

// example if it creates an error video = new Capture(this, width, height);

// Start capturing the images from the camera video.start();

numPixels = video.width * video.height; mask1 = createImage(width, height, RGB); mask2 = createImage(width, height, ALPHA); noCursor(); smooth(); }

//void mouseDragged() { //threshold = round(map(mouseX, 0, width, 0, 255)); //}

void movieEvent(Movie m) { m.read(); }

void draw() { background(0); if (video.available()) { video.read(); mask1.copy(video, 0, 0, video.width, video.height, 0, 0, mask1.width, mask1.height); numPixels = mask1.width * mask1.height; // 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 mask1.loadPixels(); mask2.loadPixels(); for (int i = 0; i < numPixels; i++) { pixelBrightness = brightness(mask1.pixels[i]); if (pixelBrightness > threshold) { // If the pixel is brighter than the mask1.pixels[i] = white; // threshold value, make it white mask2.pixels[i] = black; } else { // Otherwise, mask1.pixels[i] = black; // make it black mask2.pixels[i] = white; } } mask1.updatePixels(); mask2.updatePixels(); }

//image(mask1, 0, 0, width/2, height/2); //image(mask2, width/2, 0, width/2, height/2);

mask1.resize(movie.width, movie.height); mask2.resize(img2.width, img2.height); movie.mask(mask1); img2.mask(mask2); blendMode(ADD); //image(img1, 0, height/2, width/2, height/2); //image(img2, width/2, height/2, width/2, height/2); image(movie, 0, 0, width, height); image(img2, 0, 0, width, height); }

Sign In or Register to comment.