1
votes

I’ve written the following code and I get error an error

IllegalStateException: Could not find any devices
import processing.video.*;
Capture unicorn;

void setup(){
    size(640,480);
    unicorn=new Capture (this,640,480);
    unicorn.start();
    background(0);
}

void captureEvent(Capture video){
    video.read();
}

void draw(){
    for(int i=0; i<100; i++){
        float x=random(width);
        float y=random(height);
        color c=unicorn.get(int(x),int(y));
        fill(c);
        noStroke();
        ellipse(x,y,16,16);
    }
}
1
Did you check that you can use your camera with another software? In this post someone shares some code to list the available cameras, does your device appears when you run the code? In this post there are a few things people try which seem to help, have you tried? - statox

1 Answers

2
votes

Just to be sure: did you add the video library for Processing already (it is the library named "Video | GStreamer-based video library for Processing.")? Installation is explained in step 1 of this Processing video tutorial, which contains much more interesting information and great video examples. Since you are able to run your sketch, this should already be okay.

As statox already mentioned, be sure that the camera is working for other programs; there might be some hardware or driver issue. To list the cameras that Processing can detect, you can use code from the Capture documentation. This is only the part for showing the available cameras; use the link for the complete example:

import processing.video.*;

String[] cameras = Capture.list();

if (cameras.length == 0) {
  println("There are no cameras available for capture.");
} else {
  println("Available cameras:");
  for (int cameraIndex = 0; cameraIndex < cameras.length; cameraIndex++) {
    println(cameras[cameraIndex]);
  }
}

On my system with two cameras, the output looks like this:

Processing video library using GStreamer 1.16.2
Available cameras:
<Camera 1>
<Camera 2>

If the code from the Capture documentation does not work for you, you can try this alternative approach suggested by Neil C Smith on the Processing forum (was already mentioned by statox):

import processing.video.*;

Capture camera;

void setup() {
  size(640, 480);

  // Suggestion from Neil C Smith on the Processing forum:
  camera = new Capture(this, "pipeline:autovideosrc");
  camera.start();     
}

void draw() {
  if (camera.available()) {
    camera.read();
  }

  image(camera, 0, 0);
}