Files
kinect/core/synth/mask_stabilizer.h
T
kinect-bot 3fef71b020
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python tracker (pytest) (push) Canceled after 0s
feat(synth): articulated depth + player-index + color/IR rasterizer (wave 4; todo 7 done)
2026-11-25 04:33:33 -05:00

52 lines
1.3 KiB
C++

#ifndef NUI_CORE_SYNTH_MASK_STABILIZER_H
#define NUI_CORE_SYNTH_MASK_STABILIZER_H
#include <cstddef>
#include <cstdint>
#include <vector>
// Segmentation-mask cleanup: resize-to-requested-resolution, morphological
// close, largest-connected-component, and a short temporal hold so a
// fragmented/flickering mask still yields one stable human-shaped blob
// (nui-contracts.md §2.3, §2.5).
namespace nui::synth {
struct ImageSize {
uint32_t width;
uint32_t height;
};
struct SegmentationMask {
ImageSize size;
std::vector<float> confidence;
};
struct BinaryMask {
ImageSize size;
std::vector<uint8_t> pixels;
};
std::size_t pixel_count(ImageSize size);
bool has_body(const BinaryMask& mask);
class MaskStabilizer {
public:
explicit MaskStabilizer(std::size_t temporal_hold_frames = 2);
// Thresholds and resizes `mask` to `requested_size`, applies a
// morphological close + largest-connected-component, and, if that yields
// no body, holds the last stable mask for up to `temporal_hold_frames`
// frames before falling through to background.
BinaryMask update(const SegmentationMask& mask, ImageSize requested_size);
private:
std::size_t temporal_hold_frames_;
std::size_t hold_frames_remaining_ = 0;
BinaryMask last_stable_{};
};
} // namespace nui::synth
#endif // NUI_CORE_SYNTH_MASK_STABILIZER_H