Commit ca08ce3535807e22aff455d1f9a92f9f7653fbc6
1 parent
f4b361f6
Keep original filename in WriteTransform if you'd like
Showing
1 changed file
with
13 additions
and
2 deletions
openbr/plugins/io/write.cpp
| @@ -10,6 +10,7 @@ namespace br | @@ -10,6 +10,7 @@ namespace br | ||
| 10 | * \ingroup transforms | 10 | * \ingroup transforms |
| 11 | * \brief Write all mats to disk as images. | 11 | * \brief Write all mats to disk as images. |
| 12 | * \author Brendan Klare \cite bklare | 12 | * \author Brendan Klare \cite bklare |
| 13 | + * \br_property bool preserveFilename Writes image to original filename. | ||
| 13 | * \br_property QString outputDirectory Top level directory to write images to. | 14 | * \br_property QString outputDirectory Top level directory to write images to. |
| 14 | * \br_property QString underscore | 15 | * \br_property QString underscore |
| 15 | * \br_property QString imgExtension Extension to save images as. | 16 | * \br_property QString imgExtension Extension to save images as. |
| @@ -19,11 +20,13 @@ namespace br | @@ -19,11 +20,13 @@ namespace br | ||
| 19 | class WriteTransform : public TimeVaryingTransform | 20 | class WriteTransform : public TimeVaryingTransform |
| 20 | { | 21 | { |
| 21 | Q_OBJECT | 22 | Q_OBJECT |
| 23 | + Q_PROPERTY(bool preserveFilename READ get_preserveFilename WRITE set_preserveFilename RESET reset_preserveFilename STORED false) | ||
| 22 | Q_PROPERTY(QString outputDirectory READ get_outputDirectory WRITE set_outputDirectory RESET reset_outputDirectory STORED false) | 24 | Q_PROPERTY(QString outputDirectory READ get_outputDirectory WRITE set_outputDirectory RESET reset_outputDirectory STORED false) |
| 23 | Q_PROPERTY(QString underscore READ get_underscore WRITE set_underscore RESET reset_underscore STORED false) | 25 | Q_PROPERTY(QString underscore READ get_underscore WRITE set_underscore RESET reset_underscore STORED false) |
| 24 | Q_PROPERTY(QString imgExtension READ get_imgExtension WRITE set_imgExtension RESET reset_imgExtension STORED false) | 26 | Q_PROPERTY(QString imgExtension READ get_imgExtension WRITE set_imgExtension RESET reset_imgExtension STORED false) |
| 25 | Q_PROPERTY(int padding READ get_padding WRITE set_padding RESET reset_padding STORED false) | 27 | 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) | 28 | Q_PROPERTY(QString subDir READ get_subDir WRITE set_subDir RESET reset_subDir STORED false) |
| 29 | + BR_PROPERTY(bool, preserveFilename, false) | ||
| 27 | BR_PROPERTY(QString, outputDirectory, "Temp") | 30 | BR_PROPERTY(QString, outputDirectory, "Temp") |
| 28 | BR_PROPERTY(QString, underscore, "") | 31 | BR_PROPERTY(QString, underscore, "") |
| 29 | BR_PROPERTY(QString, imgExtension, "jpg") | 32 | BR_PROPERTY(QString, imgExtension, "jpg") |
| @@ -46,11 +49,19 @@ class WriteTransform : public TimeVaryingTransform | @@ -46,11 +49,19 @@ class WriteTransform : public TimeVaryingTransform | ||
| 46 | QString dir = src.file.get<QString>(subDir, "Temp"); | 49 | QString dir = src.file.get<QString>(subDir, "Temp"); |
| 47 | QString path = QString("%1/%2/").arg(outputDirectory, dir); | 50 | QString path = QString("%1/%2/").arg(outputDirectory, dir); |
| 48 | int value = numImages.value(dir, 0); | 51 | 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); | 52 | + path += preserveFilename ? QString("%1.%2").arg(src.file.baseName().split('.')[0], imgExtension) |
| 53 | + : QString("%1_%2.%3").arg(src.file.get<QString>(subDir, "Image")).arg(value, padding, 10, QChar('0')).arg(imgExtension); | ||
| 54 | + if ((QDir::currentPath() + "/" + path) == src.file.name) | ||
| 55 | + qFatal("Attempted to overwrite image!"); | ||
| 56 | + | ||
| 50 | numImages[dir] = ++value; | 57 | numImages[dir] = ++value; |
| 51 | OpenCVUtils::saveImage(dst.m(), path); | 58 | OpenCVUtils::saveImage(dst.m(), path); |
| 52 | } else { | 59 | } else { |
| 53 | - QString path = QString("%1/image%2%3.%4").arg(outputDirectory).arg(cnt++, padding, 10, QChar('0')).arg(underscore.isEmpty() ? "" : "_" + underscore).arg(imgExtension); | 60 | + QString path = preserveFilename ? QString("%1/%2.%3").arg(outputDirectory, src.file.baseName().split('.')[0], imgExtension) |
| 61 | + : QString("%1/image%2%3.%4").arg(outputDirectory).arg(cnt++, padding, 10, QChar('0')).arg(underscore.isEmpty() ? "" : "_" + underscore).arg(imgExtension); | ||
| 62 | + if ((QDir::currentPath() + "/" + path) == src.file.name) | ||
| 63 | + qFatal("Attempted to overwrite image!"); | ||
| 64 | + | ||
| 54 | OpenCVUtils::saveImage(dst.m(), path); | 65 | OpenCVUtils::saveImage(dst.m(), path); |
| 55 | } | 66 | } |
| 56 | } | 67 | } |