Commit a08a6cb4 authored by liucong's avatar liucong
Browse files

精简代码

parent 6878b65f
#include <CommonUtility.h> #include <CommonUtility.h>
#include <assert.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <algorithm>
#include <sstream>
#include <vector>
#ifdef _WIN32
#include <io.h>
#include <direct.h>
#include <Windows.h>
#else
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/time.h>
#endif
#include <SimpleLog.h>
namespace migraphxSamples namespace migraphxSamples
{ {
_Time GetCurrentTime3()
{
_Time currentTime;
#if (defined WIN32 || defined _WIN32)
SYSTEMTIME systemTime;
GetLocalTime(&systemTime);
char temp[8] = { 0 };
sprintf(temp, "%04d", systemTime.wYear);
currentTime.year=string(temp);
sprintf(temp, "%02d", systemTime.wMonth);
currentTime.month=string(temp);
sprintf(temp, "%02d", systemTime.wDay);
currentTime.day=string(temp);
sprintf(temp, "%02d", systemTime.wHour);
currentTime.hour=string(temp);
sprintf(temp, "%02d", systemTime.wMinute);
currentTime.minute=string(temp);
sprintf(temp, "%02d", systemTime.wSecond);
currentTime.second=string(temp);
sprintf(temp, "%03d", systemTime.wMilliseconds);
currentTime.millisecond=string(temp);
sprintf(temp, "%d", systemTime.wDayOfWeek);
currentTime.weekDay=string(temp);
#else
struct timeval tv;
struct tm *p;
gettimeofday(&tv, NULL);
p = localtime(&tv.tv_sec);
char temp[8]={0};
sprintf(temp,"%04d",1900+p->tm_year);
currentTime.year=string(temp);
sprintf(temp,"%02d",1+p->tm_mon);
currentTime.month=string(temp);
sprintf(temp,"%02d",p->tm_mday);
currentTime.day=string(temp);
sprintf(temp,"%02d",p->tm_hour);
currentTime.hour=string(temp);
sprintf(temp,"%02d",p->tm_min);
currentTime.minute=string(temp);
sprintf(temp,"%02d",p->tm_sec);
currentTime.second=string(temp);
sprintf(temp,"%03d",tv.tv_usec/1000);
currentTime.millisecond = string(temp);
sprintf(temp, "%03d", tv.tv_usec % 1000);
currentTime.microsecond = string(temp);
sprintf(temp, "%d", p->tm_wday);
currentTime.weekDay = string(temp);
#endif
return currentTime;
}
std::vector<std::string> SplitString(std::string str, std::string separator)
{
std::string::size_type pos;
std::vector<std::string> result;
str+=separator;//扩展字符串以方便操作
int size=str.size();
for(int i=0; i<size; i++)
{
pos=str.find(separator,i);
if(pos<size)
{
std::string s=str.substr(i,pos-i);
result.push_back(s);
i=pos+separator.size()-1;
}
}
return result;
}
bool CompareConfidence(const ResultOfDetection &L,const ResultOfDetection &R) bool CompareConfidence(const ResultOfDetection &L,const ResultOfDetection &R)
{ {
return L.confidence > R.confidence; return L.confidence > R.confidence;
...@@ -109,7 +13,7 @@ bool CompareArea(const ResultOfDetection &L,const ResultOfDetection &R) ...@@ -109,7 +13,7 @@ bool CompareArea(const ResultOfDetection &L,const ResultOfDetection &R)
return L.boundingBox.area() > R.boundingBox.area(); return L.boundingBox.area() > R.boundingBox.area();
} }
void NMS(vector<ResultOfDetection> &detections, float IOUThreshold) void NMS(std::vector<ResultOfDetection> &detections, float IOUThreshold)
{ {
// sort // sort
std::sort(detections.begin(), detections.end(), CompareConfidence); std::sort(detections.begin(), detections.end(), CompareConfidence);
......
...@@ -3,23 +3,16 @@ ...@@ -3,23 +3,16 @@
#ifndef __COMMON_UTILITY_H__ #ifndef __COMMON_UTILITY_H__
#define __COMMON_UTILITY_H__ #define __COMMON_UTILITY_H__
#include <mutex>
#include <string>
#include <vector>
#include <CommonDefinition.h> #include <CommonDefinition.h>
using namespace std;
namespace migraphxSamples namespace migraphxSamples
{ {
// 分割字符串
std::vector<std::string> SplitString(std::string str,std::string separator);
// 排序规则: 按照置信度或者按照面积排序 // 排序规则: 按照置信度或者按照面积排序
bool CompareConfidence(const ResultOfDetection &L,const ResultOfDetection &R); bool CompareConfidence(const ResultOfDetection &L,const ResultOfDetection &R);
bool CompareArea(const ResultOfDetection &L,const ResultOfDetection &R); bool CompareArea(const ResultOfDetection &L,const ResultOfDetection &R);
// 非极大抑制
void NMS(std::vector<ResultOfDetection> &detections, float IOUThreshold); void NMS(std::vector<ResultOfDetection> &detections, float IOUThreshold);
} }
......
...@@ -11,12 +11,7 @@ ...@@ -11,12 +11,7 @@
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
#endif #endif
#include <CommonUtility.h>
#include <opencv2/opencv.hpp>
#include <SimpleLog.h>
using namespace cv;
// 路径分隔符(Linux:‘/’,Windows:’\\’) // 路径分隔符(Linux:‘/’,Windows:’\\’)
#ifdef _WIN32 #ifdef _WIN32
#define PATH_SEPARATOR '\\' #define PATH_SEPARATOR '\\'
...@@ -24,9 +19,31 @@ using namespace cv; ...@@ -24,9 +19,31 @@ using namespace cv;
#define PATH_SEPARATOR '/' #define PATH_SEPARATOR '/'
#endif #endif
using namespace std;
namespace migraphxSamples namespace migraphxSamples
{ {
static std::vector<std::string> SplitString(std::string str, std::string separator)
{
std::string::size_type pos;
std::vector<std::string> result;
str+=separator;//扩展字符串以方便操作
int size=str.size();
for(int i=0; i<size; i++)
{
pos=str.find(separator,i);
if(pos<size)
{
std::string s=str.substr(i,pos-i);
result.push_back(s);
i=pos+separator.size()-1;
}
}
return result;
}
#if defined _WIN32 || defined WINCE #if defined _WIN32 || defined WINCE
const char dir_separators[] = "/\\"; const char dir_separators[] = "/\\";
...@@ -293,7 +310,7 @@ namespace migraphxSamples ...@@ -293,7 +310,7 @@ namespace migraphxSamples
} }
else else
{ {
LOG_INFO(stdout, "could not open directory: %s", directory.c_str()); printf("could not open directory: %s", directory.c_str());
} }
} }
...@@ -390,7 +407,7 @@ namespace migraphxSamples ...@@ -390,7 +407,7 @@ namespace migraphxSamples
#endif #endif
if (!result) if (!result)
{ {
LOG_INFO(stdout, "can't remove directory: %s\n", path.c_str()); printf("can't remove directory: %s\n", path.c_str());
} }
} }
else else
...@@ -402,7 +419,7 @@ namespace migraphxSamples ...@@ -402,7 +419,7 @@ namespace migraphxSamples
#endif #endif
if (!result) if (!result)
{ {
LOG_INFO(stdout, "can't remove file: %s\n", path.c_str()); printf("can't remove file: %s\n", path.c_str());
} }
} }
} }
...@@ -438,7 +455,7 @@ namespace migraphxSamples ...@@ -438,7 +455,7 @@ namespace migraphxSamples
{ {
RemoveAll(path); RemoveAll(path);
++numberOfFiles; ++numberOfFiles;
LOG_INFO(stdout, "%s deleted! number of deleted files:%d\n", path.c_str(), numberOfFiles); printf("%s deleted! number of deleted files:%d\n", path.c_str(), numberOfFiles);
} }
} }
...@@ -452,7 +469,7 @@ namespace migraphxSamples ...@@ -452,7 +469,7 @@ namespace migraphxSamples
} }
else else
{ {
LOG_INFO(stdout, "could not open directory: %s", directory.c_str()); printf("could not open directory: %s", directory.c_str());
} }
// ����RemoveAllɾ��Ŀ¼ // ����RemoveAllɾ��Ŀ¼
...@@ -592,17 +609,17 @@ namespace migraphxSamples ...@@ -592,17 +609,17 @@ namespace migraphxSamples
if(!srcFile.is_open()) if(!srcFile.is_open())
{ {
LOG_ERROR(stdout,"can not open %s\n",srcPath.c_str()); printf("can not open %s\n",srcPath.c_str());
return false; return false;
} }
if(!dstFile.is_open()) if(!dstFile.is_open())
{ {
LOG_ERROR(stdout, "can not open %s\n", dstPath.c_str()); printf("can not open %s\n", dstPath.c_str());
return false; return false;
} }
if(srcPath==dstPath) if(srcPath==dstPath)
{ {
LOG_ERROR(stdout, "src can not be same with dst\n"); printf("src can not be same with dst\n");
return false; return false;
} }
char buffer[2048]; char buffer[2048];
...@@ -622,7 +639,7 @@ namespace migraphxSamples ...@@ -622,7 +639,7 @@ namespace migraphxSamples
{ {
if(srcPath==dstPath) if(srcPath==dstPath)
{ {
LOG_ERROR(stdout, "src can not be same with dst\n"); printf("src can not be same with dst\n");
return false; return false;
} }
...@@ -662,9 +679,9 @@ namespace migraphxSamples ...@@ -662,9 +679,9 @@ namespace migraphxSamples
// process // process
double process = (1.0*(i + 1) / fileNameList.size()) * 100; double process = (1.0*(i + 1) / fileNameList.size()) * 100;
LOG_INFO(stdout, "%s done! %f% \n", GetFileName(fileNameList[i]).c_str(), process); printf("%s done! %f% \n", GetFileName(fileNameList[i]).c_str(), process);
} }
LOG_INFO(stdout, "all done!(the number of files:%d)\n", fileNameList.size()); printf("all done!(the number of files:%d)\n", fileNameList.size());
return true; return true;
......
...@@ -3,10 +3,8 @@ ...@@ -3,10 +3,8 @@
#ifndef __FILE_SYSTEM_H__ #ifndef __FILE_SYSTEM_H__
#define __FILE_SYSTEM_H__ #define __FILE_SYSTEM_H__
#include <vector>
#include <string> #include <string>
#include <vector>
using namespace std;
namespace migraphxSamples namespace migraphxSamples
{ {
...@@ -21,7 +19,7 @@ bool IsDirectory(const std::string &path); ...@@ -21,7 +19,7 @@ bool IsDirectory(const std::string &path);
bool IsPathSeparator(char c); bool IsPathSeparator(char c);
// 路径拼接 // 路径拼接
string JoinPath(const std::string &base, const std::string &path); std::string JoinPath(const std::string &base, const std::string &path);
// 创建多级目录,注意:创建多级目录的时候,目标目录是不能有文件存在的 // 创建多级目录,注意:创建多级目录的时候,目标目录是不能有文件存在的
bool CreateDirectories(const std::string &directoryPath); bool CreateDirectories(const std::string &directoryPath);
...@@ -49,14 +47,13 @@ void Remove(const std::string &directory, const std::string &extension=""); ...@@ -49,14 +47,13 @@ void Remove(const std::string &directory, const std::string &extension="");
/** 获取路径的文件名和扩展名 /** 获取路径的文件名和扩展名
* *
* 示例:path为D:/1/1.txt,则GetFileName()为1.txt,GetFileName_NoExtension()为1,GetExtension()为.txt,GetParentPath()为D:/1/ * 示例:path为D:/1/1.txt,则GetFileName()为1.txt,GetFileName_NoExtension()为1,GetExtension()为.txt,GetParentPath()为D:/1/
*/ */
string GetFileName(const std::string &path); // 1.txt std::string GetFileName(const std::string &path);
string GetFileName_NoExtension(const std::string &path); // 1 std::string GetFileName_NoExtension(const std::string &path);
string GetExtension(const std::string &path);// .txt std::string GetExtension(const std::string &path);
string GetParentPath(const std::string &path);// D:/1/ std::string GetParentPath(const std::string &path);
// 拷贝文件:CopyFile("D:/1.txt","D:/2.txt");将1.txt拷贝为2.txt // 拷贝文件
bool CopyFile(const std::string srcPath,const std::string dstPath); bool CopyFile(const std::string srcPath,const std::string dstPath);
/** 拷贝目录 /** 拷贝目录
......
...@@ -19,7 +19,7 @@ using namespace std; ...@@ -19,7 +19,7 @@ using namespace std;
/** 简易日志 /** 简易日志
* *
* 轻量级日志系统,不依赖于其他第三方库,只需要包含一个头文件就可以使用。提供了4种日志级别,包括INFO,DEBUG,WARN和ERROR。 * 不依赖于其他第三方库,只需要包含一个头文件就可以使用。提供了4种日志级别,包括INFO,DEBUG,WARN和ERROR。
* *
* 示例1: * 示例1:
// 初始化日志,在./Log/目录下创建两个日志文件log1.log和log2.log(注意:目录./Log/需要存在,否则日志创建失败) // 初始化日志,在./Log/目录下创建两个日志文件log1.log和log2.log(注意:目录./Log/需要存在,否则日志创建失败)
......
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <opencv2/dnn.hpp>
#include <SimpleLog.h> #include <SimpleLog.h>
#include <Filesystem.h> #include <Filesystem.h>
#include <VLPR.h> #include <VLPR.h>
#include <fstream> #include <fstream>
using namespace std;
using namespace cv;
using namespace migraphx;
using namespace migraphxSamples;
int main() int main()
{ {
// 创建PaddleOCR车牌识别 // 创建PaddleOCR车牌识别
VLPR vlpr; migraphxSamples::VLPR vlpr;
InitializationParameterOfDB initParamOfDB; migraphxSamples::InitializationParameterOfDB initParamOfDB;
InitializationParameterOfSVTR initParamOfSVTR; migraphxSamples::InitializationParameterOfSVTR initParamOfSVTR;
vlpr.Initialize(initParamOfDB, initParamOfSVTR); vlpr.Initialize(initParamOfDB, initParamOfSVTR);
// 读取测试图片 // 读取测试图片
cv:: Mat Image=cv::imread("../Resource/Images/2.jpg", 1); cv:: Mat Image=cv::imread("../Resource/Images/vlpr.jpg", 1);
// 推理 // 推理
std::vector<std::string> recTexts; std::vector<std::string> recTexts;
std::vector<float> recTextScores; std::vector<float> recTextScores;
double time1 = getTickCount(); double time1 = cv::getTickCount();
vlpr.Infer(Image, recTexts, recTextScores); vlpr.Infer(Image, recTexts, recTextScores);
double time2 = getTickCount(); double time2 = cv::getTickCount();
double elapsedTime = (time2 - time1)*1000 / getTickFrequency(); double elapsedTime = (time2 - time1)*1000 / cv::getTickFrequency();
LOG_INFO(stdout, "inference time:%f ms\n", elapsedTime); LOG_INFO(stdout, "inference time:%f ms\n", elapsedTime);
// 打印结果 // 打印结果
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment