23#include "depth_drawer.h"
26#include <core/exception.h>
27#include <fvcams/camera.h>
28#include <fvutils/color/colorspaces.h>
29#include <fvutils/color/conversions.h>
30#include <plugins/openni/utils/colors.h>
38using namespace fawkes::openni;
39using namespace firevision;
55 unsigned int max_depth)
57 depth_cam_(depth_cam),
58 label_cam_(label_cam),
59 rgb_buf_raii_(malloc_buffer(RGB, width_, height_)),
60 rgb_buf_((unsigned char *)*rgb_buf_raii_),
61 max_depth_(max_depth),
62 histogram_raii_(malloc(max_depth_ * sizeof(float))),
63 histogram_((float *)*histogram_raii_),
79 show_labels_ = !show_labels_;
89 printf(
"Capturing depth image failed, exception follows\n");
94 uint16_t * depth = (uint16_t *)depth_cam_->
buffer();
95 unsigned int num_points = 0;
96 memset(histogram_, 0, max_depth_ *
sizeof(
float));
101 ++histogram_[depth[i]];
107 for (
unsigned int i = 1; i < max_depth_; ++i) {
108 histogram_[i] += histogram_[i - 1];
112 if (num_points > 0) {
113 for (
unsigned int i = 1; i < max_depth_; ++i) {
114 histogram_[i] = truncf(256. * (1.f - (histogram_[i] / num_points)));
122 printf(
"Capturing label image failed, exception follows\n");
126 uint16_t * l = (uint16_t *)label_cam_->
buffer();
127 uint16_t * d = depth;
128 unsigned char *r = rgb_buf_;
129 for (
unsigned int i = 0; i <
width_ *
height_; ++i, ++l, ++d, r += 3) {
133 unsigned int color = *l % NUM_USER_COLORS;
134 if (!show_labels_ || (*l == 0))
135 color = NUM_USER_COLORS;
138 float hv = histogram_[*d];
139 r[0] = hv * USER_COLORS[color][0];
140 r[1] = hv * USER_COLORS[color][1];
141 r[2] = hv * USER_COLORS[color][2];
146 uint16_t * d = depth;
147 unsigned char *r = rgb_buf_;
148 for (
unsigned int i = 0; i <
width_ *
height_; ++i, ++d, r += 3) {
153 float hv = histogram_[*d];
SkelGuiDepthDrawer(firevision::Camera *depth_cam, firevision::Camera *label_cam, unsigned int max_depth)
Constructor.
virtual void fill_texture()
Fill texture.
void toggle_show_labels()
Toggle label state.
~SkelGuiDepthDrawer()
Destructor.
Draw images from camera in texture.
const unsigned int height_
Height of visible area from texture.
const unsigned int width_
Width of visible area from texture.
void copy_rgb_to_texture(const unsigned char *rgb_buf)
Copy an RGB buffer to texture.
Base class for exceptions in Fawkes.
void print_trace() noexcept
Prints trace to stderr.
Camera interface for image aquiring devices in FireVision.
virtual void dispose_buffer()=0
Dispose current buffer.
virtual void capture()=0
Capture an image.
virtual unsigned char * buffer()=0
Get access to current image buffer.
Fawkes library namespace.