I'm working on a robot that drives a USB camera around on a physical gantry. My system is OSX 10.7.5, and I'm running Processing 2.0b8. I've got everything working except for the video image, which is supposed to show up as a live feed in the Processing window when the sketch is run. When I plug the camera in, Photobooth recognizes it automatically at full resolution and full frame rate. However, when I try the boilerplate
Capture() code on the Processing site, I get a very long list of possible cameras. These include many versions of the same device, and often cause the process to stall and error out:
vailable cameras:
name=PC Cam,size=1600x1200,fps=30
name=PC Cam,size=1600x1200,fps=15
name=PC Cam,size=1600x1200,fps=1
name=PC Cam,size=800x600,fps=30
name=PC Cam,size=800x600,fps=15
name=PC Cam,size=800x600,fps=1
name=PC Cam,size=400x300,fps=30
name=PC Cam,size=400x300,fps=15
name=PC Cam,size=400x300,fps=1
name=PC Cam,size=200x150,fps=30
name=PC Cam,size=200x150,fps=15
name=PC Cam,size=200x150,fps=1
name=PC Cam,size=100x75,fps=30
name=PC Cam,size=100x75,fps=15
name=PC Cam,size=100x75,fps=1
name=FaceTime HD Camera (Built-in),size=1280x720,fps=30
name=FaceTime HD Camera (Built-in),size=1280x720,fps=15
name=FaceTime HD Camera (Built-in),size=1280x720,fps=1
name=FaceTime HD Camera (Built-in),size=640x360,fps=30
name=FaceTime HD Camera (Built-in),size=640x360,fps=15
name=FaceTime HD Camera (Built-in),size=640x360,fps=1
name=FaceTime HD Camera (Built-in),size=320x180,fps=30
name=FaceTime HD Camera (Built-in),size=320x180,fps=15
name=FaceTime HD Camera (Built-in),size=320x180,fps=1
name=FaceTime HD Camera (Built-in),size=160x90,fps=30
name=FaceTime HD Camera (Built-in),size=160x90,fps=15
name=FaceTime HD Camera (Built-in),size=160x90,fps=1
name=FaceTime HD Camera (Built-in),size=80x45,fps=30
name=FaceTime HD Camera (Built-in),size=80x45,fps=15
name=FaceTime HD Camera (Built-in),size=80x45,fps=1
Now, after reading many post on this forum, I've arrived at the following:
import processing.video.*;
Capture cam;
void setup() {
size(800, 600, P2D);
frameRate(30);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
cam = new Capture(this, "name=PC Cam");
cam.start();
}
}
void draw() {
if (cam.available() == true) {
cam.read();
}
image(cam, 0, 0);
}
I think that line 15 is the key here. The code recognizes that I want my external webcam, but it does not know which resolution I want. It's smart enough to report that:
Resolution information not available, attempting to open the capture device at 320x240
... but then it grabs a very low res image. On the bright side, this small image
runs at the maximum frame rate.
So! I feel like I'm close, but I need some guidance about how to pick a specific camera (with resolution and framerate) off my available cam list. When I just select the list number with
cam = new Capture(this, cameras[0]);
... I get the correct res but a terribly slow frame rate. The same applies to lower res camera settings on the list, so I don't think it's just a matter of too much data for Processing to handle. I've also tried specifying the full camera name from the list:
cam = new Capture(this, "name=PC Cam,size=800x600,fps=30");
... but this is also really slow. Any thoughts on how to effectively select both my res and frame rate are appreciated!