我想不断地捕捉网络摄像头并让它在画布上查看。图像的保存很好。它每秒拍一张照片。但是 canvas.showImage() 不起作用。我的屏幕仍然空白。控制台每帧都会显示“已清理相机”。
头等舱:
public class StartUp {
public static void main(String[] args) {
CanvasFrame canvas = new CanvasFrame("Cam");
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
CaptureImage captureimage = new CaptureImage();
while(true){
try {
IplImage img = captureimage.captureFrame();
canvas.showImage(img);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
二等:
public class CaptureImage {
public IplImage captureFrame() {
final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
try {
grabber.start();
IplImage img = grabber.grab();
if (img != null) {
cvSaveImage("Image.jpg",img);
return img;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}