Loading...
Logo
Processing Forum
Hello all,

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:
Exception in thread "Animation Thread" java.lang.RuntimeException: Waited 5000ms for: <1a99836, 148083b>[count 2, qsz 0, owner <AWT-EventQueue-0>] - <Animation Thread>
... and when it does work, here's the list:
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:
Copy code
  1. import processing.video.*;
  2. Capture cam;
  3. void setup() {
  4.   size(800, 600, P2D);
  5.   frameRate(30);
  6.   String[] cameras = Capture.list();
     
  7.   if (cameras.length == 0) {
  8.     println("There are no cameras available for capture.");
  9.     exit();
  10.   } else {
  11.     println("Available cameras:");
  12.     for (int i = 0; i < cameras.length; i++) {
  13.       println(cameras[i]);
  14.     }
  15.     cam = new Capture(this, "name=PC Cam");
  16.     cam.start();    
  17.   }     
  18. }
  19. void draw() {
  20.   if (cam.available() == true) {
  21.     cam.read();
  22.   }
  23.   image(cam, 0, 0);
  24. }
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
Copy code
  1. 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:
Copy code
  1.      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!

Thanks for reading.

Replies(1)

Ha!  Taking all that time to write the post helped me answer my own question.  It looks like my list of "available cameras" is a red herring.  When I tried to pick one, say:
Copy code
  1. cam = new Capture(this, "name=PC Cam,size=100x75,fps=30");
...I'd get this error:


** (Processing core video:23664): WARNING **: ColorConverter: size 16800 is not a multiple of unit size 15000
When I tried
Copy code
  1. cam = new Capture(this, "name=PC Cam");
...I'd get this:
Resolution information not available, attempting to open the capture device at 320x240 
Together, these errors suggested that the camera list that Processing was generating did not provide an accurate accounting of the possible resolutions that my camera could achieve.  Thus, when I tried scaling up my math based on 320 x 240:
Copy code
  1. cam = new Capture(this, "name=PC Cam,size=640x480,fps=30");
It worked!  Strangely, 800x600 did not.  In any case, hope that helps someone else.