我尝试使用C语言上的opencv从文件夹上的图像创建视频。 但是,它没有用。在几张图片之后,它向我显示了访问冲突内存的错误。有人可以帮帮我吗?
这是我的代码:
#include <stdio.h>
#include <opencv2\highgui\highgui_c.h>
int main(void)
{
int i = 1;
char filename[100] = { 0 };
cvNamedWindow("Test", 1);
CvVideoWriter* writer = NULL;
IplImage* img = cvLoadImage("<folder>\\1.png", 1);
CvSize size = cvSize(0, 0);
size.width = img->width;
size.height = img->height;
writer = cvCreateVideoWriter("Test.avi", CV_FOURCC('M', 'J', 'P', 'G'), 1, size, 1);
if (!writer)
{
return -1;
}
while (img != NULL)
{
sprintf(filename, "<folder>\\%d.png", i);
printf("%s\n", filename);
img = cvLoadImage(filename, 1);
if (img)
cvWriteFrame(writer, img);
i++;
}
cvReleaseVideoWriter(&writer);
cvReleaseImage(&img);
getchar();
return 0;
}
感谢您的帮助:)