17 bool profile_changed(
const std::vector<rs2::stream_profile>& current,
const std::vector<rs2::stream_profile>& prev);
19 int main(
int argc,
char * argv[])
try 22 window app(1280, 720,
"RealSense Align (Advanced) Example");
48 float depth_clipping_distance = 1.f;
68 auto processed = align.process(frameset);
75 if (!aligned_depth_frame || !other_frame)
82 remove_background(other_frame, aligned_depth_frame, depth_scale, depth_clipping_distance);
85 float w =
static_cast<float>(app.
width());
86 float h =
static_cast<float>(app.
height());
90 rect altered_other_frame_rect{ 0, 0,
w, h };
91 altered_other_frame_rect = altered_other_frame_rect.adjust_ratio({
static_cast<float>(other_frame.
get_width()),static_cast<float>(other_frame.
get_height()) });
94 renderer.
render(other_frame, altered_other_frame_rect);
98 rect pip_stream{ 0, 0, w / 5, h / 5 };
100 pip_stream.
x = altered_other_frame_rect.x + altered_other_frame_rect.w - pip_stream.w - (std::max(w, h) / 25);
101 pip_stream.y = altered_other_frame_rect.y + (std::max(w, h) / 25);
105 renderer.
show(pip_stream);
120 catch (
const std::exception & e)
134 return dpt.get_depth_scale();
137 throw std::runtime_error(
"Device does not have a depth sensor");
149 const int pixels_to_buttom_of_stream_text = 25;
150 const float slider_window_width = 30;
160 auto slider_size =
ImVec2(slider_window_width / 2, location.
h - (pixels_to_buttom_of_stream_text * 2) - 20);
167 float bars_dist = (slider_size.y / 6.0f);
168 for (
int i = 0;
i <= 6;
i++)
186 #pragma omp parallel for schedule(dynamic) //Using OpenMP to try to parallelise the loop 189 auto depth_pixel_index =
y *
width;
190 for (
int x = 0;
x <
width;
x++, ++depth_pixel_index)
193 auto pixels_distance = depth_scale * p_depth_frame[depth_pixel_index];
196 if (pixels_distance <= 0.f || pixels_distance > clipping_dist)
199 auto offset = depth_pixel_index * other_bpp;
202 std::memset(&p_other_frame[
offset], 0x99, other_bpp);
214 bool depth_stream_found =
false;
215 bool color_stream_found =
false;
221 if (!color_stream_found)
222 align_to = profile_stream;
226 color_stream_found =
true;
231 depth_stream_found =
true;
235 if(!depth_stream_found)
236 throw std::runtime_error(
"No Depth stream available");
239 throw std::runtime_error(
"No stream found to align with Depth");
244 bool profile_changed(
const std::vector<rs2::stream_profile>& current,
const std::vector<rs2::stream_profile>& prev)
246 for (
auto&& sp : prev)
frameset wait_for_frames(unsigned int timeout_ms=RS2_DEFAULT_TIMEOUT) const
void render(const rs2::frame &frame, const rect &rect, float alpha=1.f)
IMGUI_API void SetTooltip(const char *fmt,...) IM_PRINTFARGS(1)
std::vector< sensor > query_sensors() const
IMGUI_API void SetCursorPos(const ImVec2 &local_pos)
IMGUI_API void SetNextWindowPos(const ImVec2 &pos, ImGuiSetCond cond=0)
int get_bytes_per_pixel() const
void remove_background(rs2::video_frame &other, const rs2::depth_frame &depth_frame, float depth_scale, float clipping_dist)
const void * get_data() const
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
rect adjust_ratio(float2 size) const
GLfloat GLfloat GLfloat GLfloat h
void render_slider(rect location, float &clipping_dist)
const std::string & get_failed_args() const
rs2::frame process(rs2::frame frame) const override
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
void upload(const rs2::video_frame &frame)
bool ImGui_ImplGlfw_Init(GLFWwindow *window, bool install_callbacks)
GLint GLsizei GLsizei height
IMGUI_API void SetNextWindowSize(const ImVec2 &size, ImGuiSetCond cond=0)
IMGUI_API void Text(const char *fmt,...) IM_PRINTFARGS(1)
float get_depth_scale(rs2::device dev)
rs2_stream
Streams are different types of data provided by RealSense devices.
device get_device() const
IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4 &col)
rs2_stream find_stream_to_align(const std::vector< rs2::stream_profile > &streams)
void ImGui_ImplGlfw_NewFrame(float scale_factor)
std::vector< stream_profile > get_streams() const
void show(const rect &r, float alpha=1.f) const
bool profile_changed(const std::vector< rs2::stream_profile > ¤t, const std::vector< rs2::stream_profile > &prev)
int main(int argc, char *argv[])
pipeline_profile get_active_profile() const
IMGUI_API bool VSliderFloat(const char *label, const ImVec2 &size, float *v, float v_min, float v_max, const char *display_format="%.3f", float power=1.0f, bool render_bg=false)
IMGUI_API bool IsItemHovered()
const std::string & get_failed_function() const
IMGUI_API void PopStyleColor(int count=1)
std::string to_string(T value)