Video can take some time to initialize. You should use it only when the height and width becomes non zero. You can wait until the video starts and only then create opencv. I didn’t test this code but something like this might work:
void setup() {
...
// Start video here
video = new Capture(...);
...
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
if (opencv == null && video.width != 0 && video.height != 0) {
// Video is ready
// Create and config OpenCV here
opencv = new OpenCV(...);
...
}
if (opencv != null) {
// Video is ready and opencv was created
// your draw code here
opencv.loadImage(...);
...
}
}
But OP is using JAVA2D. Nonetheless, I’ve tested all renderers using my ancient sketch “Efficient WebCam Capture” from the link below, and no crashes have happened so far:
Totally agree with @Jakub and I made the exact same point the last time you advocated this - blocking setup() is a stupid idea for multiple reasons. Just because it works for you, with your camera on your system, doesn’t make it a good idea!
Jackub
I am using captureEvent already, the video loads fine. There is no background substraction like in the example.
If i move an object, nothing happens, no countours around it. So it is the OPENCV part that does not kick in,