Files

88 lines
1.9 KiB
C++

#ifndef NUI_CORE_MAPPING_H
#define NUI_CORE_MAPPING_H
#include <array>
#include <cstddef>
#include <cstdint>
#include "contract/contract.h"
namespace nui::mapping {
constexpr std::size_t kMediaPipeLandmarkCount = 33;
constexpr int kDefaultDepthWidth = 640;
constexpr int kDefaultDepthHeight = 480;
struct DepthImagePoint {
int x;
int y;
uint16_t packed_depth;
};
struct MediaPipeLandmark {
float u;
float v;
float visibility;
float world_z;
};
struct MappingConfig {
int depth_width = kDefaultDepthWidth;
int depth_height = kDefaultDepthHeight;
float z0_meters = 2.5f;
float depth_gain = 0.0f;
bool mirror = true;
};
struct SmoothingParameters {
float smoothing = 0.6f;
float correction = 0.4f;
float prediction = 0.4f;
float jitter_radius = 0.04f;
float max_deviation_radius = 0.07f;
};
contract::Vector4 depth_image_to_skeleton(
const DepthImagePoint& point,
int depth_width = kDefaultDepthWidth,
int depth_height = kDefaultDepthHeight);
DepthImagePoint skeleton_to_depth_image(
const contract::Vector4& point,
int depth_width = kDefaultDepthWidth,
int depth_height = kDefaultDepthHeight);
class HoltSmoothingFilter {
public:
explicit HoltSmoothingFilter(SmoothingParameters parameters = {});
contract::Vector4 update(const contract::Vector4& raw);
bool initialized() const;
const contract::Vector4& output() const;
private:
SmoothingParameters parameters_;
contract::Vector4 filtered_{};
contract::Vector4 trend_{};
contract::Vector4 output_{};
bool initialized_ = false;
};
class SkeletonMapper {
public:
explicit SkeletonMapper(
MappingConfig config = {},
SmoothingParameters smoothing_parameters = {});
contract::SkeletonFrame map(
const std::array<MediaPipeLandmark, kMediaPipeLandmarkCount>& landmarks);
private:
MappingConfig config_;
std::array<HoltSmoothingFilter, contract::kJointCount> filters_;
};
} // namespace nui::mapping
#endif // NUI_CORE_MAPPING_H