We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello!
I'm trying to create an application where the camera captures (without displaying on screen) a set of 5 images into the data folder while the program is running an animation loop on the screen. I'm using threads in this case to run two things parallely. I'm able to run the program with out an error and capture images successfully, but strangely Im see blank (white) images instead of what is being captured. Has anyone worked on a similar program? Could some one give a direction on where im going wrong? Also, attaching the snippets of the code for the reference. Thanks
********************************************************* THREAD CLASS
import processing.video.*;
class ImageCapture extends Thread {
int count=0;
Capture cam;
ImageCapture ( Capture cam1 ) {
cam = cam1;
}
//// We must implement run, this gets triggered by start()
void run () {
print("Begin Capture");
captureImages();
println("End of Capture");
}
//// CAPTURE IMAGES
void captureImages() {
int i=0;
cam.start();
while (i<6) {
myDelay(3000);
cam.read();
PImage pg = cam.get();
pg.save("data/"+"image_" + i + ".png");
i++;
}
count=6;
cam.stop();
}
int getCount() {
return count;
}
//// DELAY FUNCTION
void myDelay(long ms)
{
long currentTime = millis();
long waitTime=currentTime+ms;
while (millis () < waitTime) {
}
}
}
********************************************************* MAIN PROGRAM
import processing.video.*;
ImageCapture thread1;
Capture cam;
void setup() {
size(displayWidth, displayHeight, P2D);
frameRate(30);
cam = new Capture(this, 640, 480);
smooth();
}
void draw() {
eye();
thread1 = new ImageCapture(cam);
thread1.start();
}
void eye() {
background(0);
int size;
size = int(random(10, 80));
fill(255);
ellipse(width/2, height/2, size, size);
}
Answers
I see that you use frameRate(30). It means that draw() is invoked @ 30 FPS.
And consequently, a new ImageCapture thread is instantiated @ 30 FPS too, since you've place it there!!! ~X(
Moreover, all of them refers to the same Capture object and save() w/ the same names and path! 8-|
@ GoToLoop: Thanks for the revert.
I'm using frameRate(30) as it is mentioned in the 'capture' documentation as the desired frame rate. Is frame rate the issue here?
But it is performing the functions as per the need with given intervals and saving images as well except that they are blank :/
Here the same code seems to work fine though.
Finally, managed to solve it.. it was really a small mistake.. P2D rendering doesn't seem to support capture.
The fact that capture doesn't work properly under P2D/P3D may be related to this bug, as it seems get() uses same mechanisms as access to pixels[] array.
https://github.com/processing/processing/issues/1852
just FYI