"awq/modules/vscode:/vscode.git/clone" did not exist on "c6c7b06543bf3a49a9e6a85a41a7fcdcb7d29e4e"
CommonUtility.cpp 3.53 KB
Newer Older
Your Name's avatar
Your Name committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#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
{


_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)
{
    return L.confidence > R.confidence;
}

bool CompareArea(const ResultOfDetection &L,const ResultOfDetection &R)
{
    return L.boundingBox.area() > R.boundingBox.area();
}

void NMS(vector<ResultOfDetection> &detections, float IOUThreshold)
{
    // sort
    std::sort(detections.begin(), detections.end(), CompareConfidence);

    for (int i = 0; i<detections.size(); ++i)
    {
        if (detections[i].exist)
        {
            for (int j = i + 1; j<detections.size(); ++j)
            {
                if (detections[j].exist)
                {
                    // compute IOU
                    float intersectionArea = (detections[i].boundingBox & detections[j].boundingBox).area();
                    float intersectionRate = intersectionArea / (detections[i].boundingBox.area() + detections[j].boundingBox.area() - intersectionArea);

                    if (intersectionRate>IOUThreshold)
                    {
                        detections[j].exist = false;
                    }
                }
            }
        }
    }

}

}