本文整理匯總了Java中com.github.sarxos.webcam.Webcam.open方法的典型用法代碼示例。如果您正苦於以下問題:Java Webcam.open方法的具體用法?Java Webcam.open怎麽用?Java Webcam.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.sarxos.webcam.Webcam
的用法示例。
在下文中一共展示了Webcam.open方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: takePic
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public void takePic() {
// get default webcam and open it
Webcam webcam = Webcam.getDefault();
Dimension[] nonStandardResolutions = new Dimension[] { WebcamResolution.PAL.getSize(),
WebcamResolution.HD720.getSize(), new Dimension(2000, 1000), new Dimension(1000, 500), };
webcam.setCustomViewSizes(nonStandardResolutions);
webcam.setViewSize(WebcamResolution.HD720.getSize());
webcam.open();
// get image
BufferedImage image = webcam.getImage();
// save image to PNG file
try {
ImageIO.write(image, "PNG", new File("src/capture/test.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
webcam.close();
}
示例2: Capture
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public static void Capture(String filePath, String fileName, int widthx, int heighty) throws IOException {
Webcam webcam = Webcam.getDefault();
if (webcam != null) {
// System.out.println("Webcam: " + webcam.getName());
webcam.setViewSize(new Dimension(widthx, heighty));
webcam.open();
ImageIO.write(webcam.getImage(), "PNG", new File(filePath + fileName + ".png"));
webcam.close();
}
}
示例3: snapImg
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
/**
* CamBot requires dependencies for Sarxos Webcam Capture.
* If this is not a needed function in your environment,
* please exclude them to reduce payload size, and comment out the imports
* in this file.
*
*/
public static void snapImg() throws IOException
{
try
{
Webcam wc = Webcam.getDefault();
wc.open();
File tgt = new File ("C:/ClassPolicy/cam.png");
if (tgt.exists()) {
tgt.delete();
}
ImageIO.write(wc.getImage(), "PNG", tgt);
Chocolat.println("[CamBot] Successfully snapped a shot!");
}
catch (Exception e)
{
Chocolat.println("[CamBot] Encountered an exception: " + e);
}
}
示例4: run
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
@Override
public void run() {
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
webcam.open();
JFrame frame=new JFrame();
frame.setTitle("webcam capture");
// frame.setLayout(new FlowLayout());
JLabel lbl = new JLabel();
frame.add(lbl);
frame.setVisible(true);
while (true) {
if (!webcam.isOpen()) break;
BufferedImage image = webcam.getImage();
if (image == null) break;
frame.setSize(image.getWidth(),image.getHeight());
lbl.setIcon(new ImageIcon(image));
}
}
示例5: RecogApp
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public RecogApp()
{
super("Card Recognizer");
BorderLayout bl = new BorderLayout();
setLayout(bl);
list = new RecogList();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Webcam w = WebcamUtils.chooseWebcam();
JPanel right = new JPanel();
right.setLayout(new GridLayout(2,1));
wc = new WebcamCanvas(w);
JScrollPane scroll = new JScrollPane();
select = new SetLoadPanel(list);
scroll.setViewportView(select);
add(wc,BorderLayout.CENTER);
add(right,BorderLayout.EAST);
right.add(new SettingsPanel());
right.add(scroll);
right.setPreferredSize(new Dimension(300,wc.getHeight()));
pack();
setVisible(true);
setResizable(false);
try{
w.open();
}catch(WebcamLockException e)
{
JOptionPane.showMessageDialog(null, "Webcam already in use. Exiting.");
System.exit(0);
}
wc.getCanvas().addKeyListener(this);
while(true)
{
wc.draw();
if(SettingsPanel.RECOG_EVERY_FRAME)
{
doRecog();
}
}
}
示例6: findWebcam
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
private static Webcam findWebcam(String url) throws MalformedURLException {
if (url != null) {
Webcam.setDriver(new IpCamDriver());
IpCamDeviceRegistry.register(new IpCamDevice("Set", url, IpCamMode.PULL));
}
Webcam webcam = Webcam.getDefault();
if (webcam == null) {
throw new IllegalStateException("Cannot find webcam");
}
webcam.open();
return webcam;
}
示例7: webCam
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
private BufferedImage webCam()
{
//**get default webcam..set resolution..open it
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
webcam.open();
BufferedImage pic = webcam.getImage();
webcam.close(); // Not sure if webcam should stay open or be closed after each use.
return pic;
}
示例8: initCamera
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
static WebcamData initCamera(String cc, String camName)
{
LinkedHashMap<String, Webcam> detectedCameras = new LinkedHashMap<String, Webcam>();
List<Webcam> cams = Webcam.getWebcams();
Webcam webcam = null;
for (Webcam cam : cams)
{
detectedCameras.put(cam.getName(), cam);
if (cam.getName().startsWith(camName))
{
webcam = cam;
}
}
if (webcam == null)
{
throw new WebcamInitException("Webcam listed in config was not found: " + camName);
}
WebcamData data = new WebcamData(cc, webcam);
webcam.setImageTransformer(new WebcamTransformer());
log.info("Initializing webcam: " + camName);
Dimension[] sizes = webcam.getViewSizes();
Dimension dimension = null;
for (Dimension d : sizes)
{
log.info("Found image dimension: " + d.getWidth() + "x" + d.getHeight());
if (d.getWidth() == 320)
{
dimension = d;
}
}
if (dimension == null)
{
dimension = sizes[0];
}
log.info("Selected image dimension: " + dimension.getWidth() + "x" + dimension.getHeight());
if (!webcam.getViewSize().equals(dimension))
{
webcam.setViewSize(dimension);
}
webcam.open(true);
webcam.addWebcamListener(data);
System.out.println(webcam.getViewSize());
((WebcamDefaultDevice) webcam.getDevice()).FAULTY = false;
return data;
}
示例9: run
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
@Override
public void run(EyeballsConfiguration eyeballsConfiguration, Environment environment) throws Exception {
Security.addProvider(new BouncyCastleProvider());
createUnderylingStorageDirectories(eyeballsConfiguration);
if (eyeballsConfiguration.getUseAuth()) {
environment.jersey().register(new AuthDynamicFeature(
new BasicCredentialAuthFilter.Builder<BasicAuthenticator.EyeballUser>()
.setAuthenticator(new BasicAuthenticator(eyeballsConfiguration))
.setRealm("Eyeballs Motion Detection Server")
.buildAuthFilter()));
}
DB db = buildMapDb(eyeballsConfiguration);
BTreeMap<String, MotionEvent> motionEventStore = db.createTreeMap("motionEventStore")
.valueSerializer(new LocalEventSerializer())
.makeOrGet();
Webcam webcam = Webcam.getDefault();
if (webcam == null) {
throw new RuntimeException("No webcam present, or not available to the current user.");
}
PictureTakingService pictureTakingService = new PictureTakingService(webcam);
webcam.addWebcamListener(pictureTakingService);
Dimension[] dimensions = (Dimension[]) Arrays.stream(WebcamResolution.values())
.map(WebcamResolution::getSize)
.collect(Collectors.toList())
.toArray();
webcam.setCustomViewSizes(dimensions);
webcam.setViewSize(new Dimension(eyeballsConfiguration.getImageWidth(), eyeballsConfiguration.getImageHeight()));
webcam.open();
MotionEventProcessor.Builder processorBuilder = new MotionEventProcessor.Builder();
if (eyeballsConfiguration.getUseSftp()) {
processorBuilder.addMotionEventConsumer(new SftpMotionEventConsumer(eyeballsConfiguration));
}
if (eyeballsConfiguration.getUseDropbox()) {
processorBuilder.addMotionEventConsumer(new DropboxMotionEventConsumer(eyeballsConfiguration));
}
if (eyeballsConfiguration.getUseLocalPersistence()) {
LocalFSMotionEventConsumer localFSMotionEventConsumer = new LocalFSMotionEventConsumer(db, eyeballsConfiguration, motionEventStore);
processorBuilder.addMotionEventConsumer(localFSMotionEventConsumer);
processorBuilder.motionEventPersitence(localFSMotionEventConsumer);
}
if (eyeballsConfiguration.getUseDropboxPersistence()) {
processorBuilder.motionEventPersitence(new DropBoxMotionEventPersistence(eyeballsConfiguration, motionEventStore));
}
processorBuilder.motionEventStore(motionEventStore);
MotionEventProcessor motionEventProcessor = processorBuilder.build();
MotionDetectionService motionDetectionService = new MotionDetectionService(eyeballsConfiguration,
new SaveMotionDetectedListener(motionEventProcessor, eyeballsConfiguration));
motionDetectionService.startAndWait();
EyeballsResource eyeballsResource = new EyeballsResource(webcam, motionEventProcessor, pictureTakingService);
environment.jersey().register(eyeballsResource);
}
示例10: main
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
new File("img").mkdir();
Reader.init();
JFrame f = new JFrame();
JButton button = new JButton(new AbstractAction("Read aloud!") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
if (image != null) {
try {
Reader.parse(image);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
});
button.setMnemonic(KeyEvent.VK_SPACE);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension size = new Dimension(1280, 720);
f.add(button);
f.setSize(size.width, size.height);
f.setLocationRelativeTo(null);
f.setVisible(true);
Webcam webcam = Webcam.getDefault();
webcam.setCustomViewSizes(new Dimension[] { size });
webcam.setViewSize(webcam.getCustomViewSizes()[0]);
webcam.open();
while (true) {
image = webcam.getImage();
button.setIcon(new ImageIcon(image));
button.setOpaque(true);
f.pack();
}
}
示例11: picture
import com.github.sarxos.webcam.Webcam; //導入方法依賴的package包/類
public void picture(final File output) throws IOException {
final Webcam webcam = Webcam.getDefault();
webcam.open();
ImageIO.write(webcam.getImage(), "JPG", output);
}