C++程式如下:
#include <librealsense2/rs.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace rs2;
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
try
{
cout << "顯示color_grab, depth影格,加上對齊修正align。\n";
colorizer color_map(3);
/*著色的代碼如下
0 - Jet
1 - Classic
2 - WhiteToBlack
3 - BlackToWhite
4 - Bio
5 - Cold
6 - Warm
7 - Quantized
8 - Pattern
9 - Hue
*/
pipeline pipe;
rs2::align align2color(RS2_STREAM_COLOR);
config cfg;
int w = 1280, h = 720, FPS = 30;
cfg.enable_stream(RS2_STREAM_COLOR, w, h, RS2_FORMAT_BGR8, FPS);
cfg.enable_stream(RS2_STREAM_DEPTH, w, h, RS2_FORMAT_Z16, FPS);
auto profile = pipe.start(cfg);
// Camera warmup
frameset data= pipe.wait_for_frames();
hole_filling_filter holeFilter;//補洞filter
while (1)
{
frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera
data = align2color.process(data);
data.apply_filter(holeFilter);//補洞
frame color = data.get_color_frame();
frame depth = data.get_depth_frame().apply_filter(color_map);
// Create OpenCV matrix of size (w,h) from the colorized depth data
Mat color_im(h, w, CV_8UC3, (void*)color.get_data());
Mat depth_im(h, w, CV_8UC3, (void*)depth.get_data());
GaussianBlur(depth_im, depth_im, Size(3, 3), 3, 3);
dilate(depth_im, depth_im, 1);//擴張
erode(depth_im, depth_im, 1);//侵蝕
Mat depth2;
threshold(depth_im, depth2, 120, 255, THRESH_BINARY);
color_im = color_im | depth2 ;
// Update the window with new data
imshow("color_grab", color_im);
imshow("depth", depth_im);
if (waitKey(1)>0)break;
}
destroyAllWindows();
pipe.stop();
return 0;
}
catch (exception& e) {
cerr << e.what();
return 1;
}
沒有留言:
張貼留言