intel realsense2顯示depth, ir影格。參閱realsense2 SDK所附範例與intel網站https://dev.intelrealsense.com/docs/api-how-to。顯影部份採openCV,C++程式碼如下:(深度資訊來自ir的資訊,intel 的深度攝影機D435有左右ir顯影,有視角差,可修改程式兩個畫面同時呈現)
#include <librealsense2/rs.hpp>
#include <opencv2/opencv.hpp>
using namespace rs2;
using namespace cv;
using namespace std;
int main(int argc, char** argv) try
{
cout << "顯示depth, ir影格。\n";
colorizer color_map(0);
/*著色的代碼如下
0 - Jet
1 - Classic
2 - WhiteToBlack
3 - BlackToWhite
4 - Bio
5 - Cold
6 - Warm
7 - Quantized
8 - Pattern
9 - Hue
*/
pipeline pipe;
config cfg;
int w = 640, h = 360, FPS = 30;
cfg.enable_stream(RS2_STREAM_INFRARED, w, h, RS2_FORMAT_Y8, FPS);
cfg.enable_stream(RS2_STREAM_DEPTH, w, h, RS2_FORMAT_Z16, FPS);
pipe.start(cfg);
// Camera warmup - dropping several first frames to let auto-exposure stabilize
frameset data;
for (int i = 0; i < FPS; i++) data = pipe.wait_for_frames();
while (1)
{
frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera
frame depth = data.get_depth_frame().apply_filter(color_map);
frame ir = data.get_infrared_frame() ;
int i = ir.get_frame_number();
// Create OpenCV matrix of size (w,h) from the data
Mat depth_im(h, w, CV_8UC3, (void*)depth.get_data());
Mat ir_im(h, w, CV_8UC1, (void*)ir.get_data());
applyColorMap(ir_im, ir_im, COLORMAP_JET);
// Update the window with new data
setWindowTitle("depth", "depth" + to_string(i));
setWindowTitle("ir", "ir" + to_string(i));
imshow("depth", depth_im);
imshow("ir", ir_im);
int k = waitKey(1);
if (k >0) break;
}
cv::destroyAllWindows();
pipe.stop();
return 0;
}
catch (exception& e) {
cerr << e.what();
return 1;
}

沒有留言:
張貼留言