Skip to content

Commit 7bad4c5

Browse files
author
lsf
committed
lsf pc update
1 parent 110828a commit 7bad4c5

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

apps/app_track.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void inference_bytetrack(const string& engine_file, int gpuid, Yolo::Type type,
6868
int height = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
6969
BYTETracker tracker;
7070
cv::Mat image;
71+
cv::Mat prev_image;
7172
tracker.config().set_initiate_state({0.1, 0.1, 0.1, 0.1,
7273
0.2, 0.2, 1, 0.2}
7374
).set_per_frame_motion({0.1, 0.1, 0.1, 0.1,
@@ -77,28 +78,36 @@ void inference_bytetrack(const string& engine_file, int gpuid, Yolo::Type type,
7778
cv::VideoWriter writer("videos/output.mp4", cv::VideoWriter::fourcc('M', 'P', 'E', 'G'), fps, cv::Size(width, height));
7879
auto cond = [](const Yolo::Box& b){return b.label == 0;};
7980

81+
shared_future<vector<Yolo::Box>> prev_fut;
8082
int t = 0;
8183
while(cap.read(image)){
82-
83-
auto boxes = engine->commit(image).get();
8484
t++;
85-
86-
auto tracks = tracker.update(det2tracks(boxes, cond));
87-
for(auto& track : tracks){
88-
89-
vector<float> tlwh = track.tlwh;
90-
bool vertical = tlwh[2] / tlwh[3] > 1.6;
91-
if (tlwh[2] * tlwh[3] > 20 && !vertical)
92-
{
93-
auto s = tracker.get_color(track.track_id);
94-
putText(image, cv::format("%d", track.track_id), cv::Point(tlwh[0], tlwh[1] - 10),
95-
0, 2, cv::Scalar(0, 0, 255), 3, cv::LINE_AA);
96-
rectangle(image, cv::Rect(tlwh[0], tlwh[1], tlwh[2], tlwh[3]),
97-
cv::Scalar(get<0>(s), get<1>(s), get<2>(s)), 3);
85+
/// 高性能的关键:
86+
/// 先缓存一帧图像,使得读图预处理和推理后处理的时序图有重叠
87+
if(prev_fut.valid()){
88+
const auto& boxes = prev_fut.get();
89+
auto tracks = tracker.update(det2tracks(boxes, cond));
90+
for(auto& track : tracks){
91+
92+
vector<float> tlwh = track.tlwh;
93+
// 通过宽高比和面积过滤掉
94+
bool vertical = tlwh[2] / tlwh[3] > 1.6;
95+
if (tlwh[2] * tlwh[3] > 20 && !vertical)
96+
{
97+
auto s = tracker.get_color(track.track_id);
98+
putText(prev_image, cv::format("%d", track.track_id), cv::Point(tlwh[0], tlwh[1] - 10),
99+
0, 2, cv::Scalar(0, 0, 255), 3, cv::LINE_AA);
100+
rectangle(prev_image, cv::Rect(tlwh[0], tlwh[1], tlwh[2], tlwh[3]),
101+
cv::Scalar(get<0>(s), get<1>(s), get<2>(s)), 3);
102+
}
98103
}
104+
writer.write(prev_image);
105+
printf("process.\n");
99106
}
100-
writer.write(image);
101-
printf("process.\n");
107+
108+
image.copyTo(prev_image);
109+
prev_fut = engine->commit(image);
110+
102111
}
103112

104113
writer.release();

0 commit comments

Comments
 (0)