下面给出的是我用来从我的网络摄像头获取视频并将其保存在我的硬盘上的代码。在运行该程序时,它说“视频编写器未打开”。我哪里错了?视频采集和保存使用OpenCV
#include <opencv\cv.h>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>
#include <iostream>
#pragma comment(lib, "Ws2_32.lib")
#define default_buflen 1024
using namespace std;
using namespace cv;
#define default_port "1234"
int main(int argc, char** argv)
{
Mat capture;
VideoCapture cap(0);
if(!cap.isOpened())
{
cout<<"Cannot connect to camera"<<endl;
getchar();
return -1;
}
double fps=30;
Size s=Size((int)cap.get(CV_CAP_PROP_FRAME_WIDTH),(int)cap.get(CV_CAP_PROP_FRAME_WIDTH));
VideoWriter vidcapt;
vidcapt.open("c:\\out.avi",CV_FOURCC('D','I','V','X'),cap.get(CV_CAP_PROP_FPS),s,true);
if(!vidcapt.isOpened())
{
cout<<"Video writer not opening"<<endl;
getchar();
return -1;
}
while(true)
{
cap>>capture;
namedWindow("Display",1);
imshow("Display",capture);
vidcapt<<capture;
int ch=waitKey(5);
if(char(ch)==27)
{
break;
}
}
}
我已阅读给定here和here的答案,但我不明白我要去的地方错了。
尝试了所有这些。还是行不通。接下来做什么?另外,如何找出哪些编解码器已安装? –
@PrakharMohanSrivastava检查您的编解码器,重新安装它们,如果使用调试选项编译它,请调试opencv – Dabo