import uk.co.caprica.picam.Camera;
import uk.co.caprica.picam.CameraConfiguration;
import uk.co.caprica.picam.CameraException;
import uk.co.caprica.picam.CaptureFailedException;
import uk.co.caprica.picam.NativeLibraryException;
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;
import static uk.co.caprica.picam.PicamNativeLibrary.installTempLibrary;
public class MyCameraApplication {
public static void main(String[] args) throws NativeLibraryException {
installTempLibrary();
CameraConfiguration config = cameraConfiguration()
.width(1920)
.height(1080)
.automaticWhiteBalance(AutomaticWhiteBalanceMode.AUTO)
.encoding(Encoding.JPEG)
.quality(85);
try {
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());
System.exit(-1);
}
catch (CaptureFailedException e) {
System.out.println("Capture failed, reopening camera: " + e.getMessage());
camera.close();
if (!camera.open()) {
System.out.println("Failed to reopen the camera");
System.exit(-1);
}
}
}
}
catch (CameraException e) {
e.printStackTrace();
}
}
}