c++ - 使用 OpenCV C++ RaspberryPi 的慢速 FPS
问题描述
我使用 OpenCV 编写了一个简单的 C++ 程序来测试树莓派上的 fps。
#include <iostream>
#include <chrono>
#include <thread>
#include <unistd.h>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>
using namespace cv;
using namespace std;
using namespace std::chrono;
using namespace std::this_thread;
using namespace cv::ml;
int main(void)
{
VideoCapture camera(0);
camera.set(CAP_PROP_FRAME_WIDTH, 640);
camera.set(CAP_PROP_FRAME_HEIGHT, 480);
camera.set(CAP_PROP_FPS, 25);
Mat frame;
while (camera.read(frame)) {
for (size_t i = 0; i < frame.dataend - frame.datastart; i++)
std::cout << frame.data[i];
}
}
然后我使用以下脚本来测试 fps。第一个使用 raspvid 作为输入,第二个使用我的 C++ 程序作为输入 raspvid 版本达到 25fps。我的 C++ 程序从不超过 10fps。知道这是为什么吗?
raspivid -w 640 -h 480 -fps 25 -t 120000 -o -| ffmpeg -re -i pipe:0 -y -an -c:v copy -f null /dev/null
和
./PiImageAnalyzer.out | ffmpeg -re -f rawvideo -pixel_format bgr24 -video_size 640x480 -framerate 25 -i pipe:0 -y -an -c:v copy -f null /dev/null
更新
这些脚本也可以使用
raspivid -w 640 -h 480 -fps 25 -t 120000 -o -| ffplay -i -
和
./PiImageAnalyzer.out | ffplay -f rawvideo -pixel_format bgr24 -video_size 640x480 -framerate 25 -i -
解决方案
推荐阅读
- matlab - 在matlab中将wrt排序为列值
- php - 为什么 PHP in_array 函数总是返回 true
- primefaces - Primefaces 时钟组件未按照时区属性值工作
- python - Django - Celery ValueError:无法解析相关模型 u'user.User'
- php - 找不到请求的 php 资源
- python-3.x - numpy.ndarray 对象不可调用
- javascript - 多个独立语句上的 try-catch 块
- c++ - 完全专业化的模板类没有外线虚方法定义
- java - thymeleaf 禁用消息参数
- javascript - Api 在浏览器中工作但不能在 fetch javascript 中工作?