From 5695cd2207664aebc5e3431e122419399a467bc9 Mon Sep 17 00:00:00 2001 From: Jordan Cheney Date: Thu, 10 Jul 2014 16:47:35 -0400 Subject: [PATCH] Decided on the TimeVaryingTransform implementation --- openbr/plugins/time.cpp | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/openbr/plugins/time.cpp b/openbr/plugins/time.cpp index 0dd3ff8..c1b9755 100644 --- a/openbr/plugins/time.cpp +++ b/openbr/plugins/time.cpp @@ -3,66 +3,63 @@ namespace br { -class StopWatchTransform : public UntrainableTransform +/*! + * \ingroup transforms + * \brief Gives time elapsed over a specified transform as a function of both images (or frames) and pixels. + * \author Jordan Cheney \cite JordanCheney + */ +class StopWatchTransform : public TimeVaryingTransform { Q_OBJECT Q_PROPERTY(br::Transform* child READ get_child WRITE set_child RESET reset_child) BR_PROPERTY(br::Transform*, child, NULL) - mutable QMutex watchLock; mutable long timeElapsed; mutable long numImgs; mutable long numPixels; - ~StopWatchTransform() { - printf("Profiled %lu images:\n" - "\tavg time per image: %f ms\n" - "\tavg time per pixel: %f ms\n", - numImgs, (double) timeElapsed / numImgs, (double) timeElapsed / numPixels); +public: + StopWatchTransform() : TimeVaryingTransform(false, false) + { + timeElapsed = 0; + numImgs = 0; + numPixels = 0; } - void project(const Template &src, Template &dst) const +private: + void projectUpdate(const Template &src, Template &dst) { QTime watch; if (child == NULL) qFatal("Can't find child transform! Command line syntax is StopWatch(name of transform to profile)"); - watchLock.lock(); watch.start(); child->project(src, dst); int time = watch.elapsed(); - watchLock.unlock(); timeElapsed += time; numImgs++; numPixels += (src.m().rows * src.m().cols); } - void project(const TemplateList &src, TemplateList &dst) const + void finalize(TemplateList &output) { - QTime watch; - foreach (const Template &t, src) { - watchLock.lock(); - watch.start(); - - Template u; - child->project(t, u); + (void)output; - int time = watch.elapsed(); - watchLock.unlock(); + printf("\n\nProfiled %lu images:\n" + "\tavg time per image: %f ms\n" + "\tavg time per pixel: %f ms\n",numImgs, (double)timeElapsed / numImgs, (double)timeElapsed / numPixels); - timeElapsed += time; - numImgs++; - numPixels += (t.m().rows * t.m().cols); - - dst << u; - } + timeElapsed = 0; + numImgs = 0; + numPixels = 0; } }; + BR_REGISTER(Transform, StopWatchTransform) } //namespace br -- libgit2 0.21.4