OpenCV 读取 Intel RealSense2 视频

环境配置以及项目CMakeLists.txt文件参见

安装 PCL + OpenGL + GLFW

https://blog.csdn.net/u012180635/article/details/85232036

安装 RealSense2 + CMake + OpenCV

https://blog.csdn.net/u012180635/article/details/82143340

 

readVideoRealsense.cpp源码如下

#include  
#include
#include
int main(int argc, char * argv[])try
{
    rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);
    rs2::config cfg;
    cfg.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_BGR8, 30);
    cfg.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16, 30);
    rs2::pipeline pipe;
    pipe.start(cfg);
    rs2::frameset data;

    while(1)
    {
    data = pipe.wait_for_frames();
    rs2::frame depth  = data.get_depth_frame();
    rs2::frame color = data.get_color_frame();
    if (!color || !depth) break; 
    cv::Mat image(cv::Size(640, 480), CV_8UC3, (void*)color.get_data(), cv::Mat::AUTO_STEP);
    cv::Mat depthmat(cv::Size(640, 480), CV_16U, (void*)depth.get_data(), cv::Mat::AUTO_STEP);
    cv::imshow("image",image);
    cv::imshow("depth",depthmat);
    cv::waitKey(1);
    }

    return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{
    std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
    return EXIT_FAILURE;
}
catch (const std::exception & e)
{
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
}

CMakeLists.txt文件如下

#  minimum required cmake version: 3.1.0
cmake_minimum_required(VERSION 3.1.0)

project(readVideoRealsense)

# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()


add_executable(readVideoRealsense readVideoRealsense.cpp)
target_link_libraries(readVideoRealsense ${DEPENDENCIES})
set_target_properties (readVideoRealsense PROPERTIES FOLDER "readVideoRealsense")

Tip:每个子项目的CMakeLists.txt文件只需要把项目名改掉就可以。

你可能感兴趣的:(OpenCV 读取 Intel RealSense2 视频)