Java Foreign Function & Memory bindings for OpenPnP Capture.
openpnp-capture-java is available from Maven Central.
To add openpnp-capture-java as a dependency using Maven, include the following in your pom.xml:
<dependency>
<groupId>io.github.doblon8</groupId>
<artifactId>openpnp-capture-java</artifactId>
<version>0.0.3</version>
</dependency>For other build tools, retrieve the dependency from Maven Central using the same coordinates.
openpnp-capture-java bundles the native openpnp-capture libraries for supported platforms, sourced from the sparrowwallet/openpnp-capture repository, so no system-wide installation is required.
import io.github.doblon8.openpnp.capture.*;
import javax.imageio.ImageIO;
void main() throws Exception {
System.out.println("openpnp-capture version: " + OpenPnpCapture.getLibraryVersion());
OpenPnpCapture.setLogLevel(LogLevel.INFO);
OpenPnpCapture.installCustomLogFunction((logLevel, message) -> System.out.println("Log [" + logLevel + "]: " + message));
try (var capture = new OpenPnpCapture()) {
var device = capture.getDevices().stream()
.findFirst()
.orElseThrow(() -> new CaptureException("No capture devices found."));
var format = device.getFormats().stream()
.findFirst()
.orElseThrow(() -> new CaptureException("No formats found."));
try (var stream = device.openStream(format)) {
TimeUnit.SECONDS.sleep(1); // let the camera initialize
var exposureLimits = stream.getPropertyLimits(CaptureProperty.EXPOSURE);
System.out.println("Exposure limits: " + exposureLimits);
var image = stream.capture();
ImageIO.write(image, "png", new File("/tmp/image.png"));
System.out.println("Captured image saved to /tmp/image.png");
}
}
}This project is licensed under the MIT License, the same as the openpnp-capture library.
See the LICENSE file for details.