OpenCV 双目相机录制的视频,左右图像分割

双目相机输出将左右摄像头拼接在一起输出

思路:

  • 拿opencv读取视频每一帧(33ms)
  • 拿Rect分割一下就好了
  • 将left right图像保存到不同文件(这里我将提前保存好的时间戳与采集的图像一一对应起来)

不多bibi直接上代码

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>

#include<vector>
#include<string>
#include<stdio.h>
#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 << imageTimeList.size() << 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,frame.size().width / 2 , frame.size().height));
        rightImage = frame(Rect(frame.size().width / 2 , 0 , frame.size().width / 2 , frame.size().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;
}

CMakeLists.txt

cmake_minimum_required( VERSION 3.0)

project(stereotoimage)

find_package(OpenCV 3.0 REQUIRED)

add_executable(stereotoImage main.cpp)
target_link_libraries(stereotoImage ${OpenCV_LIBRARIES})

代码链接

https://gitee.com/houyiliang/stereo2-image.git

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值