some questions about using OpenCV to save and show depth image
Hello !
My camera is D435i, and I use Opencv 3.4.7 、realsense SDK 2.0 in Ubuntu 18.04. After I align the color and depth stream ,I use Mat depth_image to save the depth data of the depth frame ,and use imwrite() to save Mat depth_image to Depth.png, then use imshow() to show the Mat .
My questions are:
- why the Depth.png looks different from the imshow window? They both come from Mat depth_image.
- can I think the data of the pixel in Depth.png is the depth information I get from the camera's depth frame? Is the unit millimeter?
I would be grateful for your help!
main.cpp
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<librealsense2/rs.hpp>
using namespace std;
using namespace cv;
int main(int argc, char * argv[])
{
rs2::pipeline pipe;
rs2::config pipe_config;
pipe_config.enable_stream(RS2_STREAM_DEPTH,640,480,RS2_FORMAT_Z16,30);
pipe_config.enable_stream(RS2_STREAM_COLOR,640,480,RS2_FORMAT_BGR8,30);
rs2::pipeline_profile profile = pipe.start(pipe_config);
rs2::frameset frameset = pipe.wait_for_frames();
rs2_stream align_to = RS2_STREAM_COLOR;
rs2::align align(align_to);
auto processed = align.process(frameset);
rs2::depth_frame depth = processed.get_depth_frame();
const int depth_w=depth.as<rs2::video_frame>().get_width();
const int depth_h=depth.as<rs2::video_frame>().get_height();
Mat depth_image(Size(depth_w,depth_h),CV_16SC1,(void*)depth.get_data(),Mat::AUTO_STEP);
imwrite("Depth.png",depth_image);
imshow("depth used imshow",depth_image);
waitKey(0);
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(Align)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
set(DEPENDCIES realsense2)
add_executable(Align main.cpp)
target_link_libraries(Align ${OpenCV_LIBS} ${DEPENDCIES})
Depth.png

what I see in imshow window:

-
I thought about your question very carefully. The use of OpenCV and imwrite / imshow means that it goes outside of my programming knowledge, unfortunately. The best place to get expert advice on this subject will be the RealSense GitHub forum. Please visit the link below and click the New Issue button to re-post your question there. I do apologise.
Please sign in to leave a comment.
Comments
3 comments