java - 使用 LTI-CIVIL 库从网络摄像头捕获图像

标签 java lti

我正在运行 cod e 以使用 LTI-CIVIL 库捕获图像..

这是代码...

public class TestWebCam implements CaptureObserver {

    JButton start = null;
    JButton shot = null;
    JButton stop = null;
    CaptureStream captureStream = null;
    boolean takeShot = false;

    public TestWebCam() {
        CaptureSystemFactory factory = DefaultCaptureSystemFactorySingleton.instance();
        CaptureSystem system;
        try {
            system = factory.createCaptureSystem();
            system.init();
            List list = system.getCaptureDeviceInfoList();
            int i = 0;
            if (i < list.size()) {
                CaptureDeviceInfo info = (CaptureDeviceInfo) list.get(i);
                System.out.println((new StringBuilder()).append("Device ID ").append(i).append(": ").append(info.getDeviceID()).toString());
                System.out.println((new StringBuilder()).append("Description ").append(i).append(": ").append(info.getDescription()).toString());
                captureStream = system.openCaptureDeviceStream(info.getDeviceID());
                captureStream.setObserver(TestWebCam.this);
            }
        } catch (CaptureException ex) {
            ex.printStackTrace();
        }
//UI work of the program
        JFrame frame = new JFrame();
        frame.setSize(7000, 800);
        JPanel panel = new JPanel();
        frame.setContentPane(panel);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        start = new JButton("Start");
        stop = new JButton("Stop");
        shot = new JButton("Shot");
        panel.add(start);
        panel.add(stop);
        panel.add(shot);
        panel.revalidate();
        start.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    captureStream.start();
                } catch (CaptureException ex) {
                    ex.printStackTrace();

                }
            }
        });
        stop.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    captureStream.stop();
                } catch (CaptureException ex) {
                    ex.printStackTrace();
                }
            }
        });
        shot.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                takeShot = true;
            }
        });
    }

    public void onNewImage(CaptureStream stream, Image image) {

        if (!takeShot) {
            return;
        }
        takeShot = false;
        System.out.println("New Image Captured");
        byte bytes[] = null;
        try {
            if (image == null) {
                bytes = null;
                return;
            }
            try {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(os);
                jpeg.encode(AWTImageConverter.toBufferedImage(image));
                os.close();
                bytes = os.toByteArray();
            } catch (IOException e) {
                e.printStackTrace();
                bytes = null;
            } catch (Throwable t) {
                t.printStackTrace();
                bytes = null;
            }
            if (bytes == null) {
                return;
            }
            ByteArrayInputStream is = new ByteArrayInputStream(bytes);
            File file = new File("/img" + Calendar.getInstance().getTimeInMillis() + ".jpg");
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(bytes);
            fos.close();
            BufferedImage myImage = ImageIO.read(file);
            shot.setText("");
            shot.setIcon(new ImageIcon(myImage));
            shot.revalidate();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public void onError(CaptureStream arg0, CaptureException arg1) {
        throw new UnsupportedOperationException("Error is coming ");

    }

    public static void main(String args[])
            throws Exception {
        TestWebCam test = new TestWebCam();

    }
}

我收到错误...

com.lti.civil.CaptureException: java.lang.UnsatisfiedLinkError: no civil in java.library.path
        at com.lti.civil.impl.jni.NativeCaptureSystemFactory.createCaptureSystem(NativeCaptureSystemFactory.java:24)
        at attendance.TestWebCam.<init>(TestWebCam.java:51)
        at attendance.TestWebCam.main(TestWebCam.java:160)
Caused by: java.lang.UnsatisfiedLinkError: no civil in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
        at java.lang.Runtime.loadLibrary0(Runtime.java:845)
        at java.lang.System.loadLibrary(System.java:1084)
        at com.lti.civil.impl.jni.NativeCaptureSystemFactory.createCaptureSystem(NativeCaptureSystemFactory.java:21)
        ... 2 more

最佳答案

找到解决方案了.. 我的是 64 位机器,为此我们需要将 Civil.dll 粘贴到 syswow64 文件夹而不是 system32 中。

关于java - 使用 LTI-CIVIL 库从网络摄像头捕获图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15861234/

相关文章:

java - 需要一个简单的开源解决方案将二维表格数据导出为PDF和Word格式

Java SE 套接字输入流未得到响应

java - Web 服务与 TCP/IP 套接字 (Java) + SQL 连接

java - UnsatifiedLinkException java——由 LTI-CIVIL 引起

java - 对其他实体的可空属性进行 Spring 可分页排序

java - 模拟其属性在测试类构造函数中使用的依赖项

oauth - Desire2Learn 使用 LTI 学习工具链接的 oAuth 签名无效

ruby-on-rails - 是否有任何一款已完成/已实现的 LTI 工具,带有 ruby​​ on Rails?

node.js - 使用 node js express 实现 IMS LTI