我有以下代码使用 Javacv 使用网络摄像头捕获图像。它可以正常工作,但现在它与NullPointerException
.
代码:
public class ClientTest {
public static void main(String[] args) {
takeImage();
}
public static ImageIcon takeImage() {
FrameGrabber grabber = null;
IplImage img = null;
ImageIcon image = null;
try {
grabber = FrameGrabber.createDefault(0);
} catch (com.googlecode.javacv.FrameGrabber.Exception e1) {
e1.printStackTrace();
}
int i = 0;
try {
grabber.start();
img = grabber.grab();
if (img != null) {
cvFlip(img, img, 1);
}
// Save image
image = new ImageIcon(img.getBufferedImage());
grabber.flush();
grabber.stop();
} catch (Exception e) {
Client.showMessage("Error taking image!");
e.printStackTrace();
}
return image;
}
}
错误:
Exception in thread "main" java.lang.NullPointerException
at com.googlecode.javacv.FrameGrabber.create(FrameGrabber.java:95)
at com.googlecode.javacv.FrameGrabber.createDefault(FrameGrabber.java:118)
at Main.ClientTest.takeImage(ClientTest.java:33)
at Main.ClientTest.main(ClientTest.java:24)
如果有人能提供一些启发,我将不胜感激,这是一个紧迫的问题,因为它是我最后一年项目的一部分,该项目将于周一到期......