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);
}