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 +38,6 @@ using namespace br;
38 namespace QtUtils 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 QStringList readLines(const QString &file) 41 QStringList readLines(const QString &file)
74 { 42 {
75 QStringList lines; 43 QStringList lines;
openbr/core/qtutils.h
@@ -34,8 +34,6 @@ @@ -34,8 +34,6 @@
34 namespace QtUtils 34 namespace QtUtils
35 { 35 {
36 /**** File Utilities ****/ 36 /**** File Utilities ****/
37 - QStringList getFiles(QDir dir, bool recursive);  
38 - QStringList getFiles(const QString &regexp);  
39 QStringList readLines(const QString &file); 37 QStringList readLines(const QString &file);
40 void readFile(const QString &file, QStringList &lines); 38 void readFile(const QString &file, QStringList &lines);
41 void readFile(const QString &file, QByteArray &data, bool uncompress = false); 39 void readFile(const QString &file, QByteArray &data, bool uncompress = false);
openbr/gui/utility.cpp
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 #include <assert.h> 3 #include <assert.h>
4 #include <opencv2/imgproc/imgproc.hpp> 4 #include <opencv2/imgproc/imgproc.hpp>
5 #include <opencv2/imgproc/imgproc_c.h> 5 #include <opencv2/imgproc/imgproc_c.h>
  6 +#include <openbr/core/qtutils.h>
6 #include "utility.h" 7 #include "utility.h"
7 8
8 using namespace cv; 9 using namespace cv;
@@ -45,3 +46,35 @@ QImage br::toQImage(const Mat &amp;mat) @@ -45,3 +46,35 @@ QImage br::toQImage(const Mat &amp;mat)
45 46
46 return QImage(mat8uc3.data, mat8uc3.cols, mat8uc3.rows, 3*mat8uc3.cols, QImage::Format_RGB888).copy(); 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,6 +2,9 @@
2 #define BR_UTILITY_H 2 #define BR_UTILITY_H
3 3
4 #include <QImage> 4 #include <QImage>
  5 +#include <QStringList>
  6 +#include <QDir>
  7 +
5 #include <opencv2/core/core.hpp> 8 #include <opencv2/core/core.hpp>
6 #include <openbr/openbr_export.h> 9 #include <openbr/openbr_export.h>
7 10
@@ -9,6 +12,8 @@ namespace br @@ -9,6 +12,8 @@ namespace br
9 { 12 {
10 13
11 BR_EXPORT QImage toQImage(const cv::Mat &mat); 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 } // namespace br 18 } // namespace br
14 19
openbr/plugins/gallery/empty.cpp
@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
18 18
19 #include <openbr/plugins/openbr_internal.h> 19 #include <openbr/plugins/openbr_internal.h>
20 #include <openbr/core/qtutils.h> 20 #include <openbr/core/qtutils.h>
  21 +#include <openbr/gui/utility.h>
21 22
22 namespace br 23 namespace br
23 { 24 {
@@ -67,7 +68,7 @@ class EmptyGallery : public Gallery @@ -67,7 +68,7 @@ class EmptyGallery : public Gallery
67 templates.append(future.result()); 68 templates.append(future.result());
68 69
69 // Add root folder 70 // Add root folder
70 - foreach (const QString &fileName, QtUtils::getFiles(file.name, false)) 71 + foreach (const QString &fileName, getFiles(file.name, false))
71 templates.append(File(fileName, dir.dirName())); 72 templates.append(File(fileName, dir.dirName()));
72 73
73 if (!regexp.isEmpty()) { 74 if (!regexp.isEmpty()) {
@@ -112,7 +113,7 @@ class EmptyGallery : public Gallery @@ -112,7 +113,7 @@ class EmptyGallery : public Gallery
112 113
113 static TemplateList getTemplates(const QDir &dir) 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 TemplateList templates; templates.reserve(files.size()); 117 TemplateList templates; templates.reserve(files.size());
117 foreach (const QString &file, files) 118 foreach (const QString &file, files)
118 templates.append(File(file, dir.dirName())); 119 templates.append(File(file, dir.dirName()));