Commit 517d384d10715a96d0bf03266b2b8ae7b6f005e9

Authored by Scott Klum
2 parents 7b34a1cb 8c9d9957

Merge pull request #392 from biometrics/utility_update

Utility Update
openbr/core/qtutils.cpp
... ... @@ -38,38 +38,6 @@ using namespace br;
38 38 namespace QtUtils
39 39 {
40 40  
41   -QStringList getFiles(QDir dir, bool recursive)
42   -{
43   - dir = QDir(dir.canonicalPath());
44   -
45   - QStringList files;
46   - foreach (const QString &file, naturalSort(dir.entryList(QDir::Files)))
47   - files.append(dir.absoluteFilePath(file));
48   -
49   - if (!recursive) return files;
50   -
51   - foreach (const QString &folder, naturalSort(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))) {
52   - QDir subdir(dir);
53   - bool success = subdir.cd(folder); if (!success) qFatal("cd failure.");
54   - files.append(getFiles(subdir, true));
55   - }
56   - return files;
57   -}
58   -
59   -QStringList getFiles(const QString &regexp)
60   -{
61   - QFileInfo fileInfo(regexp);
62   - QDir dir(fileInfo.dir());
63   - QRegExp re(fileInfo.fileName());
64   - re.setPatternSyntax(QRegExp::Wildcard);
65   -
66   - QStringList files;
67   - foreach (const QString &fileName, dir.entryList(QDir::Files))
68   - if (re.exactMatch(fileName))
69   - files.append(dir.filePath(fileName));
70   - return files;
71   -}
72   -
73 41 QStringList readLines(const QString &file)
74 42 {
75 43 QStringList lines;
... ...
openbr/core/qtutils.h
... ... @@ -34,8 +34,6 @@
34 34 namespace QtUtils
35 35 {
36 36 /**** File Utilities ****/
37   - QStringList getFiles(QDir dir, bool recursive);
38   - QStringList getFiles(const QString &regexp);
39 37 QStringList readLines(const QString &file);
40 38 void readFile(const QString &file, QStringList &lines);
41 39 void readFile(const QString &file, QByteArray &data, bool uncompress = false);
... ...
openbr/gui/utility.cpp
... ... @@ -3,6 +3,7 @@
3 3 #include <assert.h>
4 4 #include <opencv2/imgproc/imgproc.hpp>
5 5 #include <opencv2/imgproc/imgproc_c.h>
  6 +#include <openbr/core/qtutils.h>
6 7 #include "utility.h"
7 8  
8 9 using namespace cv;
... ... @@ -45,3 +46,35 @@ QImage br::toQImage(const Mat &amp;mat)
45 46  
46 47 return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy();
47 48 }
  49 +
  50 +QStringList br::getFiles(QDir dir, bool recursive)
  51 +{
  52 + dir = QDir(dir.canonicalPath());
  53 +
  54 + QStringList files;
  55 + foreach (const QString &file, QtUtils::naturalSort(dir.entryList(QDir::Files)))
  56 + files.append(dir.absoluteFilePath(file));
  57 +
  58 + if (!recursive) return files;
  59 +
  60 + foreach (const QString &folder, QtUtils::naturalSort(dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))) {
  61 + QDir subdir(dir);
  62 + bool success = subdir.cd(folder); if (!success) qFatal("cd failure.");
  63 + files.append(getFiles(subdir, true));
  64 + }
  65 + return files;
  66 +}
  67 +
  68 +QStringList br::getFiles(const QString &regexp)
  69 +{
  70 + QFileInfo fileInfo(regexp);
  71 + QDir dir(fileInfo.dir());
  72 + QRegExp re(fileInfo.fileName());
  73 + re.setPatternSyntax(QRegExp::Wildcard);
  74 +
  75 + QStringList files;
  76 + foreach (const QString &fileName, dir.entryList(QDir::Files))
  77 + if (re.exactMatch(fileName))
  78 + files.append(dir.filePath(fileName));
  79 + return files;
  80 +}
... ...
openbr/gui/utility.h
... ... @@ -2,6 +2,9 @@
2 2 #define BR_UTILITY_H
3 3  
4 4 #include <QImage>
  5 +#include <QStringList>
  6 +#include <QDir>
  7 +
5 8 #include <opencv2/core/core.hpp>
6 9 #include <openbr/openbr_export.h>
7 10  
... ... @@ -9,6 +12,8 @@ namespace br
9 12 {
10 13  
11 14 BR_EXPORT QImage toQImage(const cv::Mat &mat);
  15 +BR_EXPORT QStringList getFiles(QDir dir, bool recursive);
  16 +BR_EXPORT QStringList getFiles(const QString &regexp);
12 17  
13 18 } // namespace br
14 19  
... ...
openbr/plugins/gallery/empty.cpp
... ... @@ -18,6 +18,7 @@
18 18  
19 19 #include <openbr/plugins/openbr_internal.h>
20 20 #include <openbr/core/qtutils.h>
  21 +#include <openbr/gui/utility.h>
21 22  
22 23 namespace br
23 24 {
... ... @@ -67,7 +68,7 @@ class EmptyGallery : public Gallery
67 68 templates.append(future.result());
68 69  
69 70 // Add root folder
70   - foreach (const QString &fileName, QtUtils::getFiles(file.name, false))
  71 + foreach (const QString &fileName, getFiles(file.name, false))
71 72 templates.append(File(fileName, dir.dirName()));
72 73  
73 74 if (!regexp.isEmpty()) {
... ... @@ -112,7 +113,7 @@ class EmptyGallery : public Gallery
112 113  
113 114 static TemplateList getTemplates(const QDir &dir)
114 115 {
115   - const QStringList files = QtUtils::getFiles(dir, true);
  116 + const QStringList files = getFiles(dir, true);
116 117 TemplateList templates; templates.reserve(files.size());
117 118 foreach (const QString &file, files)
118 119 templates.append(File(file, dir.dirName()));
... ...