Mask on video
in
Contributed Library Questions
•
6 months ago
Hello,
I hope someone can help me.
I want to make a mask tool for on a movie, first i draw on a movie then save that as a png and then load that in a keystone.
I have the code but i get a error: The pixels array is null.
This is the code:
import deadpixel.keystone.*;
import processing.video.*;
Keystone ks;
CornerPinSurface surface;
PGraphics offscreen;
Movie mov;
boolean a = false;
PImage mask;
PGraphics topLayer;
void setup() {
// Keystone will only work with P3D or OPENGL renderers,
// since it relies on texture mapping to deform
size(800, 600, P3D);
ks = new Keystone(this);
surface = ks.createCornerPinSurface( 550, 400,10);
mask = loadImage("mask.png");
// We need an offscreen buffer to draw the surface we
// want projected
// note that we're matching the resolution of the
// CornerPinSurface.
// (The offscreen buffer can be P2D or P3D)
offscreen = createGraphics(550, 400, P2D);
topLayer = createGraphics(width, height, g.getClass().getName());
mov = new Movie(this, "animatie.mov");
mov.loop();
}
void movieEvent(Movie movie) {
mov.read();
}
void draw() {
// Convert the mouse coordinate into surface coordinates
// this will allow you to use mouse events inside the
// surface from your screen.
PVector surfaceMouse = surface.getTransformedMouse();
image(mov, 0,0, width, height);
topLayer.beginDraw();
topLayer.fill(1);
topLayer.ellipse( pmouseX, pmouseY, 50, 50 );
topLayer.endDraw();
image( topLayer, 0, 0 );
if (a) {
// Draw the scene, offscreen
background(0);
offscreen.beginDraw();
offscreen. image(mov,0,0);
offscreen.endDraw();
image(mask,0,0);
}
// most likely, you'll want a black background to minimize
// bleeding around your projection area
background(0);
// render the scene, transformed using the corner pin surface
surface.render(offscreen);
}
void keyPressed() {
switch(key) {
case 'c':
// enter/leave calibration mode, where surfaces can be warped
// and moved
ks.toggleCalibration();
break;
case 'l':
// loads the saved layout
ks.load();
break;
case 's':
// saves the layout
ks.save();
break;
case 'a':
// saves the layout
topLayer.save(" mask.png" );
break;
case 'q':
// saves the layout
a = true;
break;
}
I hope someone can help me.
I want to make a mask tool for on a movie, first i draw on a movie then save that as a png and then load that in a keystone.
I have the code but i get a error: The pixels array is null.
This is the code:
import deadpixel.keystone.*;
import processing.video.*;
Keystone ks;
CornerPinSurface surface;
PGraphics offscreen;
Movie mov;
boolean a = false;
PImage mask;
PGraphics topLayer;
void setup() {
// Keystone will only work with P3D or OPENGL renderers,
// since it relies on texture mapping to deform
size(800, 600, P3D);
ks = new Keystone(this);
surface = ks.createCornerPinSurface( 550, 400,10);
mask = loadImage("mask.png");
// We need an offscreen buffer to draw the surface we
// want projected
// note that we're matching the resolution of the
// CornerPinSurface.
// (The offscreen buffer can be P2D or P3D)
offscreen = createGraphics(550, 400, P2D);
topLayer = createGraphics(width, height, g.getClass().getName());
mov = new Movie(this, "animatie.mov");
mov.loop();
}
void movieEvent(Movie movie) {
mov.read();
}
void draw() {
// Convert the mouse coordinate into surface coordinates
// this will allow you to use mouse events inside the
// surface from your screen.
PVector surfaceMouse = surface.getTransformedMouse();
image(mov, 0,0, width, height);
topLayer.beginDraw();
topLayer.fill(1);
topLayer.ellipse( pmouseX, pmouseY, 50, 50 );
topLayer.endDraw();
image( topLayer, 0, 0 );
if (a) {
// Draw the scene, offscreen
background(0);
offscreen.beginDraw();
offscreen. image(mov,0,0);
offscreen.endDraw();
image(mask,0,0);
}
// most likely, you'll want a black background to minimize
// bleeding around your projection area
background(0);
// render the scene, transformed using the corner pin surface
surface.render(offscreen);
}
void keyPressed() {
switch(key) {
case 'c':
// enter/leave calibration mode, where surfaces can be warped
// and moved
ks.toggleCalibration();
break;
case 'l':
// loads the saved layout
ks.load();
break;
case 's':
// saves the layout
ks.save();
break;
case 'a':
// saves the layout
topLayer.save(" mask.png" );
break;
case 'q':
// saves the layout
a = true;
break;
}
1