feat: sensecap watcher add inference (#1312)

* feat: Wake up when a person is detected

* fix: Solve the problem of no sound when using WakeWordInvoke

* fix: Solve the problem of triggering dialogue when the person has not left

* feat(vision): 优化视觉检测逻辑并增加配置接口

本次提交旨在优化视觉检测功能,使其行为更自然、更智能,并为用户提供灵活的配置选项。

主要更新包括:

1. 引入了更精细的检测状态机:

   - IDLE: 空闲状态,等待检测目标。

   - VALIDATING: 验证状态,在检测到目标后,持续一段时间(可配置)以确认其存在,防止误触发。

   - COOLDOWN: 冷却状态,在一次成功交互后进入,避免过于频繁的打扰。

2. 新增了用于配置视觉检测的 MCP 工具:

   - self.vision.get_detection_config: 获取当前的检测参数(阈值、冷却间隔、验证时长、目标类型)。

   - self.vision.set_detection_config: 允许用户动态修改这些参数,以适应不同场景。

3. 性能优化:

   - 增加了配置参数的内存缓存,避免了在检测循环中对 NVS 的频繁访问。

* feat: Inference using Model 4

* feat: default inference disable

* feat: version cmd change to output json

* fix: fix image display

* Fix include directives for esp_check and esp_app_desc

---------

Co-authored-by: Spencer <love4yzp@gmail.com>
Co-authored-by: Xiaoxia <terrence@tenclass.com>
This commit is contained in:
virgil
2025-10-20 21:18:44 +08:00
committed by GitHub
parent ac03f8097d
commit a601a5cbc1
4 changed files with 455 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
#ifndef SSCMA_CAMERA_H
#define SSCMA_CAMERA_H
#include <cstdint>
#include <lvgl.h>
#include <thread>
#include <memory>
@@ -35,9 +36,31 @@ private:
jpeg_dec_handle_t jpeg_dec_;
jpeg_dec_io_t *jpeg_io_;
jpeg_dec_header_info_t *jpeg_out_;
// 检测状态机
enum DetectionState {
IDLE, // 空闲状态
VALIDATING, // 验证中连续检测3秒
COOLDOWN // 冷却期(等待重新检测)
};
DetectionState detection_state = IDLE;
int64_t state_start_time = 0;
bool need_start_cooldown = false; // 是否需要开始冷却期
int64_t last_detected_time = 0; // 验证期间最后一次检测到物体的时间
int detect_target = 0;
int detect_threshold = 75;
int detect_duration_sec = 2; // 检测持续时间2秒确认人员持续存在
int detect_invoke_interval_sec = 8; // 默认15秒冷却期避免频繁开始会话
int detect_debounce_sec = 1; // 验证期间人员离开的去抖动时间1秒
int inference_en = 0; // 推理使能开关0: 关闭, 1: 开启)
sscma_client_model_t *model;
int model_class_cnt = 0;
public:
SscmaCamera(esp_io_expander_handle_t io_exp_handle);
~SscmaCamera();
void InitializeMcpTools();
virtual void SetExplainUrl(const std::string& url, const std::string& token);
virtual bool Capture();
@@ -45,6 +68,7 @@ public:
virtual bool SetHMirror(bool enabled) override;
virtual bool SetVFlip(bool enabled) override;
virtual std::string Explain(const std::string& question);
};
#endif // ESP32_CAMERA_H