I’m trying to use the webcam and it works the the first time I run it, after opening Processing. But after restarting it it crashes and won’t work anymore until I restart the whole Processing.
This is my code:
import processing.video.*;
Capture webcam;
int size = 300;
float theta;
PImage img;
void setup() {
img = loadImage("data/sap-blanco.png");
noFill();
colorMode(HSB, 1.0);
size(794, 794, P3D);
sphereDetail(20);
stroke(1, 0, 1);
strokeWeight(3);
background(0);
frameRate(30);
shapeMode(CENTER);
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]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
webcam = new Capture(this, cameras[0]);
webcam.start();
}
}
void draw() {
if (webcam.available() == true) {
webcam.read();
}
background(sin(theta), 1., 1., 1);
push();
translate(width/2, height/2);
rotateY(theta);
sphere(300) ;
pop();
theta += 0.01;
push();
image(webcam, 0, 0);
pop();
image(img, 0, 0);
}
Hi @animanoir
It would help to know what operating system and version of Processing you are using, as well as the error message you are getting.
You’re right, sorry—here is the error code:
Processing video library using GStreamer 1.16.2
There are no cameras available for capture.
finishLifecycleAction(com.jogamp.opengl.util.FPSAnimator$3): ++++++ timeout reached ++++++ main-FPSAWTAnimator#00-Timer0
finishLifecycleAction(com.jogamp.opengl.util.FPSAnimator$3): OK false- pollPeriod 29, blocking true -> res false, waited 1001/1000 - main-FPSAWTAnimator#00-Timer0
- com.jogamp.opengl.util.FPSAnimator[started true, animating true, paused false, drawable 1, totals[dt 0, frames 0, fps 0.0], modeBits 1, init'ed true, animThread Thread[main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1,5,main], exclCtxThread false(null)]
[2]: com.jogamp.opengl.util.AnimatorBase.finishLifecycleAction(AnimatorBase.java:634)
[3]: com.jogamp.opengl.util.FPSAnimator.stop(FPSAnimator.java:326)
[4]: processing.opengl.PSurfaceJOGL.stopThread(PSurfaceJOGL.java:675)
[5]: processing.core.PApplet.dispose(PApplet.java:3522)
[6]: processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:836)
[7]: jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
[8]: jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
[9]: jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
[10]: jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
[11]: jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
[12]: com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:782)
[13]: com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
[14]: com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:453)
[15]: com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
[16]: java.base/java.util.TimerThread.mainLoop(Timer.java:566)
[17]: java.base/java.util.TimerThread.run(Timer.java:516)
WARNING: no real random source present!
I do have a webcam and it does works the first time, but restarting it it fails with this.