generated from guanyuankai/bonus-edge-proxy
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
#include "algorithm_service.hpp"
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <chrono>
|
|
|
|
AlgorithmService::AlgorithmService() {}
|
|
AlgorithmService::~AlgorithmService() {}
|
|
|
|
absl::Status AlgorithmService::Init() {
|
|
spdlog::info("Initializing Algorithm Model...");
|
|
// TODO: 在这里加载你的 AI 模型 (如 TensorRT, OpenVINO 等)
|
|
// 模拟加载耗时
|
|
// std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
return absl::OkStatus();
|
|
}
|
|
|
|
absl::Status AlgorithmService::Process(cv::Mat& frame) {
|
|
if (frame.empty())
|
|
return absl::InvalidArgumentError("Empty frame");
|
|
|
|
// --- 算法处理区域 START ---
|
|
|
|
// 1. 模拟:绘制时间戳
|
|
auto now = std::chrono::system_clock::now();
|
|
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
|
|
std::string timeStr = std::ctime(&now_c);
|
|
if (!timeStr.empty())
|
|
timeStr.pop_back(); // 去掉换行符
|
|
|
|
cv::putText(frame, "Live: " + timeStr, cv::Point(30, 50), cv::FONT_HERSHEY_SIMPLEX, 1.0,
|
|
cv::Scalar(0, 255, 0), 2);
|
|
|
|
// 2. 模拟:绘制检测框 (假设检测到了物体)
|
|
int centerX = frame.cols / 2;
|
|
int centerY = frame.rows / 2;
|
|
cv::rectangle(frame, cv::Rect(centerX - 100, centerY - 100, 200, 200), cv::Scalar(0, 0, 255),
|
|
3);
|
|
cv::putText(frame, "Detected Object", cv::Point(centerX - 100, centerY - 110),
|
|
cv::FONT_HERSHEY_SIMPLEX, 0.8, cv::Scalar(0, 0, 255), 2);
|
|
|
|
// --- 算法处理区域 END ---
|
|
|
|
return absl::OkStatus();
|
|
}
|