Add: class Utils

Remove: unnecessary vars
1.3
Micooz 10 years ago
parent 590affc3c7
commit c1a485dfe3

@ -304,7 +304,7 @@ int CCharsSegment::SortRect(const vector<Rect>& vecRect, vector<Rect>& out)
xpositions.push_back(vecRect[i].x);
}
float min=xpositions[0];
float min;
int minIdx=0;
for(int i=0; i< xpositions.size(); i++)
{

@ -2,8 +2,17 @@
#ifndef __UTIL_H__
#define __UTIL_H__
namespace easypr {
class Utils {
public:
static long getTimestamp();
};
}
//C++的获取文件夹函数
void getFiles(string path, vector<string>& files);
void getFiles(std::string path, std::vector<std::string>& files);
//Linux下的GetTickCount函数
#if defined (linux) || defined (__linux__)
@ -11,24 +20,24 @@ double GetTickCount();
#endif
//C++的spilt函数
void SplitString(const string& s, vector<string>& v, const string& c);
void SplitString(const std::string& s, std::vector<std::string>& v, const std::string& c);
//C++的从文件路径名称到文件名称(不包括后缀)的方法
void getFileName(const string& filepath, string& name);
void getFileName(const std::string& filepath, std::string& name);
//! levenshtein距离用于计算两个车牌的距离
//EasyPR中用levenshtein距离衡量车牌识别与真实车牌的误差
template<class T>
unsigned int levenshtein_distance(const T &s1, const T & s2) {
const size_t len1 = s1.size(), len2 = s2.size();
vector<unsigned int> col(len2+1), prevCol(len2+1);
std::vector<unsigned int> col(len2+1), prevCol(len2+1);
for (unsigned int i = 0; i < prevCol.size(); i++)
prevCol[i] = i;
for (unsigned int i = 0; i < len1; i++) {
col[0] = i+1;
for (unsigned int j = 0; j < len2; j++)
col[j+1] = min( min(prevCol[1 + j] + 1, col[j] + 1), \
col[j+1] = std::min(std::min(prevCol[1 + j] + 1, col[j] + 1), \
prevCol[j] + (s1[i]==s2[j] ? 0 : 1) );
col.swap(prevCol);
}
@ -40,13 +49,13 @@ unsigned int levenshtein_distance(const T &s1, const T & s2) {
int testMain();
/// accuracy_test.cpp中方法
int acurayTest(const string&);
int acurayTest(const std::string&);
/// mc_data_prepare.cpp中方法
void getLearnData();
void Code2Province(const string& code, string& province);
void Code2Province(const std::string& code, std::string& province);
void changeFileName();
void getPlateLicense(const string& filepath, string& plateLicense);
void getPlateLicense(const std::string& filepath, std::string& plateLicense);
/// learn_prepare.cpp中方法
void label_data();

@ -232,10 +232,10 @@ void saveModel(int _predictsize, int _neurons)
cout << "Begin to saveModelChar predictSize:" << _predictsize
<< " neurons:" << _neurons << endl;
double start = GetTickCount();
long start = Utils::getTimestamp();
annTrain(TrainingData, Classes, _neurons);
double end = GetTickCount();
cout << "GetTickCount:" << (end-start)/1000 << endl;
long end = Utils::getTimestamp();
cout << "Elapse:" << (end-start)/1000 << endl;
cout << "End the saveModelChar" << endl;

@ -74,14 +74,12 @@ int deface()
Mat detectAndMaskFace(Mat& img, CascadeClassifier& cascade, double scale)
{
double t = 0;
vector<Rect> faces;
Mat gray, smallImg( cvRound (img.rows/scale), cvRound(img.cols/scale), CV_8UC1 );
cvtColor( img, gray, COLOR_BGR2GRAY );
resize( gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR );
equalizeHist( smallImg, smallImg );
t = (double)cv::getTickCount();
cascade.detectMultiScale( smallImg, faces,
1.1, 2, 0
//|CASCADE_FIND_BIGGEST_OBJECT

@ -18,13 +18,42 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/timeb.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include "../include/util.h"
using namespace std;
using namespace easypr;
long
Utils::getTimestamp()
{
#if defined (WIN32) || defined (_WIN32)
return GetTickCount();
#endif
#if (linux) || defined (__linux__)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * 1e3 + ts.tv_nsec / 1e6);
#endif
#if defined (__APPLE__)
// there is no function provided by osx to get system tick count.
// but considering the purpose by using this function,
// we can simply return a millisecond since 1970/1/1 to calc the time elapse.
struct timeb tb;
ftime(&tb);
return tb.time * 1e3 + tb.millitm;
#endif
}
#if defined (WIN32) || defined (_WIN32)
@ -88,17 +117,6 @@ void getFiles(string path, vector<string>& files) {
#endif
#if (linux) || defined (__linux__)
double GetTickCount() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * 1e3 + ts.tv_nsec / 1e6);
}
#endif
//C++的spilt函数
void SplitString(const string& s, vector<string>& v, const string& c)
{

Loading…
Cancel
Save