How to Fullscreen Window a LowRes Webcam and Background Remove live ? No so easy as its sounds..

edited May 2015 in Library Questions

I am using this code to achieve Background Remove in processing:

https://github.com/shiffman/LearningProcessing/blob/master/chp16_video/example_16_12_BackgroundRemove/example_16_12_BackgroundRemove.pde#L1

Which works like a charm. WHAT I WANT TO is that Processing window becomes FULL SCREEN simultaneously.

But, things is, when I try to change the size of the window Processing warms me that:

The requested resolution of "x" is not supported by the selected capture device.

or in other franksteinian mixing codes I tried (which one are a shame to show) things like: ArrayIndexOutOfBoundsException> or Could not run the sketch (Target VM failed to initialize).> And in the best of the cases a get the same video image repeating through the width. I tried what its discussed here:

http://forum.processing.org/two/discussion/10894/how-do-i-resize-the-output-of-my-capture-video

Trying to adapt the code to my case, but seems like the line

 color bgColor = backgroundImage.pixels[loc];

awake some error.

Thanks in advance, I am getting crazy with this easy trouble!

Answers

  • edited May 2015

    AFAIK, in order to know which cameras and resolutions are available, we use:
    printArray(Capture.list());

    Take a look at this recent forum thread:
    http://forum.processing.org/two/discussion/10541/problems-with-video

    There are some resize() techniques there! B-)

  • edited May 2015

    Well, first of all, thanks for taking the time! I already checked that thread but I tryed again after you wrote it.

    I have to say that I can make that Capture becomes FullScreen, but not at the same time I am removing the background...maybe too many data to process?

    This is my initial code to remove background:

    // Learning Processing
    // Daniel Shiffman
    // http://www.learningprocessing.com
    
    // Exercise 16-6: Instead of replacing the background with green pixels,           replace it with another 
    // image. What values work well for threshold and what values do not work at all? Try 
    // controlling the threshold variable with the mouse.   
    
    
    // Click the mouse to memorize a current background image
    import processing.video.*;
    
        // Variable for capture device
    Capture video;
    
    // Saved background
    PImage backgroundImage;
    
    PImage backgroundReplace;
    
    // How different must a pixel be to be a foreground pixel
    float threshold = 80;
    
    void setup() {
      size(640, 480);
     video = new Capture(this, width, height, 30);
      video.start();
    
      // Create an empty image the same size as the video
      backgroundImage = createImage(video.width, video.height, RGB);
      backgroundReplace = loadImage("beach.jpg");
    }
    
    // New frame available from camera
    void captureEvent(Capture video) {
      video.read();
    }
    
    
    void draw() {
    
    
      // We are looking at the video's pixels, the memorized backgroundImage's     pixels, as well as accessing the display pixels. 
      // So we must loadPixels() for all!
      loadPixels();
      video.loadPixels(); 
      backgroundImage.loadPixels();
    
      // Begin loop to walk through every pixel
      for (int x = 0; x < video.width; x ++ ) {
        for (int y = 0; y < video.height; y ++ ) {
          int loc = x + y*video.width; // Step 1, what is the 1D pixel location
          color fgColor = video.pixels[loc]; // Step 2, what is the foreground color
    
          // Step 3, what is the background color
          color bgColor = backgroundImage.pixels[loc];
    
          // Step 4, compare the foreground and background color
          float r1 = red(fgColor);
          float g1 = green(fgColor);
          float b1 = blue(fgColor);
          float r2 = red(bgColor);
          float g2 = green(bgColor);
          float b2 = blue(bgColor);
          float diff = dist(r1, g1, b1, r2, g2, b2);
    
          // Step 5, Is the foreground color different from the background color
          if (diff > threshold) {
            // If so, display the foreground color
            pixels[loc] = fgColor;
          } else {
            // If not, display the beach scene
            pixels[loc] = backgroundReplace.pixels[loc];
          }
        }
      }
      updatePixels();
    }
    
    void mousePressed() {
      // Copying the current frame of video into the backgroundImage object
      // Note copy takes 5 arguments:
      // The source image
      // x,y,width, and height of region to be copied from the source
      // x,y,width, and height of copy destination
      backgroundImage.copy(video, 0, 0, video.width, video.height, 0, 0,     video.width, video.height);
      backgroundImage.updatePixels();
    }
    

    So I edited the line 26 inside void setup about the video, like this:

     video = new Capture(this);
    

    So now give me this error: (java.exe:6624): GStreamer-CRITICAL **: _gst_util_uint64_scale_int: assertion `denom > 0' failed

    To infinity. And inside void draw, highlight the line 56 :

          color bgColor = backgroundImage.pixels[loc];
    

    How make fullscreen (THE SKETCH WINDOW, not just the video) the Removal Background from a webcam?

Sign In or Register to comment.