我正在尝试使用我的笔记本电脑摄像头使用 OpenCV 编写视频,但出现以下错误:
VIDEOIO ERROR: V4L/V4L2: VIDIOC_S_CROP
VIDEOIO ERROR: V4L2: getting property #5 is not supported
OpenCV Error: Unsupported format or combination of formats (Gstreamer Opencv backend does not support this file type.) in CvVideoWriter_GStreamer::open, file /home/tul1/Downloads/opencv-3.0.0-alpha/modules/videoio/src/cap_gstreamer.cpp, line 1265
terminate called after throwing an instance of 'cv::Exception'
what(): /home/tul1/Downloads/opencv-3.0.0-alpha/modules/videoio/src/cap_gstreamer.cpp:1265: error: (-210) Gstreamer Opencv backend does not support this file type. in function CvVideoWriter_GStreamer::open
我正在使用的代码是:
#include <opencv/cv.hpp>
#include <opencv2/opencv.hpp>
#include <opencv/highgui.h>
int main(int argc, char** argv)
{
cvNamedWindow("DisplayCamera", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
const char filename[] = "video";
// int fourcc = CV_FOURCC('X','V','I','D');
// int fourcc = CV_FOURCC('P','I','M','1');
int fourcc = CV_FOURCC('M','J','P','G');
// int fourcc = CV_FOURCC('M', 'P', '4', '2');
// int fourcc = CV_FOURCC('D', 'I', 'V', '3');
// int fourcc = CV_FOURCC('D', 'I', 'V', 'X');
// int fourcc = CV_FOURCC('U', '2', '6', '3');
// int fourcc = CV_FOURCC('I', '2', '6', '3');
// int fourcc = CV_FOURCC('F', 'L', 'V', '1');
// fourcc = -1;
// int fourcc = 0;
// printf("%d\n", fourcc);
double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int width = (int) cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH );
int height = (int) cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT );
CvSize size = cvSize( width , height );
int isColor = 1;
CvVideoWriter* writer = cvCreateVideoWriter(filename, fourcc, fps, size, isColor);
while(1)
{
frame = cvQueryFrame( capture );
if( !frame )
{
fprintf(stderr,"Frame error");
break;
}
cvWriteFrame(writer , frame);
cvShowImage("DisplayCamera", frame);
char c = cvWaitKey( 30 );
if( c == 27 ) break;
}
cvReleaseVideoWriter(&writer);
cvReleaseImage(&frame);
cvReleaseCapture(&capture);
cvDestroyWindow("DisplayCamera");
return 0;
}
如您所见,我已经使用 CV_FOURCC 测试了每个编解码器,但仍然出现错误。
我究竟做错了什么?我有编解码器问题吗?