Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/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
Opencv 视频处理中改变fps的问题有哪些?_Opencv_Image Processing_Opencl_Video Processing - Fatal编程技术网

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

Opencv 视频处理中改变fps的问题有哪些?,opencv,image-processing,opencl,video-processing,Opencv,Image Processing,Opencl,Video Processing,我正在尝试使用OpenCV和OpenCL检测运动中的白色对象。我使用的相机是我的笔记本电脑相机,每秒30帧。我所观察到的是,在不同的位置,我得到了不同的fps,相机和代码是相同的。对于Ex,在我的房间里,当我执行代码时,我得到了完整的fps 30,而在实验室里是22…请任何人告诉我可能的原因是什么,以及如何纠正它…我使用的代码如下…提前感谢你 #include <iostream> #include "opencv2/highgui/highgui.hpp" #include "op

我正在尝试使用OpenCV和OpenCL检测运动中的白色对象。我使用的相机是我的笔记本电脑相机,每秒30帧。我所观察到的是,在不同的位置,我得到了不同的fps,相机和代码是相同的。对于Ex,在我的房间里,当我执行代码时,我得到了完整的fps 30,而在实验室里是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;
}
#包括
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括
#包括
#包括
使用名称空间cv;
使用名称空间std;
int main(int argc,字符**argv)
{
时间t=时间(0);
VideoCapture cap(0);//从网络摄像机捕获视频
如果(!cap.isopend())//如果不成功,退出程序
{

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

对不起,我没有对于你所说的腐蚀操作,请你详细说明一下,我已经禁用了摄像头驱动程序所做的所有预处理操作…很抱歉反应太晚。腐蚀操作是一种最简单的循环,里面有一个if()语句。如果满足某些条件,则包含在if()中的操作语句将被执行,这将延长计算时间。这就是为什么您永远不会为每一帧获得相同的计算时间-因为您的输入不同,并且为不同的帧执行不同的操作数。在您的房间和实验室中执行的代码之间的差异只有12毫秒,我上面解释的可能会导致这种差异差异。光线级别是否不同?当相机处于弱光状态时,它们进入帧积分模式,这可能会降低帧速率。或者,在实验室位置(更复杂的背景)时,图像内容占用您的算法更多的时间