基于java的可移植应用程序与web摄像头配合使用
如果我能得到关于我的问题的建议,那就太好了:我正在使用一个应用程序,它应该向用户显示一个连接的PC摄像头列表。例如,使用笔记本电脑,我有一个内置网络摄像头和一个USB摄像头。运行应用程序时,用户应该能够选择所需的设备,并使用它创建照片 我已经研究这个问题好几天了,并使用以下现有框架进行了研究:JMF、FMJ、VLCJ、Xuggler、JMyron、JavaFX、JavaCV 其中一些已经被弃用;另一些则要求为每台客户端PC安装SDK。然而,我的应用程序的主要要求是可移植性,这使我厌倦了使用外部SDK 是否可以仅使用Java完成此任务 现在我的应用程序应该只能在Windows操作系统上运行 那么,我能就如何解决我的问题提出一些建议吗基于java的可移植应用程序与web摄像头配合使用,java,windows,webcam,Java,Windows,Webcam,如果我能得到关于我的问题的建议,那就太好了:我正在使用一个应用程序,它应该向用户显示一个连接的PC摄像头列表。例如,使用笔记本电脑,我有一个内置网络摄像头和一个USB摄像头。运行应用程序时,用户应该能够选择所需的设备,并使用它创建照片 我已经研究这个问题好几天了,并使用以下现有框架进行了研究:JMF、FMJ、VLCJ、Xuggler、JMyron、JavaFX、JavaCV 其中一些已经被弃用;另一些则要求为每台客户端PC安装SDK。然而,我的应用程序的主要要求是可移植性,这使我厌倦了使用外部S
你好,叶甫盖尼,很抱歉我这么早就把问题发出去了。我刚刚解决了这个问题。我用了LTI-CIVIL。它已经5年没有更新了。。。不管怎样,它对我所有的网络摄影师都很好。我对其中一个使用示例进行了一些更改,以在现有设备之间切换。 这是我的密码:
public class CaptureFrame extends ImageFrame
{
private Map <String, String>cams = new HashMap<String, String>();
public static void main(String[] args) throws CaptureException
{
new CaptureFrame(DefaultCaptureSystemFactorySingleton.instance()).run();
}
private CaptureSystem system;
private CaptureStream captureStream;
private final CaptureSystemFactory factory;
private volatile boolean disposing = false;
public CaptureFrame(CaptureSystemFactory factory)
{
super("LTI-CIVIL");
this.factory = factory;
}
public void run() throws CaptureException
{
initCapture();
setLocation(200, 200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
try
{
disposeCapture();
} catch (CaptureException e1)
{
e1.printStackTrace();
}
System.exit(0);
}
});
setVisible(true);
pack();
system = factory.createCaptureSystem();
system.init();
List <CaptureDeviceInfo>list = system.getCaptureDeviceInfoList();
String[] possibilities = new String[list.size()];
int i=0;
for (CaptureDeviceInfo info : list){
possibilities[i] = info.getDescription();
cams.put(info.getDescription(), info.getDeviceID());
i++;
}
String s = (String) JOptionPane.showInputDialog(
this,
"Please, choose needed web camera:\n",
"Select one...",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities, null);
captureStream = system.openCaptureDeviceStream(cams.get(s));
captureStream.setObserver(new MyCaptureObserver());
setSize(captureStream.getVideoFormat().getWidth(), captureStream.getVideoFormat().getHeight());
startCapture();
}
public void initCapture() throws CaptureException
{
system = factory.createCaptureSystem();
system.init();
}
public void startCapture() throws CaptureException
{
captureStream.start();
}
public void disposeCapture() throws CaptureException
{
disposing = true;
if (captureStream != null)
{ System.out.println("disposeCapture: stopping capture stream...");
captureStream.stop();
System.out.println("disposeCapture: stopped capture stream.");
captureStream.dispose();
captureStream = null;
}
if (system != null)
system.dispose();
System.out.println("disposeCapture done.");
}
class MyCaptureObserver implements CaptureObserver
{
public void onError(CaptureStream sender, CaptureException e)
{
e.printStackTrace();
}
public void onNewImage(CaptureStream sender, com.lti.civil.Image image)
{
if (disposing)
return;
try
{
setImage(AWTImageConverter.toBufferedImage(image));
}
catch (Throwable t)
{ t.printStackTrace();
}
}
}
}
此外,我的项目的大小只有大约3 MB,其中包含Windows操作系统的所有.dll库
我希望它能帮助别人
你好,叶甫盖尼,很抱歉我这么早就把问题发出去了。我刚刚解决了这个问题。我用了LTI-CIVIL。它已经5年没有更新了。。。不管怎样,它对我所有的网络摄影师都很好。我对其中一个使用示例进行了一些更改,以在现有设备之间切换。 这是我的密码:
public class CaptureFrame extends ImageFrame
{
private Map <String, String>cams = new HashMap<String, String>();
public static void main(String[] args) throws CaptureException
{
new CaptureFrame(DefaultCaptureSystemFactorySingleton.instance()).run();
}
private CaptureSystem system;
private CaptureStream captureStream;
private final CaptureSystemFactory factory;
private volatile boolean disposing = false;
public CaptureFrame(CaptureSystemFactory factory)
{
super("LTI-CIVIL");
this.factory = factory;
}
public void run() throws CaptureException
{
initCapture();
setLocation(200, 200);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
try
{
disposeCapture();
} catch (CaptureException e1)
{
e1.printStackTrace();
}
System.exit(0);
}
});
setVisible(true);
pack();
system = factory.createCaptureSystem();
system.init();
List <CaptureDeviceInfo>list = system.getCaptureDeviceInfoList();
String[] possibilities = new String[list.size()];
int i=0;
for (CaptureDeviceInfo info : list){
possibilities[i] = info.getDescription();
cams.put(info.getDescription(), info.getDeviceID());
i++;
}
String s = (String) JOptionPane.showInputDialog(
this,
"Please, choose needed web camera:\n",
"Select one...",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities, null);
captureStream = system.openCaptureDeviceStream(cams.get(s));
captureStream.setObserver(new MyCaptureObserver());
setSize(captureStream.getVideoFormat().getWidth(), captureStream.getVideoFormat().getHeight());
startCapture();
}
public void initCapture() throws CaptureException
{
system = factory.createCaptureSystem();
system.init();
}
public void startCapture() throws CaptureException
{
captureStream.start();
}
public void disposeCapture() throws CaptureException
{
disposing = true;
if (captureStream != null)
{ System.out.println("disposeCapture: stopping capture stream...");
captureStream.stop();
System.out.println("disposeCapture: stopped capture stream.");
captureStream.dispose();
captureStream = null;
}
if (system != null)
system.dispose();
System.out.println("disposeCapture done.");
}
class MyCaptureObserver implements CaptureObserver
{
public void onError(CaptureStream sender, CaptureException e)
{
e.printStackTrace();
}
public void onNewImage(CaptureStream sender, com.lti.civil.Image image)
{
if (disposing)
return;
try
{
setImage(AWTImageConverter.toBufferedImage(image));
}
catch (Throwable t)
{ t.printStackTrace();
}
}
}
}
此外,我的项目的大小只有大约3 MB,其中包含Windows操作系统的所有.dll库
我希望它能帮助别人
您好,EvgeniyXuggler既没有被弃用,也不需要安装。@LanguageSnamedAfterCofe,谢谢您的评论。据我所知,Xugler生成API,以按驱动程序名和设备名捕获网络摄像头。如果你给我一个建议,我怎样才能在Windows操作系统上获得它们,那就太好了。根据这个线程groups.google.com/forum/?fromgroups=!topic/xuggler users/…xuggler不支持正确使用网络摄像头。xuggler既不被弃用,也不需要安装。@LanguageSnamedAfterCofe,谢谢您的评论。据我所知,Xugler生成API,以按驱动程序名和设备名捕获网络摄像头。如果你给我一个建议,我怎样才能在Windows操作系统上获得它们,那就太好了。根据这个线程groups.google.com/forum/?fromgroups=!topic/Xugler users/…Xugler不支持正确使用网络摄像头。它不适用于Windows OS x64。所以,如果有人知道更好的解决方案,请告诉我。它不适用于Windows OS x64。所以,如果有人知道更好的解决方案,请告诉我。