How do I resize the output of my capture video?

edited May 2015 in How To...

I've got a project that uses the webcam of my laptop, but the output window is really small. I've tried to use a bigger resolution, but that still only makes it a little bigger. I want it to be full screen, is there a function I could use to get that? I'm fine with it being a small resolution, I just want to scale the output to fit the width of my screen. I've tried using size(displayWidth, displayHeight); in the setup{} but then I get the error message that the resolution 1920x1080 is not supported by the selected output device. Does anyone have an idea for how to fix this?

Answers

  • edited May 2015

    Try this

    void setup() {
      size(displayWidth, displayHeight);
    }
    

    But try to run the sketch with Sketch -> Present.

    From here.

  • edited May 2015

    Ok I put in displayWidth and -Height again, and tried to run it with Sketch -> Present, but then nothing happens apart from my screen going grey, and if I try to do anything, java crashes.. is there anything else I might need to put in?

    void setup() {
      size(displayWidth, displayHeight);
      video = new Capture(this, width, height);
      video.start();
    }
    
  • edited May 2015

    Using this:

            void setup() {
              size(1280, 720);  
              if (frame != null) {
              frame.setResizable(true);
              }
              video = new Capture(this, width, height);
              video.start();
              }
    

    and the regular run-button, I managed to get my window fullscreen, but half of the window is now empty, as opposed to the whole video being bigger; also, the video is now repeated three times, which I'm also not sure why it's doing that.. any ideas? screenshot

  • edited May 2015

    How about this 1?: >-)

    // forum.processing.org/two/discussion/10894/
    // how-do-i-resize-the-output-of-my-capture-video
    
    // 2015-May-19
    
    import processing.video.Capture;
    Capture c;
    
    volatile PImage img;
    
    void setup() {
      size(1280, 720, JAVA2D);
      noLoop();
      frameRate(40);
    
      String[] cams = Capture.list();
      printArray(cams);
    
      (c = new Capture(this, cams[1])).start();
      while (img == null || img.width != width)  delay(10);
    }
    
    void draw() {
      background(img);
      frame.setTitle(str(round(frameRate)));
    }
    
    void captureEvent(Capture capture) {
      capture.read();
    
      PImage pic = capture.get();
      pic.resize(width, height);
      img = pic;
    
      redraw = true;
    }
    
  • edited May 2015

    Another similar 1: :(|)

    // forum.processing.org/two/discussion/10894/
    // how-do-i-resize-the-output-of-my-capture-video
    
    // 2015-May-19
    
    import processing.video.Capture;
    Capture c;
    
    void setup() {
      size(1280, 720, JAVA2D);
      noLoop();
      frameRate(40);
    
      String[] cams = Capture.list();
      printArray(cams);
    
      (c = new Capture(this, cams[1])).start();
      while (c.width == 0)  delay(10);
    }
    
    void draw() {
      PImage img = c.get();
      img.resize(width, height);
    
      background(img);
      frame.setTitle(str(round(frameRate)));
    }
    
    void captureEvent(Capture capture) {
      capture.read();
      redraw = true;
    }
    
  • Both of those codes just created a bigger output window for me, but not a fullscreen one. I was kind of hoping that there was some kind of resize() function, I don't mind the resolution being really bad, I just need it to be fullscreen.

    I found this bit of code on here

    boolean sketchFullScreen() {
      return true;
    }
    

    which creates a fullscreen window, but leaves a thick grey boarder around my video, which I'm not sure why it's doing that..

  • So this doesn't work for you?

    import processing.video.Capture;
    Capture c;
    
    void setup() {
      size(displayWidth, displayHeight); 
      String[] cams = Capture.list();
      printArray(cams);
      c = new Capture(this, cams[1]);
      c.start();
    }
    
    void draw() {
      background(0);
      image(c, 0, 0, width, height);
    }
    
    void captureEvent(Capture capture) {
      capture.read();
    }
    boolean sketchFullScreen() {
      return true;
    }
    
  • edited May 2015

    I tried out your code on its own, and it worked fine, (thankyou!!) but then I tried to fit it into my code, and the screen just went black (because of the background I'm assuming), so I think I've made a mistake somewhere.. maybe to do with the layering of the background/capture? But I'm not sure how write it.. Before, I had everything in the event() function in my draw() function, but I've split that bit up, like in your code. What else do I need to do?

    import processing.video.*;
    
    Capture video;
    
    PImage prevFrame;
    float threshold = 50;
    
    void setup() {
      size(displayWidth, displayHeight);
        String[] cams = Capture.list();
      printArray(cams);
      video = new Capture(this, cams[1]);
      prevFrame = createImage(video.width, video.height, RGB);
      video.start();
    }
    void draw() {
      background(0);
      image(video, 0, 0, width, height);
    }
    void event(){ 
      if (video.available()) {
        prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
        prevFrame.updatePixels();
        video.read();
      }
    
      loadPixels();
      video.loadPixels();
      prevFrame.loadPixels();
    
      for (int x = 0; x < video.width; x ++ ) {
        for (int y = 0; y < video.height; y ++ ) {
    
          int loc = x + y*video.width;
          color current = video.pixels[loc];
          color previous = prevFrame.pixels[loc]; 
    
          float r1 = red(current); 
          float g1 = green(current); 
          float b1 = blue(current);
          float r2 = red(previous); 
          float g2 = green(previous); 
          float b2 = blue(previous);
          float diff = dist(r1, g1, b1, r2, g2, b2);
    
    
          if (diff > threshold) { 
            pixels[loc] = color(214, 250, 250);
          } else {
            pixels[loc] = color(62, 193, 193);
          }
        }
      }
      updatePixels();
    }
    
    boolean sketchFullScreen() {
      return true;
    }
    
Sign In or Register to comment.