com.github.sarxos.webcam.ds.openimaj.OpenImajDriver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webcam-capture-driver-openimaj Show documentation
Show all versions of webcam-capture-driver-openimaj Show documentation
Webcam Capture driver allowing you to capture images using OpenIMAJ library.
package com.github.sarxos.webcam.ds.openimaj;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openimaj.video.capture.Device;
import org.openimaj.video.capture.VideoCapture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.sarxos.webcam.WebcamDevice;
import com.github.sarxos.webcam.WebcamDriver;
import com.github.sarxos.webcam.WebcamTask;
/**
* This is webcam driver for OpenIMAJ library.
*
* @author Bartosz Firyn (SarXos)
*/
public class OpenImajDriver implements WebcamDriver {
static {
if (!"true".equals(System.getProperty("webcam.debug"))) {
System.setProperty("bridj.quiet", "true");
}
}
private static final Logger LOG = LoggerFactory.getLogger(OpenImajDriver.class);
private static class GetDevicesTask extends WebcamTask {
private volatile List devices = null;
public GetDevicesTask(WebcamDriver driver) {
super(driver, null);
}
/**
* Return camera devices.
*
* @return Camera devices.
*/
public List getDevices() {
try {
process();
} catch (InterruptedException e) {
LOG.debug("Interrupted", e);
return Collections.emptyList();
}
return devices;
}
@Override
protected void handle() {
devices = new ArrayList();
for (Device device : VideoCapture.getVideoDevices()) {
devices.add(new OpenImajDevice(device));
}
}
}
@Override
public List getDevices() {
List devices = new GetDevicesTask(this).getDevices();
if (LOG.isDebugEnabled()) {
for (WebcamDevice device : devices) {
LOG.debug("OpenIMAJ found device {}", device.getName());
}
}
return devices;
}
@Override
public boolean isThreadSafe() {
return false;
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}