我需要使用CV_CAP_PROP_FOURCC
属性将我的网络摄像头设置为MJPG以增加FPS。如果我尝试将参数设置为MJPG,则会出现错误
HIGHGUI ERROR: V4L: Property <unknown property string>(6) not supported by device
cam1x.cpp
#include "opencv2/opencv.hpp"
#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
#include <unistd.h>
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap(7); // open the default camera
//*********trying to set it here****************
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M','J','P','G') );
cap.set(CV_CAP_PROP_FRAME_WIDTH,320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,280);
//cap.set(CV_CAP_PROP_CONTRAST, 0.5);
//cap.set(CV_CAP_PROP_BRIGHTNESS, 0.5);
if(!cap.isOpened() ) // check if we succeeded
return -1;
//double contrast = cap.get(CV_CAP_PROP_CONTRAST);
//double brightness = cap.get(CV_CAP_PROP_BRIGHTNESS);
//cout << "Contrast = " << contrast << "BRIghtness" << brightness << endl;
//Mat edges;
namedWindow("cam1",1);
int x = 0;
while(true)
{
x++;
Mat frame;
if( !cap.grab())
{
cout << "Can not grab images." << endl;
return -1;
}
if(cap.retrieve(frame,3) ){
imshow("cam1", frame);
}
//cap >> frame; // get a new frame from camera
//cap1 >> frame1;
//imshow("edges1", frame1);
//sleep(2);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
表明我的相机支持mjpg
v4l2-ctl -d /dev/video7 --list-formats
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'UYVY'
Name : UYVY 4:2:2
Index : 1
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : Motion-JPEG
如何解决此问题,以便我可以将捕获设置为MJPG而不会出现错误???
请注意,在opencv论坛上有一个与UNANSWERED相似的问题。