我正在使用OpenCV 2.3.1版本。当我尝试获得各种Videocapture属性时,opencv会提供错误的输出,除了高度和宽度:
我的代码:
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video file for reading
if ( !cap.isOpened() ) // if not success, exit program
{
cout << "Cannot open the video file" << endl;
return -1;
}
//cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms
double msec = cap.get(CV_CAP_PROP_POS_MSEC ); //Current position of the video file in milliseconds or video capture timestamp
cout << "current position : " << msec << endl;
double fra = cap.get(CV_CAP_PROP_POS_FRAMES); //0-based index of the frame to be decoded/captured next
cout << "fra: " << fra << endl;
double width = cap.get(CV_CAP_PROP_FRAME_WIDTH); //width of the frames in the video stream.
cout << "width: " << width << endl;
double height = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //Height of the frames in the video stream.
cout << "height: " << height << endl;
double fps = cap.get(CV_CAP_PROP_FPS); //frame rate
cout << "fps: " << fps << endl;
double fourcc = cap.get(CV_CAP_PROP_FOURCC); //4-character code of codec
cout << "fourcc: " << fourcc << endl;
double frame_count = cap.get(CV_CAP_PROP_FRAME_COUNT ); //Frame count in the video
cout << "frame count: " << frame_count << endl;
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
while(1)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read the frame from video file" << endl;
break;
}
imshow("MyVideo", frame); //show the frame in "MyVideo" window
if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}
输出类似于除高度和宽度之外的任何属性:
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(0) - Invalid argument
current position : -1
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(1) - Invalid argument
fra: -1
width: 640
height: 480
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(5) - Invalid argument
fps: -1
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(6) - Invalid argument
fourcc: -1
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(7) - Invalid argument
frame count: -1