Skip to content

Commit 628f74d

Browse files
committed
Small code-style refactoring
1 parent b0dd19f commit 628f74d

4 files changed

Lines changed: 18 additions & 98 deletions

File tree

async_detector/AsyncDetector.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,17 @@ void AsyncDetector::Process()
106106
DrawData(processedFrame, framesCounter, currTime);
107107

108108
if (!m_outFile.empty() && !writer.isOpened())
109-
{
110109
writer.open(m_outFile, cv::VideoWriter::fourcc('H', 'F', 'Y', 'U'), m_fps, processedFrame->m_frame.size(), true);
111-
}
112110
if (writer.isOpened())
113-
{
114111
writer << processedFrame->m_frame;
115-
}
116112

117113
#ifndef SILENT_WORK
118114
cv::imshow("Video", processedFrame->m_frame);
119115

120116
int waitTime = 1;// std::max<int>(1, cvRound(1000 / m_fps - currTime));
121117
int k = cv::waitKey(waitTime);
122118
if (k == 27)
123-
{
124119
break;
125-
}
126120
#else
127121
std::this_thread::sleep_for(std::chrono::milliseconds(1));
128122
#endif
@@ -140,9 +134,7 @@ void AsyncDetector::Process()
140134
m_framesQue.SetBreak(true);
141135

142136
if (thCapture.joinable())
143-
{
144137
thCapture.join();
145-
}
146138

147139
std::cout << "work time = " << (allTime / freq) << std::endl;
148140
#ifndef SILENT_WORK
@@ -161,8 +153,7 @@ void AsyncDetector::Process()
161153
void AsyncDetector::DrawTrack(cv::Mat frame,
162154
int resizeCoeff,
163155
const TrackingObject& track,
164-
bool drawTrajectory
165-
)
156+
bool drawTrajectory)
166157
{
167158
auto ResizeRect = [&](const cv::Rect& r) -> cv::Rect
168159
{
@@ -226,9 +217,7 @@ void AsyncDetector::DrawData(frame_ptr frameInfo, int framesCounter, int currTim
226217
std::cout << "Frame " << framesCounter << ": ";
227218
int id = frameInfo->m_inDetector.load();
228219
if (id > 0)
229-
{
230220
std::cout << "(" << id << ") detects = " << frameInfo->m_regions.size() << ", ";
231-
}
232221
std::cout << "tracks = " << frameInfo->m_tracks.size() << ", time = " << currTime << std::endl;
233222
}
234223

@@ -242,8 +231,7 @@ void AsyncDetector::DrawData(frame_ptr frameInfo, int framesCounter, int currTim
242231
{
243232
if (track.IsRobust(1, // Minimal trajectory size
244233
0.3f, // Minimal ratio raw_trajectory_points / trajectory_lenght
245-
cv::Size2f(0.1f, 8.0f)) // Min and max ratio: width / height
246-
)
234+
cv::Size2f(0.1f, 8.0f))) // Min and max ratio: width / height
247235
{
248236
//std::cout << track.m_type << " - " << track.m_rect << std::endl;
249237

@@ -271,13 +259,10 @@ void AsyncDetector::CaptureThread(std::string fileName, int startFrame, float* f
271259
{
272260
cv::VideoCapture capture;
273261
if (fileName.size() == 1)
274-
{
275262
capture.open(atoi(fileName.c_str()));
276-
}
277263
else
278-
{
279264
capture.open(fileName);
280-
}
265+
281266
if (!capture.isOpened())
282267
{
283268
*stopFlag = true;
@@ -372,9 +357,7 @@ void AsyncDetector::CaptureThread(std::string fileName, int startFrame, float* f
372357
break;
373358
}
374359
if (frameInfo->m_clFrame.empty())
375-
{
376360
frameInfo->m_clFrame = frameInfo->m_frame.getUMat(cv::ACCESS_READ);
377-
}
378361

379362
framesQue->AddNewFrame(frameInfo, 15);
380363

@@ -389,14 +372,12 @@ void AsyncDetector::CaptureThread(std::string fileName, int startFrame, float* f
389372

390373
framesQue->SetBreak(true);
391374
if (thTracking.joinable())
392-
{
393375
thTracking.join();
394-
}
376+
395377
framesQue->SetBreak(true);
396378
if (thDetection.joinable())
397-
{
398379
thDetection.join();
399-
}
380+
400381
framesQue->SetBreak(true);
401382
}
402383

async_detector/Queue.h

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ class FramesQueue
7070
std::lock_guard<std::mutex> lock(m_mutex);
7171

7272
if (!maxQueueSize || (maxQueueSize > 0 && m_que.size() < maxQueueSize))
73-
{
7473
m_que.push_back(frameInfo);
75-
}
74+
7675
#if SHOW_QUE_LOG
7776
QUE_LOG << "AddNewFrame end: " << frameInfo->m_dt << ", frameInd " << frameInfo->m_frameInd << ", queue size " << m_que.size() << std::endl;
7877
#endif
@@ -91,21 +90,14 @@ class FramesQueue
9190
for (auto it : m_que)
9291
{
9392
if (it->m_inDetector.load() && it->m_inTracker.load())
94-
{
9593
std::cout << i << " d" << it->m_inDetector.load() << " t" << it->m_inTracker.load() << "; ";
96-
}
9794
else if (it->m_inDetector.load())
98-
{
9995
std::cout << i << " d" << it->m_inDetector.load() << "; ";
100-
}
10196
else if (it->m_inTracker.load())
102-
{
10397
std::cout << i << " t" << it->m_inTracker.load() << "; ";
104-
}
10598
else
106-
{
10799
std::cout << i << "; ";
108-
}
100+
109101
++i;
110102
}
111103
std::cout << std::endl;
@@ -124,9 +116,7 @@ class FramesQueue
124116
while (m_que.empty() || m_que.back()->m_inDetector.load())
125117
{
126118
if (m_break.load())
127-
{
128119
break;
129-
}
130120

131121
m_cond.wait(lock);
132122
//PrintQue();
@@ -155,9 +145,8 @@ class FramesQueue
155145
for (queue_t::iterator it = m_que.begin(); it != m_que.end(); ++it)
156146
{
157147
if ((*it)->m_inDetector.load() == 1)
158-
{
159148
break;
160-
}
149+
161150
else if ((*it)->m_inTracker.load() == 0)
162151
{
163152
res_it = it;
@@ -181,9 +170,7 @@ class FramesQueue
181170
while (it == m_que.end())
182171
{
183172
if (m_break.load())
184-
{
185173
break;
186-
}
187174

188175
m_cond.wait(lock);
189176
it = SearchUntracked();
@@ -216,9 +203,7 @@ class FramesQueue
216203
while (m_que.empty() || m_que.front()->m_inTracker.load() != 2)
217204
{
218205
if (m_break.load())
219-
{
220206
break;
221-
}
222207

223208
m_cond.wait(lock);
224209
//PrintQue();

example/VideoExample.cpp

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ void VideoExample::SyncProcess()
7171
{
7272
capture >> frame;
7373
if (frame.empty())
74-
{
7574
break;
76-
}
7775

7876
if (!m_isDetectorInitialized || !m_isTrackerInitialized)
7977
{
@@ -117,13 +115,9 @@ void VideoExample::SyncProcess()
117115
int waitTime = manualMode ? 0 : 1;// std::max<int>(1, cvRound(1000 / m_fps - currTime));
118116
int k = cv::waitKey(waitTime);
119117
if (k == 27)
120-
{
121118
break;
122-
}
123119
else if (k == 'm' || k == 'M')
124-
{
125120
manualMode = !manualMode;
126-
}
127121
#else
128122
std::this_thread::sleep_for(std::chrono::milliseconds(1));
129123
#endif
@@ -229,9 +223,8 @@ void VideoExample::AsyncProcess()
229223
frameInfo.m_cond.notify_one();
230224

231225
if (k == 27)
232-
{
233226
break;
234-
}
227+
235228
++framesCounter;
236229
if (m_endFrame && framesCounter > m_endFrame)
237230
{
@@ -243,9 +236,7 @@ void VideoExample::AsyncProcess()
243236
stopCapture = true;
244237

245238
if (thCapDet.joinable())
246-
{
247239
thCapDet.join();
248-
}
249240

250241
int64 stopLoopTime = cv::getTickCount();
251242

@@ -358,13 +349,9 @@ void VideoExample::Tracking(cv::Mat frame, const regions_t& regions)
358349
{
359350
cv::UMat uframe;
360351
if (m_tracker->CanColorFrameToTrack())
361-
{
362352
uframe = frame.getUMat(cv::ACCESS_READ);
363-
}
364353
else
365-
{
366354
cv::cvtColor(frame, uframe, cv::COLOR_BGR2GRAY);
367-
}
368355

369356
m_tracker->Update(regions, uframe, m_fps);
370357
}
@@ -379,8 +366,7 @@ void VideoExample::Tracking(cv::Mat frame, const regions_t& regions)
379366
void VideoExample::DrawTrack(cv::Mat frame,
380367
int resizeCoeff,
381368
const TrackingObject& track,
382-
bool drawTrajectory
383-
)
369+
bool drawTrajectory)
384370
{
385371
auto ResizePoint = [resizeCoeff](const cv::Point& pt) -> cv::Point
386372
{
@@ -506,9 +492,8 @@ bool VideoExample::WriteFrame(cv::VideoWriter& writer, const cv::Mat& frame)
506492
if (!m_outFile.empty())
507493
{
508494
if (!writer.isOpened())
509-
{
510495
writer.open(m_outFile, m_fourcc, m_fps, frame.size(), true);
511-
}
496+
512497
if (writer.isOpened())
513498
{
514499
writer << frame;

0 commit comments

Comments
 (0)