opencv读取摄像头并读取时间戳
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv
免费下载资源
·
下面这行代码是获取摄像头每帧的时间戳:
double timestamp = cap.get(cv::CAP_PROP_POS_MSEC);
改变帧率的方法是:
cap.set(cv::CAP_PROP_FPS, 30); //帧率改为30
但是实际测试时发现帧率并未被改变,这个可能和VideoCapture cap(cv::CAP_V4L2)有关,cv::CAP_V4L2只是其中一种读取方法,这个参数可能需要和相机采用的驱动方法有关。
编译:
g++ camera_data.cpp -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_videoio
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <time.h>
using namespace std;
// OpenCV includes
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
int main(int argc, const char** argv)
{
// 1.创建视频采集对象;
VideoCapture cap(cv::CAP_V4L);
// 2.打开默认相机;
cap.open(0);
int curFPS=cap.get(cv::CAP_PROP_FPS);
cout<< "FPS: "<< curFPS<<endl;
cap.set(cv::CAP_PROP_FPS, 30);
int curFpsSet=cap.get(cv::CAP_PROP_FPS);
cout<< "set FPS: "<< curFpsSet<<endl;
// 3.判断相机是否打开成功;
if (!cap.isOpened())
return -1;
namedWindow("Video", 1);
for (;;)
{
// 获取新的一帧;
Mat frame;
double timestamp = cap.get(cv::CAP_PROP_POS_MSEC);
cout<<fixed;
cout<<"time: "<< timestamp<<endl;
time_t end_time = time(NULL);
printf("ctime is %s\n",ctime(&end_time)); //得到日历时间
cap >> frame;
if (frame.empty())
return 0;
// 显示新的帧;
imshow("Video", frame);
// cv::waitKey(1);
// 按键退出显示;
if (waitKey(3) >= 0) break;
}
// 5.释放视频采集对象;
cap.release();
return 0;
}
GitHub 加速计划 / opencv31 / opencv
77.38 K
55.71 K
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:2 个月前 )
c3747a68
Added Universal Windows Package build to CI. 7 天前
9b635da5 - 7 天前
更多推荐
已为社区贡献6条内容
所有评论(0)