Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在c++;具有所需的fps_C++_Opencv_Video_Frame Rate - Fatal编程技术网

C++ 如何在c++;具有所需的fps

C++ 如何在c++;具有所需的fps,c++,opencv,video,frame-rate,C++,Opencv,Video,Frame Rate,我需要用OpenCV拍摄一帧作为第二帧。 问题是VideoCapture::get(CV\u CAP\u PROP\u FPS);始终返回0。 如果我尝试使用VideoCapture::set nothing change设置所需的fps 这是我的代码: VideoCapture cap(0); if (!cap.isOpened()) { cout << "Cannot open the video cam" << endl; return -1;

我需要用OpenCV拍摄一帧作为第二帧。 问题是VideoCapture::get(CV\u CAP\u PROP\u FPS);始终返回0。 如果我尝试使用VideoCapture::set nothing change设置所需的fps

这是我的代码:

VideoCapture cap(0); 

if (!cap.isOpened()) {
    cout << "Cannot open the video cam" << endl;
    return -1;
}

double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
double fps = 1;
cap.set(CV_CAP_PROP_FPS, fps);
cout << "FPS : " << fps << endl;

cout << "Frame size : " << dWidth << " x " << dHeight << endl;


namedWindow("CAPTURE EXPRESSION",CV_WINDOW_AUTOSIZE);     
while (1) {
    Mat frame;

    bool bSuccess = cap.read(frame);

    if (!bSuccess) {
        cout << "Cannot read a frame from video stream" << endl;
        break;
    }
    fps = cap.get(CV_CAP_PROP_FPS);
    imshow("MyVideo", frame); 
    cout << "FPS : " << fps << endl;

    if (waitKey(30) == 27) {
        cout << "esc key is pressed by user" << endl;
        break; 
    }
}
VideoCapture(0);
如果(!cap.isOpened()){

cout您不能为相机馈送设置帧速率,因为当您的代码请求它们时,它们只是通过管道传输进来的。您可以在代码中设置一个延迟,仅每1秒请求一次,我认为这对您的用例很有帮助

请参阅下面的代码

视频捕获上限(0)

而(1){

}


这组fps总是乱七八糟的,即使是我过去跟踪的时候,它们也是随机的,从某人那里得到一个合适的解释是一件有趣的事情。它可能对视频容器有一些依赖性

但是,我不认为fps的设置参数适用于实时摄像头,这就像要求网络摄像头前面的世界运行缓慢,这是不会发生的。另一种方法是将实时帧存储在缓冲区中,并按照您要求的速度显示。我不认为opencv会这样做。因此,如果您想要更慢的速度,请录制视频,然后嗯,设置fps并检查录制的视频


而waitKey的数字更高,在直播流中,它会跳过间隔之间的帧,因此只有在您认为有帮助的情况下才使用它。

VideoCapture的网络摄像头流没有fps(您既不能设置也不能获取fps)。您所能做的就是自己测量时间,并在waitKey()中设置超时使用外置摄像头?不,同样的问题。只需使用waitKey(1000)即可获得约1fps。
Mat frame;

bool bSuccess = cap.read(frame);

imshow("MyVideo", frame); 
//This Sets the Frame Rate to 1000ms (1s)
cv::waitKey(1000);