2012-12-05 57 views
0

我有一個簡單的網絡攝像頭程序在「偶爾」的作品,但大多數時候它試圖找到默認驅動程序掛起。網絡攝像頭捕捉有時只有作品

public class JavaApplication54 { 

/** 
* @param args the command line arguments 
*/ 
public static void main(String[] args) throws IOException { 
    Webcam webcam = Webcam.getWebcams().get(0); 

    webcam.open(); 
    BufferedImage image = webcam.getImage(); 
    ImageIO.write(image, "PNG", new File("test.png")); 
    image = null; 
    webcam.close(); 
} 

} 我得到的輸出是

13:22:08.910 [main] INFO c.g.sarxos.webcam.WebcamDriverUtils - 
    Searching driver com.github.sarxos.webcam.ds.openimaj.OpenImajDriver 
    13:22:08.915 [main] DEBUG c.g.sarxos.webcam.WebcamDriverUtils - 
    Driver com.github.sarxos.webcam.ds.openimaj.OpenImajDriver not found 
    13:22:08.915 [main] INFO c.g.sarxos.webcam.WebcamDriverUtils - 
    Searching driver com.github.sarxos.webcam.ds.civil.LtiCivilDriver 
    13:22:08.915 [main] DEBUG c.g.sarxos.webcam.WebcamDriverUtils - 
    Driver com.github.sarxos.webcam.ds.civil.LtiCivilDriver not found 
    13:22:08.915 [main] INFO c.g.sarxos.webcam.WebcamDriverUtils - 
    Searching driver com.github.sarxos.webcam.ds.jmf.JmfDriver 
    13:22:08.916 [main] DEBUG c.g.sarxos.webcam.WebcamDriverUtils - 
    Driver com.github.sarxos.webcam.ds.jmf.JmfDriver not found 
    13:22:08.916 [main] INFO com.github.sarxos.webcam.Webcam - Webcam 
    driver has not been found, default one will be used! 13:22:08.925 
    [main] DEBUG c.g.s.w.d.b.WebcamDefaultDriver - Searching devices 
+0

我剛剛發現,這似乎只發生在我運行Netbeans時。如果我運行JAR,我會獲得100%的成功。所以我想這個問題可能與netbeans包裝它運行的程序的方式有關。任何人都知道如何解決這個問題,因爲這會使調試變得更容易。謝謝 – user845854

回答

1

如果我是正確的,這是在攝像頭捕獲API代碼中發現了僵局問題之一。有關詳細信息,您可以檢查Webcam Capture Github project頁面上可用這些票:#128#30

我想辦法解決你的將是使用最新的版本,這是(對的時候,我正在寫這個答案)0.3.10-RC6。無論IDE(或CLI)用於開發,它都應該工作。