We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Help with masking out parts of a movie
Page Index Toggle Pages: 1
Help with masking out parts of a movie (Read 510 times)
Help with masking out parts of a movie
Apr 5th, 2007, 7:57pm
 
So I took the code from the examples that people sent me last time and used it for trying to mask my video. Now processing is giving me some kind of "NegativeArraySizeException" error. When I try to change the size of the mask...it then gives me an error that looks like "the PImage used with mask() must be the same size as the applet." I'm stuck and don't know what to do! Please help! Here's my code:

import processing.video.*;

//PImage img;
Movie doorMovie;
PImage masked;
color cp;
int xPos, yPos;
boolean doCopy = false;
int maskW, maskH;
int[] maskArray;

void setup() {
 size(320, 240);
 //img = loadImage("pic1.jpg");
 doorMovie = new Movie(this, "The Shining Door-small.mpg");
 doorMovie.loop();

 maskW = 100;
 maskH = 230;
 int arraySize = maskW * maskH;
 maskArray = new int[arraySize];

 createMaskArray();
 xPos = width/2;
 yPos = height/2;

 masked = new PImage(maskW, maskH);
 copyApplyMask();
}

void draw() {

 //image(img, 0, 0);
 image(doorMovie, 0, 0);
 background(0);
 image(masked, xPos - maskW/2, yPos - maskH/2);

}
//Called every time a new frame is available to read
void movieEvent(Movie m) {
 m.read();
}

void mouseMoved() {
 if (!(mouseX < maskW/2 || mouseX > width - maskW/2))
 {
   xPos = mouseX;
   doCopy = true;
 }
 if (!(mouseY < maskH/2 || mouseY > height - maskH/2))
 {
   yPos = mouseY;
   doCopy = true;
 }
 if (doCopy) copyApplyMask();
 doCopy = false;
}

void createMaskArray() {
 background(0);
 fill(255);
 rectMode(CORNER);
 rect(0, 0, maskW, maskH);

 loadPixels();
 for (int x = 0; x < maskW; x++)
 {
   for (int y = 0; y < maskH; y++)
   {
     maskArray[x + (y * maskW)] = pixels[x + (y * width)];  
   }
 }
 updatePixels();
}

void copyApplyMask() {
 // this is what andreas was doing translated to Processing 124
 masked = doorMovie.get(xPos - maskW/2, yPos - maskH/2, maskW, maskH);
 masked.mask(maskArray);
}


Thanks for any kind of help I can get!!
Re: Help with masking out parts of a movie
Reply #1 - Apr 5th, 2007, 10:32pm
 
There is a problem when you check the mouse coordinates. Cause you check first the mouseX and then the mouseY coordinates. But if the mouseX section is false and the mouseY gives you true toCopy will be true instead of the wrong mouseX section.
This will check all parameters at ones:
Code:

if (!(mouseX < maskW/2 || mouseX > width - maskW/2)&&!(mouseY < maskH/2 || mouseY > height - maskH/2))
{
xPos = mouseX;
yPos = mouseY;
doCopy = true;
}
Page Index Toggle Pages: 1