如何在 OpenCV 中获取网络摄像头的 fps 速率?

发布于 2024-10-01 04:42:05 字数 51 浏览 3 评论 0原文

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

So I need to get web camera fps rate in OpenCV. Which function can do such thing for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

演多会厌 2024-10-08 04:42:05
int cvGetCaptureProperty( CvCapture* capture, int property_id);

property_id = CV_CAP_PROP_FPS

int cvGetCaptureProperty( CvCapture* capture, int property_id);

with property_id = CV_CAP_PROP_FPS

小镇女孩 2024-10-08 04:42:05

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

例如:

cvSetCaptureProperty(capture,CV_CAP_PROP_FPS,500);

稍后

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

会给你 500。

但是如果我使用 网络摄像头 fps 链接,大约是正常的 30fps。

It seems that for live webcam capture, you can set an arbitrary fps and read back that same fps, which has nothing to do with the real fps from webcam. Is it a bug?

For example:

cvSetCaptureProperty(capture,CV_CAP_PROP_FPS,500);

and later

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

will give you 500.

But if I timed it using web cam fps link, it's around the normal 30fps.

烟若柳尘 2024-10-08 04:42:05

就我而言, 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/< /a>

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()

In my case, fps = video.get(cv2.CAP_PROP_FPS) did not work.

So, I found this code in this link:

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()
ゃ人海孤独症 2024-10-08 04:42:05

*OpenCV 2 解决方案:

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

例如

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

*OpenCV 2 solution:

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

E.g.

VideoCapture myvid("video.mpg");
int fps=myvid.get(CV_CAP_PROP_FPS);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文