Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Thiago Santini
EyeRecToo
Commits
6ebf0634
Commit
6ebf0634
authored
Jun 13, 2019
by
Thiago Santini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactors DataRecorder
parent
9c41bfeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
45 deletions
+60
-45
EyeRecToo/src/DataRecorder.cpp
EyeRecToo/src/DataRecorder.cpp
+49
-41
EyeRecToo/src/DataRecorder.h
EyeRecToo/src/DataRecorder.h
+11
-4
No files found.
EyeRecToo/src/DataRecorder.cpp
View file @
6ebf0634
...
...
@@ -10,10 +10,8 @@ DataRecorder::DataRecorder(QString id, QString header, QObject* parent)
,
dataFile
(
nullptr
)
,
dataStream
(
nullptr
)
,
videoWriter
(
nullptr
)
,
framerate
(
0
)
,
firstFrame
(
true
)
,
framerate
(
30
)
// if the fps doesn't get specified, defaults to 30
,
recording
(
false
)
,
videoIdx
(
1
)
{
if
(
!
id
.
contains
(
"Journal"
))
pmIdx
=
gPerformanceMonitor
.
enrol
(
id
,
"Data Recorder"
);
...
...
@@ -40,10 +38,7 @@ void DataRecorder::startRecording()
void
DataRecorder
::
startRecording
(
double
fps
)
{
videoWriter
=
std
::
make_unique
<
VideoWriter
>
();
firstFrame
=
true
;
framerate
=
fps
;
videoIdx
=
1
;
startRecording
();
}
...
...
@@ -68,24 +63,37 @@ void DataRecorder::stopRecording()
}
}
template
<
typename
T
>
bool
DataRecorder
::
shouldStore
(
const
T
&
data
)
{
return
recording
&&
(
!
gPerformanceMonitor
.
shouldDrop
(
pmIdx
,
data
.
timestamp
,
2000
));
}
void
DataRecorder
::
newData
(
EyeData
eyeData
)
{
storeData
(
eyeData
);
if
(
!
shouldStore
(
eyeData
))
return
;
storeSerializableData
(
eyeData
);
storeVideoData
(
eyeData
);
}
void
DataRecorder
::
newData
(
FieldData
fieldData
)
{
storeData
(
fieldData
);
if
(
!
shouldStore
(
fieldData
))
return
;
storeSerializableData
(
fieldData
);
storeVideoData
(
fieldData
);
}
void
DataRecorder
::
newData
(
DataTuple
dataTuple
)
{
// Note that the Journal data recorder isn't registered with the
// performance monitor since it's cheap to store its data.
if
(
dataStream
&&
dataStream
->
status
()
==
QTextStream
::
Ok
)
{
*
dataStream
<<
dataTuple
.
toQString
();
*
dataStream
<<
Token
::
Newline
;
}
// since we don't store frames here, just check for recording status
if
(
!
recording
)
return
;
storeSerializableData
(
dataTuple
);
}
bool
DataRecorder
::
splitVideoFile
()
...
...
@@ -97,42 +105,42 @@ bool DataRecorder::splitVideoFile()
return
false
;
}
template
<
class
T
>
void
DataRecorder
::
storeData
(
T
&
data
)
void
DataRecorder
::
initializeVideoWriter
(
int
width
,
int
height
,
bool
color
)
{
videoWriter
=
std
::
make_unique
<
VideoWriter
>
();
if
(
!
recording
)
return
;
if
(
firstFrame
&&
videoWriter
)
{
firstFrame
=
false
;
// todo: migrate to ffmpeg or libav
QString
fileName
=
id
+
".mp4"
;
// todo: migrate to ffmpeg or libav
QString
fileName
=
id
+
".mp4"
;
auto
fourcc
=
[](
const
char
str
[
4
])
{
return
VideoWriter
::
fourcc
(
str
[
0
],
str
[
1
],
str
[
2
],
str
[
3
]);
};
int
codec
=
fourcc
(
"jpeg"
);
// Uncompressed; Motion JPEG Video
//int codec = fourcc("xvid"); // Compressed; MPEG-4 Video
//int codec = fourcc("divx"); // Compressed; MPEG-4 Video
auto
fourcc
=
[](
const
char
str
[
4
])
{
return
VideoWriter
::
fourcc
(
str
[
0
],
str
[
1
],
str
[
2
],
str
[
3
]);
};
int
codec
=
fourcc
(
"jpeg"
);
// Uncompressed; Motion JPEG Video
//int codec = fourcc("xvid"); // Compressed; MPEG-4 Video
//int codec = fourcc("divx"); // Compressed; MPEG-4 Video
if
(
videoWriter
->
isOpened
())
videoWriter
->
release
();
if
(
videoWriter
->
isOpened
(
))
videoWriter
->
release
(
);
if
(
!
videoWriter
->
open
(
fileName
.
toStdString
(),
codec
,
framerate
,
{
width
,
height
},
color
))
qWarning
()
<<
"Recording failure."
<<
QString
(
"Could not open %1"
).
arg
(
fileName
);
if
(
!
videoWriter
->
open
(
fileName
.
toStdString
(),
codec
,
framerate
,
Size
(
data
.
input
.
cols
,
data
.
input
.
rows
),
data
.
input
.
channels
()
==
1
?
false
:
tru
e
)
)
qWarning
()
<<
"Recording failure."
<<
QString
(
"Could not open %1"
).
arg
(
fileName
);
currentVideoFileInfo
.
setFile
(
fileNam
e
)
;
}
currentVideoFileInfo
.
setFile
(
fileName
);
template
<
typename
T
>
void
DataRecorder
::
storeSerializableData
(
const
T
&
data
)
{
if
(
dataStream
&&
dataStream
->
status
()
==
QTextStream
::
Ok
)
*
dataStream
<<
data
.
toQString
()
<<
Token
::
Newline
;
// TODO: add recording timestamp?
}
videoIdx
++
;
}
template
<
typename
T
>
void
DataRecorder
::
storeVideoData
(
const
T
&
data
)
{
if
(
gPerformanceMonitor
.
shouldDrop
(
pmIdx
,
data
.
timestamp
,
2000
)
)
return
;
if
(
!
videoWriter
)
initializeVideoWriter
(
data
.
input
.
cols
,
data
.
input
.
rows
,
data
.
input
.
channels
()
==
1
?
false
:
true
)
;
if
(
videoWriter
&&
videoWriter
->
isOpened
())
if
(
videoWriter
->
isOpened
())
*
videoWriter
<<
data
.
input
;
if
(
dataStream
&&
dataStream
->
status
()
==
QTextStream
::
Ok
)
*
dataStream
<<
data
.
toQString
()
<<
Token
::
Newline
;
// TODO: add recording timestamp?
}
EyeRecToo/src/DataRecorder.h
View file @
6ebf0634
...
...
@@ -38,16 +38,23 @@ private:
std
::
unique_ptr
<
cv
::
VideoWriter
>
videoWriter
;
double
framerate
;
QFileInfo
currentVideoFileInfo
;
bool
firstFrame
;
std
::
atomic_bool
recording
;
int
videoIdx
;
template
<
class
T
>
void
storeData
(
T
&
data
);
template
<
typename
T
>
bool
shouldStore
(
const
T
&
data
);
template
<
typename
T
>
void
storeVideoData
(
const
T
&
data
);
template
<
typename
T
>
void
storeSerializableData
(
const
T
&
data
);
bool
splitVideoFile
();
double
fps
;
unsigned
int
pmIdx
;
void
initializeVideoWriter
(
int
width
,
int
height
,
bool
color
);
};
class
DataRecorderThread
:
public
QObject
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment