当前位置: 代码迷 >> 综合 >> terminating async callback----Opencv,java.fx ,调摄像头的看过来
  详细解决方案

terminating async callback----Opencv,java.fx ,调摄像头的看过来

热度:24   发布时间:2024-02-10 05:40:09.0
视频流,有问题都来看了,就当是警示自己千万别加下面这行代码,说三遍
千万别加下面这行代码,说三遍
千万别加下面这行代码,说三遍VideoCapture.release()下面是正确可以运行的代码,少了几个大括号,要用的别忘了加上System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture capture = new VideoCapture(0);
Mat matrix = new Mat();
Task task = new Task<Void>() {@Overridepublic Void call() {WritableImage WritableImage = null;while (true) {capture.read(matrix);if (capture.isOpened()) {if (capture.read(matrix)) {BufferedImage image = new BufferedImage(matrix.width(), matrix.height(), BufferedImage.TYPE_3BYTE_BGR);WritableRaster raster = image.getRaster();DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer();byte[] data = dataBuffer.getData();matrix.get(0, 0, data);WritableImage = SwingFXUtils.toFXImage(image, null);videoPreview.setImage(WritableImage);}}