mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-30 11:26:39 +08:00
* 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> Signed-off-by: ChaoII <849453582@qq.com> Co-authored-by: Jason <jiangjiajun@baidu.com>
101 lines
3.2 KiB
C++
101 lines
3.2 KiB
C++
// 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.
|
|
|
|
#ifdef ENABLE_VISION_VISUALIZE
|
|
#include "fastdeploy/vision/visualize/visualize.h"
|
|
#include <iomanip>
|
|
|
|
namespace fastdeploy {
|
|
namespace vision {
|
|
|
|
cv::Scalar GetMOTBoxColor(int idx) {
|
|
idx = idx * 3;
|
|
cv::Scalar color = cv::Scalar((37 * idx) % 255, (17 * idx) % 255, (29 * idx) % 255);
|
|
return color;
|
|
}
|
|
|
|
|
|
cv::Mat VisMOT(const cv::Mat &img, const MOTResult &results, float fps, int frame_id) {
|
|
|
|
cv::Mat vis_img = img.clone();
|
|
int im_h = img.rows;
|
|
int im_w = img.cols;
|
|
float text_scale = std::max(1, static_cast<int>(im_w / 1600.));
|
|
float text_thickness = 2.;
|
|
float line_thickness = std::max(1, static_cast<int>(im_w / 500.));
|
|
|
|
std::ostringstream oss;
|
|
oss << std::setiosflags(std::ios::fixed) << std::setprecision(4);
|
|
oss << "frame: " << frame_id << " ";
|
|
oss << "fps: " << fps << " ";
|
|
oss << "num: " << results.boxes.size();
|
|
std::string text = oss.str();
|
|
|
|
cv::Point origin;
|
|
origin.x = 0;
|
|
origin.y = static_cast<int>(15 * text_scale);
|
|
cv::putText(vis_img,
|
|
text,
|
|
origin,
|
|
cv::FONT_HERSHEY_PLAIN,
|
|
text_scale,
|
|
cv::Scalar(0, 0, 255),
|
|
text_thickness);
|
|
|
|
for (int i = 0; i < results.boxes.size(); ++i) {
|
|
const int obj_id = results.ids[i];
|
|
const float score = results.scores[i];
|
|
|
|
cv::Scalar color = GetMOTBoxColor(obj_id);
|
|
|
|
cv::Point pt1 = cv::Point(results.boxes[i][0], results.boxes[i][1]);
|
|
cv::Point pt2 = cv::Point(results.boxes[i][2], results.boxes[i][3]);
|
|
cv::Point id_pt =
|
|
cv::Point(results.boxes[i][0], results.boxes[i][1] + 10);
|
|
cv::Point score_pt =
|
|
cv::Point(results.boxes[i][0], results.boxes[i][1] - 10);
|
|
cv::rectangle(vis_img, pt1, pt2, color, line_thickness);
|
|
|
|
std::ostringstream idoss;
|
|
idoss << std::setiosflags(std::ios::fixed) << std::setprecision(4);
|
|
idoss << obj_id;
|
|
std::string id_text = idoss.str();
|
|
|
|
cv::putText(vis_img,
|
|
id_text,
|
|
id_pt,
|
|
cv::FONT_HERSHEY_PLAIN,
|
|
text_scale,
|
|
cv::Scalar(0, 255, 255),
|
|
text_thickness);
|
|
|
|
std::ostringstream soss;
|
|
soss << std::setiosflags(std::ios::fixed) << std::setprecision(2);
|
|
soss << score;
|
|
std::string score_text = soss.str();
|
|
|
|
cv::putText(vis_img,
|
|
score_text,
|
|
score_pt,
|
|
cv::FONT_HERSHEY_PLAIN,
|
|
text_scale,
|
|
cv::Scalar(0, 255, 255),
|
|
text_thickness);
|
|
}
|
|
return vis_img;
|
|
}
|
|
}// namespace vision
|
|
} //namespace fastdepoly
|
|
#endif
|