diff --git a/openbr/plugins/time.cpp b/openbr/plugins/time.cpp index 5e32646..484031d 100644 --- a/openbr/plugins/time.cpp +++ b/openbr/plugins/time.cpp @@ -7,56 +7,78 @@ namespace br * \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 + * \author Josh Klontz \cite jklontz */ -class StopWatchTransform : public TimeVaryingTransform +class StopWatchTransform : public MetaTransform { Q_OBJECT + Q_PROPERTY(QString description READ get_description WRITE set_description RESET reset_description) + BR_PROPERTY(QString, description, "Identity") - Q_PROPERTY(br::Transform* child READ get_child WRITE set_child RESET reset_child) - BR_PROPERTY(br::Transform*, child, NULL) - - long timeElapsed; - long numImgs; - long numPixels; + br::Transform *transform; + mutable QMutex mutex; + mutable long miliseconds; + mutable long images; + mutable long pixels; public: - StopWatchTransform() : TimeVaryingTransform(false, false) + StopWatchTransform() { - timeElapsed = 0; - numImgs = 0; - numPixels = 0; + reset(); } private: - void projectUpdate(const Template &src, Template &dst) + void reset() { - QTime watch; - - if (child == NULL) - qFatal("Can't find child transform! Command line syntax is StopWatch(name of transform to profile)"); + miliseconds = 0; + images = 0; + pixels = 0; + } - watch.start(); + void init() + { + transform = Transform::make(description); + } - child->project(src, dst); + void train(const QList &data) + { + transform->train(data); + } - int time = watch.elapsed(); + void project(const Template &src, Template &dst) const + { + QTime watch; + watch.start(); + transform->project(src, dst); - timeElapsed += time; - numImgs++; - numPixels += (src.m().rows * src.m().cols); + QMutexLocker locker(&mutex); + miliseconds += watch.elapsed(); + images++; + foreach (const cv::Mat &m, src) + pixels += (m.rows * m.cols); } - void finalize(TemplateList &output) + void finalize(TemplateList &) { - (void)output; + qDebug("\nProfile for \"%s\"\n" + "\tSeconds: %g\n" + "\tTemplates/s: %g\n" + "\tPixels/s: %g\n", + qPrintable(description), + miliseconds / 1000.0, + images * 1000.0 / miliseconds, + pixels * 1000.0 / miliseconds); + reset(); + } - qDebug() << "\n\nProfiled " << numImgs << " images:\n" << - "\tavg time per image: " << (double)timeElapsed / numImgs << " ms\n" << - "\tavg time per pixel: " << (double)timeElapsed / numPixels << " ms\n"; + void store(QDataStream &stream) const + { + transform->store(stream); + } - timeElapsed = 0; - numImgs = 0; - numPixels = 0; + void load(QDataStream &stream) + { + transform->load(stream); } };