Commit 24cb3be6aa34134f5e1c9d995c84b0a9421336b4
1 parent
d9adaaad
Tweaks to Show2, allow display of properties in the window title
Also, add FPSCalc, and FPSSynch to calculate the frequency of frames passing through a stream, and to slow down processing to a specific frame rate (note: does not work particularly well), respecively.
Showing
2 changed files
with
124 additions
and
1 deletions
openbr/plugins/gui.cpp
| 1 | #include <QApplication> | 1 | #include <QApplication> |
| 2 | #include <QLabel> | 2 | #include <QLabel> |
| 3 | +#include <QElapsedTimer> | ||
| 3 | #include <opencv2/imgproc/imgproc.hpp> | 4 | #include <opencv2/imgproc/imgproc.hpp> |
| 4 | #include <openbr/openbr_plugin.h> | 5 | #include <openbr/openbr_plugin.h> |
| 5 | 6 | ||
| @@ -66,13 +67,13 @@ public slots: | @@ -66,13 +67,13 @@ public slots: | ||
| 66 | { | 67 | { |
| 67 | window->setPixmap(input); | 68 | window->setPixmap(input); |
| 68 | window->setFixedSize(input.size()); | 69 | window->setFixedSize(input.size()); |
| 69 | - window->setVisible(true); | ||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | void createWindow() | 72 | void createWindow() |
| 73 | { | 73 | { |
| 74 | delete window; | 74 | delete window; |
| 75 | window = new QLabel(); | 75 | window = new QLabel(); |
| 76 | + window->setVisible(true); | ||
| 76 | } | 77 | } |
| 77 | }; | 78 | }; |
| 78 | 79 | ||
| @@ -87,6 +88,9 @@ class Show2Transform : public TimeVaryingTransform | @@ -87,6 +88,9 @@ class Show2Transform : public TimeVaryingTransform | ||
| 87 | { | 88 | { |
| 88 | Q_OBJECT | 89 | Q_OBJECT |
| 89 | public: | 90 | public: |
| 91 | + Q_PROPERTY(QStringList keys READ get_keys WRITE set_keys RESET reset_keys STORED false) | ||
| 92 | + BR_PROPERTY(QStringList, keys, QStringList("FrameNumber")) | ||
| 93 | + | ||
| 90 | Show2Transform() : TimeVaryingTransform(false, false) | 94 | Show2Transform() : TimeVaryingTransform(false, false) |
| 91 | { | 95 | { |
| 92 | // Create our GUI proxy | 96 | // Create our GUI proxy |
| @@ -120,9 +124,22 @@ public: | @@ -120,9 +124,22 @@ public: | ||
| 120 | return; | 124 | return; |
| 121 | 125 | ||
| 122 | foreach (const Template & t, src) { | 126 | foreach (const Template & t, src) { |
| 127 | + // build label | ||
| 128 | + QString newTitle; | ||
| 129 | + foreach (const QString & s, keys) { | ||
| 130 | + | ||
| 131 | + if (t.file.contains(s)) { | ||
| 132 | + QString out = t.file.get<QString>(s); | ||
| 133 | + newTitle = newTitle + s + ": " + out + " "; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + } | ||
| 137 | + emit this->changeTitle(newTitle); | ||
| 138 | + | ||
| 123 | foreach(const cv::Mat & m, t) { | 139 | foreach(const cv::Mat & m, t) { |
| 124 | qImageBuffer = toQImage(m); | 140 | qImageBuffer = toQImage(m); |
| 125 | displayBuffer.convertFromImage(qImageBuffer); | 141 | displayBuffer.convertFromImage(qImageBuffer); |
| 142 | + | ||
| 126 | // Emit an explicit copy of our pixmap so that the pixmap used | 143 | // Emit an explicit copy of our pixmap so that the pixmap used |
| 127 | // by the main thread isn't damaged when we update displayBuffer | 144 | // by the main thread isn't damaged when we update displayBuffer |
| 128 | // later. | 145 | // later. |
| @@ -140,6 +157,7 @@ public: | @@ -140,6 +157,7 @@ public: | ||
| 140 | void init() | 157 | void init() |
| 141 | { | 158 | { |
| 142 | emit needWindow(); | 159 | emit needWindow(); |
| 160 | + connect(this, SIGNAL(changeTitle(QString)), gui->window, SLOT(setWindowTitle(QString))); | ||
| 143 | } | 161 | } |
| 144 | 162 | ||
| 145 | protected: | 163 | protected: |
| @@ -150,10 +168,114 @@ protected: | @@ -150,10 +168,114 @@ protected: | ||
| 150 | signals: | 168 | signals: |
| 151 | void needWindow(); | 169 | void needWindow(); |
| 152 | void updateImage(const QPixmap & input); | 170 | void updateImage(const QPixmap & input); |
| 171 | + void changeTitle(const QString & input); | ||
| 153 | }; | 172 | }; |
| 154 | 173 | ||
| 155 | BR_REGISTER(Transform, Show2Transform) | 174 | BR_REGISTER(Transform, Show2Transform) |
| 156 | 175 | ||
| 176 | +class FPSSynch : public TimeVaryingTransform | ||
| 177 | +{ | ||
| 178 | + Q_OBJECT | ||
| 179 | + Q_PROPERTY(int targetFPS READ get_targetFPS WRITE set_targetFPS RESET reset_targetFPS STORED false) | ||
| 180 | + BR_PROPERTY(int, targetFPS, 30) | ||
| 181 | + | ||
| 182 | +public: | ||
| 183 | + FPSSynch() : TimeVaryingTransform(false, false) {} | ||
| 184 | + | ||
| 185 | + ~FPSSynch() {} | ||
| 186 | + | ||
| 187 | + void train(const TemplateList &data) { (void) data; } | ||
| 188 | + | ||
| 189 | + | ||
| 190 | + void projectUpdate(const TemplateList &src, TemplateList &dst) | ||
| 191 | + { | ||
| 192 | + dst = src; | ||
| 193 | + qint64 time_delta = timer.elapsed(); | ||
| 194 | + | ||
| 195 | + qint64 wait_time = target_wait - time_delta; | ||
| 196 | + timer.start(); | ||
| 197 | + | ||
| 198 | + if (wait_time < 0) { | ||
| 199 | + return; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + QThread::msleep(wait_time); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + void finalize(TemplateList & output) | ||
| 206 | + { | ||
| 207 | + (void) output; | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + void init() | ||
| 211 | + { | ||
| 212 | + target_wait = 1000 / targetFPS; | ||
| 213 | + timer.start(); | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | +protected: | ||
| 217 | + QElapsedTimer timer; | ||
| 218 | + qint64 target_wait; | ||
| 219 | +}; | ||
| 220 | +BR_REGISTER(Transform, FPSSynch) | ||
| 221 | + | ||
| 222 | +class FPSCalc : public TimeVaryingTransform | ||
| 223 | +{ | ||
| 224 | + Q_OBJECT | ||
| 225 | + Q_PROPERTY(int targetFPS READ get_targetFPS WRITE set_targetFPS RESET reset_targetFPS) | ||
| 226 | + BR_PROPERTY(int, targetFPS, 30) | ||
| 227 | + | ||
| 228 | + | ||
| 229 | +public: | ||
| 230 | + FPSCalc() : TimeVaryingTransform(false, false) { initialized = false; } | ||
| 231 | + | ||
| 232 | + ~FPSCalc() {} | ||
| 233 | + | ||
| 234 | + void train(const TemplateList &data) { (void) data; } | ||
| 235 | + | ||
| 236 | + | ||
| 237 | + void projectUpdate(const TemplateList &src, TemplateList &dst) | ||
| 238 | + { | ||
| 239 | + dst = src; | ||
| 240 | + | ||
| 241 | + if (!initialized) { | ||
| 242 | + initialized = true; | ||
| 243 | + timer.start(); | ||
| 244 | + } | ||
| 245 | + framesSeen++; | ||
| 246 | + | ||
| 247 | + if (dst.empty()) | ||
| 248 | + return; | ||
| 249 | + | ||
| 250 | + qint64 elapsed = timer.elapsed(); | ||
| 251 | + if (elapsed > 1000) { | ||
| 252 | + double fps = 1000 * framesSeen / elapsed; | ||
| 253 | + //output.data.last().file.set("FrameNumber", output.sequenceNumber); | ||
| 254 | + dst.first().file.set("AvgFPS", fps); | ||
| 255 | + } | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + void finalize(TemplateList & output) | ||
| 259 | + { | ||
| 260 | + (void) output; | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + void init() | ||
| 264 | + { | ||
| 265 | + initialized = false; | ||
| 266 | + framesSeen = 0; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | +protected: | ||
| 270 | + bool initialized; | ||
| 271 | + QElapsedTimer timer; | ||
| 272 | + qint64 framesSeen; | ||
| 273 | +}; | ||
| 274 | +BR_REGISTER(Transform, FPSCalc) | ||
| 275 | + | ||
| 276 | + | ||
| 277 | + | ||
| 278 | + | ||
| 157 | } // namespace br | 279 | } // namespace br |
| 158 | 280 | ||
| 159 | #include "gui.moc" | 281 | #include "gui.moc" |
openbr/plugins/stream.cpp
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | #include <QThreadPool> | 3 | #include <QThreadPool> |
| 4 | #include <QSemaphore> | 4 | #include <QSemaphore> |
| 5 | #include <QMap> | 5 | #include <QMap> |
| 6 | +#include <opencv/highgui.h> | ||
| 6 | #include <QtConcurrent> | 7 | #include <QtConcurrent> |
| 7 | #include <openbr/openbr_plugin.h> | 8 | #include <openbr/openbr_plugin.h> |
| 8 | 9 |