diff --git a/openbr/core/qtutils.cpp b/openbr/core/qtutils.cpp index aaccf0a..1be8b99 100644 --- a/openbr/core/qtutils.cpp +++ b/openbr/core/qtutils.cpp @@ -429,6 +429,17 @@ QString toString(const QVariant &variant) return QString(); } +QString toTime(int s) +{ + int h = s / (60*60); + int m = (s - h*60*60) / 60; + s = (s - h*60*60 - m*60); + + const QChar fillChar = QLatin1Char('0'); + + return QString("%1:%2:%3").arg(h,2,10,fillChar).arg(m,2,10,fillChar).arg(s,2,10,fillChar); +} + float euclideanLength(const QPointF &point) { return sqrt(pow(point.x(), 2) + pow(point.y(), 2)); diff --git a/openbr/core/qtutils.h b/openbr/core/qtutils.h index 9eb2c6c..649f771 100644 --- a/openbr/core/qtutils.h +++ b/openbr/core/qtutils.h @@ -65,6 +65,7 @@ namespace QtUtils QPointF toPoint(const QString &string, bool *ok = NULL); QRectF toRect(const QString &string, bool *ok = NULL); QStringList naturalSort(const QStringList &strings); + QString toTime(int s); /**** Process Utilities ****/ bool runRScript(const QString &file); diff --git a/openbr/openbr_plugin.cpp b/openbr/openbr_plugin.cpp index 4963867..d5ac481 100644 --- a/openbr/openbr_plugin.cpp +++ b/openbr/openbr_plugin.cpp @@ -845,10 +845,7 @@ void br::Context::printStatus() const float p = progress(); if (p < 1) { int s = timeRemaining(); - int h = s / (60*60); - int m = (s - h*60*60) / 60; - s = (s - h*60*60 - m*60); - fprintf(stderr, "%05.2f%% REMAINING=%02d:%02d:%02d COUNT=%g \r", 100 * p, h, m, s, totalSteps); + fprintf(stderr, "%05.2f%% REMAINING=%s COUNT=%g \r", 100 * p, QtUtils::toTime(s/1000.0f).toStdString().c_str(), totalSteps); } } diff --git a/openbr/plugins/misc.cpp b/openbr/plugins/misc.cpp index a29ec16..77579d9 100644 --- a/openbr/plugins/misc.cpp +++ b/openbr/plugins/misc.cpp @@ -19,6 +19,7 @@ #include #include "openbr_internal.h" #include "openbr/core/opencvutils.h" +#include "openbr/core/qtutils.h" using namespace cv; @@ -579,12 +580,7 @@ class ProgressCounterTransform : public TimeVaryingTransform // seconds remaining int s = float(remaining) / speed; - int h = s / (60*60); - int m = (s - h*60*60) / 60; - s = (s - h*60*60 - m*60); - - // hours:minutes:seconds - fprintf(stderr, "%05.2f%% REMAINING=%02d:%02d:%02d COUNT=%g \r", p, h, m, s, float(calls)); + fprintf(stderr, "%05.2f%% ELAPSED=%s REMAINING=%s COUNT=%g \r", p, QtUtils::toTime(Globals->startTime.elapsed()/1000.0f).toStdString().c_str(), QtUtils::toTime(s).toStdString().c_str(), float(calls)); timer.start(); set_calls = 0; @@ -603,11 +599,13 @@ class ProgressCounterTransform : public TimeVaryingTransform { (void) data; } + void init() { calls = 0; set_calls = 0; timer.start(); + Globals->startTime.start(); } public: