【问题标题】:How to get web camera fps rate in OpenCV?如何在 OpenCV 中获得网络摄像头 fps 速率?
【发布时间】:2011-05-05 07:01:56
【问题描述】:

所以我需要在 OpenCV 中获取网络摄像头 fps 速率。哪个函数可以做这样的事情?

【问题讨论】:

    标签: c++ c video opencv webcam


    【解决方案1】:

    就我而言,fps = video.get(cv2.CAP_PROP_FPS) 不起作用。

    所以,我在这个链接中找到了这段代码:

    https://www.learnopencv.com/how-to-find-frame-rate-or-frames-per-second-fps-in-opencv-python-cpp/

    import cv2
    import time
    
    if __name__ == '__main__':
    
        video = cv2.VideoCapture(1)
    
        # Find OpenCV version
        (major_ver, _, _) = (cv2.__version__).split('.')
    
        # With webcam get(CV_CAP_PROP_FPS) does not work.
        # Let's see for ourselves.
    
        if int(major_ver) < 3:
            fps = video.get(cv2.cv.CV_CAP_PROP_FPS)
            print "Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".format(fps)
        else:
            fps = video.get(cv2.CAP_PROP_FPS)
            print "Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(fps)
    
        # Number of frames to capture
        num_frames = 120
    
        print "Capturing {0} frames".format(num_frames)
    
        # Start time
        start = time.time()
    
        # Grab a few frames
        for i in xrange(0, num_frames):
            ret, frame = video.read()
    
        # End time
        end = time.time()
    
        # Time elapsed
        seconds = end - start
        print "Time taken : {0} seconds".format(seconds)
    
        # Calculate frames per second
        fps = num_frames / seconds
        print "Estimated frames per second : {0}".format(fps);
    
        # Release video
        video.release()
    

    【讨论】:

      【解决方案2】:

      *OpenCV 2 解决方案:

      C++: double VideoCapture::get(int propId)
      

      例如

      VideoCapture myvid("video.mpg");
      int fps=myvid.get(CV_CAP_PROP_FPS);
      

      【讨论】:

        【解决方案3】:

        似乎对于实时网络摄像头捕获,您可以设置任意 fps 并读回相同的 fps,这与网络摄像头的真实 fps 无关。是bug吗?

        例如:

        cvSetCaptureProperty(capture,CV_CAP_PROP_FPS,500);
        

        以后

        double rates = cvGetCaptureProperty(capture,CV_CAP_PROP_FPS);
        printf("%f\n",rates);
        

        会给你500。

        但如果我使用web cam fps link 对其进行计时,它大约是正常的 30fps。

        【讨论】:

          【解决方案4】:
          int cvGetCaptureProperty( CvCapture* capture, int property_id);
          

          property_id = CV_CAP_PROP_FPS

          【讨论】:

          • 这对我不起作用。在 opencv/python 中,鉴于 cap = cv2.VideoCapture(0), print "frame rate = ", cap.get(5) 给我的 fps 为零。请注意,对于 cv_cap_prop,fps 是常数 5。
          猜你喜欢
          • 1970-01-01
          • 2012-06-12
          • 2015-08-18
          • 2022-06-30
          • 1970-01-01
          • 1970-01-01
          • 2020-10-15
          • 2021-06-30
          • 1970-01-01
          相关资源
          最近更新 更多