Commit 6e3bec09fa8ef387f6a146fe80af45b0015b246a

Authored by bhklein
1 parent 3fcbaa15

group images by metadata key in subdirectories in WriteTransform

Showing 1 changed file with 19 additions and 3 deletions
openbr/plugins/io/write.cpp
... ... @@ -10,6 +10,11 @@ namespace br
10 10 * \ingroup transforms
11 11 * \brief Write all mats to disk as images.
12 12 * \author Brendan Klare \cite bklare
  13 + * \br_property QString outputDirectory Top level directory to write images to.
  14 + * \br_property QString underscore
  15 + * \br_property QString imgExtension Extension to save images as.
  16 + * \br_property int padding Zero pad the image filenames.
  17 + * \br_property QString subDir Optional group images by a metadata key in subdirectories.
13 18 */
14 19 class WriteTransform : public TimeVaryingTransform
15 20 {
... ... @@ -18,12 +23,15 @@ class WriteTransform : public TimeVaryingTransform
18 23 Q_PROPERTY(QString underscore READ get_underscore WRITE set_underscore RESET reset_underscore STORED false)
19 24 Q_PROPERTY(QString imgExtension READ get_imgExtension WRITE set_imgExtension RESET reset_imgExtension STORED false)
20 25 Q_PROPERTY(int padding READ get_padding WRITE set_padding RESET reset_padding STORED false)
  26 + Q_PROPERTY(QString subDir READ get_subDir WRITE set_subDir RESET reset_subDir STORED false)
21 27 BR_PROPERTY(QString, outputDirectory, "Temp")
22 28 BR_PROPERTY(QString, underscore, "")
23 29 BR_PROPERTY(QString, imgExtension, "jpg")
24 30 BR_PROPERTY(int, padding, 5)
  31 + BR_PROPERTY(QString, subDir, "")
25 32  
26 33 int cnt;
  34 + QMap<QString, int> numImages;
27 35  
28 36 void init() {
29 37 cnt = 0;
... ... @@ -34,10 +42,18 @@ class WriteTransform : public TimeVaryingTransform
34 42 void projectUpdate(const Template &src, Template &dst)
35 43 {
36 44 dst = src;
37   - QString path = QString("%1/image%2%3.%4").arg(outputDirectory).arg(cnt++, padding, 10, QChar('0')).arg(underscore.isEmpty() ? "" : "_" + underscore).arg(imgExtension);
38   - OpenCVUtils::saveImage(dst.m(), path);
  45 + if (!subDir.isEmpty()) {
  46 + QString dir = src.file.get<QString>(subDir, "Temp");
  47 + QString path = QString("%1/%2/").arg(outputDirectory, dir);
  48 + int value = numImages.value(dir, 0);
  49 + path += QString("%1_%2.%3").arg(src.file.get<QString>(subDir, "Image")).arg(value, padding, 10, QChar('0')).arg(imgExtension);
  50 + numImages[dir] = ++value;
  51 + OpenCVUtils::saveImage(dst.m(), path);
  52 + } else {
  53 + QString path = QString("%1/image%2%3.%4").arg(outputDirectory).arg(cnt++, padding, 10, QChar('0')).arg(underscore.isEmpty() ? "" : "_" + underscore).arg(imgExtension);
  54 + OpenCVUtils::saveImage(dst.m(), path);
  55 + }
39 56 }
40   -
41 57 };
42 58  
43 59 BR_REGISTER(Transform, WriteTransform)
... ...