双目相机输出将左右摄像头拼接在一起输出
思路:
- 拿opencv读取视频每一帧(33ms)
- 拿Rect分割一下就好了
- 将left right图像保存到不同文件(这里我将提前保存好的时间戳与采集的图像一一对应起来)
不多bibi直接上代码
#include<opencv2/core/>
#include<opencv2/highgui/>
#include<opencv2/imgproc/>
#include<vector>
#include<string>
#include<>
#include<iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv){
printf("read timestampes: %s \n" , argv[1]); //时间戳文件路径
std::string timeStampesPath = argv[1];
std::FILE * file;
std::cout << timeStampesPath << endl;
file = std::fopen((timeStampesPath ).c_str(),"r");
if(file == NULL){
printf("cannot find file : %s \n" , timeStampesPath.c_str());
return 0;
}
std::vector<long> imageTimeList;
long nanosec;
char string_Temp[60];
// for (int i = 0 ; i < 1 ; i++){
// fscanf(file , "%s" , &string_Temp);
// }
int index = 0;
while(fscanf(file , "%ld" , &nanosec ) != EOF){
cout << "reading" << index << endl;
index++;
imageTimeList.push_back(nanosec);
}
std::fclose(file);
std::cout << () << endl;
std::cout << argv[2] << std::endl;
VideoCapture capture(argv[2]); //视频路径
int j = 0;
while(1){
Mat frame;
capture >> frame;
resize(frame , frame , Size(1280,480));
Mat leftImage , rightImage;
leftImage = frame(Rect(0,0,().width / 2 , ().height));
rightImage = frame(Rect(().width / 2 , 0 , ().width / 2 , ().height));
string leftImageName ="/home/junjun/hyl/datasets/leftImage/" + std::to_string(imageTimeList[j]) + ".png";
string rightImageName ="/home/junjun/hyl/datasets/rightImage/" + std::to_string(imageTimeList[j]) + ".png";
// imshow("leftImage" , leftImage);
// imshow("rightImage" , rightImage);
imwrite(leftImageName , leftImage);
imwrite(rightImageName , rightImage);
j++;
waitKey(33.33);
std::cout << "Saveing :" << j << " Image" << endl;
}
return 0;
}
cmake_minimum_required( VERSION 3.0)
project(stereotoimage)
find_package(OpenCV 3.0 REQUIRED)
add_executable(stereotoImage )
target_link_libraries(stereotoImage ${OpenCV_LIBRARIES})
代码链接
/houyiliang/