We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
lemonFlower2 - Kopie
For those who might want to see how this was resolved...