我面临的问题是,当我尝试使用Videowriter保存图像时,它会创建视频文件但大小为0.我创建了一个标题,声明了一个保存视频的功能和一个单独的.cpp文件定义函数。当我只在一个文件中编写整个代码而不是像以前一样包含ViceoCapture和VideoWriter时,它运行正常,甚至可以保存具有适当文件大小的视频文件。
当我开始调试时,我发现每次收到一个帧但VideoWriter.open为null或者说没有为opencv_highgui.dll加载符号
**savevideo.cpp file**
#include"SaveVideo.h"
int CSaveVideo::savevideo()//string InpVideo, int pinstatus)
{
VideoCapture oVcam(0);
Mat vFrame;
string OutPath = "C:\\Users\\20080031\\Desktop\\";
string Filename = "Vout.avi";
int vfourcc = CV_FOURCC('M', 'J', 'P', 'G');
int vfps = 20;
VideoWriter oVWrite;
oVWrite.open(Filename, vfourcc, vfps, Size(480, 640), true);
if (!oVcam.isOpened())
{
cout << "Camera not opened" << endl;
}
while (1)
{
oVcam.read(vFrame);
imshow("Input", vFrame);
waitKey(1);
oVWrite.write(vFrame);
}
}
CSaveVideo::CSaveVideo()
{
cout << "Inside Constructor" << endl;
}
CSaveVideo::~CSaveVideo()
{
//VideoCapture Vcam0;
cout << "Inside Distructor" << endl;
//Vcam0.release();
}
**saveVideo.h**
#ifndef SAVEVIDEO_H
#define SAVEVIDEO_H
#include<iostream>
#include<stdio.h>
#include<string>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/core/core.hpp>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
class CSaveVideo
{
public:
CSaveVideo();
~CSaveVideo();
//string m_sGPIOpinstatus;
//char m_cSTOP;
int savevideo();//string PinStatus, char End, );
};
#endif SAVEVIDEO_H
**main.cpp**
#include"SaveVideo.h"
int main()
{
CSaveVideo save;
save.savevideo();
/*cout << out<<endl;*/
return 0;
}
答案 0 :(得分:1)
最好使用这种格式 -
VideoWriter oVidWrite;
int nframe_width = oVidCap.get(CV_CAP_PROP_FRAME_WIDTH);
int nframe_height = oVidCap.get(CV_CAP_PROP_FRAME_HEIGHT);
string str_Path = "video.avi";
int fps = 30;
oVidWrite.open(str_Path, CV_FOURCC('M', 'J', 'P', 'G'), fps, Size(nframe_width, nframe_height), true);