在运行程序从网络摄像头捕获视频中抓取帧时,我遇到了NullPointerException问题。我试图更改捕获设备的设置但是没有像
这样的选项“vfw:Microsoft WDM图像捕获(Win32):0” 无法在jmf中找到设备。 .so直接提到参考资料的代码。但是没有工作! 我正在使用net bean,jmf的库也包含在netbeans中。 请帮我解决这个问题。我的代码:
package VideoSource;
/**
*
* @author sri
*/
import java.awt.Frame;
import javax.imageio.ImageIO;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import javax.media.Buffer;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.CaptureDeviceInfo;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
import javax.media.*;
public class frames {
public static final String DEVICE ="vfw:Microsoft WDM Image Capture (Win32):0";
//protected Player player;
public static void main(String args[]) throws IOException, CannotRealizeException{
try{
CaptureDeviceInfo cdi = CaptureDeviceManager.getDevice(DEVICE);
Player player = Manager.createRealizedPlayer(cdi.getLocator());
player.start();
FrameGrabbingControl frameGrabber = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
Buffer buf = frameGrabber.grabFrame();
//BufferedImage buf1 = frameGrabber.grabFrame();
// Convert frame to an buffered image so it can be processed and saved
Image img = (new BufferToImage((VideoFormat) buf.getFormat()).createImage(buf));
if(img!=null){
RenderedImage img1=(RenderedImage) img;
int i=0;
File outputfile = new File("d:/Project/frame"+(i++)+".jpg");
ImageIO.write(img1, "jpg", outputfile);
}
else
System.out.println("null from frame grabbing");
//return img;
}
catch(NoPlayerException n)
{
}
}
}
我有例外:
Exception in thread "main" java.lang.NullPointerException
at VideoSource.frames.main(frames.java:37)
Java Result: 1