com.github.sarxos.webcam.Webcam类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中com.github.sarxos.webcam.Webcam类的一些代码示例,展示了Webcam类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Webcam类的具体详情如下:
包路径:com.github.sarxos.webcam.Webcam
类名称:Webcam

Webcam介绍

[英]Webcam class. It wraps webcam device obtained from webcam driver.
[中]网络摄像头课。它包装了从网络摄像头驱动程序获取的网络摄像头设备。

代码示例

代码示例来源:origin: sarxos/webcam-capture

public void stop() {
  if (started.compareAndSet(true, false)) {
    executor.shutdown();
    webcam.removeWebcamListener(this);
    webcam.close();
  }
}

代码示例来源:origin: sarxos/webcam-capture

public static final void capture(Webcam webcam, File file) {
  if (!webcam.isOpen()) {
    webcam.open();
  }
  try {
    ImageIO.write(webcam.getImage(), ImageUtils.FORMAT_JPG, file);
  } catch (IOException e) {
    throw new WebcamException(e);
  }
}

代码示例来源:origin: sarxos/webcam-capture

webcam.removeWebcamListener(this);
webcam.setViewSize(WebcamResolution.VGA.getSize());
webcam.addWebcamListener(this);
System.out.println("selected " + webcam.getName());

代码示例来源:origin: sarxos/webcam-capture

@Override
  protected Void doInBackground() throws Exception {
    try {
      if (webcam.isOpen()) {
        errored = !webcam.close();
      }
    } catch (WebcamException e) {
      errored = true;
      throw e;
    } finally {
      repaintPanel();
    }
    return null;
  }
};

代码示例来源:origin: sarxos/webcam-capture

@Override
  protected Void doInBackground() throws Exception {
    try {
      if (!webcam.isOpen()) {
        errored = !webcam.open();
      }
    } catch (WebcamException e) {
      errored = true;
      throw e;
    } finally {
      starting = false;
      repaintPanel();
    }
    return null;
  }
};

代码示例来源:origin: sarxos/webcam-capture

@Override
  public void run() {
    LOG.info("Automatic {} deallocation", webcam.getName());
    webcam.dispose();
  }
}

代码示例来源:origin: sarxos/webcam-capture

@Override
  public void run() {
    running.set(true);
    while (running.get() && webcam.isOpen()) {
      try {
        detect();
        Thread.sleep(interval);
      } catch (InterruptedException e) {
        break;
      } catch (Exception e) {
        WebcamExceptionHandler.handle(e);
      }
    }
    running.set(false);
  }
}

代码示例来源:origin: sarxos/webcam-capture

assert listeners != null;
if (!disposed.compareAndSet(false, true)) {
  return;
open.set(false);
LOG.info("Disposing webcam {}", getName());
removeShutdownHook();
LOG.debug("Webcam disposed {}", getName());

代码示例来源:origin: sarxos/webcam-capture

/**
 * Lock webcam.
 */
public void lock() {
  if (disabled.get()) {
    return;
  }
  if (isLocked()) {
    throw new WebcamLockException(String.format("Webcam %s has already been locked", webcam.getName()));
  }
  if (!locked.compareAndSet(false, true)) {
    return;
  }
  LOG.debug("Lock {}", webcam);
  update();
  updater = new LockUpdater();
  updater.start();
}

代码示例来源:origin: sarxos/webcam-capture

if (open.compareAndSet(false, true)) {
  } catch (InterruptedException e) {
    lock.unlock();
    open.set(false);
    LOG.debug("Thread has been interrupted in the middle of webcam opening process!", e);
    return false;
  } catch (WebcamException e) {
    lock.unlock();
    open.set(false);
    LOG.debug("Webcam exception when opening", e);
    throw e;
  LOG.debug("Webcam is now open {}", getName());
    LOG.trace(e.getMessage(), e);
    close();
  LOG.debug("Webcam is already open {}", getName());

代码示例来源:origin: sarxos/webcam-capture

/**
   * Perform single panel area update (repaint newly obtained image).
   */
  private void update() {
    // do nothing when updater not running, when webcam is closed, or
    // panel repainting is paused
    if (!running.get() || !webcam.isOpen() || paused) {
      return;
    }
    // get new image from webcam
    BufferedImage tmp = supplier.get();
    boolean repaint = true;
    if (tmp != null) {
      // ignore repaint if image is the same as before
      if (image == tmp) {
        repaint = false;
      }
      errored = false;
      image = tmp;
    }
    if (repaint) {
      repaintPanel();
    }
  }
}

代码示例来源:origin: sarxos/webcam-capture

/**
 * Is webcam ready to be read.
 *
 * @return True if ready, false otherwise
 */
private boolean isReady() {
  assert disposed != null;
  assert open != null;
  if (disposed.get()) {
    LOG.warn("Cannot get image, webcam has been already disposed");
    return false;
  }
  if (!open.get()) {
    if (autoOpen) {
      open();
    } else {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: sarxos/webcam-capture

if (open.get()) {
  throw new IllegalStateException("Cannot change resolution when webcam is open, please close it first");
Dimension current = getViewSize();
if (current != null && current.width == size.width && current.height == size.height) {
  return;
Dimension[] predefined = getViewSizes();
Dimension[] custom = getCustomViewSizes();

代码示例来源:origin: sarxos/webcam-capture

socket.setTcpNoDelay(true);
while (started.get()) {
    if (!webcam.isOpen() || socket.isInputShutdown() || socket.isClosed()) {
      br.close();
      bos.close();
      image = webcam.getImage();
  } while (started.get());

代码示例来源:origin: sarxos/webcam-capture

public void stop() {
  if (running.compareAndSet(true, false)) {
    webcam.close();
    executor.shutdownNow();
  }
}

代码示例来源:origin: sarxos/webcam-capture

public void start() {
  if (started.compareAndSet(false, true)) {
    webcam.addWebcamListener(this);
    webcam.open();
    executor.execute(new Acceptor());
  }
}

代码示例来源:origin: sarxos/webcam-capture

/**
 * Start updater.
 */
public void start() {
  if (running.compareAndSet(false, true)) {
    image.set(new WebcamGetImageTask(Webcam.getDriver(), webcam.getDevice()).getImage());
    executor = Executors.newSingleThreadScheduledExecutor(THREAD_FACTORY);
    executor.execute(this);
    LOG.debug("Webcam updater has been started");
  } else {
    LOG.debug("Webcam updater is already started");
  }
}

代码示例来源:origin: sarxos/webcam-capture

public void start() {
  if (running.compareAndSet(false, true)) {
    webcam.open();
    executor.submit(new Runner());
    executor.submit(new Inverter());
  }
}

代码示例来源:origin: stackoverflow.com

wCam.setViewSize(WebcamResolution.VGA.getSize());
wCam.open();
while (true)
  BufferedImage frame = wCam.getImage(); //get frame from webcam
  wCam.close();

代码示例来源:origin: org.activecomponents.jadex/jadex-applications-micro

public static void main(String[] args) throws Exception
  {
    Webcam webcam = Webcam.getDefault();
    webcam.setViewSize(WebcamResolution.VGA.getSize());
    if(webcam.isOpen()) 
      webcam.close();
    webcam.open();
    
    SequenceEncoder enc = new SequenceEncoder(new File("out.ts"));
    
    for(int i=0; i<100; i++)
    {
      enc.encodeImage(webcam.getImage());
      try
      {
        Thread.sleep(100);
      }
      catch(Exception e)
      {
      }
    }
    enc.finish();
  }
}

相关文章