从 OpenCV 3 切换到 OpenCV 4 会导致网络摄像头以最大 5 fps 的速度录制,而不是通常的 30 f
Switching from OpenCV 3 to OpenCV 4 causes webcam to record at a max of 5 fps instead the usual 30 fps
自从我在C++项目中从OpenCV 3.x更改为4.x(从源代码编译(以来,我遇到了一些麻烦。我在一个小示例中复制了这种行为,该示例仅打开网络摄像头并记录 5 秒钟。
使用 3.x,我可以将全高清网络摄像头帧速率设置为 30,但 4.x 的相同代码只是忽略camera.set(cv::CAP_PROP_FPS,30)
并将其设置为 5。如果我使用 720p,则 fps 设置为 10。
也许代码在这里无关紧要,因为它是一个经典的例子,但以防万一我会把它留在这里。
#include "opencv2/opencv.hpp"
#include "iostream"
#include "thread"
#include <unistd.h>
using namespace cv;
VideoCapture camera(0);
bool stop = false;
int fc = 0;
void saveFrames()
{
while(!stop)
{
Mat frame;
camera >> frame;
cv::imwrite("/tmp/frames/frame" + std::to_string(fc) + ".jpg", frame);
fc++;
}
}
int main()
{
if(!camera.isOpened())
return -1;
camera.set(cv::CAP_PROP_FRAME_WIDTH,1920);
camera.set(cv::CAP_PROP_FRAME_HEIGHT,1080);
camera.set(cv::CAP_PROP_FPS,30);
double fps = camera.get(cv::CAP_PROP_FPS);
std::cout << "FPS setting: " << fps << std::endl; // 5 with OCV4, 30 with OCV3
std::thread tr(saveFrames);
int waitSeconds = 5;
usleep(waitSeconds * 1e6);
stop = true;
tr.join();
std::cout << "Written " << fc << " frames of " << fps * waitSeconds << std::endl;
return 0;
}
编辑:与其他计算机进行的更多测试会产生相同的结果,除了在Macbook Pro(但运行相同的发行版(中,OpenCV 4.3似乎可以工作。其他 2 台计算机是带有 USB 网络摄像头的台式机。
编辑 2:从源代码构建 3.4 版本存在相同的问题。目前,回购中只有 3.2 在两台带有 usbcams 的计算机上工作正常。
这是一个已知的错误,会影响OpenCV> 3.3
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 从 OpenCV 3 切换到 OpenCV 4 会导致网络摄像头以最大 5 fps 的速度录制,而不是通常的 30 f
- C++、OpenCV和Kinect:处理速度下降
- 较小的速度,具有多个流程的OPENCV
- 我可以加快OpenCV的'raspicam_node'发布速度吗?
- OpenCV Mat对象复制速度更快
- MATLAB与DFT中的FFT2在OpenCV C 速度比较中
- iOS上的OpenCV:二进制大小、加载时间、速度等
- OpenCV中的网络摄像头图像处理C++速度很慢
- 使用 opencv 2.3.1 捕获视频的速度较慢
- 为什么OpenCV(@Banana Pi,Raspbian)中的全屏窗口分辨率会减慢相机镜头的速度并使其滞后
- OpenCV减慢了摄像头的捕捉速度
- OpenCV ORB GPU的实现速度比CPU慢
- OpenCV速度问题
- OpenCV CUDA运行速度比OpenCV CPU慢
- 与CPU版本相比,OpenCV GPU对象检测速度慢,检测次数少
- OpenCV的执行速度(for loops和meanStdDev)
- OpenCV:C++API和C API在功能或速度上是否不同
- 如果我在opencv中使用UMat并关闭GPU处理,会有速度差异吗