import uk.co.caprica.picam.Camera;
import uk.co.caprica.picam.CameraConfiguration;
import uk.co.caprica.picam.CaptureFailedException;
import uk.co.caprica.picam.PictureCaptureHandler;
import uk.co.caprica.picam.enums.AutomaticWhiteBalanceMode;
import uk.co.caprica.picam.enums.Encoding;
import static uk.co.caprica.picam.CameraConfiguration.cameraConfiguration;
public class MyCameraApplication {
public static void main(String[] args) {
CameraConfiguration config = cameraConfiguration()
.width(1920)
.height(1080)
.automaticWhiteBalance(AutomaticWhiteBalanceMode.AUTO)
.encoding(Encoding.JPEG)
.quality(85);
Camera camera = new Camera(config);
PictureCaptureHandler<?> pictureCaptureHandler = new MyPictureCaptureHandler();
for (;;) {
try {
Thread.sleep(5000);
camera.takePicture(pictureCaptureHandler);
}
catch (InterruptedException e) {
System.out.println("Thread interrupted while sleeping: " + e.getMessage());
break;
}
catch (CaptureFailedException e) {
System.out.println("Capture failed, replacing camera: " + e.getMessage());
camera.close();
camera = new Camera(config);
}
}
camera.close();
}
}