我想不斷捕捉攝像頭並讓它在畫布上進行查看。保存圖像很好。它每秒鐘拍攝一張照片。但是canvas.showImage()不起作用。我的屏幕保持空白。控制檯說每個框架都有「清理相機」。JavaCV畫布保留空白
頭等艙:
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;
}
}
在上面的代碼變量fr,im,gr是未使用&不需要的。 –