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 & HelpSyntax Questions › img.mask(maskImg) problem
Page Index Toggle Pages: 1
img.mask(maskImg) problem (Read 493 times)
img.mask(maskImg) problem
Feb 5th, 2007, 11:39am
 
hi

i have a problem with image masking. why is the code down there not always working? in some cases the masking is just not working correct. after drawing a shape on the screen it should display the new captured image in only this area.


import processing.video.*;  

Capture myCapture;
PImage img;
PImage maskImg;

void captureEvent(Capture myCapture) {
 myCapture.read();
}

void setup() {
 size(320, 240);
 colorMode(RGB, 100);
 //println(myCapture.list());
 //String s = "SN9C120+OV7660 WebCam";
 myCapture = new Capture(this, 320, 240, 12);
 background(0);
 stroke(0, 255, 0);
 strokeWeight(50);
}

void draw() {
 if (mousePressed == true) {
   point(mouseX, mouseY);
 }
}


void mouseReleased() {
 maskImg = get();
 int dimension = (width*height);
 for (int i=0; i<dimension; i++) {  
   if(maskImg.pixels[i] == -16711936) {
     maskImg.pixels[i] = -1;
   }
   else {
     maskImg.pixels[i] = -16777216;
   }
 }
 img = myCapture;
 for (int i=0; i<dimension; i++) {  
   img.pixels[i] = myCapture.pixels[i];
 }
 img.mask(maskImg);
 image(img, 0, 0);
}


Page Index Toggle Pages: 1