55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "IAnalysisModule.h"
|
|
#include "rknn/postprocess.h"
|
|
#include "rknn/rkYolov8.hpp"
|
|
#include "rknn/rknnPool.hpp"
|
|
#include <algorithm>
|
|
#include <chrono>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <opencv2/core/core.hpp>
|
|
#include <string>
|
|
|
|
struct PersonTrackInfo {
|
|
int id;
|
|
cv::Rect box;
|
|
double entry_time;
|
|
bool is_in_zone;
|
|
bool alarm_triggered;
|
|
int frames_unseen;
|
|
};
|
|
|
|
class HumanDetectionModule : public IAnalysisModule {
|
|
public:
|
|
/**
|
|
* @brief 构造函数
|
|
*/
|
|
HumanDetectionModule(std::string model_path, int thread_num,
|
|
cv::Rect intrusion_zone,
|
|
double intrusion_time_threshold);
|
|
|
|
virtual ~HumanDetectionModule() = default;
|
|
|
|
virtual bool init(const nlohmann::json &module_config) override;
|
|
virtual bool process(cv::Mat &frame) override;
|
|
virtual void stop() override;
|
|
|
|
private:
|
|
void update_tracker(detect_result_group_t &detect_result_group,
|
|
const cv::Size &frame_size);
|
|
void draw_results(cv::Mat &frame);
|
|
void trigger_alarm(int person_id, const cv::Rect &box);
|
|
double get_current_time_seconds();
|
|
|
|
std::string model_path_;
|
|
int thread_num_;
|
|
|
|
std::unique_ptr<rknnPool<rkYolov8, cv::Mat, detect_result_group_t>>
|
|
rknn_pool_;
|
|
|
|
cv::Rect intrusion_zone_;
|
|
std::map<int, PersonTrackInfo> tracked_persons_;
|
|
int next_track_id_;
|
|
double intrusion_time_threshold_;
|
|
}; |