Integrate these two codes?

edited September 2019 in Kinect

Hello Processing Forum folks,

I am working on a project that uses 3 webcams that when looked at, will play a video. I am thinking of the screens as entities that need to be acknowledged before they communicate with someone.

Everything was going dandy until I ran into two hiccups.

One is that opencv.loadImage(camright); seems to the culprit of this error "width(0) and height (0) cannot be <=0" which doesn't make any sense to me because there are opencv.loadImage(camleft); and opencv.loadImage(camcenter); before it and they don't seem to be returning the same issue.

The second hiccup is that I am trying to use keystone so that I can projection map these videos to hanging plexi... I just can't seem to figure out how to get the videos onto the keystone 'mesh'. Did that make sense?

Anyways, I am very green (taking my first class) and any help would be appreciated immensely. Especially since this project is due next week...

Below is my code... (I really couldn't get the whole code thing to work- I tried- I am sorry-if you want to help me with that too that'd be nice)

//LIBRARIES 
import deadpixel.keystone.*;
import gab.opencv.*;
import processing.video.*;
import java.awt.*; 
import java.awt.Rectangle;

//keystone stuff 
Keystone ks;
CornerPinSurface surfaceleft;
CornerPinSurface surfacecenter;
CornerPinSurface surfaceright;
PGraphics offscreenleft;
PGraphics offscreencenter;
PGraphics offscreenright;

// movie object to play and pause later
//there will be three videos playing... 
Movie myMovieleft;
Movie myMoviecenter;
Movie myMovieright;

OpenCV opencv;

//https://processing.org/discourse/beta/num_1221233526.html
//https://forum.processing.org/two/discussion/5960/capturing-feeds-from-multiple-webcams
Capture camleft;
Capture camcenter;
Capture camright;

String[] captureDevices;  

void setup() {
  //this will println listing the webcams you need to but the number on the left in the [] 
  //to make them work 
  printArray(Capture.list());
  background(0);
  size(2640, 1080, P3D); //this should be large enough to house all the videos 
  opencv = new OpenCV(this, 160, 120);

  //keystone stuff 
  ks = new Keystone(this);
  //this can change 
  surfaceleft = ks.createCornerPinSurface(400, 300, 20);
  surfacecenter = ks.createCornerPinSurface(400, 300, 20);
  surfaceright = ks.createCornerPinSurface(400, 300, 20);
  // We need an offscreen buffer to draw the surface we
  // want projected
  // note that we're matching the resolution of the
  // CornerPinSurface.
  // (The offscreen buffer can be P2D or P3D)
  //P3D is telling processing to be in 3D mode
  //the number is 400, 300 is related to eachother they must be the same 
  offscreenleft = createGraphics(400, 300, P3D);
  offscreencenter = createGraphics(400, 300, P3D);
  offscreenright = createGraphics(400, 300, P3D);

  //webcam stuff 
  //this is turning the webcam on and to run
  //the numbers correlate to the println list 
  camleft = new Capture(this, Capture.list()[3] ); //LEFT CAM IS LOGITECH HD 
  //WEBCAM C310 
  camleft.start();

  camcenter = new Capture(this, Capture.list()[79] ); //CENTER CAM IS LOGITECH HD
  //WEBCAM C310-1 
  camcenter.start();

  camright = new Capture(this, Capture.list()[155] ); //RIGHT CAM IS LOGITECH HD 
  //WEBCAM C310-2
  camright.start();

  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);

  // movie stuff 
  // load video
  myMovieleft = new Movie(this, "testvideo.mp4");

  // need to play, pause, loop 
  myMovieleft.play();
  myMovieleft.pause();
  myMovieleft.loop();

  myMoviecenter = new Movie(this, "testvideo-1.mp4");

  // need to play, pause, loop 
  myMoviecenter.play();
  myMoviecenter.pause();
  myMoviecenter.loop();

  myMovieright = new Movie(this, "testvideo-2.mp4");

  // need to play, pause, loop 
  myMovieright.play();
  myMovieright.pause();
  myMovieright.loop();
}
void captureEvent(Capture cam) {
  cam.read();
}

void draw() {

  // open cv detect faces
  opencv.loadImage(camleft);

  // load in faces as rectangles
  Rectangle[] facesleft = opencv.detect();

  // are there faces?
  if (facesleft.length > 0) {
    // sees a face!
    myMovieleft.play();
  } else {
    // no face
    myMovieleft.pause();
  }

  // play video
  if (myMovieleft.available()) {
    myMovieleft.read();
    //offscreen.image
    image(myMovieleft, 0, 540);
  }

  opencv.loadImage(camcenter);

  // load in faces as rectangles
  Rectangle[] facescenter = opencv.detect();

  // are there faces?
  if (facescenter.length > 0) {
    // sees a face!
    myMoviecenter.play();
  } else {
    // no face
    myMoviecenter.pause();
  }

  // play video
  if (myMoviecenter.available()) {
    myMoviecenter.read();
    image(myMoviecenter, 780, height/2);
  }

// THERE IS SOMETHING WRONG WITH THIS opencv.loadImage(camright);

//RIGHT CAM
  // load in faces as rectangles
  Rectangle[] facesright = opencv.detect();

  // are there faces?
  if (facesright.length > 0) {
    // sees a face!
    myMovieright.play();
  } else {
    // no face
    myMovieright.pause();
  }

  // play video
  if (myMovieright.available()) {
    myMovieright.read();
    image(myMovieright, 1560, height/2);

    //keystone stuff
    surfaceleft.render(offscreenleft);
    surfacecenter.render(offscreencenter);
    surfaceright.render(offscreenright);
  }
}
//the save and load function for keystone 
void keyPressed() {
  switch(key) {
  case 'c':
    // enter/leave calibration mode, where surfaces can be warped 
    // and moved
    ks.toggleCalibration();
    break;

  case 'l':
    // loads the saved layout
    ks.load();
    break;

  case 's':
    // saves the layout
    ks.save();
    break;
  }
}
`

Answers

  • Edit post, highlight code, press ctrl-o

  • edited May 2016

    For those who might want to see how this was resolved...

      //LIBRARIES if you use another computer with Processing you need to install video, keystone, 
        //and open.cv libraries (Sketch > Import Library > Add Library 
        import deadpixel.keystone.*;
        import gab.opencv.*;
        import processing.video.*;
        import java.awt.*; 
        import java.awt.Rectangle;
    
        //KEYSTONE stuff 
        Keystone ks;
        CornerPinSurface surfaceleft;
        CornerPinSurface surfacecenter;
        CornerPinSurface surfaceright;
        PGraphics offscreenleft;
        PGraphics offscreencenter;
        PGraphics offscreenright;
    
        // movie object to play and pause later
        //there will be three videos playing on one screen...
        Movie myMovieleft;
        Movie myMoviecenter;
        Movie myMovieright;
    
        //WEBCAM/FACE DETECTION stuff 
        OpenCV opencv;
        Capture camleft;
        Capture camcenter;
        Capture camright;
        String[] captureDevices;  
    
        boolean start=false;
    
        void setup() {
          //this will println listing the webcams you need to but the number on the left in the [] 
          //to make them work 
          printArray(Capture.list());
          background(0);
          size(2640, 1080, P3D); //this should be large enough to house all the videos 
    
          opencv = new OpenCV(this, 160, 120);
    
          //KEYSTONE stuff 
          ks = new Keystone(this);
          //these values can change but must be the same for offscreenleft/center/right 
          surfaceleft = ks.createCornerPinSurface(400, 300, 20);
          surfacecenter = ks.createCornerPinSurface(400, 300, 20);
          surfaceright = ks.createCornerPinSurface(400, 300, 20);
          // We need an offscreen buffer to draw the surface we
          // want projected
          // note that we're matching the resolution of the
          // CornerPinSurface.
          // (The offscreen buffer can be P2D or P3D)
          // P3D is telling processing to be in 3D mode
          // the number is 400, 300 is related to eachother they must be the same 
          offscreenleft = createGraphics(400, 300, P3D);
          offscreencenter = createGraphics(400, 300, P3D);
          offscreenright = createGraphics(400, 300, P3D);
    
          //WEBCAM stuff 
          //this is turning the webcam on and to run
          //the numbers within [ ] correlate to the println list on line 37
          camleft = new Capture(this, Capture.list()[3] ); //LEFT CAM IS LOGITECH HD 
          //WEBCAM C310 
          camleft.start();
    
          camcenter = new Capture(this, Capture.list()[79] ); //CENTER CAM IS LOGITECH HD
          //WEBCAM C310-1 
          camcenter.start();
    
          camright = new Capture(this, Capture.list()[155] ); //RIGHT CAM IS LOGITECH HD 
          //WEBCAM C310-2
          camright.start();
    
          opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
    
          // VIDEO stuff 
          // load videos 
          myMovieleft = new Movie(this, "testvideo.mp4"); //load this video
          //videos must be placed in a folder titled data within the sketch folder 
          // need to play, pause, loop 
          myMovieleft.play();
          myMovieleft.pause();
          myMovieleft.loop();
    
          myMoviecenter = new Movie(this, "testvideo-1.mp4");
          myMoviecenter.play();
          myMoviecenter.pause();
          myMoviecenter.loop();
    
          myMovieright = new Movie(this, "testvideo-2.mp4");
          myMovieright.play();
          myMovieright.pause();
          myMovieright.loop();
        }
        void captureEvent(Capture cam) { 
          cam.read();
        }
    
        void draw() {
          background(0);
          //THIS IS FOR THE LEFT 
          //this is to delay the start of the video so that the webcams have time to initalize 
          if (camleft.available()==true && start ==true) {
            // open cv detect faces
            opencv.loadImage(camleft);
    
            // load in faces as rectangles
            Rectangle[] facesleft = opencv.detect();
    
            // are there faces?
            if (facesleft.length > 0) {
              // sees a face!
              myMovieleft.play();
            } else {
              // no face
              myMovieleft.pause();
            }
    
            // play video
            if (myMovieleft.available()) {
              myMovieleft.read();
              //offscreen.image
              //image(myMovieleft, 0, 540);
              offscreenleft.beginDraw();
              offscreenleft.image(myMovieleft, 0, 0, 400, 300);
              offscreenleft.endDraw();
            }
    
            //THIS IS FOR THE CENTER 
            if (camcenter.available()==true && start ==true) {
              opencv.loadImage(camcenter);
              Rectangle[] facescenter = opencv.detect();
              if (facescenter.length > 0) {
                myMoviecenter.play();
              } else {
                myMoviecenter.pause();
              }
              if (myMoviecenter.available()) {
                myMoviecenter.read();
                offscreencenter.beginDraw();
                offscreencenter.image(myMoviecenter, 0, 0, 400, 300);
                offscreencenter.endDraw();
              }
              //THIS IS FOR THE RIGHT  
              if (camright.available()==true && start ==true) {
                opencv.loadImage(camright);
                Rectangle[] facesright = opencv.detect();
                if (facesright.length > 0) {
                  myMovieright.play();
                } else {
                  myMovieright.pause();
                }
                if (myMovieright.available()) {
                  myMovieright.read();
                  offscreenright.beginDraw();
                  offscreenright.image(myMovieright, 0, 0, 400, 300);
                  offscreenright.endDraw();
                }
              }
              //KEYSTONE stuff
              surfaceleft.render(offscreenleft);
              surfacecenter.render(offscreencenter);
              surfaceright.render(offscreenright);
            }
          }
        }
        //the save and load function for KEYSTONE stuff
        void keyPressed() {
          switch(key) {
          case 'c':
            // enter/leave calibration mode, where surfaces can be warped 
            // and moved
            ks.toggleCalibration();
            break;
    
          case 'l':
            // loads the saved layout
            ks.load();
            break;
    
          case 's':
            // saves the layout
            ks.save();
            break;
    
            //WEBCAM/VIDEO stuff 
          case ' ':
            //spacebar will start videos/webcam thing 
            //this is so Processing doesn't have to do so much work at once 
            start=true;
            println("starting");
            break;
          }
    }
    
Sign In or Register to comment.