Move getFiles() to class Utils.

1.3
Micooz 11 years ago
parent 4ae3b06b17
commit 1e99b0307a

@ -17,7 +17,7 @@
#if defined (WIN32) || defined (_WIN32) #if defined (WIN32) || defined (_WIN32)
#include <io.h> #include <io.h>
#elif defined (linux) || defined (__linux__) #elif defined (linux) || defined (__linux__)
#include <sys/io.h>
#endif #endif
#include <iostream> #include <iostream>

@ -1,43 +1,50 @@
#ifndef __UTIL_H__ #ifndef __UTIL_H__
#define __UTIL_H__ #define __UTIL_H__
#include <vector>
#include <string>
#ifdef min #ifdef min
#undef min #undef min
#endif #endif
namespace easypr { namespace easypr {
class Utils { class Utils {
public: public:
static long getTimestamp(); static long getTimestamp();
/* /*
* Get file name from a given path * Get file name from a given path
* bool postfix: including the postfix * bool postfix: including the postfix
*/ */
static std::string getFileName(const std::string &path, const bool postfix = false); static std::string getFileName(const std::string& path,
const bool postfix = false);
/*
* Split the given string into segements by a delimiter /*
*/ * Split the given string into segements by a delimiter
static std::vector<std::string> splitString(const std::string &str, const char delimiter); */
static std::vector<std::string> splitString(const std::string& str,
/* const char delimiter);
* returns the smaller of the two numbers
*/ /*
template<typename T> * returns the smaller of the two numbers
static T min(const T &v1, const T &v2) { */
return (v1 < v2) ? v1 : v2; template <typename T>
} static T min(const T& v1, const T& v2) {
return (v1 < v2) ? v1 : v2;
}; }
/*
* Get files from a given folder
* all: including all sub-folders
*/
static std::vector<std::string> getFiles(const std::string& folder,
const bool all = true);
};
} }
//C++µÄ»ñÈ¡Îļþ¼Ðº¯Êý
void getFiles(std::string path, std::vector<std::string>& files);
//! levenshtein距离用于计算两个车牌的距离 //! levenshtein距离用于计算两个车牌的距离
//EasyPR中用levenshtein距离衡量车牌识别与真实车牌的误差 //EasyPR中用levenshtein距离衡量车牌识别与真实车牌的误差
template<class T> template<class T>

File diff suppressed because it is too large Load Diff

@ -16,7 +16,7 @@
#if defined (WIN32) || defined (_WIN32) #if defined (WIN32) || defined (_WIN32)
#include <io.h> #include <io.h>
#elif defined (linux) || defined (__linux__) #elif defined (linux) || defined (__linux__)
#include <sys/io.h> //#include <sys/io.h>
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -140,8 +140,7 @@ int saveTrainData()
stringstream ss(stringstream::in | stringstream::out); stringstream ss(stringstream::in | stringstream::out);
ss << path << "/" << strCharacters[i]; ss << path << "/" << strCharacters[i];
vector<string> files; auto files = Utils::getFiles(ss.str());
getFiles(ss.str(), files);
int size = files.size(); int size = files.size();
for (int j = 0; j < size; j++) for (int j = 0; j < size; j++)
@ -169,8 +168,7 @@ int saveTrainData()
stringstream ss(stringstream::in | stringstream::out); stringstream ss(stringstream::in | stringstream::out);
ss << path << "/" << strChinese[i]; ss << path << "/" << strChinese[i];
vector<string> files; auto files = Utils::getFiles(ss.str());
getFiles(ss.str(), files);
int size = files.size(); int size = files.size();
for (int j = 0; j < size; j++) for (int j = 0; j < size; j++)

@ -13,10 +13,9 @@ void learn2HasPlate(float bound = 0.7)
{ {
const char * filePath = "train/data/plate_detect_svm/learn/HasPlate"; const char * filePath = "train/data/plate_detect_svm/learn/HasPlate";
vector<string> files;
////获取该路径下的所有文件 ////获取该路径下的所有文件
getFiles(filePath, files ); auto files = Utils::getFiles(filePath);
int size = files.size(); int size = files.size();
if (0 == size) { if (0 == size) {
@ -60,10 +59,9 @@ void learn2NoPlate(float bound = 0.7)
{ {
const char * filePath = "train/data/plate_detect_svm/learn/NoPlate"; const char * filePath = "train/data/plate_detect_svm/learn/NoPlate";
vector<string> files;
////获取该路径下的所有文件 ////获取该路径下的所有文件
getFiles(filePath, files ); auto files = Utils::getFiles(filePath);
int size = files.size(); int size = files.size();
if (0 == size) { if (0 == size) {
cout << "File not found in " << filePath << endl; cout << "File not found in " << filePath << endl;
@ -107,10 +105,9 @@ void getHasPlateTrain(Mat& trainingImages, vector<int>& trainingLabels,
{ {
int label = 1; int label = 1;
const char * filePath = "train/data/plate_detect_svm/train/HasPlate"; const char * filePath = "train/data/plate_detect_svm/train/HasPlate";
vector<string> files;
////获取该路径下的所有文件 ////获取该路径下的所有文件
getFiles(filePath, files ); auto files = Utils::getFiles(filePath);
int size = files.size(); int size = files.size();
if (0 == size) { if (0 == size) {
@ -139,10 +136,9 @@ void getNoPlateTrain(Mat& trainingImages, vector<int>& trainingLabels,
{ {
int label = 0; int label = 0;
const char * filePath = "train/data/plate_detect_svm/train/NoPlate"; const char * filePath = "train/data/plate_detect_svm/train/NoPlate";
vector<string> files;
////获取该路径下的所有文件 ////获取该路径下的所有文件
getFiles(filePath, files ); auto files = Utils::getFiles(filePath);
int size = files.size(); int size = files.size();
if (0 == size) { if (0 == size) {
@ -169,10 +165,9 @@ void getHasPlateTest(vector<Mat>& testingImages, vector<int>& testingLabels)
{ {
int label = 1; int label = 1;
const char * filePath = "train/data/plate_detect_svm/test/HasPlate"; const char * filePath = "train/data/plate_detect_svm/test/HasPlate";
vector<string> files;
////获取该路径下的所有文件 ////获取该路径下的所有文件
getFiles(filePath, files ); auto files = Utils::getFiles(filePath);
int size = files.size(); int size = files.size();
if (0 == size) { if (0 == size) {
@ -194,10 +189,9 @@ void getNoPlateTest(vector<Mat>& testingImages, vector<int>& testingLabels)
{ {
int label = 0; int label = 0;
const char * filePath = "train/data/plate_detect_svm/test/NoPlate"; const char * filePath = "train/data/plate_detect_svm/test/NoPlate";
vector<string> files;
////获取该路径下的所有文件 ////获取该路径下的所有文件
getFiles(filePath, files ); auto files = Utils::getFiles(filePath);
int size = files.size(); int size = files.size();
if (0 == size) { if (0 == size) {

@ -19,8 +19,7 @@ const string dst_path = "F:/data/easypr-data/tmp-6";
int general_test() int general_test()
{ {
////获取该路径下的所有文件 ////获取该路径下的所有文件
vector<string> files; auto files = Utils::getFiles(src_path);
getFiles(src_path, files);
CPlateLocate lo; CPlateLocate lo;
CPlateJudge ju; CPlateJudge ju;

@ -31,8 +31,7 @@ int generate_gdts()
string cascadeName="model/haarcascade_frontalface_alt_tree.xml"; string cascadeName="model/haarcascade_frontalface_alt_tree.xml";
////获取该路径下的所有文件 ////获取该路径下的所有文件
vector<string> files; auto files = Utils::getFiles(src_path);
getFiles(src_path, files);
int size = files.size(); int size = files.size();
if (0 == size) if (0 == size)

@ -24,8 +24,7 @@ char * noPlatePath = "F:/data/easypr-data/learn/noPlate/";
void label_data() void label_data()
{ {
////获取该路径下的所有文件 ////获取该路径下的所有文件
vector<string> files; auto files = Utils::getFiles(notlabelPath);
getFiles(notlabelPath, files);
CPlateLocate lo; CPlateLocate lo;
CPlateJudge ju; CPlateJudge ju;

@ -9,7 +9,7 @@
#if defined (WIN32) || defined (_WIN32) #if defined (WIN32) || defined (_WIN32)
#include <io.h> #include <io.h>
#elif defined (linux) || defined (__linux__) #elif defined (linux) || defined (__linux__)
#include <sys/io.h> //#include <sys/io.h>
#endif #endif
#include <opencv/cv.h> #include <opencv/cv.h>
@ -24,8 +24,6 @@ using namespace easypr;
const int LEARANDATA_COUNT = 5000; const int LEARANDATA_COUNT = 5000;
void getFiles( string path, vector<string>& files );
//! 省份对应map //! 省份对应map
map<string, string> mc_map; map<string, string> mc_map;
@ -195,8 +193,7 @@ void getLearnData()
const char * filePath = "F:/data/easypr-data/rawdata"; const char * filePath = "F:/data/easypr-data/rawdata";
////获取该路径下的所有文件 ////获取该路径下的所有文件
vector<string> files; auto files = Utils::getFiles(filePath);
getFiles(filePath, files );
int size = files.size(); int size = files.size();
if (0 == size) { if (0 == size) {
@ -248,8 +245,7 @@ void changeFileName()
char * filePath = "F:/data/PlateLocate/pic1"; char * filePath = "F:/data/PlateLocate/pic1";
////获取该路径下的所有文件 ////获取该路径下的所有文件
vector<string> files; auto files = Utils::getFiles(filePath);
getFiles(filePath, files );
int size = files.size(); int size = files.size();
if (0 == size) if (0 == size)

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save