2025-06-06 14:22:39 +08:00
|
|
|
|
#ifndef SSCMA_CAMERA_H
|
|
|
|
|
|
#define SSCMA_CAMERA_H
|
|
|
|
|
|
|
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>
2025-10-20 21:18:44 +08:00
|
|
|
|
#include <cstdint>
|
2025-06-06 14:22:39 +08:00
|
|
|
|
#include <lvgl.h>
|
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
|
|
#include <freertos/queue.h>
|
|
|
|
|
|
#include <esp_io_expander_tca95xx_16bit.h>
|
|
|
|
|
|
#include <esp_jpeg_dec.h>
|
|
|
|
|
|
#include <mbedtls/base64.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "sscma_client.h"
|
|
|
|
|
|
#include "camera.h"
|
|
|
|
|
|
|
|
|
|
|
|
struct SscmaData {
|
|
|
|
|
|
uint8_t* img;
|
|
|
|
|
|
size_t len;
|
|
|
|
|
|
};
|
|
|
|
|
|
struct JpegData {
|
|
|
|
|
|
uint8_t* buf;
|
|
|
|
|
|
size_t len;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SscmaCamera : public Camera {
|
|
|
|
|
|
private:
|
|
|
|
|
|
lv_img_dsc_t preview_image_;
|
|
|
|
|
|
std::string explain_url_;
|
|
|
|
|
|
std::string explain_token_;
|
|
|
|
|
|
sscma_client_io_handle_t sscma_client_io_handle_;
|
|
|
|
|
|
sscma_client_handle_t sscma_client_handle_;
|
|
|
|
|
|
QueueHandle_t sscma_data_queue_;
|
|
|
|
|
|
JpegData jpeg_data_;
|
2025-08-08 21:00:34 +08:00
|
|
|
|
jpeg_dec_handle_t jpeg_dec_;
|
2025-06-06 14:22:39 +08:00
|
|
|
|
jpeg_dec_io_t *jpeg_io_;
|
|
|
|
|
|
jpeg_dec_header_info_t *jpeg_out_;
|
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>
2025-10-20 21:18:44 +08:00
|
|
|
|
// 检测状态机
|
|
|
|
|
|
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;
|
2025-06-06 14:22:39 +08:00
|
|
|
|
public:
|
|
|
|
|
|
SscmaCamera(esp_io_expander_handle_t io_exp_handle);
|
|
|
|
|
|
~SscmaCamera();
|
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>
2025-10-20 21:18:44 +08:00
|
|
|
|
void InitializeMcpTools();
|
2025-06-06 14:22:39 +08:00
|
|
|
|
|
|
|
|
|
|
virtual void SetExplainUrl(const std::string& url, const std::string& token);
|
|
|
|
|
|
virtual bool Capture();
|
|
|
|
|
|
// 翻转控制函数
|
|
|
|
|
|
virtual bool SetHMirror(bool enabled) override;
|
|
|
|
|
|
virtual bool SetVFlip(bool enabled) override;
|
|
|
|
|
|
virtual std::string Explain(const std::string& question);
|
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>
2025-10-20 21:18:44 +08:00
|
|
|
|
|
2025-06-06 14:22:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // ESP32_CAMERA_H
|