Java captureDeviceManager.getDevice返回未在ubuntu上找到任何捕获设备

问题描述 投票:3回答:1

我想从便携式计算机的网络摄像头捕获图像。

运行Skype或任何网络摄像头应用程序时,网络摄像头可以正常工作。

我的工作站是ubuntu 11.10。

我的网络摄像头找到/ dev / v4l,此路径包括by-id by-path。

   Vector deviceList = CaptureDeviceManager.getDeviceList(new YUVFormat());

网络摄像头RGB和YUV的两种格式。

我运行v4l-info,并且我知道格式YUV。

返回没有找到的捕获设备

手动地,我在参考库中添加了jmf.jar。

请帮助我。

我只想在ubuntu 11.10中使用Java捕获图像。

如果找不到上述问题的解决方案,您能推荐我其他方法吗?

谢谢您的帮助

java ubuntu webcam jmf
1个回答
0
投票

在调用CaptureDeviceManager.getDeviceList()之前,必须先将可用设备加载到内存中。

您可以在安装JMF之后通过运行JMFRegistry手动进行操作。

enter image description here

或借助于扩展库FMJ(Java中的Free Media)以编程方式进行。这是代码:

import java.lang.reflect.Field;
import java.util.Vector;
import javax.media.*;
import javax.media.format.RGBFormat;
import net.sf.fmj.media.cdp.GlobalCaptureDevicePlugger;

public class FMJSandbox {
    static {
        System.setProperty("java.library.path", "D:/fmj-sf/native/win32-x86/");
        try {
            final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
            sysPathsField.setAccessible(true);
            sysPathsField.set(null, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String args[]) {
        GlobalCaptureDevicePlugger.addCaptureDevices(); 
        Vector deviceInfo = CaptureDeviceManager.getDeviceList(new RGBFormat());
        System.out.println(deviceInfo.size());
        for (Object obj : deviceInfo ) {
            System.out.println(obj);
        }
    }
}

这里是输出:

USB2.0 Camera : civil:\\?\usb#vid_5986&pid_02d3&mi_00#7&584a19f&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global
RGB, -1-bit, Masks=-1:-1:-1, PixelStride=-1, LineStride=-1
© www.soinside.com 2019 - 2024. All rights reserved.