在MacOSX上使用OpenCV 2.4.13.2上的C API创建并保存视频后,无法打开视频 我在Mac Oxon上使用OpenCV 2.4.132的C API创建和保存视频后无法打开视频,我已经查看了一个教程,因为C++ API现在对OpenCV很受欢迎。我花了两天的时间学习教程,特别是在这里我试图重现这个例子
我可以启动相机,开始录制并写入文件“out.avi”,但是我无法用VLC或Quicktime打开它 这是我的整个计划:在MacOSX上使用OpenCV 2.4.13.2上的C API创建并保存视频后,无法打开视频 我在Mac Oxon上使用OpenCV 2.4.132的C API创建和保存视频后无法打开视频,我已经查看了一个教程,因为C++ API现在对OpenCV很受欢迎。我花了两天的时间学习教程,特别是在这里我试图重现这个例子,c,opencv,computer-vision,video-capture,C,Opencv,Computer Vision,Video Capture,我可以启动相机,开始录制并写入文件“out.avi”,但是我无法用VLC或Quicktime打开它 这是我的整个计划: #include <stdio.h> #include <cv.h> #include "highgui.h" #include "cxcore.h" int main(int argc, char **argv) { int key = 0; int i = 0; CvCapture *capture = 0; //The camera
#include <stdio.h>
#include <cv.h>
#include "highgui.h"
#include "cxcore.h"
int main(int argc, char **argv) {
int key = 0;
int i = 0;
CvCapture *capture = 0; //The camera
IplImage* frame = 0; //The images you bring out of the camera
capture = cvCaptureFromCAM(0); //Open the camera
if (!capture ){
printf("Could not connect to camera\n" ); return 1;
}
cvQueryFrame(capture);
double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int frame_height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
int frame_width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
cvNamedWindow("win", CV_WINDOW_AUTOSIZE);
cvMoveWindow("win", 100, 100);
CvVideoWriter *writer = cvCreateVideoWriter("out.avi", CV_FOURCC('D', 'I', 'V', 'X'), fps, cvSize(frame_width, frame_height), 1);
if (!writer) {
printf("CvVideoWriter failed\n");
exit(1);
}
IplImage *img = 0;
int nframes = 1000;
for (i = 0; i < nframes; i++) {
if (!cvGrabFrame(capture)) {
printf("Unable to grab frame!\n");
exit(0);
}
img = cvRetrieveFrame(capture, 0);
cvWriteFrame(writer, img);
cvShowImage("win", img);
key = cvWaitKey(20);
}
return 0;
}
#包括
#包括
#包括“highgui.h”
#包括“cxcore.h”
int main(int argc,字符**argv){
int键=0;
int i=0;
CvCapture*capture=0;//摄像机
IplImage*frame=0;//从相机中取出的图像
capture=cvCaptureFromCAM(0);//打开相机
如果(!捕获){
printf(“无法连接到摄像头”);返回1;
}
cvQueryFrame(捕获);
双fps=cvGetCaptureProperty(捕获,CV\u CAP\u PROP\u fps);
int frame\u height=cvGetCaptureProperty(捕获、CV\u CAP\u PROP\u frame\u height);
int frame_width=cvGetCaptureProperty(捕获、CV_CAP_PROP_frame_width);
cvNamedWindow(“赢”,CV\u窗口\u自动调整大小);
cvMoveWindow(“win”,100100);
CvVideoWriter*writer=cvCreateVideoWriter(“out.avi”,CV_FOURCC(“D”,“I”,“V”,“X”),fps,cvSize(帧宽,帧高),1);
if(!writer){
printf(“CvVideoWriter失败\n”);
出口(1);
}
IplImage*img=0;
int nframes=1000;
对于(i=0;i
我做错了什么?谢谢。 错误是由C++库中未处理的目标C异常引起的。我记录了这个OpenCV票证上的错误,并帮助提交了一个请求。现在,查看OpenCV 2.4 branch的最新版本可以解决上述问题。您不需要发布吗?即
cvReleaseVideoWriter(&writer)
@AlexanderReynolds是的,我需要释放VideoWriter并破坏窗口,但在这样一个小程序中,这不是问题所在,因为它在视频完成后被释放。问题是,在写入“out.avi”后,该文件无法播放——但我拥有的其他avi文件可以播放。当创建程序退出时,“out.avi”文件的大小是多少?@AlexanderReynolds发现这是OpenCV中的一个bug,最新的2.4分支现在包含了影响MacOS的修复程序