gpt4 book ai didi

swing - Java CV 1.0 网络摄像头视频捕获 :Frame cannot be converted to IplImage

转载 作者:行者123 更新时间:2023-12-04 22:56:08 25 4
gpt4 key购买 nike

我无法 录制网络摄像头视频 (即 捕获 保存 .avi 或 .mp4 文件)使用 JavaCV/OpenCV/FFMPEG , 我究竟做错了什么?

使用的版本 (全部 64 位)

Win 7,NetBeans8.0.2,jdk1.7.0_10,JavaCV 1.0,OpenCV 3.0.0,ffmpeg-2.1.1-win64-shared。

我的系统变量设置为

C:\Program Files\Java\jdk1.7.0_10;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 1.5\Doctrine extensions for PHP\;C:\opencv\build\x64\vc11\bin;C:\ffmpeg\bin



下载并设置路径变量后,我将 jar 文件添加到 Netbeans 项目

C:\opencv\build\java\opencv-300.jar C:\javacv-1.0-bin\javacv-bin\videoinput.jar C:\javacv-1.0-bin\javacv-bin\videoinput-windows-x86_64.jar C:\javacv-1.0-bin\javacv-bin\videoinput-windows-x86.jar C:\javacv-1.0-bin\javacv-bin\opencv.jar C:\javacv-1.0-bin\javacv-bin\opencv-windows-x86_64.jar C:\javacv-1.0-bin\javacv-bin\opencv-windows-x86.jar C:\javacv-1.0-bin\javacv-bin\libfreenect.jar C:\javacv-1.0-bin\javacv-bin\libfreenect-windows-x86_64.jar C:\javacv-1.0-bin\javacv-bin\libfreenect-windows-x86.jar C:\javacv-1.0-bin\javacv-bin\libdc1394.jar C:\javacv-1.0-bin\javacv-bin\junit.jar C:\javacv-1.0-bin\javacv-bin\javacv.jar C:\javacv-1.0-bin\javacv-bin\javacpp.jar C:\javacv-1.0-bin\javacv-bin\hamcrest-core.jar C:\javacv-1.0-bin\javacv-bin\flycapture.jar C:\javacv-1.0-bin\javacv-bin\flycapture-windows-x86_64.jar C:\javacv-1.0-bin\javacv-bin\flycapture-windows-x86.jar C:\javacv-1.0-bin\javacv-bin\flandmark.jar C:\javacv-1.0-bin\javacv-bin\flandmark-windows-x86_64.jar C:\javacv-1.0-bin\javacv-bin\flandmark-windows-x86.jar C:\javacv-1.0-bin\javacv-bin\ffmpeg.jar C:\javacv-1.0-bin\javacv-bin\ffmpeg-windows-x86_64.jar C:\javacv-1.0-bin\javacv-bin\ffmpeg-windows-x86.jar C:\javacv-1.0-bin\javacv-bin\artoolkitplus.jar C:\javacv-1.0-bin\javacv-bin\artoolkitplus-windows-x86_64.jar C:\javacv-1.0-bin\javacv-bin\artoolkitplus-windows-x86.jar



问题一:
第一个捕获网络摄像头视频(显示并保存到 output.avi 文件)的程序如下所示。

它显示网络摄像头并创建 output.avi。但是当我在媒体播放器中打开文件 output.avi 时终止程序后,它不显示任何内容:)

它不起作用
import java.io.File;
import java.net.URL;
import org.bytedeco.javacv.*;
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.indexer.*;
import static org.bytedeco.javacpp.opencv_core.*;
import static org.bytedeco.javacpp.opencv_imgproc.*;
import static org.bytedeco.javacpp.opencv_calib3d.*;
import static org.bytedeco.javacpp.opencv_objdetect.*;

public class JCVdemo3 {
public static void main(String[] args) throws Exception {

// Preload the opencv_objdetect module to work around a known bug.
Loader.load(opencv_objdetect.class);

// The available FrameGrabber classes include OpenCVFrameGrabber (opencv_videoio),
// DC1394FrameGrabber, FlyCaptureFrameGrabber, OpenKinectFrameGrabber,
// PS3EyeFrameGrabber, VideoInputFrameGrabber, and FFmpegFrameGrabber.
FrameGrabber grabber = FrameGrabber.createDefault(0);
grabber.start();

// CanvasFrame, FrameGrabber, and FrameRecorder use Frame objects to communicate image data.
// We need a FrameConverter to interface with other APIs (Android, Java 2D, or OpenCV).
OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();


IplImage grabbedImage = converter.convert(grabber.grab());
int width = grabbedImage.width();
int height = grabbedImage.height();


FrameRecorder recorder = FrameRecorder.createDefault("output.avi", width, height);
recorder.start();


CanvasFrame frame = new CanvasFrame("Some Title");

while (frame.isVisible() && (grabbedImage = converter.convert(grabber.grab())) != null) {
// cvWarpPerspective(grabbedImage, rotatedImage, randomR);

Frame rotatedFrame = converter.convert(grabbedImage);

//opencv_core.IplImage grabbedImage = grabber.grab();
frame.showImage(rotatedFrame);
recorder.record(rotatedFrame);
}
frame.dispose();
recorder.stop();
grabber.stop();
}
}

问题2:当我运行以下代码时
opencv_core.IplImage grabbedImage = grabber.grab();  

不兼容的类型:帧无法转换为 IplImage 出现消息
import java.io.File;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bytedeco.javacv.*;
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.indexer.*;
import static org.bytedeco.javacpp.opencv_core.*;
import static org.bytedeco.javacpp.opencv_imgproc.*;
import static org.bytedeco.javacpp.opencv_calib3d.*;
import static org.bytedeco.javacpp.opencv_objdetect.*;

public class Demo {
public static void main(String[] args) {
try {
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
grabber.start();
opencv_core.IplImage grabbedImage = grabber.grab();
CanvasFrame canvasFrame = new CanvasFrame("Video with JavaCV");
canvasFrame.setCanvasSize(grabbedImage.width(), grabbedImage.height());
grabber.setFrameRate(grabber.getFrameRate());

FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("mytestvideo.mp4", grabber.getImageWidth(), grabber.getImageHeight());
recorder.setFormat("mp4");
recorder.setFrameRate(30);
recorder.setVideoBitrate(10 * 1024 * 1024);


recorder.start();
while (canvasFrame.isVisible() && (grabbedImage = grabber.grab()) != null) {
canvasFrame.showImage(grabbedImage);
recorder.record(grabbedImage);
}
recorder.stop();
grabber.stop();
canvasFrame.dispose();

} catch (FrameGrabber.Exception ex) {
Logger.getLogger(JCVdemo.class.getName()).log(Level.SEVERE, null, ex);
} catch (FrameRecorder.Exception ex) {
Logger.getLogger(JCVdemo.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

问题是:我究竟做错了什么?

我无法录制任何类型的视频;无论我使用什么版本的 JavaCV/OPenCv。

请告诉我从网络摄像头录制视频的工作示例以及工作 JavaCV/OpenCV/FFmpeg 兼容版本。

最佳答案

使用:OpenCVFrameConverter

OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
img = converter.convert(grabber.grab());

发件人: https://github.com/bytedeco/javacv#sample-usage

关于swing - Java CV 1.0 网络摄像头视频捕获 :Frame cannot be converted to IplImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32422809/

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