请查看以下代码:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <string>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/video/background_segm.hpp>
using namespace std;
using namespace cv;
double getMSE(const Mat& I1, const Mat& I2);
int main()
{
Mat current;
VideoCapture cam1;
VideoWriter *writer = new VideoWriter();
cam1.open(0);
namedWindow("Normal");
if(!cam1.isOpened())
{
cout << "Cam not found" << endl;
return -1;
}
cam1>>current;
Size *s = new Size((int)current.cols,current.rows);
writer->open("D:/OpenCV Final Year/OpenCV Video/MyVideo.avi",CV_FOURCC('D','I','V','X'),10,*s,true);
while(true)
{
//Take the input
cam1 >> current;
*writer << current;
imshow("Normal",current);
if(waitKey(30)>=0)
{
break;
}
}
}这段代码运行良好,没有问题。但是,当我运行录制的视频,它是超级快!就像它被快速转发一样。我真的不明白为什么。
发布于 2013-07-10 18:28:32
检查从摄像机获取帧的速度,并确保此速率与将帧记录到输出文件的速率相匹配。
将写入文件的帧速率指定为fps参数到这一功能:
bool VideoWriter::open(const string& filename, int fourcc,
double fps, Size frameSize, bool isColor=true);至于摄像机fps,对于某些相机,您可以确定其帧率如下所示。
double fps = cam1.get(CV_CAP_PROP_FPS); 或者,如果相机不支持这种方法,您可以通过测量连续帧之间的平均延迟来找到它的帧速率。
更新:,如果你的相机不支持cam1.get(CV_CAP_PROP_FPS);,可以从实验上估计帧速率。例如,就像这样:
while(true) {
int64 start = cv::getTickCount();
//Grab a frame
cam1 >> current;
if(waitKey(3)>=0) {
break;
}
double fps = cv::getTickFrequency() / (cv::getTickCount() - start);
std::cout << "FPS : " << fps << std::endl;
}此外,确保输出视频文件是开放的,以便写入。
if ( !writer->isOpened())
{
cout << "Could not open the output video for write: " << endl;
return -1;
}https://stackoverflow.com/questions/17575455
复制相似问题