在运行程序以从网络摄像头捕获的视频中抓取帧时,我遇到了 NullPointerException 的问题。我试图更改捕获设备的设置,但没有类似的选项
“vfw:Microsoft WDM Image Capture (Win32):0” 无法在 jmf 中定位设备。.so 在引用材料的代码中直接提到。但不起作用!我正在为此使用 net beans,并且 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