我正在关注 OpenCV 书籍的教程,但以下代码不起作用:
#include <iostream>
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace std;
int main() {
string arg1 = "new.mov";
string arg2 = "mov.mov";
CvCapture* capture = 0;
capture = cvCreateFileCapture(arg1.c_str());
if(!capture){
return -1;
}
IplImage *bgr_frame=cvQueryFrame(capture);
double fps = cvGetCaptureProperty (
capture,
CV_CAP_PROP_FPS
);
CvSize size = cvSize(
(int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH)
);
CvVideoWriter* writer = cvCreateVideoWriter(
arg2.c_str(),
CV_FOURCC('N', 'T', 'S', 'C'),
fps,
size
);
IplImage* logpolar_frame = cvCreateImage(
size,
IPL_DEPTH_8U,
3
);
while((bgr_frame=cvQueryFrame(capture)) != NULL){
cvLogPolar(
bgr_frame, logpolar_frame,
cvPoint2D32f(bgr_frame->width/2, bgr_frame->height/2),
40,
CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS
);
cvWriteFrame(writer, logpolar_frame);
}
cvReleaseVideoWriter(&writer);
cvReleaseImage(&logpolar_frame);
cvReleaseCapture(&capture);
return 0;
}
当我运行代码时它不会给我一个错误 - 而是程序输出到控制台:
WARNING: Could not create empty movie file container.
接下来是 100 左右行:
Didn't successfully update movie file.
这个错误(或任何它的名字)是什么意思,是什么原因造成的?
我不知道这是否有帮助,但它曾经给我一个关于编解码器的错误(在书中是 MJPG),所以我CV_FOURCC('M', 'J', 'P', 'G')
改为CV_FOURCC('N', 'T', 'S', 'C')
.