List of cameras available but none accessible

Hi there!

I’m trying to run a code that needs to use a camera using the processing.video library but would give me errors. After some trial and error, I found that processing is able to list out the cameras that are connected to my laptop but responds with false when checking using cam.available(). Running the code below would print “no cameras available” and would give the error “WARNING: no real random source present!” no matter which camera I try. Trying external cameras has not helped either. I tried giving it camera access via windows settings but processing won’t show up as an application installed. What could I do to make this work? Many thanks in advance!

import processing.video.*;

Capture cam;


void setup() {
  // get list of cameras
  String[] cameras =  Capture.list();
  for (int i =0; i<cameras.length; i++) {
    String camerainfo = cameras[i];
    println(camerainfo);
  }
    cam = new Capture(this, cameras[0]);
  cam.start(); 
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  else {
   println("no cameras available"); 
  }
  image(cam, 0, 0, width, height);
}

Hi

Hello @loom,

See:

The camera frame rate is slower than draw() and your print statement will print when it is not available.

This print statement would better reflect the condition:
println("new frame from the device is NOT available to read.");

This will help to visualize when a frame is not available and show a red background between updated cam frames:

void draw() 
  {
  background(255, 0, 0);        // Try with and without this line
  if (cam.available() == true) 
    {
    cam.read();
    image(cam, 0, 0, width, height); // Try with this here or below
    }
  //image(cam, 0, 0, width, height); // Try with this here or below 
  }

Keep in mind that image() is displaying the last frame that was captured and only updated when a new one is available.

This may be of interest:

Another related topic:

It helps to resolve problems if you share which Processing version, Video library and operating system you are using.

I am using:

  • Processing 4.2
  • Video Library for Processing 2.2.2
  • Windows 10

This shows up in the console with your code (else printl() removed):

image

:)