gpt4 book ai didi

JavaCV Canvas 保持空白

转载 作者:行者123 更新时间:2023-11-30 07:20:54 26 4
gpt4 key购买 nike

我想不断捕捉网络摄像头并让它在 Canvas 上查看。图像的保存很好。它每秒拍摄一张照片。但是 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;
}
}

最佳答案

尝试使用此代码捕获网络摄像头。在运行此代码之前加载库。 (JavaCV jar 文件等)

import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.FrameGrabber.Exception;
import com.googlecode.javacv.OpenCVFrameGrabber;
import static com.googlecode.javacv.cpp.opencv_core.*;

public class capture{

CanvasFrame frame,fr;
IplImage image,im;
OpenCVFrameGrabber grabber,gr;
public capture() throws Exception {
frame=new CanvasFrame("Cam 1");
grabber=new OpenCVFrameGrabber(0);
grabber.start();
while (((frame.isVisible()) && (image = grabber.grab()) != null)){
//cvFlip(image,image,1); if needed to flip.

frame.showImage(image);


}
frame.setDefaultCloseOperation(1);
frame.setDefaultCloseOperation(CanvasFrame.EXIT_ON_CLOSE);
}

关于JavaCV Canvas 保持空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13687270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com