Processing - random video array + webcam (to make security camera-type visuals)

edited November 2016 in Library Questions

I'm attempting to make the visuals for an art installation I'm working on, and I'm not quite sure how to go about it in Processing. Here's what I would like to do (I'll be using an old CCTV monitor):

  • Divide the screen into four quadrants (as if it were displaying feed from security cameras, but I'd be using videos, for the most part)

  • Have videos load randomly to those quadrants (from a total of 8 videos) and have the videos change after a certain number of seconds (they don't all have to change at once, but whatever's easiest)

  • Have a webcam send its feed into one of the quadrants as if it were another video (I can always fix the webcam to one of the fourths of the screen and load random videos onto the other 3 available quadrants, if it simplifies things.)

My Processing skills are quite basic; so far I've managed to split the screen in 4 and load 4 videos, but I honestly don't know how to work with a video array, which sounds like the more reasonable way for the program to do what I would like it to.

Here is the basic code:

import processing.video.*;

Movie mov, mov1, mov2, mov3;

void setup() {
  size(1280, 640);
  frameRate(30);
  mov = new Movie(this,"0.mov");
  mov1 = new Movie(this,"1.mov");
  mov2 = new Movie(this,"2.mov");
  mov3 = new Movie(this,"3.mov");

  mov.play();
  mov1.play();
  mov2.play();
  mov3.play();

  mov.volume(0);
  mov1.volume(0);
  mov2.volume(0);
  mov3.volume(0);
}

void movieEvent(Movie mov) {
  mov.read();
}

void draw() {
  image(mov, 0, 0, 640, 320);
  image(mov1, 640, 0, 640, 320);
  image(mov2, 0, 320, 640, 320);
  image(mov3, 640, 320, 640, 320);
}

I started out with the above and then tried working with an array of videos, but only got so far:

import processing.video.*;

Capture cam;

int maxmyMovies = 8;
int myMoviesIndex = 0;
Movie[] myMovies = new Movie[maxmyMovies];

void setup() {

size(640,480);

cam = new Capture(this, 640, 480, 12);
cam.start();
smooth();

   for (int i = 0; i < myMovies.length; i ++ ) {
    myMovies[i] = new Movie(this, i + ".mov");

   }
}

void draw() {
 image(myMovies[myMoviesIndex], 0, 0);

  if (key == 'r') myMoviesIndex = int(random(0,8));

}

void movieEvent(Movie myMovies) {
  myMovies.read();
}

(The above is just copy/paste from other codes, I don't really want it to randomize when pressing the letter "r" but rather after a set time.) So, you can see I'm at a loss here... I would really appreciate any help.

Thanks!!

Tagged:

Answers

  • Try the following code. It might not do all the things you wanted, but pretty close. I hope this helps,

    Kf

    import processing.video.*;
    
    Capture cam;
    
    int limitTime=2000; // 2 seconds or 2000 milliseconds
    int nextTime;
    
    final int maxmyMovies = 8;
    final int maxNumberScreen=4;
    int myMoviesIndex = 0;
    Movie[] myMovies = new Movie[maxmyMovies];
    
    int[] screenNumber = new int[maxNumberScreen];
    
    void setup() {
    
      size(640, 480);
    
      cam = new Capture(this, cam.list()[0]);
      cam.start();
      smooth();
    
      for (int i = 0; i < myMovies.length; i ++ ) {
        myMovies[i] = new Movie(this, i + ".mov");
        myMovies[i].loop();
      }
    
      shuffleScreens();
    }
    
    void draw() {
      background(0);
      if (cam.available() == true) {
        cam.read();
      }
    
      for (int i=0; i<maxNumberScreen; i++) {
    
        PImage aimg;
        int vx1=0, vx2=0, vy1=0, vy2=0;
        switch(screenNumber[i]) {
        case -1:
          aimg=cam;
          break;
        default:
          aimg=myMovies[i];
          break;
        }
    
        switch(i) {
        case 0:
          vx1=0;
          vy1=0;
          vx2=width/2;
          vy2=height/2;
          break;
        case 1:
          vx1=width/2;
          vy1=0;
          vx2=width;
          vy2=height/2;
          break;
        case 2:
          vx1=0;
          vy1=height/2;
          vx2=width/2;
          vy2=height;
          break;
        case 3:
          vx1=width/2;
          vy1=height/2;
          vx2=width;
          vy2=height;
          break;
        }
        image(aimg, vx1, vy1, vx2, vy2);
      }
    
      if (millis()>nextTime)
        shuffleScreens();
    }
    
    void movieEvent(Movie myMovies) {
      myMovies.read();
    }
    
    
    
    void shuffleScreens() {
    
      //STEP 1: Setup video index to each screen
      for (int i = 0; i < maxNumberScreen; i++ )
        screenNumber[i]=round(random(maxmyMovies-1));
    
      //STEP 2:Set camera on a screen   
      screenNumber[round(random(maxNumberScreen-1))]=-1;  // -1 indicating from the cam
    
      //STEP 3:Start reference time to trigger video index rearrangement 
      nextTime=millis()+limitTime;
    }
    
Sign In or Register to comment.