From ca08ce3535807e22aff455d1f9a92f9f7653fbc6 Mon Sep 17 00:00:00 2001 From: bhklein Date: Wed, 10 Feb 2016 16:25:24 -0800 Subject: [PATCH] Keep original filename in WriteTransform if you'd like --- openbr/plugins/io/write.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/openbr/plugins/io/write.cpp b/openbr/plugins/io/write.cpp index 7b88966..5735926 100644 --- a/openbr/plugins/io/write.cpp +++ b/openbr/plugins/io/write.cpp @@ -10,6 +10,7 @@ namespace br * \ingroup transforms * \brief Write all mats to disk as images. * \author Brendan Klare \cite bklare + * \br_property bool preserveFilename Writes image to original filename. * \br_property QString outputDirectory Top level directory to write images to. * \br_property QString underscore * \br_property QString imgExtension Extension to save images as. @@ -19,11 +20,13 @@ namespace br class WriteTransform : public TimeVaryingTransform { Q_OBJECT + Q_PROPERTY(bool preserveFilename READ get_preserveFilename WRITE set_preserveFilename RESET reset_preserveFilename STORED false) Q_PROPERTY(QString outputDirectory READ get_outputDirectory WRITE set_outputDirectory RESET reset_outputDirectory STORED false) Q_PROPERTY(QString underscore READ get_underscore WRITE set_underscore RESET reset_underscore STORED false) Q_PROPERTY(QString imgExtension READ get_imgExtension WRITE set_imgExtension RESET reset_imgExtension STORED false) Q_PROPERTY(int padding READ get_padding WRITE set_padding RESET reset_padding STORED false) Q_PROPERTY(QString subDir READ get_subDir WRITE set_subDir RESET reset_subDir STORED false) + BR_PROPERTY(bool, preserveFilename, false) BR_PROPERTY(QString, outputDirectory, "Temp") BR_PROPERTY(QString, underscore, "") BR_PROPERTY(QString, imgExtension, "jpg") @@ -46,11 +49,19 @@ class WriteTransform : public TimeVaryingTransform QString dir = src.file.get(subDir, "Temp"); QString path = QString("%1/%2/").arg(outputDirectory, dir); int value = numImages.value(dir, 0); - path += QString("%1_%2.%3").arg(src.file.get(subDir, "Image")).arg(value, padding, 10, QChar('0')).arg(imgExtension); + path += preserveFilename ? QString("%1.%2").arg(src.file.baseName().split('.')[0], imgExtension) + : QString("%1_%2.%3").arg(src.file.get(subDir, "Image")).arg(value, padding, 10, QChar('0')).arg(imgExtension); + if ((QDir::currentPath() + "/" + path) == src.file.name) + qFatal("Attempted to overwrite image!"); + numImages[dir] = ++value; OpenCVUtils::saveImage(dst.m(), path); } else { - QString path = QString("%1/image%2%3.%4").arg(outputDirectory).arg(cnt++, padding, 10, QChar('0')).arg(underscore.isEmpty() ? "" : "_" + underscore).arg(imgExtension); + QString path = preserveFilename ? QString("%1/%2.%3").arg(outputDirectory, src.file.baseName().split('.')[0], imgExtension) + : QString("%1/image%2%3.%4").arg(outputDirectory).arg(cnt++, padding, 10, QChar('0')).arg(underscore.isEmpty() ? "" : "_" + underscore).arg(imgExtension); + if ((QDir::currentPath() + "/" + path) == src.file.name) + qFatal("Attempted to overwrite image!"); + OpenCVUtils::saveImage(dst.m(), path); } } -- libgit2 0.21.4