本文整理了Java中com.github.sarxos.webcam.Webcam.getWebcams()
方法的一些代码示例,展示了Webcam.getWebcams()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Webcam.getWebcams()
方法的具体详情如下:
包路径:com.github.sarxos.webcam.Webcam
类名称:Webcam
方法名:getWebcams
[英]Get list of webcams to use. This method will wait predefined time interval for webcam devices to be discovered. By default this time is set to 1 minute.
[中]获取要使用的网络摄像头列表。此方法将等待网络摄像头设备被发现的预定义时间间隔。默认情况下,此时间设置为1分钟。
代码示例来源:origin: sarxos/webcam-capture
public WebcamPicker() {
this(Webcam.getWebcams());
}
代码示例来源:origin: sarxos/webcam-capture
/**
* Get list of webcams to use. This method will wait predefined time interval for webcam devices
* to be discovered. By default this time is set to 1 minute.
*
* @return List of webcams existing in the system
* @throws WebcamException when something is wrong
* @see Webcam#getWebcams(long, TimeUnit)
*/
public static List<Webcam> getWebcams() throws WebcamException {
// timeout exception below will never be caught since user would have to
// wait around three hundreds billion years for it to occur
try {
return getWebcams(Long.MAX_VALUE);
} catch (TimeoutException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: sarxos/webcam-capture
/**
* Get list of webcams to use. This method will wait given time interval for webcam devices to
* be discovered. Time argument is given in milliseconds.
*
* @param timeout the time to wait for webcam devices to be discovered
* @return List of webcams existing in the ssytem
* @throws TimeoutException when timeout occurs
* @throws WebcamException when something is wrong
* @throws IllegalArgumentException when timeout is negative
* @see Webcam#getWebcams(long, TimeUnit)
*/
public static List<Webcam> getWebcams(long timeout) throws TimeoutException, WebcamException {
if (timeout < 0) {
throw new IllegalArgumentException(String.format("Timeout cannot be negative (%d)", timeout));
}
return getWebcams(timeout, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: sarxos/webcam-capture
/**
* Will discover and return first webcam available in the system.
*
* @param timeout the webcam discovery timeout (1 minute by default)
* @param tunit the time unit
* @return Default webcam (first from the list)
* @throws TimeoutException when discovery timeout has been exceeded
* @throws WebcamException if something is really wrong
* @throws IllegalArgumentException when timeout is negative or tunit null
* @see Webcam#getWebcams(long, TimeUnit)
*/
public static Webcam getDefault(long timeout, TimeUnit tunit) throws TimeoutException, WebcamException {
if (timeout < 0) {
throw new IllegalArgumentException(String.format("Timeout cannot be negative (%d)", timeout));
}
if (tunit == null) {
throw new IllegalArgumentException("Time unit cannot be null!");
}
List<Webcam> webcams = getWebcams(timeout, tunit);
assert webcams != null;
if (!webcams.isEmpty()) {
return webcams.get(0);
}
LOG.warn("No webcam has been detected!");
return null;
}
代码示例来源:origin: sarxos/webcam-capture
/**
* Return webcam with given name or null if no device with given name has been found. Please
* note that specific webcam name may depend on the order it was connected to the USB port (e.g.
* /dev/video0 vs /dev/video1).
*
* @param name the webcam name
* @return Webcam with given name or null if not found
* @throws IllegalArgumentException when name is null
*/
public static Webcam getWebcamByName(String name) {
if (name == null) {
throw new IllegalArgumentException("Webcam name cannot be null");
}
for (Webcam webcam : getWebcams()) {
if (webcam.getName().equals(name)) {
return webcam;
}
}
return null;
}
}
代码示例来源:origin: openpnp/openpnp
public List<String> getDeviceIds() throws Exception {
ArrayList<String> deviceIds = new ArrayList<>();
for (Webcam cam : Webcam.getWebcams()) {
deviceIds.add(cam.getName());
}
return deviceIds;
}
代码示例来源:origin: org.boofcv/WebcamCapture
public static Webcam findDevice( String deviceName ) {
List<Webcam> found = Webcam.getWebcams();
for( Webcam cam : found ) {
if( cam.getName().contains(deviceName)) {
return cam;
}
}
return null;
}
代码示例来源:origin: org.boofcv/boofcv-WebcamCapture
public static Webcam findDevice( String deviceName ) {
List<Webcam> found = Webcam.getWebcams();
for( Webcam cam : found ) {
if( cam.getName().contains(deviceName)) {
return cam;
}
}
return null;
}
代码示例来源:origin: org.boofcv/boofcv-WebcamCapture
public boolean loadPreferences() {
Preferences prefs = Preferences.userRoot().node(getClass().getSimpleName());
String cameraName = prefs.get("camera","");
final int width = prefs.getInt("width",-1);
final int height = prefs.getInt("height",-1);
if( cameraName.length() <= 0 )
return false;
List<Webcam> cameras = Webcam.getWebcams();
int match = -1;
for( int i = 0; i < cameras.size(); i++ ) {
Webcam w = cameras.get(i);
if( w.getName().equals(cameraName)) {
match = i;
break;
}
}
if( match == -1 )
return false;
comboCameras.removeActionListener(cameraListener);
comboCameras.setSelectedIndex(match);
if( width > 0 && height > 0 ) {
setCameraSize(width,height);
}
comboCameras.addActionListener(cameraListener);
return true;
}
代码示例来源:origin: org.boofcv/boofcv-WebcamCapture
public static Selection showDialog( Window owner )
if( Webcam.getWebcams().size() == 0 ) {
JOptionPane.showMessageDialog(owner, "No webcams found!");
return null;
代码示例来源:origin: openpnp/openpnp
for (Webcam cam : Webcam.getWebcams()) {
if (cam.getName().equals(deviceId)) {
webcam = cam;
代码示例来源:origin: io.rhiot/camel-webcam
@Override
protected void doStart() throws Exception {
super.doStart();
installer = resolveInstaller();
String requiredPackages = getRequiredPackages();
try {
if (!installer.install(requiredPackages) && !ignoreInstallerProblems) {
throw new IllegalStateException("Unable to start webcam, failed to install dependencies");
}
} catch (Exception ex) {
if(ignoreInstallerProblems) {
LOG.warn(ex.getMessage());
} else {
throw ex;
}
}
//Use the provided webcam/s
if (getWebcams().size() == 0) {
loadWebcamDriver();
List<Webcam> webcamList = Webcam.getWebcams(timeout);
if (webcamList == null || webcamList.size() == 0) {
throw new IllegalStateException("No webcams found");
}
webcamList.forEach(w -> webcams.put(w.getDevice().getName(), w));
LOG.info("Detected webcams : {}", webcams.keySet());
}
}
代码示例来源:origin: org.boofcv/WebcamCapture
@Override
public <T extends ImageBase> SimpleImageSequence<T>
open(String device, int width, int height, ImageType<T> imageType) {
if( device != null ) {
Webcam webcam;
try {
int which = Integer.parseInt(device);
webcam = Webcam.getWebcams().get(which);
}catch (NumberFormatException ignore) {
webcam = UtilWebcamCapture.findDevice(device);
}
if( webcam == null ) {
throw new RuntimeException("Can't find webcam with ID or name at "+device);
}
try {
if (width >= 0 && height >= 0) {
UtilWebcamCapture.adjustResolution(webcam, width, height);
}
webcam.open();
return new SimpleSequence<>(webcam, imageType);
} catch (RuntimeException ignore) {}
}
return new SimpleSequence<>(device, width, height, imageType);
}
代码示例来源:origin: org.boofcv/boofcv-WebcamCapture
@Override
public <T extends ImageBase<T>> SimpleImageSequence<T>
open(String device, int width, int height, ImageType<T> imageType) {
if( device != null ) {
Webcam webcam;
try {
int which = Integer.parseInt(device);
webcam = Webcam.getWebcams().get(which);
}catch (NumberFormatException ignore) {
webcam = UtilWebcamCapture.findDevice(device);
}
if( webcam == null ) {
throw new RuntimeException("Can't find webcam with ID or name at "+device);
}
try {
if (width >= 0 && height >= 0) {
UtilWebcamCapture.adjustResolution(webcam, width, height);
}
webcam.open();
return new SimpleSequence<>(webcam, imageType);
} catch (RuntimeException ignore) {}
}
return new SimpleSequence<>(device, width, height, imageType);
}
代码示例来源:origin: org.boofcv/boofcv-WebcamCapture
setBorder(BorderFactory.createEmptyBorder(6,6,6,6));
final List<Webcam> cameras = Webcam.getWebcams();
Vector<String> names = new Vector<>();
内容来源于网络,如有侵权,请联系作者删除!