com.github.sarxos.webcam.Webcam.open()方法的使用及代码示例

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

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

Webcam.open介绍

[英]Is webcam open?
[中]网络摄像头开着吗?

代码示例

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

/**
 * Open the webcam in blocking (synchronous) mode.
 *
 * @return True if webcam has been open, false otherwise
 * @see #open(boolean, DelayCalculator)
 * @throws WebcamException when something went wrong
 */
public boolean open() {
  return open(false);
}

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

Webcam webcam = Webcam.getDefault();
webcam.open();
ImageIO.write(webcam.getImage(), "PNG", new File("test.png"));

代码示例来源: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

/**
 * Open the webcam in either blocking (synchronous) or non-blocking (asynchronous) mode. If the
 * non-blocking mode is enabled the DefaultDelayCalculator is used for calculating delay between
 * two image fetching.
 * 
 * @param async true for non-blocking mode, false for blocking
 * @return True if webcam has been open, false otherwise
 * @see #open(boolean, DelayCalculator)
 * @throws WebcamException when something went wrong
 */
public boolean open(boolean async) {
  return open(async, new DefaultDelayCalculator());
}

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

Webcam webcam = Webcam.getDefault();
webcam.open();
BufferedImage image = webcam.getImage();
ImageIO.write(image, "JPG", new File("test.jpg"));

代码示例来源: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

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

代码示例来源: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

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

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

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

import com.github.sarxos.webcam.Webcam;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Main {

  public static void main(String[] args) throws IOException {
    Webcam webcam = Webcam.getDefault();
    webcam.open();
    File f =  new File("webcam_snap.png");
    ImageIO.write(webcam.getImage(), "PNG",f);
    System.out.println("Saved image "+f.getAbsolutePath());
  }
}

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

Webcam webcam = Webcam.getDefault();
webcam.open()
BufferedImage image = webcam.getImage();
ImageIO.write(image, "JPG", new File("test.jpg"));

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

public class TakePictureExample {
  public static void main(String[] args) throws IOException {

    Webcam webcam = Webcam.getDefault();

    webcam.setViewSize(new Dimension(1024,768));

    webcam.open(false);

    // get image
    BufferedImage image = webcam.getImage();

    // save image to PNG file
    ImageIO.write(image, "PNG", new File("test.png"));  
  }
}

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

Webcam webcam = Webcam.getDefault();
webcam.open();
try {
 ImageIO.write(webcam.getImage(), "PNG", new File("test.png"));
} catch (IOException e) {
 e.printStackTRace();
} finally {
 webcam.close();
}

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

Intelligence intel = new Intelligence();
Webcam webcam = Webcam.getDefault();
webcam.open();

CarSnapshot carSnap = new CarSnapshot(webcam.getImage());
String numberPlate = intel.recognize(carSnap);

代码示例来源:origin: org.boofcv/boofcv-WebcamCapture

/**
 * Opens the default camera while adjusting its resolution
 */
public static Webcam openDefault( int desiredWidth , int desiredHeight) {
  Webcam webcam = Webcam.getDefault();
  // Webcam doesn't list all available resolutions. Just pass in a custom
  // resolution and hope it works
  adjustResolution(webcam,desiredWidth,desiredHeight);
  webcam.open();
  return webcam;
}

代码示例来源:origin: org.boofcv/boofcv-WebcamCapture

/**
 * Searches for the first device which matches the pattern.  Webcam capture doesn't name devices
 * using the standard "/dev/video0" scheme, but it includes that in its name.
 *
 * @param deviceName Partial or complete name of the device you wish to pen
 * @return The webcam it found
 */
public static Webcam openDevice( String deviceName , int desiredWidth , int desiredHeight ) {
  Webcam webcam = findDevice(deviceName);
  if( webcam == null )
    throw new IllegalArgumentException("Can't find camera "+deviceName);
  adjustResolution(webcam,desiredWidth,desiredHeight);
  webcam.open();
  return webcam;
}

代码示例来源:origin: org.boofcv/WebcamCapture

/**
 * Opens the default camera while adjusting its resolution
 */
public static Webcam openDefault( int desiredWidth , int desiredHeight) {
  Webcam webcam = Webcam.getDefault();
  adjustResolution(webcam,desiredWidth,desiredHeight);
  webcam.open();
  return webcam;
}

代码示例来源:origin: io.rhiot/camel-webcam

@Override
public void process(Exchange exchange) throws Exception {
  Webcam webcam = getEndpoint().getWebcam();
  if (webcam == null) {
    throw new WebcamNotFoundException("No webcams found");
  } else if (!webcam.isOpen() && !webcam.open()) {
    throw new IllegalStateException("Unable to open webcam");
  } 
  
  BufferedImage image = webcam.getImage();
  if (image != null) {
    exchange.getIn().setBody(ImageUtils.toByteArray(image, getEndpoint().getFormat()));
  }
}

代码示例来源:origin: io.rhiot/camel-webcam

private Webcam openWebcam(Webcam webcam, Dimension dimension) {
  
  //Once started another endpoint may want to change from low res to high res, for example
  if (webcam.isOpen() && isStarted() && !dimension.equals(webcam.getViewSize())) {
    webcam.close();
  } 
  
  if (!webcam.isOpen() && dimension != null) {
    webcam.setCustomViewSizes(new Dimension[]{dimension});
    webcam.setViewSize(dimension);
    webcam.open(true);
  } else if (!webcam.isOpen()) {
    webcam.open(true);
  }
  
  return webcam;
}

相关文章