gpt4 book ai didi

c - 在 MacOSX 上使用 OpenCV 2.4.13.2 上的 C API 创建并保存视频后无法打开视频

转载 作者:太空宇宙 更新时间:2023-11-03 22:47:47 24 4
gpt4 key购买 nike

在 MacOSX 上使用 OpenCV 2.4.13.2 上的 C API 创建并保存视频后,我无法打开它,我查看了一些过时的教程,因为 C++ API 现在更受 OpenCV 青睐。我花了两天时间学习教程,特别是我试图在此处重现该示例 http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html#SECTION00073000000000000000

我可以启动相机并开始录制和写入文件“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
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;
}

我做错了什么?提前致谢。

最佳答案

错误是由 C++ 库中未处理的 Objective C 异常引起的。我在这张 OpenCV 票证上记录了错误 https://github.com/opencv/opencv/issues/8305并帮助提交了拉取请求。检查最新版本的 OpenCV 2.4 分支现在可以解决上述问题。

关于c - 在 MacOSX 上使用 OpenCV 2.4.13.2 上的 C API 创建并保存视频后无法打开视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44690671/

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