46、OAK基本接口学习笔记&显示深度图和视差图

基本思想:继续学习oak的接口函数,具体参考官方demo,自己做下笔记记录一下

46、OAK基本接口学习笔记&显示深度图和视差图_第1张图片

 46、OAK基本接口学习笔记&显示深度图和视差图_第2张图片

看结构写代码比较方便 

cmakelists.txt

cmake_minimum_required(VERSION 3.16)
project(depthai)
set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV REQUIRED)
#message(STATUS ${OpenCV_INCLUDE_DIRS})
#添加头文件
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/include/utility)
#链接Opencv库
find_package(depthai CONFIG REQUIRED)
add_executable(depthai main.cpp include/utility/utility.cpp)
target_link_libraries(depthai ${OpenCV_LIBS}  depthai::opencv)

main.cpp

#include 

#include "utility.hpp"

#include "depthai/depthai.hpp"


int main(int argc, char** argv) {
    dai::Pipeline pipeline;
    //定义左相机
    auto Leftmono=pipeline.create();
    Leftmono->setBoardSocket(dai::CameraBoardSocket::LEFT);
    auto Rigthmono=pipeline.create();
    Rigthmono->setBoardSocket(dai::CameraBoardSocket::RIGHT);

    // 深度模块
    auto stereo=pipeline.create();
    stereo->setLeftRightCheck(true);


    //相机和输出链接
    Leftmono->out.link(stereo->left);
    Rigthmono->out.link(stereo->right);
    //

    //定义输出
    auto xlinkDetpth=pipeline.create();
    xlinkDetpth->setStreamName("depth");
    auto xlinkdisparity=pipeline.create();
    xlinkdisparity->setStreamName("disparity");

    auto xlinkRectifiedLeft=pipeline.create();
    xlinkRectifiedLeft->setStreamName("RectifiedLeft");
    auto xlinkRectifiedRight=pipeline.create();
    xlinkRectifiedRight->setStreamName("RectifiedRight");

    //连接
    stereo->disparity.link(xlinkdisparity->input);
    stereo->depth.link(xlinkDetpth->input);
    stereo->rectifiedLeft.link(xlinkRectifiedLeft->input);
    stereo->rectifiedRight.link(xlinkRectifiedRight->input);


    //结构推送相机
    dai::Device device(pipeline);
    //取帧显示
    auto disparityqueue=device.getOutputQueue("disparity",8, false);//maxsize 代表缓冲数据
    auto RectifiedLeftqueue=device.getOutputQueue("RectifiedLeft",8, false);//maxsize 代表缓冲数据
    auto RectifiedRightqueue=device.getOutputQueue("RectifiedRight",8, false);//maxsize 代表缓冲数据
    auto depthqueue=device.getOutputQueue("depth",8, false);//maxsize 代表缓冲数据
    while(1){


        auto Depthframe=depthqueue->get();
        auto Depthimage=Depthframe->getCvFrame();

        cv::Mat depthFrameColor;
        cv::normalize(Depthimage, depthFrameColor, 255, 0, cv::NORM_INF, CV_8UC1);
        cv::equalizeHist(depthFrameColor, depthFrameColor);
        cv::applyColorMap(depthFrameColor, depthFrameColor, cv::COLORMAP_HOT);
        cv::imshow("Depthimage",depthFrameColor);

        cv::imwrite("depthFrameColor.jpg",depthFrameColor);
        //std::cout<<(int)Depthimage.at(40, 40)<get();
        auto disparityimage=disparityframe->getCvFrame();

        cv::imshow("disparityimage",disparityimage);
        cv::imwrite("disparityimage.jpg",disparityimage);
        auto RectifiedRightframe=RectifiedRightqueue->get();
        auto RectifiedRightimage=RectifiedRightframe->getCvFrame();

       // cv::imshow("RectifiedRight",RectifiedRightimage);


        auto RectifiedLeftframe=RectifiedLeftqueue->get();
        auto RectifiedLeftimage=RectifiedLeftframe->getCvFrame();
        cv::Mat result;
         cv::hconcat(RectifiedRightimage, RectifiedLeftimage, result);
        cv::imshow("RectifiedRight RectifiedLeft",result);
        cv::imwrite("result.jpg",result);
        cv::waitKey(1);

    }


    return 0;
}

测试图片 左右纠正图

视觉差图

46、OAK基本接口学习笔记&显示深度图和视差图_第3张图片

 深度图(添加了暖色)

参考:

StereoDepth — DepthAI documentation | Luxonis

你可能感兴趣的:(硬件的基本知识,学习,opencv,计算机视觉)