Move getFiles() to class Utils.

1.3
Micooz 10 years ago
parent 4ae3b06b17
commit 1e99b0307a

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

@ -1,43 +1,50 @@
#ifndef __UTIL_H__
#define __UTIL_H__
#include <vector>
#include <string>
#ifdef min
#undef min
#undef min
#endif
namespace easypr {
class Utils {
public:
static long getTimestamp();
/*
* Get file name from a given path
* bool postfix: including the postfix
*/
static std::string getFileName(const std::string &path, const bool postfix = false);
/*
* Split the given string into segements by a delimiter
*/
static std::vector<std::string> splitString(const std::string &str, const char delimiter);
/*
* returns the smaller of the two numbers
*/
template<typename T>
static T min(const T &v1, const T &v2) {
return (v1 < v2) ? v1 : v2;
}
};
class Utils {
public:
static long getTimestamp();
/*
* Get file name from a given path
* bool postfix: including the postfix
*/
static std::string getFileName(const std::string& path,
const bool postfix = false);
/*
* Split the given string into segements by a delimiter
*/
static std::vector<std::string> splitString(const std::string& str,
const char delimiter);
/*
* returns the smaller of the two numbers
*/
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距离用于计算两个车牌的距离
//EasyPR中用levenshtein距离衡量车牌识别与真实车牌的误差
template<class T>

File diff suppressed because it is too large Load Diff

@ -16,7 +16,7 @@
#if defined (WIN32) || defined (_WIN32)
#include <io.h>
#elif defined (linux) || defined (__linux__)
#include <sys/io.h>
//#include <sys/io.h>
#endif
#include <stdlib.h>
@ -140,8 +140,7 @@ int saveTrainData()
stringstream ss(stringstream::in | stringstream::out);
ss << path << "/" << strCharacters[i];
vector<string> files;
getFiles(ss.str(), files);
auto files = Utils::getFiles(ss.str());
int size = files.size();
for (int j = 0; j < size; j++)
@ -169,8 +168,7 @@ int saveTrainData()
stringstream ss(stringstream::in | stringstream::out);
ss << path << "/" << strChinese[i];
vector<string> files;
getFiles(ss.str(), files);
auto files = Utils::getFiles(ss.str());
int size = files.size();
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";
vector<string> files;
////获取该路径下的所有文件
getFiles(filePath, files );
auto files = Utils::getFiles(filePath);
int size = files.size();
if (0 == size) {
@ -60,10 +59,9 @@ void learn2NoPlate(float bound = 0.7)
{
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();
if (0 == size) {
cout << "File not found in " << filePath << endl;
@ -107,10 +105,9 @@ void getHasPlateTrain(Mat& trainingImages, vector<int>& trainingLabels,
{
int label = 1;
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();
if (0 == size) {
@ -139,10 +136,9 @@ void getNoPlateTrain(Mat& trainingImages, vector<int>& trainingLabels,
{
int label = 0;
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();
if (0 == size) {
@ -169,10 +165,9 @@ void getHasPlateTest(vector<Mat>& testingImages, vector<int>& testingLabels)
{
int label = 1;
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();
if (0 == size) {
@ -194,10 +189,9 @@ void getNoPlateTest(vector<Mat>& testingImages, vector<int>& testingLabels)
{
int label = 0;
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();
if (0 == size) {

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

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

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

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

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