4 #define GLFW_INCLUDE_GLU 12 static uint32_t histogram[0x10000];
13 memset(histogram, 0,
sizeof(histogram));
15 for(
int i = 0; i < width*
height; ++i) ++histogram[depth_image[i]];
16 for(
int i = 2; i < 0x10000; ++i) histogram[i] += histogram[i-1];
17 for(
int i = 0; i < width*
height; ++i)
19 if(uint16_t d = depth_image[i])
21 int f = histogram[d] * 255 / histogram[0xFFFF];
22 rgb_image[i*3 + 0] = 255 -
f;
23 rgb_image[i*3 + 1] = 0;
24 rgb_image[i*3 + 2] =
f;
28 rgb_image[i*3 + 0] = 20;
29 rgb_image[i*3 + 1] = 5;
30 rgb_image[i*3 + 2] = 0;
49 glEnableClientState(GL_VERTEX_ARRAY);
50 glVertexPointer(2, GL_FLOAT, 16, buffer);
51 glDrawArrays(GL_QUADS, 0, 4*
stb_easy_font_print((
float)x, (
float)(y-7), (
char *)text,
nullptr, buffer,
sizeof(buffer)));
52 glDisableClientState(GL_VERTEX_ARRAY);
63 std::vector<uint8_t>
rgb;
69 texture_buffer() : texture(), last_timestamp(-1), fps(), num_frames(), next_time(1000) {}
76 if(!texture) glGenTextures(1, &texture);
77 glBindTexture(GL_TEXTURE_2D, texture);
79 glPixelStorei(GL_UNPACK_ROW_LENGTH,
stride);
83 throw std::runtime_error(
"not a valid format");
86 rgb.resize(
stride * height * 3);
88 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
stride, height, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb.data());
92 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, data);
95 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, data);
98 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
101 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
104 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
107 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, data);
110 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
115 rgb.clear(); rgb.resize(width/2 * height/2 * 3);
116 auto out = rgb.data();
auto in0 =
reinterpret_cast<const uint8_t *
>(
data), in1 = in0 + width*5/4;
121 *out++ = in0[0]; *out++ = (in0[1] + in1[0]) / 2; *out++ = in1[1];
122 *out++ = in0[2]; *out++ = (in0[3] + in1[2]) / 2; *out++ = in1[3];
125 in0 = in1; in1 += width*5/4;
127 glPixelStorei(GL_UNPACK_ROW_LENGTH, width / 2);
128 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width/2, height/2, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb.data());
133 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, data);
137 std::stringstream ss;
139 throw std::runtime_error(ss.str().c_str());
142 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
143 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
144 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
145 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
146 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
147 glBindTexture(GL_TEXTURE_2D, 0);
156 if(timestamp != last_timestamp)
159 last_timestamp = timestamp;
162 if(timestamp >= next_time)
174 if(timestamp != last_timestamp)
177 last_timestamp = timestamp;
180 if(timestamp >= next_time)
189 void show(
float rx,
float ry,
float rw,
float rh)
const 191 glBindTexture(GL_TEXTURE_2D, texture);
192 glEnable(GL_TEXTURE_2D);
194 glTexCoord2f(0, 0); glVertex2f(rx, ry );
195 glTexCoord2f(1, 0); glVertex2f(rx+rw, ry );
196 glTexCoord2f(1, 1); glVertex2f(rx+rw, ry+rh);
197 glTexCoord2f(0, 1); glVertex2f(rx, ry+rh);
199 glDisable(GL_TEXTURE_2D);
200 glBindTexture(GL_TEXTURE_2D, 0);
207 glEnableClientState(GL_VERTEX_ARRAY);
208 glVertexPointer(2, GL_FLOAT, 16, buffer);
209 glDrawArrays(GL_QUADS, 0, 4*
stb_easy_font_print((
float)x, (
float)y, (
char *)text,
nullptr, buffer,
sizeof(buffer)));
210 glDisableClientState(GL_VERTEX_ARRAY);
220 float h = (float)rh,
w = (
float)rh * width /
height;
228 show(rx + (rw -
w)/2, ry + (rh - h)/2,
w, h);
231 draw_text(rx+9, ry+17, ss.str().c_str());
233 draw_text(rx+8, ry+16, ss.str().c_str());
236 void show(
rs::stream stream,
rs::format format,
int stream_framerate,
unsigned long long frame_number,
double timestamp,
int rx,
int ry,
int rw,
int rh,
int width,
int height)
238 show(rx, ry, rw, rh, width, height);
240 std::ostringstream ss; ss << stream <<
": " << width <<
" x " << height <<
" " << format <<
" (" << fps <<
"/" << stream_framerate <<
")" <<
", F#: " << frame_number <<
", TS: " << timestamp;
242 draw_text(rx+9, ry+17, ss.str().c_str());
244 draw_text(rx+8, ry+16, ss.str().c_str());
249 float h = (float)rh,
w = (
float)rh * width /
height;
257 show(rx + (rw -
w) / 2, ry + (rh - h) / 2,
w, h);
264 upload(data, width, height, format);
266 float h = (float)rh,
w = (
float)rh * width /
height;
274 show(rx + (rw -
w)/2, ry + (rh - h)/2,
w, h);
276 std::ostringstream ss; ss << caption <<
": " << width <<
" x " << height <<
" " <<
format;
278 draw_text(rx+9, ry+17, ss.str().c_str());
280 draw_text(rx+8, ry+16, ss.str().c_str());
286 static uint8_t rgb_image[640*480*3];
288 glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, rgb_image);
Provides convenience methods relating to devices.
int get_width() const
Returns image width in pixels.
int get_stride() const
Retrieves frame stride, meaning the actual line width in memory in bytes (not the logical image width...
void show(rs::stream stream, rs::format format, int stream_framerate, unsigned long long frame_number, double timestamp, int rx, int ry, int rw, int rh, int width, int height)
GLint GLint GLsizei GLsizei height
void show(int rx, int ry, int rw, int rh, int width, int height)
void draw_depth_histogram(const uint16_t depth_image[], int width, int height)
GLint GLint GLint GLint GLint GLint y
GLenum GLenum GLenum GLenum GLenum scale
static int stb_easy_font_print(float x, float y, char *text, unsigned char color[4], void *vertex_buffer, int vbuf_size)
GLsizei const GLchar *const * string
int get_stream_width(stream stream) const
Retrieves width, in pixels, of a specific stream, equivalent to the width field from the stream's int...
GLfloat GLfloat GLfloat GLfloat h
const void * get_frame_data(stream stream) const
Retrieves contents of latest frame on a stream.
format get_stream_format(stream stream) const
Retrieves pixel format for specific stream.
std::vector< uint8_t > rgb
void show(rs::device &dev, rs::stream stream, int rx, int ry, int rw, int rh)
void show(float rx, float ry, float rw, float rh) const
int get_height() const
Returns image height in pixels.
stream
Streams are different types of data provided by RealSense devices.
int get_stream_height(stream stream) const
Retrieves height, in pixels, of a specific stream, equivalent to the height field from the stream's i...
bool is_stream_enabled(stream stream) const
Determines if specific stream is enabled.
format get_format() const
Retrieves frame format.
format
Formats: defines how each stream can be encoded. rs_format specifies how a frame is represented in me...
void print(int x, int y, const char *text)
int get_stream_framerate(stream stream) const
Retrieves frame rate for specific stream.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
const void * get_data() const
unsigned long long get_frame_number(stream stream) const
Retrieves frame number.
rs_format
Formats: defines how each stream can be encoded.
int get_text_width(const char *text)
double get_frame_timestamp(stream stream) const
Retrieves time at which the latest frame on a stream was captured.
void upload(rs::frame &frame)
void upload(rs::device &dev, rs::stream stream)
static int stb_easy_font_width(char *text)
const char * rs_format_to_string(rs_format format)
GLint GLint GLsizei width
double get_timestamp() const
int get_bpp() const
Retrieves bits per pixel.
void draw_text(int x, int y, const char *text)
void make_depth_histogram(uint8_t rgb_image[640 *480 *3], const uint16_t depth_image[], int width, int height)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
GLuint get_gl_handle() const
void show(const void *data, int width, int height, rs::format format, const std::string &caption, int rx, int ry, int rw, int rh)
GLint GLint GLint GLint GLint x
GLubyte GLubyte GLubyte GLubyte w
void upload(const void *data, int width, int height, rs::format format, int stride=0)
typedef GLuint(APIENTRYP PFNGLCREATEPROGRAMPROC)(void)