Skip to content

Commit 2df9553

Browse files
committed
Write results to log each N frames
1 parent 65ef289 commit 2df9553

3 files changed

Lines changed: 53 additions & 45 deletions

File tree

example/FileLogger.h

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class ResultsLog
1313
{
1414
public:
1515
///
16-
ResultsLog(const std::string& fileName)
17-
: m_fileName(fileName)
16+
ResultsLog(const std::string& fileName, int writeEachNFrame)
17+
: m_fileName(fileName), m_writeEachNFrame(writeEachNFrame)
1818
{
1919
}
2020

@@ -98,6 +98,7 @@ class ResultsLog
9898
};
9999
std::map<int, DetectsOnFrame> m_frames;
100100
std::set<size_t> m_robustIDs;
101+
int m_writeEachNFrame = 1;
101102

102103
///
103104
void WriteAll(bool byFrames)
@@ -108,16 +109,19 @@ class ResultsLog
108109
char delim = ',';
109110
for (const auto& frame : m_frames)
110111
{
111-
for (const auto& detect : frame.second.m_detects)
112-
{
113-
if (m_robustIDs.find(detect.m_trackID) != std::end(m_robustIDs))
114-
{
115-
m_resCSV << frame.first << delim << TypeConverter::Type2Str(detect.m_type) << delim << detect.m_rect.x << delim << detect.m_rect.y << delim <<
116-
detect.m_rect.width << delim << detect.m_rect.height << delim <<
117-
detect.m_conf << delim << std::endl;
118-
}
119-
}
120-
}
112+
if (frame.first % m_writeEachNFrame == 0)
113+
{
114+
for (const auto& detect : frame.second.m_detects)
115+
{
116+
if (m_robustIDs.find(detect.m_trackID) != std::end(m_robustIDs))
117+
{
118+
m_resCSV << frame.first << delim << TypeConverter::Type2Str(detect.m_type) << delim << detect.m_rect.x << delim << detect.m_rect.y << delim <<
119+
detect.m_rect.width << delim << detect.m_rect.height << delim <<
120+
detect.m_conf << delim << std::endl;
121+
}
122+
}
123+
}
124+
}
121125
#else
122126
char delim = ' ';
123127
for (const auto& frame : m_frames)
@@ -138,21 +142,24 @@ class ResultsLog
138142
{
139143
char delim = ',';
140144
for (size_t id : m_robustIDs)
141-
{
142-
for (const auto& frame : m_frames)
143-
{
144-
for (const auto& detect : frame.second.m_detects)
145-
{
146-
if (detect.m_trackID == id)
147-
{
148-
m_resCSV << frame.first << delim << id << delim << detect.m_rect.x << delim << detect.m_rect.y << delim <<
149-
detect.m_rect.width << delim << detect.m_rect.height << delim <<
150-
detect.m_conf << ",-1,-1,-1," << std::endl;
151-
break;
152-
}
153-
}
154-
}
155-
}
145+
{
146+
for (const auto& frame : m_frames)
147+
{
148+
if (frame.first % m_writeEachNFrame == 0)
149+
{
150+
for (const auto& detect : frame.second.m_detects)
151+
{
152+
if (detect.m_trackID == id)
153+
{
154+
m_resCSV << frame.first << delim << id << delim << detect.m_rect.x << delim << detect.m_rect.y << delim <<
155+
detect.m_rect.width << delim << detect.m_rect.height << delim <<
156+
detect.m_conf << ",-1,-1,-1," << std::endl;
157+
break;
158+
}
159+
}
160+
}
161+
}
162+
}
156163
}
157164
}
158165
};

example/VideoExample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// \param parser
99
///
1010
VideoExample::VideoExample(const cv::CommandLineParser& parser)
11-
: m_resultsLog(parser.get<std::string>("res"))
11+
: m_resultsLog(parser.get<std::string>("res"), parser.get<int>("write_n_frame"))
1212
{
1313
m_inFile = parser.get<std::string>(0);
1414
m_outFile = parser.get<std::string>("out");

example/main.cpp

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

2424
const char* keys =
2525
{
26-
"{ @1 |../data/atrium.avi | movie file | }"
27-
"{ 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 | }"
28-
"{ sf start_frame |0 | Start a video from this position | }"
29-
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
30-
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
31-
"{ o out | | Name of result video file | }"
32-
"{ sl show_logs |1 | Show Trackers logs | }"
33-
"{ g gpu |0 | Use OpenCL acceleration | }"
34-
"{ a async |1 | Use 2 theads for processing pipeline | }"
35-
"{ r res | | Path to the csv file with tracking result | }"
36-
"{ s settings | | Path to the init file with tracking settings | }"
37-
"{ bs batch_size |1 | Batch size - frames count for processing | }"
38-
"{ inf inference |darknet | For CarsCounting: Type of inference framework: darknet, ocvdnn | }"
39-
"{ w weights | | For CarsCounting: Weights of neural network: yolov4.weights | }"
40-
"{ c config | | For CarsCounting: Config file of neural network: yolov4.cfg | }"
41-
"{ n names | | For CarsCounting: File with classes names: coco.names | }"
42-
"{ hm heat_map |0 | For CarsCounting: Draw heat map | }"
26+
"{ @1 |../data/atrium.avi | movie file | }"
27+
"{ 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 | }"
28+
"{ sf start_frame |0 | Start a video from this position | }"
29+
"{ ef end_frame |0 | Play a video to this position (if 0 then played to the end of file) | }"
30+
"{ ed end_delay |0 | Delay in milliseconds after video ending | }"
31+
"{ o out | | Name of result video file | }"
32+
"{ sl show_logs |1 | Show Trackers logs | }"
33+
"{ g gpu |0 | Use OpenCL acceleration | }"
34+
"{ a async |1 | Use 2 theads for processing pipeline | }"
35+
"{ r res | | Path to the csv file with tracking result | }"
36+
"{ s settings | | Path to the init file with tracking settings | }"
37+
"{ bs batch_size |1 | Batch size - frames count for processing | }"
38+
"{ inf inference |darknet | For CarsCounting: Type of inference framework: darknet, ocvdnn | }"
39+
"{ w weights | | For CarsCounting: Weights of neural network: yolov4.weights | }"
40+
"{ c config | | For CarsCounting: Config file of neural network: yolov4.cfg | }"
41+
"{ n names | | For CarsCounting: File with classes names: coco.names | }"
42+
"{ wf write_n_frame |1 | Write logs on each N frame: 1 for writing each frame | }"
43+
"{ hm heat_map |0 | For CarsCounting: Draw heat map | }"
4344
};
4445

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

0 commit comments

Comments
 (0)