How to make the webcam capture window go away or put images over it

edited May 2016 in Library Questions

I'm using a webcam for the beginning of my project, but after a while I want to clear the screen and start a whole new page. I can probably do this by covering up the screen with a big white rectangle, however, nothing will cover up the webcam window. The camera part of my code looks like this:

String[] cameras = Capture.list(); cam = new Capture(this, cameras[000]); cam.start();

and then

void draw() { if (cam.available() == true) { cam.read(); }

Since it says if(cam.available() == true), I tried to set cam.available to false, but even that wouldn't work, giving the error, "the field capture.available is not visible." I'm very desperate.

As an alternative, does anyone know a way to make different pages, so when you click a button, it takes everything you've already done away completely? I've looked into it a lot, and found people saying setting the background(255) at the beggining of draw, or doing multiple draws, but I couldn't get it to work. I also tried the redraw() and clear() functions without any success.

PLEASE help

Answers

  • edited December 2018 Answer ✓
    /**
     * Efficient WebCam Capture (2.0.2)
     * GoToLoop (2016-May-05)
     *
     * Forum.Processing.org/two/discussion/16435/
     * how-to-make-the-webcam-capture-window-go-away-
     * or-put-images-over-it#Item_1
     *
     * GitHub.com/processing/processing-video/pull/30
     */
    
    import processing.video.Capture;
    Capture cam;
    
    static final String RENDERER = JAVA2D;
    //static final String RENDERER = FX2D;
    //static final String RENDERER = P2D;
    //static final String RENDERER = P3D;
    
    static final int CAM = 1, FPS_ADJUST = 5, DELAY = 5;
    
    void setup() {
      size(640, 480, RENDERER);
      initFeed();
    
      float canvasFPS = cam.frameRate + FPS_ADJUST;
      frameRate(canvasFPS);
    
      println("Cam's FPS:", cam.frameRate, "\t\tCanvas's FPS:", canvasFPS);
      print("Cam's size:", cam.width, 'x', cam.height, '\t');
      println("Canvas's size:", width, 'x', height);
    }
    
    void draw() {
      background(cam);
      getSurface().setTitle( str(round(frameRate)) );
    }
    
    void captureEvent(final Capture c) {
      c.read();
    }
    
    void initFeed() {
      final String[] cams = Capture.list();
      printArray(cams);
      println("\nChosen Cam #" + CAM + ':', cams[CAM], ENTER);
    
      ( cam = new Capture(this, cams[CAM]) ).start();
    
      println("cam.width: " + cam.width);
      while (cam.width == 0)  delay(DELAY);
      println("cam.width: " + cam.width + ENTER);
    
      if (cam.width > 0)  getSurface().setSize(cam.width, cam.height);
    }
    
Sign In or Register to comment.