视频处理中改变fps的问题有哪些?

What are the problems that changes the fps in video processing?

我正在尝试使用 OpenCV 和 OpenCL 检测运动中的白色物体。我使用的相机是我的 30 fps 笔记本电脑相机。我观察到的是,在不同的位置,我得到不同的 fps,相机和代码是相同的。对于我房间里的 Ex,当我执行代码时,我得到了 30 的完整 fps,而在实验室中它是 22 ...请任何人告诉它可能的原因是什么以及如何纠正它...我使用的代码如下...提前谢谢...

#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2\ocl\ocl.hpp>
#include <time.h>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
 {
     time_t t= time(0);
    VideoCapture cap(0); //capture the video from web cam

    if ( !cap.isOpened() )  // if not success, exit program
    {
         cout << "Cannot open the web cam" << endl;
         return -1;
    }

  namedWindow("Control", CV_WINDOW_AUTOSIZE); //create a window called "Control"

   int iLowH = 0;
   int iHighH = 255;

   int iLowS = 0; 
   int iHighS = 255;

   int iLowV = 0;
   int iHighV = 255;

   //Create trackbars in "Control" window
   cvCreateTrackbar("LowH", "Control", &iLowH, 255); //Hue (0 - 179)
   cvCreateTrackbar("HighH", "Control", &iHighH, 255);

   cvCreateTrackbar("LowS", "Control", &iLowS, 255); //Saturation (0 - 255)
   cvCreateTrackbar("HighS", "Control", &iHighS, 255);

   cvCreateTrackbar("LowV", "Control", &iLowV, 255); //Value (0 - 255)
   cvCreateTrackbar("HighV", "Control", &iHighV, 255);

   ocl::oclMat alpha;
   int fps=0;
   int cur=0;
   while (true)
    {
      fps++;
      t=time(0);
      struct tm *tmp = gmtime(&t);

      int h= (t/360) %24;
      int m= (t/60) %60;
      int s = t%60;
      if(cur !=s)
      {
        cout<<fps;
        fps=0;
        cur=s;
      }

      Mat imgOriginal;
      bool bSuccess = cap.read(imgOriginal); // read a new frame from video

      if (!bSuccess) //if not success, break loop
      {
         cout << "Cannot read a frame from video stream" << endl;
         break;
      }

      alpha.upload(imgOriginal);
      ocl::oclMat imgHSV;

      ocl::cvtColor(alpha, imgHSV, CV_RGB2HSV); //Convert the captured frame from BGR to HSV
      ocl::oclMat channel[4];
      ocl::split(alpha,channel);
      ocl::oclMat imgThresholded[2];

      ocl::threshold(channel[0], imgThresholded[0] , iLowH , 255 , 0 );
      ocl::threshold(channel[0], imgThresholded[1] , iHighH , 255 , 1 );
      ocl::bitwise_and(imgThresholded[0],imgThresholded[1],channel[0]);

      ocl::threshold(channel[1], imgThresholded[0] , iLowS , 255 , 0 );
      ocl::threshold(channel[1], imgThresholded[1] , iHighS , 255 , 1 );
      ocl::bitwise_and(imgThresholded[0],imgThresholded[1],channel[1]);

      ocl::threshold(channel[2], imgThresholded[0] , iLowV , 255 , 0 );
      ocl::threshold(channel[2], imgThresholded[1] , iHighV , 255 , 1 );
      ocl::bitwise_and(imgThresholded[0],imgThresholded[1],channel[2]);

      ocl::bitwise_and(channel[0],channel[1],imgThresholded[0]);
      ocl::bitwise_and(imgThresholded[0],channel[2],imgThresholded[1]);

      //morphological opening (remove small objects from the foreground)
      ocl::erode(imgThresholded[1], imgThresholded[1], getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
      ocl::dilate( imgThresholded[1], imgThresholded[1], getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) ); 

      //morphological closing (fill small holes in the foreground)
      ocl::dilate( imgThresholded[1], imgThresholded[1], getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) ); 
      ocl::erode(imgThresholded[1], imgThresholded[1], getStructuringElement(MORPH_ELLIPSE, Size(5, 5)) );
      int c= ocl::countNonZero(imgThresholded[1]);
      Mat result = imgThresholded[1];
      //Mat r2 = channel[0];

      imshow("Thresholded Image", result); //show the thresholded image
      //imshow("Original", r2); //show the original image
      cout<<"\t"<<c<<endl;

      if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
         {
          cout << "esc key is pressed by user" << endl;
          break; 
         }
      }
      return 0;
}

您正在图像捕获循环中进行图像处理。图像处理的时间取决于输入,因为例如腐蚀操作不会在每个图像像素上执行,而是在满足特定条件的像素上执行。因此,您在不同的环境中获得不同的执行时间也就不足为奇了。 我还可以想象笔记本电脑摄像头驱动程序正在执行一些预处理操作,例如在设置帧已准备好输出的标志之前进行亮度调整。如果您对恒定帧率感兴趣,或者使用 SDK 无法提供此类功能的其他相机,则应禁用此类预处理。