3D视觉(一):双目摄像头的调用
3D视觉(一):双目摄像头的调用文章目录3D视觉(一):双目摄像头的调用1、计时器 chrono2、单目摄像头的调用3、双目摄像头的调用参考1、计时器 chronochrono是C++11新加入的方便时间日期操作的标准库,它既是相应的头文件名称,也是std命名空间下的一个子命名空间,所有时间日期相关定义均在std::chrono命名空间下。通过这个新的标准库,可以非常方便进行时间日期相关操作。#i
·
3D视觉(一):双目摄像头的调用
1、计时器 chrono
chrono是C++11新加入的方便时间日期操作的标准库,它既是相应的头文件名称,也是std命名空间下的一个子命名空间,所有时间日期相关定义均在std::chrono命名空间下。
通过这个新的标准库,可以非常方便进行时间日期相关操作。
#include <iostream>
#include<unistd.h>
#include <chrono>
using namespace std;
int main()
{
chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
// cout << "begin"<< endl;
// sleep(2);
// cout << "end"<< endl;
long int x = 0;
for(int i=0; i<1000000000; i++)
{
x = x + i;
}
cout << x << endl;
chrono::steady_clock::time_point t2 = chrono::steady_clock::now();
chrono::duration<double> time_used = chrono::duration_cast<chrono::duration<double>>(t2 - t1);
cout << "耗时: " << time_used.count() << " 秒. " << endl;
return 0;
}
2、单目摄像头的调用
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture capture(0);
while (true)
{
Mat frame;
capture >> frame;
imshow("read stream !", frame);
int c = waitKey(30);
//exit the loop if user press "Esc" key (ASCII value of "Esc" is 27)
if(27 == char(c)) break;
}
return 0;
}
3、双目摄像头的调用
调用双目摄像头时遇到一个小问题,编译器报错带宽不够。查询原因后发现,原图分辨率为 480*640 大小,在调用单目时不会出现问题,但对于双目同时调用,USB接口带宽不够,摄像头获取失败。
此时需要手动调小摄像头分辨率,此处我调整成了 240*320 大小,即可成功调用。
#include <opencv2/opencv.hpp>
#include<iostream>
#define CV_CAP_PROP_FRAME_WIDTH 3
#define CV_CAP_PROP_FRAME_HEIGHT 4
using namespace cv;
using namespace std;
int main()
{
//initialize and allocate memory to load the video stream from camera
VideoCapture camera0(2);
camera0.set(CV_CAP_PROP_FRAME_WIDTH, 320);
camera0.set(CV_CAP_PROP_FRAME_HEIGHT,240);
VideoCapture camera1(0);
camera1.set(CV_CAP_PROP_FRAME_WIDTH,320);
camera1.set(CV_CAP_PROP_FRAME_HEIGHT,240);
if( !camera0.isOpened() ) return 1;
if( !camera1.isOpened() ) return 1;
while(true) {
// grab and retrieve each frames of the video sequentially
Mat3b frame0;
camera0 >> frame0;
Mat3b frame1;
camera1 >> frame1;
Mat r0;
Mat r1;
resize(frame0, r0, Size(640, 480), 0, 0, INTER_LINEAR);
resize(frame1, r1, Size(640, 480), 0, 0, INTER_LINEAR);
imshow("Video00", frame0);
imshow("Video11", frame1);
imshow("Video0", r0);
imshow("Video1", r1);
// std::cout << frame1.rows() << std::endl;
// wait for 40 milliseconds
int c = waitKey(40);
// exit the loop if user press "Esc" key (ASCII value of "Esc" is 27)
if(27 == char(c)) break;
}
return 0;
}
参考
https://jingyan.baidu.com/article/9158e000392cada25412281a.html
https://blog.csdn.net/qq_32900237/article/details/102392445
更多推荐
所有评论(0)