Skip to content

Commit efca7cd

Browse files
committed
Add contrast adjustment option with CLAHE
1 parent 3a7e44f commit efca7cd

7 files changed

Lines changed: 100 additions & 40 deletions

File tree

async_detector/main.cpp

Lines changed: 8 additions & 7 deletions
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

Lines changed: 10 additions & 9 deletions
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_rfdetr.ini

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 17 additions & 1 deletion
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)

example/VideoExample.h

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,38 @@ class Frame
2020
{
2121
public:
2222
Frame() = default;
23-
Frame(cv::Mat imgBGR)
23+
Frame(cv::Mat imgBGR, bool useCLAHE)
2424
{
2525
m_mBGR = imgBGR;
26+
if (useCLAHE)
27+
{
28+
m_clahe = cv::createCLAHE(1.2, cv::Size(4, 4));
29+
AdjustMatBGR();
30+
}
31+
}
32+
33+
///
34+
void SetUseAdjust(bool useCLAHE)
35+
{
36+
if (useCLAHE)
37+
{
38+
m_clahe = cv::createCLAHE(1.2, cv::Size(4, 4));
39+
AdjustMatBGR();
40+
}
41+
else
42+
{
43+
m_clahe.reset();
44+
}
2645
}
2746

2847
///
29-
bool empty() const
48+
bool empty() const noexcept
3049
{
3150
return m_mBGR.empty();
3251
}
3352

3453
///
35-
const cv::Mat& GetMatBGR()
54+
const cv::Mat& GetMatBGR() const noexcept
3655
{
3756
return m_mBGR;
3857
}
@@ -45,6 +64,22 @@ class Frame
4564
return m_mBGR;
4665
}
4766
///
67+
bool AdjustMatBGR()
68+
{
69+
if (m_mBGR.empty() || m_clahe.empty())
70+
return false;
71+
72+
cv::cvtColor(m_mBGR, m_mHSV, cv::COLOR_BGR2HSV);
73+
cv::split(m_mHSV, m_chansHSV);
74+
m_clahe->apply(m_chansHSV[2], m_chansHSV[2]);
75+
cv::merge(m_chansHSV, m_mHSV);
76+
cv::cvtColor(m_mHSV, m_mBGR, cv::COLOR_HSV2BGR);
77+
78+
//std::cout << "AdjustMatBGR()" << std::endl;
79+
80+
return true;
81+
}
82+
///
4883
const cv::Mat& GetMatGray()
4984
{
5085
if (m_mGray.empty() || !m_mGrayGenerated)
@@ -104,6 +139,10 @@ class Frame
104139
bool m_umGrayGenerated = false;
105140
std::thread::id m_umBGRThreadID;
106141
std::thread::id m_umGrayThreadID;
142+
143+
cv::Ptr<cv::CLAHE> m_clahe;
144+
cv::Mat m_mHSV;
145+
std::vector<cv::Mat> m_chansHSV;
107146
};
108147

109148
///
@@ -198,6 +237,8 @@ class VideoExample
198237
cv::Size m_frameSize;
199238
int m_framesCount = 0;
200239

240+
bool m_useContrastAdjustment = false;
241+
201242
size_t m_batchSize = 1;
202243

203244
int m_captureTimeOut = 60000;

example/main.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,23 @@ static void Help()
2424

2525
const char* keys =
2626
{
27-
"{ @1 |../data/atrium.avi | movie file | }"
28-
"{ e example |1 | number of example 0 - MouseTracking, 1 - MotionDetector, 2 - FaceDetector, 3 - PedestrianDetector, 4 - OpenCV dnn objects detector, 5 - YOLO Darknet detector, 6 - YOLO TensorRT Detector, 7 - Cars counting | }"
29-
"{ sf start_frame |0 | Start a video from this position | }"
30-
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
31-
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
32-
"{ o out | | Name of result video file | }"
33-
"{ sl show_logs |1 | Show Trackers logs | }"
34-
"{ g gpu |0 | Use OpenCL acceleration | }"
35-
"{ a async |1 | Use 2 theads for processing pipeline | }"
36-
"{ r log_res | | Path to the csv file with tracking result | }"
37-
"{ cvat_res | | Path to the xml file in cvat format with tracking result | }"
38-
"{ s settings | | Path to the ini file with tracking settings | }"
39-
"{ bs batch_size |1 | Batch size - frames count for processing | }"
40-
"{ wf write_n_frame |1 | Write logs on each N frame: 1 for writing each frame | }"
41-
"{ hm heat_map |0 | For CarsCounting: Draw heat map | }"
42-
"{ geo_bind |geo_bind.ini | For CarsCounting: ini file with geographical binding | }"
27+
"{ @1 |../data/atrium.avi | movie file | }"
28+
"{ e example |1 | number of example 0 - MouseTracking, 1 - MotionDetector, 2 - FaceDetector, 3 - PedestrianDetector, 4 - OpenCV dnn objects detector, 5 - YOLO Darknet detector, 6 - YOLO TensorRT Detector, 7 - Cars counting | }"
29+
"{ sf start_frame |0 | Start a video from this position | }"
30+
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
31+
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
32+
"{ o out | | Name of result video file | }"
33+
"{ sl show_logs |1 | Show Trackers logs | }"
34+
"{ g gpu |0 | Use OpenCL acceleration | }"
35+
"{ a async |1 | Use 2 theads for processing pipeline | }"
36+
"{ r log_res | | Path to the csv file with tracking result | }"
37+
"{ cvat_res | | Path to the xml file in cvat format with tracking result | }"
38+
"{ s settings | | Path to the ini file with tracking settings | }"
39+
"{ bs batch_size |1 | Batch size - frames count for processing | }"
40+
"{ wf write_n_frame |1 | Write logs on each N frame: 1 for writing each frame | }"
41+
"{ hm heat_map |0 | For CarsCounting: Draw heat map | }"
42+
"{ geo_bind |geo_bind.ini | For CarsCounting: ini file with geographical binding | }"
43+
"{ contrast_adjustment |0 | Use contrast adjustment for frames before detection | }"
4344
};
4445

4546
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)