Skip to content

Commit 4996e1a

Browse files
authored
Merge pull request #478 from Nuzhny007/master
Add TensorRT D-FINE detector
2 parents c9050d6 + ff9554c commit 4996e1a

17 files changed

+416
-87
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# Last changes
66

7+
* D-FINE detector worked with TensorRT! Export pretrained Pytorch models [here (Peterande/D-FINE)](https://github.com/Peterande/D-FINE) to onnx format and run Multitarget-tracker with -e=6 example
8+
79
* RF-DETR detector worked with TensorRT! Export pretrained Pytorch models [here (roboflow/rf-detr)](https://github.com/roboflow/rf-detr) to onnx format and run Multitarget-tracker with -e=6 example
810

911
* YOLOv12 detector worked with TensorRT! Export pretrained Pytorch models [here (sunsmarterjie/yolov12)](https://github.com/sunsmarterjie/yolov12) to onnx format and run Multitarget-tracker with -e=6 example

async_detector/main.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ static void Help()
1818

1919
const char* keys =
2020
{
21-
"{ @1 |../data/atrium.avi | movie file | }"
22-
"{ sf start_frame |0 | Start a video from this position | }"
23-
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
24-
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
25-
"{ o out | | Name of result video file | }"
26-
"{ sl show_logs |1 | Show Trackers logs | }"
27-
"{ g gpu |0 | Use OpenCL acceleration | }"
21+
"{ @1 |../data/atrium.avi | movie file | }"
22+
"{ sf start_frame |0 | Start a video from this position | }"
23+
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
24+
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
25+
"{ o out | | Name of result video file | }"
26+
"{ sl show_logs |1 | Show Trackers logs | }"
27+
"{ g gpu |0 | Use OpenCL acceleration | }"
28+
"{ contrast_adjustment |0 | Use contrast adjustment for frames before detection | }"
2829
};
2930

3031
// ----------------------------------------------------------------------

combined/main.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ static void Help()
1818

1919
const char* keys =
2020
{
21-
"{ @1 |../data/atrium.avi | movie file | }"
22-
"{ sf start_frame |0 | Start a video from this position | }"
23-
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
24-
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
25-
"{ o out | | Name of result video file | }"
26-
"{ sl show_logs |1 | Show Trackers logs | }"
27-
"{ g gpu |0 | Use OpenCL acceleration | }"
28-
"{ a async |1 | Use 2 theads for processing pipeline | }"
29-
"{ fv flipv |0 | Flip frames vertically | }"
21+
"{ @1 |../data/atrium.avi | movie file | }"
22+
"{ sf start_frame |0 | Start a video from this position | }"
23+
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
24+
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
25+
"{ o out | | Name of result video file | }"
26+
"{ sl show_logs |1 | Show Trackers logs | }"
27+
"{ g gpu |0 | Use OpenCL acceleration | }"
28+
"{ a async |1 | Use 2 theads for processing pipeline | }"
29+
"{ fv flipv |0 | Flip frames vertically | }"
30+
"{ contrast_adjustment |0 | Use contrast adjustment for frames before detection | }"
3031
};
3132

3233
// ----------------------------------------------------------------------

data/settings_dfine.ini

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
[detection]
2+
3+
#-----------------------------
4+
# opencv_dnn = 12
5+
# darknet_cudnn = 10
6+
# tensorrt = 11
7+
detector_backend = 11
8+
9+
#-----------------------------
10+
# Target and backend for opencv_dnn detector
11+
# DNN_TARGET_CPU
12+
# DNN_TARGET_OPENCL
13+
# DNN_TARGET_OPENCL_FP16
14+
# DNN_TARGET_MYRIAD
15+
# DNN_TARGET_CUDA
16+
# DNN_TARGET_CUDA_FP16
17+
ocv_dnn_target = DNN_TARGET_CPU
18+
19+
# DNN_BACKEND_DEFAULT
20+
# DNN_BACKEND_HALIDE
21+
# DNN_BACKEND_INFERENCE_ENGINE
22+
# DNN_BACKEND_OPENCV
23+
# DNN_BACKEND_VKCOM
24+
# DNN_BACKEND_CUDA
25+
# DNN_BACKEND_INFERENCE_ENGINE_NGRAPH
26+
# DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019
27+
ocv_dnn_backend = DNN_BACKEND_OPENCV
28+
29+
#-----------------------------
30+
nn_weights = C:/work/home/mtracker/Multitarget-tracker/data/coco/dfine_m_obj2coco.onnx
31+
nn_config = C:/work/home/mtracker/Multitarget-tracker/data/coco/dfine_m_obj2coco.onnx
32+
class_names = C:/work/home/mtracker/Multitarget-tracker/data/coco/coco_91.names
33+
34+
#-----------------------------
35+
confidence_threshold = 0.5
36+
37+
max_crop_ratio = 0
38+
max_batch = 1
39+
gpu_id = 0
40+
41+
#-----------------------------
42+
# YOLOV3
43+
# YOLOV4
44+
# YOLOV5
45+
net_type = DFINE
46+
47+
#-----------------------------
48+
# INT8
49+
# FP16
50+
# FP32
51+
inference_precision = FP16
52+
53+
54+
[tracking]
55+
56+
#-----------------------------
57+
# DistCenters = 0 // Euclidean distance between centers, pixels
58+
# DistRects = 1 // Euclidean distance between bounding rectangles, pixels
59+
# DistJaccard = 2 // Intersection over Union, IoU, [0, 1]
60+
# DistHist = 3 // Bhatacharia distance between histograms, [0, 1]
61+
62+
distance_type = 0
63+
64+
#-----------------------------
65+
# KalmanLinear = 0
66+
# KalmanUnscented = 1
67+
68+
kalman_type = 0
69+
70+
#-----------------------------
71+
# FilterCenter = 0
72+
# FilterRect = 1
73+
# FilterRRect = 2
74+
75+
filter_goal = 0
76+
77+
#-----------------------------
78+
# TrackNone = 0
79+
# TrackKCF = 1
80+
# TrackMIL = 2
81+
# TrackMedianFlow = 3
82+
# TrackGOTURN = 4
83+
# TrackMOSSE = 5
84+
# TrackCSRT = 6
85+
# TrackDAT = 7
86+
# TrackSTAPLE = 8
87+
# TrackLDES = 9
88+
# TrackDaSiamRPN = 10
89+
# Used if filter_goal == FilterRect
90+
91+
lost_track_type = 0
92+
93+
#-----------------------------
94+
# MatchHungrian = 0
95+
# MatchBipart = 1
96+
97+
match_type = 0
98+
99+
#-----------------------------
100+
# Use constant acceleration motion model:
101+
# 0 - unused (stable)
102+
# 1 - use acceleration in Kalman filter (experimental)
103+
use_aceleration = 0
104+
105+
#-----------------------------
106+
# Delta time for Kalman filter
107+
delta_time = 0.4
108+
109+
#-----------------------------
110+
# Accel noise magnitude for Kalman filter
111+
accel_noise = 0.2
112+
113+
#-----------------------------
114+
# Distance threshold between region and object on two frames
115+
dist_thresh = 0.8
116+
117+
#-----------------------------
118+
# If this value > 0 than will be used circle with this radius
119+
# If this value <= 0 than will be used ellipse with size (3*vx, 3*vy), vx and vy - horizontal and vertical speed in pixelsa
120+
min_area_radius_pix = -1
121+
122+
#-----------------------------
123+
# Minimal area radius in ration for object size. Used if min_area_radius_pix < 0
124+
min_area_radius_k = 0.8
125+
126+
#-----------------------------
127+
# If the object do not assignment more than this frames then it will be removed
128+
max_skip_frames = 50
129+
130+
#-----------------------------
131+
# The maximum trajectory length
132+
max_trace_len = 50
133+
134+
#-----------------------------
135+
# Detection abandoned objects
136+
detect_abandoned = 0
137+
# After this time (in seconds) the object is considered abandoned
138+
min_static_time = 5
139+
# After this time (in seconds) the abandoned object will be removed
140+
max_static_time = 25
141+
# Speed in pixels. If speed of object is more that this value than object is non static
142+
max_speed_for_static = 10

data/settings_rfdetr.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ ocv_dnn_target = DNN_TARGET_CPU
2727
ocv_dnn_backend = DNN_BACKEND_OPENCV
2828

2929
#-----------------------------
30-
nn_weights = C:/work/home/mtracker/Multitarget-tracker/data/coco/rfdetr_coco.onnx
31-
nn_config = C:/work/home/mtracker/Multitarget-tracker/data/coco/rfdetr_coco.onnx
30+
nn_weights = C:/work/home/mtracker/Multitarget-tracker/data/coco/rfdetr_sim_coco.onnx
31+
nn_config = C:/work/home/mtracker/Multitarget-tracker/data/coco/rfdetr_sim_coco.onnx
3232
class_names = C:/work/home/mtracker/Multitarget-tracker/data/coco/coco_91.names
3333

3434
#-----------------------------

data/settings_yolov12.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ nn_config = C:/work/home/mtracker/Multitarget-tracker/data/coco/yolov12m.onnx
3232
class_names = C:/work/home/mtracker/Multitarget-tracker/data/coco/coco.names
3333

3434
#-----------------------------
35-
confidence_threshold = 0.5
35+
confidence_threshold = 0.4
3636

3737
max_crop_ratio = 0
3838
max_batch = 1
@@ -42,7 +42,7 @@ gpu_id = 0
4242
# YOLOV3
4343
# YOLOV4
4444
# YOLOV5
45-
net_type = YOLOV11
45+
net_type = YOLOV12
4646

4747
#-----------------------------
4848
# INT8

example/VideoExample.cpp

+24-7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ VideoExample::VideoExample(const cv::CommandLineParser& parser)
4747
m_endFrame = parser.get<int>("end_frame");
4848
m_finishDelay = parser.get<int>("end_delay");
4949
m_batchSize = std::max(1, parser.get<int>("batch_size"));
50+
m_useContrastAdjustment = parser.get<int>("contrast_adjustment") != 0;
5051

5152
m_colors.emplace_back(255, 0, 0);
5253
m_colors.emplace_back(0, 255, 0);
@@ -68,6 +69,14 @@ VideoExample::VideoExample(const cv::CommandLineParser& parser)
6869
m_frameInfo[0].SetBatchSize(m_batchSize);
6970
m_frameInfo[1].SetBatchSize(m_batchSize);
7071
}
72+
for (auto& fr : m_frameInfo[0].m_frames)
73+
{
74+
fr.SetUseAdjust(m_useContrastAdjustment);
75+
}
76+
for (auto& fr : m_frameInfo[1].m_frames)
77+
{
78+
fr.SetUseAdjust(m_useContrastAdjustment);
79+
}
7180
}
7281

7382
///
@@ -136,6 +145,11 @@ void VideoExample::SyncProcess()
136145
frameInfo.m_frames.resize(frameInfo.m_batchSize);
137146
frameInfo.m_frameInds.resize(frameInfo.m_batchSize);
138147

148+
for (auto& fr : frameInfo.m_frames)
149+
{
150+
fr.SetUseAdjust(m_useContrastAdjustment);
151+
}
152+
139153
int64 startLoopTime = cv::getTickCount();
140154

141155
for (;;)
@@ -147,6 +161,7 @@ void VideoExample::SyncProcess()
147161
if (frameInfo.m_frames[i].empty())
148162
break;
149163
frameInfo.m_frameInds[i] = framesCounter;
164+
frameInfo.m_frames[i].AdjustMatBGR();
150165

151166
++framesCounter;
152167
if (m_endFrame && framesCounter > m_endFrame)
@@ -400,7 +415,8 @@ void VideoExample::CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& st
400415
break;
401416
}
402417
frameInfo.m_frames[i].GetMatBGRWrite() = frame;
403-
frameInfo.m_frameInds[i] = framesCounter;
418+
frameInfo.m_frames[i].AdjustMatBGR();
419+
frameInfo.m_frameInds[i] = framesCounter;
404420
++framesCounter;
405421

406422
if (localEndFrame && framesCounter > localEndFrame)
@@ -585,13 +601,14 @@ void VideoExample::DrawTrack(cv::Mat frame,
585601
}
586602

587603
cv::Rect brect = track.m_rrect.boundingRect();
588-
std::string label = track.m_ID.ID2Str();
604+
std::stringstream label;
605+
label << track.m_ID.ID2Str();
589606
if (track.m_type != bad_type)
590-
label += ": " + TypeConverter::Type2Str(track.m_type);
607+
label << ": " << TypeConverter::Type2Str(track.m_type);
591608
else if (!userLabel.empty())
592-
label += ": " + userLabel;
609+
label << ": " << userLabel;
593610
if (track.m_confidence > 0)
594-
label += ", " + std::to_string(track.m_confidence);
611+
label << ", " << std::fixed << std::setw(2) << std::setprecision(2) << track.m_confidence;
595612
#if 0
596613
track_t mean = 0;
597614
track_t stddev = 0;
@@ -619,7 +636,7 @@ void VideoExample::DrawTrack(cv::Mat frame,
619636
#endif
620637
int baseLine = 0;
621638
double fontScale = (frame.cols < 1920) ? 0.5 : 0.7;
622-
cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_TRIPLEX, fontScale, 1, &baseLine);
639+
cv::Size labelSize = cv::getTextSize(label.str(), cv::FONT_HERSHEY_TRIPLEX, fontScale, 1, &baseLine);
623640
if (brect.x < 0)
624641
{
625642
brect.width = std::min(brect.width, frame.cols - 1);
@@ -641,7 +658,7 @@ void VideoExample::DrawTrack(cv::Mat frame,
641658
brect.height = std::min(brect.height, frame.rows - 1);
642659
}
643660
DrawFilledRect(frame, cv::Rect(cv::Point(brect.x, brect.y - labelSize.height), cv::Size(labelSize.width, labelSize.height + baseLine)), cv::Scalar(200, 200, 200), 150);
644-
cv::putText(frame, label, brect.tl(), cv::FONT_HERSHEY_TRIPLEX, fontScale, cv::Scalar(0, 0, 0));
661+
cv::putText(frame, label.str(), brect.tl(), cv::FONT_HERSHEY_TRIPLEX, fontScale, cv::Scalar(0, 0, 0));
645662

646663
m_resultsLog.AddTrack(framesCounter, track.m_ID, brect, track.m_type, track.m_confidence);
647664
m_resultsLog.AddRobustTrack(track.m_ID);

0 commit comments

Comments
 (0)