gpt4 book ai didi

c++ - 如何使用 opencv 计算视频的 fps(经过处理)

转载 作者:行者123 更新时间:2023-11-28 04:50:31 24 4
gpt4 key购买 nike

我似乎无法弄清楚我的代码片段有什么问题...由于某种原因它一直在输出超过 200 fps。我使用 OpenCV 进行了测试,未处理的视频大约为 30 fps。

int n_frame = 0;
Mat previous;
auto start = chrono::high_resolution_clock::now();
while (m_cap.isOpened()) {
if (n_frame % 100 == 1) {
auto end = chrono::high_resolution_clock::now();
auto time = chrono::duration_cast<chrono::seconds>(end - start);
cout << "the fps is: " << 1.0 / (static_cast<double>(time.count()) / n_frame) << endl;
//cin.ignore(1000, '\n');
}
n_frame++;
cout << "frame number: " << n_frame << endl;
Mat frame, original;

m_cap >> frame;
if (frame.empty())
break;


//do some video processing down here eg thresholding
}

最佳答案

我想你忘了重新初始化开始时间,这里是修改后的代码,这提供了一致的 fps 值,我在我的笔记本电脑上测试了大约 33.2,我只数到 100 帧并重新初始化所有内容,这似乎工作

int n_frame = 0;
Mat previous;
auto start = std::chrono::high_resolution_clock::now();
VideoCapture m_cap(0);

while (m_cap.isOpened()) {
n_frame++;
if (n_frame == 100) {
auto end = std::chrono::high_resolution_clock::now();
auto time = std::chrono::duration_cast<chrono::seconds>(end - start);
cout << "the fps is: " << (n_frame / static_cast<double>(time.count())) << endl;
start = end;
n_frame = 0;
}
//cout << "frame number: " << n_frame << endl;
Mat frame, original;
m_cap >> frame;
if (frame.empty())
break;
}

关于c++ - 如何使用 opencv 计算视频的 fps(经过处理),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48312740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com