很抱歉,我很早就發佈了這個問題。我剛剛解決了這個問題。我使用了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庫我希望這會幫助別人。
此致,Evgeniy
Xuggler既不被棄用也不需要安裝。 – LanguagesNamedAfterCofee
@LanguagesNamedAfterCofee,謝謝你的評論。據我所知,Xuggler通過驅動程序名稱和設備名稱生成API來捕獲網絡攝像頭。如果你給我一個建議,我怎樣才能讓他們在Windows操作系統上,這將是偉大的。根據此線程groups.google.com/forum/?fromgroups=#!topic/xuggler-users/... Xuggler不支持正確使用網絡攝像頭。 – evgeniy44