我正在使用opencv,javacv,javafx。
我想在CanvasFrame上显示捕获的网络摄像头,但是在我正在运行的应用程序的场景中。 这是捕获方法的代码,
@FXML
void openWebcamOnBtnClick(ActionEvent event)
{
Thread thread=new Thread()
{
@Override
public void run()
{
//super.run(); //To change body of generated methods, choose Tools | Templates.
opencv_highgui.CvCapture capture=opencv_highgui.cvCreateCameraCapture(0);
opencv_highgui.cvSetCaptureProperty(capture, opencv_highgui.CV_CAP_PROP_FRAME_HEIGHT, 360);
opencv_highgui.cvSetCaptureProperty(capture, opencv_highgui.CV_CAP_PROP_FRAME_WIDTH, 640);
opencv_core.IplImage grabbedImage=opencv_highgui.cvQueryFrame(capture);
CanvasFrame frame=new CanvasFrame("Webcam");
frame.setCanvasSize(640, 360);
while(frame.isVisible() && (grabbedImage=opencv_highgui.cvQueryFrame(capture))!=null)
{
frame.showImage(grabbedImage);
}
opencv_highgui.cvReleaseCapture(capture);
grabbedImage.release();
//frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
};
thread.start();
}
通过这样做,网络摄像头开始完全捕获并在CanvasFrame(On new Stage)上显示。但是我希望它能在老舞台上展示,每当我点击旧网站上的“打开网络摄像头”按钮时。
我可以在ImageView或任何窗格中显示捕捉网络摄像头吗?