Commit d3796708 authored by Thiago Santini's avatar Thiago Santini

Improves post processing timestamp matching

parent af6cf409
...@@ -587,8 +587,11 @@ void PostProcessingWidget::present(const VideoFrame& videoFrame) ...@@ -587,8 +587,11 @@ void PostProcessingWidget::present(const VideoFrame& videoFrame)
updatePresentIdx(videoFrame.idx); updatePresentIdx(videoFrame.idx);
ui->playbackSlider->setValue(presentIdx); ui->playbackSlider->setValue(presentIdx);
auto getTimestamp = [](const DataTuple& d) { return d.timestamp; }; // Note that given a field frame, there might be more than one data tuple that contains it
size_t idx = ts2idx(playbackTuples, videoFrame.t, getTimestamp) + 1; // we simply pick one of them
auto getTimestamp = [](const DataTuple& d) { return d.field.timestamp; };
auto idx = findClosestIdx(playbackTuples, videoFrame.t, getTimestamp);
DataTuple tuple; DataTuple tuple;
if (idx < playbackTuples.size()) if (idx < playbackTuples.size())
tuple = playbackTuples[idx]; tuple = playbackTuples[idx];
......
...@@ -156,25 +156,6 @@ private: ...@@ -156,25 +156,6 @@ private:
void updatePresentIdx(const int idx); void updatePresentIdx(const int idx);
void keyPressEvent(QKeyEvent* event) override; void keyPressEvent(QKeyEvent* event) override;
template <typename T, typename Functor>
size_t ts2idx(const std::vector<T>& v, const double& t, Functor& functor) const
{
size_t s = 0;
size_t e = v.size();
while (true) {
size_t mid = round((e + s) / 2);
if (mid == s || mid == e)
return mid;
if (t < functor(v[mid]))
e = mid;
else
s = mid;
}
return -1;
}
QStateMachine batchStateMachine; QStateMachine batchStateMachine;
}; };
......
...@@ -80,20 +80,7 @@ private: ...@@ -80,20 +80,7 @@ private:
size_t ts2idx(const Timestamp& t) const size_t ts2idx(const Timestamp& t) const
{ {
size_t s = 0; return findClosestIdx(timestamps, t, [](const Timestamp& t) { return t; });
size_t e = timestamps.size();
while (true) {
size_t mid = round((e + s) / 2);
if (mid == s || mid == e)
return mid;
if (t < timestamps[mid])
e = mid;
else
s = mid;
}
return -1;
} }
private slots: private slots:
......
...@@ -130,7 +130,7 @@ public: ...@@ -130,7 +130,7 @@ public:
{ {
total = 0; total = 0;
} }
double average() const { return mean(values); } double average() const { return total / values.size(); }
void update(const T t) void update(const T t)
{ {
values.emplace_back(t); values.emplace_back(t);
...@@ -148,4 +148,16 @@ private: ...@@ -148,4 +148,16 @@ private:
double total; double total;
}; };
template <typename Vec, typename Val, typename Functor>
size_t findClosestIdx(const Vec& vec, const Val& val, const Functor& f, size_t start = 0, size_t end = 0)
{
if (start == 0 && end == 0)
return findClosestIdx(vec, val, f, 0, vec.size() - 1);
if (end - start <= 1)
return abs(f(vec[start]) - val) < abs(f(vec[end]) - val) ? start : end;
auto mid = (end + start) / 2;
return f(vec[mid]) > val ? findClosestIdx(vec, val, f, start, mid) : findClosestIdx(vec, val, f, mid, end);
}
#endif // UTILS_H #endif // UTILS_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment