Files
DoorCounter/firmware/lib/cv/cv.h
Peter Woolery e28a4c1863 feat(cv): add CVTuning struct and NVS persistence scaffolding
Adds CVTuning to CVState, populates defaults from existing file-scope
constants in cv_init, and introduces config_load_tuning/config_save_tuning
backed by the doorcounter NVS namespace. No runtime behavior change yet;
CV code still reads the existing constants (Task 2 will migrate reads).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 15:45:53 -07:00

51 lines
1.3 KiB
C++

// firmware/lib/cv/cv.h
#pragma once
#include <stdint.h>
#include <vector>
static const int CV_W = 96;
static const int CV_H = 96;
static const int CV_PIXELS = CV_W * CV_H;
static const uint8_t CV_DIFF_THRESH = 30;
static const int CV_MIN_BLOB_PX = 64;
static const float CV_MAX_MOVE = 15.0f;
static const int CV_MAX_MISSED = 10;
struct CVTrack {
int id;
float x, y;
bool above_line;
int missed;
};
struct CVTuning {
uint8_t diff_thresh; // per-pixel motion threshold
int min_blob_px; // min foreground pixels for a blob
float max_move; // max inter-frame track jump (px)
int max_missed; // frames before drop
uint8_t line_offset; // 0-100, percent of frame height for virtual line
uint32_t cfg_version; // monotonic; server increments on push
};
struct CVState {
uint8_t background[CV_PIXELS];
bool bg_valid;
uint32_t last_motion_frame;
uint32_t frame_index;
int next_id;
std::vector<CVTrack> tracks;
int entries;
int exits;
CVTuning tuning;
};
struct CVResult {
int entries_delta;
int exits_delta;
};
void cv_init(CVState& state);
CVResult cv_process(CVState& state, const uint8_t* frame, uint8_t line_pct);
void cv_reset_counts(CVState& state);