Files
FastDeploy/fastdeploy/vision/tracking/pptracking/model.h
ChaoII 22d60fdadf [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>
2022-11-03 09:57:07 +08:00

100 lines
3.6 KiB
C++
Executable File

// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <map>
#include "fastdeploy/vision/common/processors/transform.h"
#include "fastdeploy/fastdeploy_model.h"
#include "fastdeploy/vision/common/result.h"
#include "fastdeploy/vision/tracking/pptracking/tracker.h"
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:
/** \brief Set path of model file and configuration file, and the configuration of runtime
*
* \param[in] model_file Path of model file, e.g pptracking/model.pdmodel
* \param[in] params_file Path of parameter file, e.g pptracking/model.pdiparams, if the model format is ONNX, this parameter will be ignored
* \param[in] config_file Path of configuration file for deployment, e.g pptracking/infer_cfg.yml
* \param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends`
* \param[in] model_format Model format of the loaded model, default is Paddle format
*/
PPTracking(const std::string& model_file,
const std::string& params_file,
const std::string& config_file,
const RuntimeOption& custom_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::PADDLE);
/// Get model's name
std::string ModelName() const override { return "pptracking"; }
/** \brief Predict the detection result for an input image(consecutive)
*
* \param[in] im The input image data which is consecutive frame, comes from imread() or videoCapture.read()
* \param[in] result The output tracking result will be writen to this structure
* \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();
bool Initialize();
bool Preprocess(Mat* img, std::vector<FDTensor>* outputs);
bool Postprocess(std::vector<FDTensor>& infer_result, MOTResult *result);
std::vector<std::shared_ptr<Processor>> processors_;
std::string config_file_;
float draw_threshold_;
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