简体   繁体   English

我可以使用C ++和Opencv以20 fps捕获吗?

[英]Can i capture at 20 fps with C++ and Opencv?

i have a Raspberry Pi and installed on it the OpenCV and Guvcview. 我有一个Raspberry Pi,并在其上安装了OpenCV和Guvcview。 When i open Guvcview, i get ~ 17-21 fps but when i run a simple program (only capture from webcam and display frame) in C++ with Opencv, i get only 6 fps. 当我打开Guvcview时,我的速度约为17-21 fps,但是当我使用Opencv在C ++中运行一个简单的程序(仅从网络摄像头和显示帧捕获)时,我的速度仅为6 fps。

What is wrong? 怎么了? i need to configure Opencv to use Guvcview's configuration? 我需要配置Opencv以使用Guvcview的配置吗? why guvcview get 20 fps? guvcview为什么会获得20 fps? What can i do? 我能做什么?

thanks. 谢谢。

PD I've done the same in my computer and i get 29 fps in both cases. PD我在计算机上也做过同样的事情,在两种情况下都可以达到29 fps。

// * ** * ** * ** * ** * ** * ** * ** * ** * ** * **** *this is the code C++ : // * ** * ** * ** * ** * ** * ** * ** * ** * ** * **** *这是代码C ++:

 #include <iostream>
    #include "opencv2/opencv.hpp"
    using namespace std;
    using namespace cv;

    time_t start, end; //variabile di tipo time_t , contiene tempo in sec. 
    // inizializzo contatore nella dichiarazione 
    int counter=0;

    int main()
    { time(&start);
    VideoCapture cap(1);
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480); 

    if (!cap.isOpened())
    { cout << "could not capture";
    return 0; }

    Mat frame;
    namedWindow("camera", 1);
    char key = 'a';

    while(key != 27)
    {   cap.read( frame);
    imshow("camera", frame);

    //##################
    //time at the end of 1 show, Stop the clock and show FPS
    time(&end);
    ++counter;
    cout <<"fps: "<< counter/ difftime(end,start) <<endl <<endl;
    //##################

    key = waitKey(3); }

    destroyAllWindows();
    return 0;
    }

OpenCV is a heavy weight API and following tips may introduce minor improvements: OpenCV是一个重量级的API,以下提示可能会带来一些小的改进:

you can disable RGB conversion: 您可以禁用RGB转换:

 cap.set(CV_CAP_PROP_CONVERT_RGB , false);

you can increase frame rate if its default frame rate is low: 如果其默认帧速率较低,则可以提高帧速率:

cap.set(CV_CAP_PROP_FPS , 60);

I'd suggest to do direct video capture via V4L, since OpenCV may do YUYV to RGB transformations and other stuff that involves floating point calculations, that are expensive on this kind of hardware. 我建议通过V4L进行直接视频捕获,因为OpenCV可能会进行YUYV到RGB转换以及涉及浮点计算的其他工作,而在此类硬件上这很昂贵。 We have done many robotics projects on embedded systems and the rule of the thumb is that you will be always better of either directly using V4L or small 3rd party libraries like CMVision ( http://www.cs.cmu.edu/~jbruce/cmvision/ ) to do image processing on embedded systems. 我们已经在嵌入式系统上完成了许多机器人项目,并且凭经验得出的结论是,直接使用V4L或小型第三方库(例如CMVision)始终会更好( http://www.cs.cmu.edu/~jbruce/ cmvision / )在嵌入式系统上进行图像处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM