-
Notifications
You must be signed in to change notification settings - Fork 32
/
StaticImageProperties.cpp
33 lines (27 loc) · 1004 Bytes
/
StaticImageProperties.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <cmath>
#include "StaticImageProperties.h"
void sen::ColorizeDepthImage(const k4a::image &depthImage,
DepthPixelVisualizationFunction visualizationFn,
std::pair<uint16_t, uint16_t> expectedValueRange,
std::vector<Pixel> *buffer)
{
const k4a_image_format_t imageFormat = depthImage.get_format();
if (imageFormat != K4A_IMAGE_FORMAT_DEPTH16 && imageFormat != K4A_IMAGE_FORMAT_IR16)
{
throw std::logic_error("Attempted to colorize a non-depth image!");
}
const int width = depthImage.get_width_pixels();
const int height = depthImage.get_height_pixels();
buffer->resize(static_cast<size_t>(width * height));
const uint16_t *depthData = reinterpret_cast<const uint16_t *>(depthImage.get_buffer());
for (int h = 0; h < height; ++h)
{
for (int w = 0; w < width; ++w)
{
const size_t currentPixel = static_cast<size_t>(h * width + w);
(*buffer)[currentPixel] = visualizationFn(depthData[currentPixel],
expectedValueRange.first,
expectedValueRange.second);
}
}
}