mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-22 08:09:28 +08:00
[Model] add tracking trail on vis_mot (#461)
* add override mark * delete some * recovery * recovery * add tracking * add tracking py_bind and example * add pptracking * add pptracking * iomanip head file * add opencv_video lib * add python libs package Signed-off-by: ChaoII <849453582@qq.com> * complete comments Signed-off-by: ChaoII <849453582@qq.com> * add jdeTracker_ member variable Signed-off-by: ChaoII <849453582@qq.com> * add 'FASTDEPLOY_DECL' macro Signed-off-by: ChaoII <849453582@qq.com> * remove kwargs params Signed-off-by: ChaoII <849453582@qq.com> * [Doc]update pptracking docs * delete 'ENABLE_PADDLE_FRONTEND' switch * add pptracking unit test * update pptracking unit test Signed-off-by: ChaoII <849453582@qq.com> * modify test video file path and remove trt test * update unit test model url * remove 'FASTDEPLOY_DECL' macro Signed-off-by: ChaoII <849453582@qq.com> * fix build python packages about pptracking on win32 Signed-off-by: ChaoII <849453582@qq.com> * update comment Signed-off-by: ChaoII <849453582@qq.com> * add pptracking model explain Signed-off-by: ChaoII <849453582@qq.com> * add tracking trail on vis_mot * add tracking trail * modify code for some suggestion * remove unused import * fix import bug Signed-off-by: ChaoII <849453582@qq.com> Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
@@ -161,9 +161,7 @@ bool PPTracking::Initialize() {
|
||||
return false;
|
||||
}
|
||||
// create JDETracker instance
|
||||
std::unique_ptr<JDETracker> jdeTracker(new JDETracker);
|
||||
jdeTracker_ = std::move(jdeTracker);
|
||||
|
||||
jdeTracker_ = std::unique_ptr<JDETracker>(new JDETracker);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -245,7 +243,6 @@ bool PPTracking::Postprocess(std::vector<FDTensor>& infer_result, MOTResult *res
|
||||
cv::Mat dets(bbox_shape[0], 6, CV_32FC1, bbox_data);
|
||||
cv::Mat emb(bbox_shape[0], emb_shape[1], CV_32FC1, emb_data);
|
||||
|
||||
|
||||
result->Clear();
|
||||
std::vector<Track> tracks;
|
||||
std::vector<int> valid;
|
||||
@@ -264,7 +261,6 @@ bool PPTracking::Postprocess(std::vector<FDTensor>& infer_result, MOTResult *res
|
||||
result->boxes.push_back(box);
|
||||
result->ids.push_back(1);
|
||||
result->scores.push_back(*dets.ptr<float>(0, 4));
|
||||
|
||||
} else {
|
||||
std::vector<Track>::iterator titer;
|
||||
for (titer = tracks.begin(); titer != tracks.end(); ++titer) {
|
||||
@@ -285,9 +281,36 @@ bool PPTracking::Postprocess(std::vector<FDTensor>& infer_result, MOTResult *res
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!is_record_trail_) return true;
|
||||
int nums = result->boxes.size();
|
||||
for (int i=0; i<nums; i++) {
|
||||
float center_x = (result->boxes[i][0] + result->boxes[i][2]) / 2;
|
||||
float center_y = (result->boxes[i][1] + result->boxes[i][3]) / 2;
|
||||
int id = result->ids[i];
|
||||
recorder_->Add(id,{int(center_x), int(center_y)});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PPTracking::BindRecorder(TrailRecorder* recorder){
|
||||
|
||||
recorder_ = recorder;
|
||||
is_record_trail_ = true;
|
||||
}
|
||||
|
||||
void PPTracking::UnbindRecorder(){
|
||||
|
||||
is_record_trail_ = false;
|
||||
std::map<int, std::vector<std::array<int, 2>>>::iterator iter;
|
||||
for(iter = recorder_->records.begin(); iter != recorder_->records.end(); iter++){
|
||||
iter->second.clear();
|
||||
iter->second.shrink_to_fit();
|
||||
}
|
||||
recorder_->records.clear();
|
||||
std::map<int, std::vector<std::array<int, 2>>>().swap(recorder_->records);
|
||||
recorder_ = nullptr;
|
||||
}
|
||||
|
||||
} // namespace tracking
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include "fastdeploy/vision/common/processors/transform.h"
|
||||
#include "fastdeploy/fastdeploy_model.h"
|
||||
#include "fastdeploy/vision/common/result.h"
|
||||
@@ -22,6 +23,21 @@
|
||||
namespace fastdeploy {
|
||||
namespace vision {
|
||||
namespace tracking {
|
||||
struct TrailRecorder{
|
||||
std::map<int, std::vector<std::array<int, 2>>> records;
|
||||
void Add(int id, const std::array<int, 2>& record);
|
||||
};
|
||||
|
||||
inline void TrailRecorder::Add(int id, const std::array<int, 2>& record) {
|
||||
auto iter = records.find(id);
|
||||
if (iter != records.end()) {
|
||||
auto trail = records[id];
|
||||
trail.push_back(record);
|
||||
records[id] = trail;
|
||||
} else {
|
||||
records[id] = {record};
|
||||
}
|
||||
}
|
||||
|
||||
class FASTDEPLOY_DECL PPTracking: public FastDeployModel {
|
||||
public:
|
||||
@@ -49,6 +65,14 @@ class FASTDEPLOY_DECL PPTracking: public FastDeployModel {
|
||||
* \return true if the prediction successed, otherwise false
|
||||
*/
|
||||
virtual bool Predict(cv::Mat* img, MOTResult* result);
|
||||
/** \brief bind tracking trail struct
|
||||
*
|
||||
* \param[in] recorder The MOT trail will record the trail of object
|
||||
*/
|
||||
void BindRecorder(TrailRecorder* recorder);
|
||||
/** \brief cancel binding and clear trail information
|
||||
*/
|
||||
void UnbindRecorder();
|
||||
|
||||
private:
|
||||
bool BuildPreprocessPipelineFromConfig();
|
||||
@@ -65,8 +89,11 @@ class FASTDEPLOY_DECL PPTracking: public FastDeployModel {
|
||||
float conf_thresh_;
|
||||
float tracked_thresh_;
|
||||
float min_box_area_;
|
||||
bool is_record_trail_ = false;
|
||||
std::unique_ptr<JDETracker> jdeTracker_;
|
||||
TrailRecorder *recorder_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace tracking
|
||||
} // namespace vision
|
||||
} // namespace fastdeploy
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
|
||||
namespace fastdeploy {
|
||||
void BindPPTracking(pybind11::module &m) {
|
||||
|
||||
pybind11::class_<vision::tracking::TrailRecorder>(m, "TrailRecorder")
|
||||
.def(pybind11::init<>())
|
||||
.def_readwrite("records", &vision::tracking::TrailRecorder::records)
|
||||
.def("add", &vision::tracking::TrailRecorder::Add);
|
||||
pybind11::class_<vision::tracking::PPTracking, FastDeployModel>(
|
||||
m, "PPTracking")
|
||||
.def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
|
||||
@@ -26,6 +31,8 @@ void BindPPTracking(pybind11::module &m) {
|
||||
vision::MOTResult *res = new vision::MOTResult();
|
||||
self.Predict(&mat, res);
|
||||
return res;
|
||||
});
|
||||
})
|
||||
.def("bind_recorder", &vision::tracking::PPTracking::BindRecorder)
|
||||
.def("unbind_recorder", &vision::tracking::PPTracking::UnbindRecorder);
|
||||
}
|
||||
} // namespace fastdeploy
|
||||
|
||||
@@ -118,7 +118,7 @@ void Trajectory::update(Trajectory *traj,
|
||||
if (update_embedding_) update_embedding(traj->current_embedding);
|
||||
}
|
||||
|
||||
void Trajectory::activate(int &cnt,int timestamp_) {
|
||||
void Trajectory::activate(int &cnt, int timestamp_) {
|
||||
id = next_id(cnt);
|
||||
TKalmanFilter::init(cv::Mat(xyah));
|
||||
length = 0;
|
||||
@@ -130,7 +130,7 @@ void Trajectory::activate(int &cnt,int timestamp_) {
|
||||
starttime = timestamp_;
|
||||
}
|
||||
|
||||
void Trajectory::reactivate(Trajectory *traj,int &cnt, int timestamp_, bool newid) {
|
||||
void Trajectory::reactivate(Trajectory *traj, int &cnt, int timestamp_, bool newid) {
|
||||
TKalmanFilter::correct(cv::Mat(traj->xyah));
|
||||
update_embedding(traj->current_embedding);
|
||||
length = 0;
|
||||
|
||||
@@ -74,8 +74,8 @@ class FASTDEPLOY_DECL Trajectory : public TKalmanFilter {
|
||||
virtual void update(Trajectory *traj,
|
||||
int timestamp,
|
||||
bool update_embedding = true);
|
||||
virtual void activate(int& cnt, int timestamp);
|
||||
virtual void reactivate(Trajectory *traj, int & cnt,int timestamp, bool newid = false);
|
||||
virtual void activate(int &cnt, int timestamp);
|
||||
virtual void reactivate(Trajectory *traj, int &cnt, int timestamp, bool newid = false);
|
||||
virtual void mark_lost(void);
|
||||
virtual void mark_removed(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user