zkzhu0110 发表于 2023-11-13 08:55:23

RK3588 opencv读取视频速度慢

我在RK3588上,用opencv读取和播放一个本地视频,发现用opencv读取帧数据耗时过长,每个帧基本上要0.28s左右,如下图所示:




然后我在笔记本电脑的ubuntu20.04虚拟机上执行了同样的代码,发现每个帧读取时间要少很多,大致在0.025s,如下图:





请问我如何解决这个问题?谢谢各位~




附:main.cpp源码

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

int main()
{
    clock_t start, end;
    clock_t t1, t2, t3, t4;

    double open_time, grab_time, read_time, show_time;

    namedWindow("example", WINDOW_AUTOSIZE);

    Mat mframe;
    VideoCapture vcapture;

    start = clock();
    bool openResult = vcapture.open("/home/zhuzhikai/QT_Programming/sample.mp4");
    if (!openResult)
    {
      cout << "The video cannot be opened!" << endl;
    }
    end = clock();
    open_time = (double)(end-start)/CLOCKS_PER_SEC;
    cout << "open_time = " << open_time << " ms " << endl;



    int num = 0;

    t1 = clock();

    while (vcapture.grab())
    {
      t2 = clock();
      grab_time = (double)(t2-t1)/CLOCKS_PER_SEC;

      vcapture >> mframe;

      t3 = clock();
      read_time = (double)(t3-t2)/CLOCKS_PER_SEC;

      if (mframe.size().width > 0 || mframe.size().height > 0)
      {
            imshow("example", mframe);
      }
      else
      {
            break;
      }

      if (waitKey(10) >= 0)
      {
            break;
      }

      t4 = clock();
      show_time = (double)(t4-t3)/CLOCKS_PER_SEC;

      cout << "Frame " << num << ":   "
             << "grab_time = " << grab_time << " ms , "
             << "read_time = " << read_time << " ms , "
             << "show_time = " << show_time << " ms" << endl;
      num++;

      t1 = clock();
    }

    cout << "frame number = " << num << endl;

    return 0;
}



萨拉玩偶 发表于 2024-5-9 18:28:23

你好,大佬,请问你解决了吗?

bxkslx 发表于 2024-7-27 19:54:25

opencv在这种板子上解码能力不够吧
页: [1]
查看完整版本: RK3588 opencv读取视频速度慢