mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 12:06:51 +08:00
Fixed clock timing on Windows.
Previously, clock timing was mocked out to 0. This fixes it and gives correct timings in ms for plate recognitions
This commit is contained in:
@@ -1,35 +1,103 @@
|
|||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
|
|
||||||
#ifdef __MACH__
|
|
||||||
#include <mach/clock.h>
|
|
||||||
#include <mach/mach.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|
||||||
|
|
||||||
timespec diff(timespec start, timespec end);
|
timespec diff(timespec start, timespec end);
|
||||||
|
|
||||||
|
|
||||||
|
// Windows timing code
|
||||||
|
LARGE_INTEGER getFILETIMEoffset()
|
||||||
|
{
|
||||||
|
SYSTEMTIME s;
|
||||||
|
FILETIME f;
|
||||||
|
LARGE_INTEGER t;
|
||||||
|
|
||||||
|
s.wYear = 1970;
|
||||||
|
s.wMonth = 1;
|
||||||
|
s.wDay = 1;
|
||||||
|
s.wHour = 0;
|
||||||
|
s.wMinute = 0;
|
||||||
|
s.wSecond = 0;
|
||||||
|
s.wMilliseconds = 0;
|
||||||
|
SystemTimeToFileTime(&s, &f);
|
||||||
|
t.QuadPart = f.dwHighDateTime;
|
||||||
|
t.QuadPart <<= 32;
|
||||||
|
t.QuadPart |= f.dwLowDateTime;
|
||||||
|
return (t);
|
||||||
|
}
|
||||||
|
|
||||||
|
int clock_gettime(int X, timespec *tv)
|
||||||
|
{
|
||||||
|
LARGE_INTEGER t;
|
||||||
|
FILETIME f;
|
||||||
|
double microseconds;
|
||||||
|
static LARGE_INTEGER offset;
|
||||||
|
static double frequencyToMicroseconds;
|
||||||
|
static int initialized = 0;
|
||||||
|
static BOOL usePerformanceCounter = 0;
|
||||||
|
|
||||||
|
if (!initialized) {
|
||||||
|
LARGE_INTEGER performanceFrequency;
|
||||||
|
initialized = 1;
|
||||||
|
usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
|
||||||
|
if (usePerformanceCounter) {
|
||||||
|
QueryPerformanceCounter(&offset);
|
||||||
|
frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.;
|
||||||
|
} else {
|
||||||
|
offset = getFILETIMEoffset();
|
||||||
|
frequencyToMicroseconds = 10.;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (usePerformanceCounter) QueryPerformanceCounter(&t);
|
||||||
|
else {
|
||||||
|
GetSystemTimeAsFileTime(&f);
|
||||||
|
t.QuadPart = f.dwHighDateTime;
|
||||||
|
t.QuadPart <<= 32;
|
||||||
|
t.QuadPart |= f.dwLowDateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
t.QuadPart -= offset.QuadPart;
|
||||||
|
microseconds = (double)t.QuadPart / frequencyToMicroseconds;
|
||||||
|
t.QuadPart = microseconds;
|
||||||
|
tv->tv_sec = t.QuadPart / 1000000;
|
||||||
|
tv->tv_usec = t.QuadPart % 1000000;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void getTime(timespec* time)
|
void getTime(timespec* time)
|
||||||
{
|
{
|
||||||
// Do nothing on Windows
|
clock_gettime(0, time);
|
||||||
|
|
||||||
}
|
}
|
||||||
double diffclock(timespec time1,timespec time2)
|
double diffclock(timespec time1,timespec time2)
|
||||||
{
|
{
|
||||||
// Mock this out for Windows
|
timespec delta = diff(time1,time2);
|
||||||
return 0;
|
double milliseconds = (delta.tv_sec * 1000) + (((double) delta.tv_usec) / 1000.0);
|
||||||
|
|
||||||
|
|
||||||
|
return milliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
timespec diff(timespec start, timespec end)
|
timespec diff(timespec start, timespec end)
|
||||||
{
|
{
|
||||||
// Mock this out for Windows
|
timespec temp;
|
||||||
return 0;
|
if ((end.tv_usec-start.tv_usec)<0) {
|
||||||
|
temp.tv_sec = end.tv_sec-start.tv_sec-1;
|
||||||
|
temp.tv_usec = 1000000+end.tv_usec-start.tv_usec;
|
||||||
|
} else {
|
||||||
|
temp.tv_sec = end.tv_sec-start.tv_sec;
|
||||||
|
temp.tv_usec = end.tv_usec-start.tv_usec;
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
timespec diff(timespec start, timespec end);
|
|
||||||
|
|
||||||
void getTime(timespec* time)
|
void getTime(timespec* time)
|
||||||
{
|
{
|
||||||
|
@@ -3,10 +3,17 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
// Support for OS X
|
||||||
|
#ifdef __MACH__
|
||||||
|
#include <mach/clock.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Support for Windows
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
// Mock this out for Windows
|
#include <windows.h>
|
||||||
#define timespec int
|
|
||||||
|
#define timespec timeval
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void getTime(timespec* time);
|
void getTime(timespec* time);
|
||||||
|
Reference in New Issue
Block a user