generated from guanyuankai/bonus-edge-proxy
feat(data structure):使用通用的数据结构头文件来把DTO和Classes分离。
This commit is contained in:
parent
f0d47d2ec0
commit
14330c393f
|
|
@ -137,6 +137,6 @@
|
|||
// 如果您有 .prettierrc,请务必在其中设置 "useTabs": true, "tabWidth": 4
|
||||
// --- JSON 配置 ---
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
"editor.defaultFormatter": "vscode.json-language-features"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,35 @@
|
|||
{
|
||||
"alarm_rules_path": "alarms.json",
|
||||
"config_base_path": "/app/config/",
|
||||
"data_cache_db_path": "edge_data_cache.db",
|
||||
"data_storage_db_path": "edge_proxy_data.db",
|
||||
"db_database": "smart-car-dev",
|
||||
"db_host": "127.0.0.1",
|
||||
"db_pwd": "forlinx",
|
||||
"db_user": "forlinx",
|
||||
"device_id": "rk3588-proxy-002",
|
||||
"log_level": "info",
|
||||
"mqtt_broker": "tcp://localhost:1883",
|
||||
"mqtt_client_id_prefix": "vehicle-road-counter-",
|
||||
"piper_executable_path": "/usr/bin/piper",
|
||||
"piper_model_path": "/app/models/model.onnx",
|
||||
"tcp_server_ports": [
|
||||
12345
|
||||
],
|
||||
"video_config_path": "video_config.json",
|
||||
"web_server_port": 8080
|
||||
"alarm_rules_path": "alarms.json",
|
||||
"config_base_path": "/app/config/",
|
||||
"data_cache_db_path": "edge_data_cache.db",
|
||||
"data_storage_db_path": "edge_proxy_data.db",
|
||||
"db_database": "smart-car-dev",
|
||||
"db_host": "127.0.0.1",
|
||||
"db_pwd": "forlinx",
|
||||
"db_user": "forlinx",
|
||||
"device_id": "rk3588-proxy-002",
|
||||
"log_level": "info",
|
||||
"mqtt_broker": "tcp://localhost:1883",
|
||||
"mqtt_client_id_prefix": "vehicle-road-counter-",
|
||||
"piper_executable_path": "/usr/bin/piper",
|
||||
"piper_model_path": "/app/models/model.onnx",
|
||||
"tcp_server_ports": [
|
||||
12345
|
||||
],
|
||||
"video_config_path": "video_config.json",
|
||||
"web_server_port": 8080,
|
||||
"tripwire": {
|
||||
"enable": true,
|
||||
"line": {
|
||||
"p1": {
|
||||
"x": 0.0,
|
||||
"y": 0.8
|
||||
},
|
||||
"p2": {
|
||||
"x": 1.0,
|
||||
"y": 0.8
|
||||
}
|
||||
},
|
||||
"name": "Main_Gate_Line"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#pragma once
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// 如果 DetectionResult 定义在 yolo_detector.hpp 中,需要包含它
|
||||
// 或者,如果 DetectionResult 很简单,建议把它也直接移到这里来
|
||||
// #include "yoloDetector/yolo_detector.hpp"
|
||||
|
||||
// ===========================
|
||||
// 1. 核心检测与追踪数据结构
|
||||
// ===========================
|
||||
|
||||
// 追踪到的车辆对象
|
||||
struct TrackedVehicle {
|
||||
int id; // 轨迹ID
|
||||
cv::Rect box; // 当前位置
|
||||
float ev_score; // 新能源平滑分数
|
||||
int missing_frames; // 丢失帧数计数
|
||||
int last_class_id; // 最终判定类别 (0: Fuel, 1: Green)
|
||||
std::string label; // 显示标签
|
||||
|
||||
// [预留] 如果需要记录车辆经过线条的时间,可以在这里加字段
|
||||
// int64_t cross_line_timestamp = 0;
|
||||
};
|
||||
|
||||
// 每一帧的数据包(用于线程间传递)
|
||||
struct FrameData {
|
||||
long frame_id; // 帧序号
|
||||
cv::Mat original_frame; // 原始图像
|
||||
std::vector<DetectionResult> results; // 检测结果
|
||||
};
|
||||
|
||||
// ===========================
|
||||
// 2. 业务配置结构
|
||||
// ===========================
|
||||
|
||||
// 绊线配置结构 (归一化坐标方案)
|
||||
struct TripwireConfig {
|
||||
bool enabled = false;
|
||||
std::string name; // 例如 "南门出口"
|
||||
|
||||
// 使用 Point2f 存储 0.0-1.0 的归一化坐标
|
||||
cv::Point2f p1_norm; // 起点
|
||||
cv::Point2f p2_norm; // 终点
|
||||
};
|
||||
|
||||
struct DetectionResult {
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
std::string label;
|
||||
float confidence;
|
||||
int class_id;
|
||||
};
|
||||
|
|
@ -11,26 +11,10 @@
|
|||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "DTOs/common_types.hpp"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "yoloDetector/yolo_detector.hpp"
|
||||
|
||||
// ... TrackedVehicle 结构体保持不变 ...
|
||||
struct TrackedVehicle {
|
||||
int id;
|
||||
cv::Rect box;
|
||||
float ev_score;
|
||||
int missing_frames;
|
||||
int last_class_id;
|
||||
std::string label;
|
||||
};
|
||||
|
||||
// [新增] 每一帧的数据包
|
||||
struct FrameData {
|
||||
long frame_id; // 帧序号,用于排序
|
||||
cv::Mat original_frame; // 原始图像
|
||||
std::vector<DetectionResult> results; // 检测结果
|
||||
};
|
||||
|
||||
class VideoPipeline {
|
||||
public:
|
||||
VideoPipeline();
|
||||
|
|
@ -39,6 +23,7 @@ public:
|
|||
void Start(const std::string& inputUrl, const std::string& outputUrl);
|
||||
void StartTest(const std::string& filePath, const std::string& outputUrl);
|
||||
void Stop();
|
||||
void setTripwire(const TripwireConfig& config);
|
||||
|
||||
private:
|
||||
void processLoop(std::string inputUrl, std::string outputUrl, bool isFileSource);
|
||||
|
|
@ -50,6 +35,11 @@ private:
|
|||
void updateTracker(const std::vector<DetectionResult>& detections);
|
||||
float computeIOU(const cv::Rect& box1, const cv::Rect& box2);
|
||||
|
||||
bool isLineCrossed(const cv::Point& p1, const cv::Point& p2, const cv::Point& line_start,
|
||||
const cv::Point& line_end);
|
||||
|
||||
void processCrossing(const TrackedVehicle& vehicle, const cv::Mat& frame);
|
||||
|
||||
private:
|
||||
std::atomic<bool> running_;
|
||||
std::thread processingThread_; // 主处理线程
|
||||
|
|
|
|||
|
|
@ -7,18 +7,19 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "DTOs/common_types.hpp"
|
||||
#include "postprocess.h"
|
||||
#include "rknn_api.h"
|
||||
|
||||
struct DetectionResult {
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
std::string label;
|
||||
float confidence;
|
||||
int class_id;
|
||||
};
|
||||
// struct DetectionResult {
|
||||
// int x;
|
||||
// int y;
|
||||
// int width;
|
||||
// int height;
|
||||
// std::string label;
|
||||
// float confidence;
|
||||
// int class_id;
|
||||
// };
|
||||
|
||||
class YoloDetector {
|
||||
public:
|
||||
|
|
|
|||
Loading…
Reference in New Issue