• java 调用摄像头拍照


    <dependency>
    <groupId>com.github.sarxos</groupId>
    <artifactId>webcam-capture</artifactId>
    <version>0.3.12</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.humble/humble-video-all -->
    <dependency>
    <groupId>io.humble</groupId>
    <artifactId>humble-video-all</artifactId>
    <version>0.3.0</version>
    </dependency>
    package com.sys.springbootcaputre;

    import com.github.sarxos.webcam.Webcam;
    import com.github.sarxos.webcam.WebcamPanel;
    import com.github.sarxos.webcam.WebcamResolution;
    import lombok.extern.slf4j.Slf4j;

    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.nio.charset.Charset;

    /**
    * @ClassName test
    * @Author sys
    * @Date 2020/11/4 16:49
    * @Description //TODO
    * @Version
    **/
    @Slf4j
    public class test {
    public static void main(String[] args) {
    Webcam webcam = Webcam.getDefault();

    webcam.setViewSize(WebcamResolution.VGA.getSize());

    WebcamPanel panel = new WebcamPanel(webcam);

    panel.setFPSDisplayed(true);

    panel.setDisplayDebugInfo(true);

    panel.setImageSizeDisplayed(true);

    panel.setMirrored(true);

    JFrame window = new JFrame("Test webcam panel");
    JButton b = new JButton(new String("拍照".getBytes(), Charset.defaultCharset()));
    b.setPreferredSize(new Dimension(50,30));
    b.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
    Webcam webcamc = Webcam.getDefault();
    webcamc.open();
    BufferedImage image = webcamc.getImage();
    // save image to PNG file
    try {
    ImageIO.write(image, "PNG", new File("e:/cap/testbut.png"));
    } catch (IOException ex) {
    log.info("拍照失败");
    ex.printStackTrace();
    }
    log.info("拍照成功");
    }
    });
    panel.add(b);
    window.add(panel);

    window.setResizable(true);

    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    window.pack();
    //webcam.open();
    window.setVisible(true);
    // Thread t = new Thread(() -> {
    // Webcam webcamc = Webcam.getDefault();
    // webcamc.open();
    // try {
    // // get image //保存图片
    // for(int i=0;i<600;i++) {
    // BufferedImage image = webcamc.getImage();
    // // save image to PNG file
    // ImageIO.write(image, "PNG", new File("e:/cap/test"+i+".png"));
    // Thread.sleep(1000);//1s
    // }
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    //
    // });
    // t.start();

    }
    }

    https://github.com/sarxos/webcam-capture

  • 相关阅读:
    只能输入数字
    js 添加、获取、删除 cookie
    获取一个对象的属性/属性值,以及动态给属性赋值
    自定义注解
    C#快捷方式
    前端乱码
    句法错误#{}, 也会导致的异常 org.apache.ibatis.builder.BuilderException java.lang.StringIndexOutOfBoundsException
    [mybatis重复mapper] Error parsing SQL Mapper Configuration
    [aop报错] Cannot resolve reference to bean 'txPointCut' while setting bean property 'pointcut'
    Java工具安装配置(JDK、MySql、Tomcat、Maven、Idea)
  • 原文地址:https://www.cnblogs.com/syscn/p/13927403.html
Copyright © 2020-2023  润新知