5 #include <opencv2/opencv.hpp> 6 #include "../cv-helpers.hpp" 8 int main(
int argc,
char * argv[])
try 21 const auto window_name =
"Display Image";
22 namedWindow(window_name, WINDOW_AUTOSIZE);
25 auto gen_element = [](
int erosion_size)
27 return getStructuringElement(MORPH_RECT,
28 Size(erosion_size + 1, erosion_size + 1),
29 Point(erosion_size, erosion_size));
32 const int erosion_size = 3;
33 auto erode_less = gen_element(erosion_size);
34 auto erode_more = gen_element(erosion_size * 2);
38 auto create_mask_from_depth = [&](Mat&
depth,
int thresh, ThresholdTypes
type)
40 threshold(depth, depth, thresh, 255,
type);
41 dilate(depth, depth, erode_less);
42 erode(depth, depth, erode_more);
48 while (waitKey(1) < 0 && getWindowProperty(window_name, WND_PROP_AUTOSIZE) >= 0)
64 cvtColor(near, near, COLOR_BGR2GRAY);
67 create_mask_from_depth(near, 180, THRESH_BINARY);
71 cvtColor(
far,
far, COLOR_BGR2GRAY);
73 create_mask_from_depth(
far, 100, THRESH_BINARY_INV);
78 mask.create(near.size(), CV_8UC1);
80 mask.setTo(GC_PR_BGD,
far == 0);
81 mask.setTo(GC_FGD, near == 255);
85 grabCut(color_mat, mask, Rect(), bgModel, fgModel, 1, GC_INIT_WITH_MASK);
88 Mat3b foreground = Mat3b::zeros(color_mat.rows, color_mat.cols);
89 color_mat.copyTo(foreground, (mask == GC_FGD) | (mask == GC_PR_FGD));
90 imshow(window_name, foreground);
100 catch (
const std::exception& e)
frame apply_filter(filter_interface &filter)
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
GLint GLint GLsizei GLsizei GLsizei depth
depth_frame get_depth_frame() const
video_frame get_color_frame() const
const std::string & get_failed_args() const
frameset process(frameset frames)
int main(int argc, char *argv[])
void set_option(rs2_option option, float value) const
static cv::Mat frame_to_mat(const rs2::frame &f)
const std::string & get_failed_function() const
::geometry_msgs::Point_< std::allocator< void > > Point