mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 16:01:05 +08:00
Merge commit 'bcdb010cc5fb469b593150979a020af4cda3698a' into develop
This commit is contained in:
49
src/main.cpp
49
src/main.cpp
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <valarray>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@@ -139,32 +140,46 @@
|
|||||||
}
|
}
|
||||||
else if (hasEnding(filename, ".avi") || hasEnding(filename, ".mp4") || hasEnding(filename, ".webm") || hasEnding(filename, ".flv"))
|
else if (hasEnding(filename, ".avi") || hasEnding(filename, ".mp4") || hasEnding(filename, ".webm") || hasEnding(filename, ".flv"))
|
||||||
{
|
{
|
||||||
int framenum = 0;
|
if (fileExists(filename.c_str()))
|
||||||
|
|
||||||
cv::VideoCapture cap=cv::VideoCapture();
|
|
||||||
cap.open(filename);
|
|
||||||
cap.set(CV_CAP_PROP_POS_MSEC, seektoms);
|
|
||||||
|
|
||||||
while (cap.read(frame) == true)
|
|
||||||
{
|
{
|
||||||
if (SAVE_LAST_VIDEO_STILL == true)
|
int framenum = 0;
|
||||||
{
|
|
||||||
cv::imwrite(LAST_VIDEO_STILL_LOCATION, frame);
|
|
||||||
}
|
|
||||||
std::cout << "Frame: " << framenum << std::endl;
|
|
||||||
|
|
||||||
detectandshow( &alpr, frame, "", outputJson);
|
cv::VideoCapture cap=cv::VideoCapture();
|
||||||
//create a 1ms delay
|
cap.open(filename);
|
||||||
cv::waitKey(1);
|
cap.set(CV_CAP_PROP_POS_MSEC, seektoms);
|
||||||
framenum++;
|
|
||||||
|
while (cap.read(frame) == true)
|
||||||
|
{
|
||||||
|
if (SAVE_LAST_VIDEO_STILL == true)
|
||||||
|
{
|
||||||
|
cv::imwrite(LAST_VIDEO_STILL_LOCATION, frame);
|
||||||
|
}
|
||||||
|
std::cout << "Frame: " << framenum << std::endl;
|
||||||
|
|
||||||
|
detectandshow( &alpr, frame, "", outputJson);
|
||||||
|
//create a 1ms delay
|
||||||
|
cv::waitKey(1);
|
||||||
|
framenum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Video file not found: " << filename << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (hasEnding(filename, ".png") || hasEnding(filename, ".jpg") || hasEnding(filename, ".gif"))
|
else if (hasEnding(filename, ".png") || hasEnding(filename, ".jpg") || hasEnding(filename, ".gif"))
|
||||||
{
|
{
|
||||||
frame = cv::imread( filename );
|
if (fileExists(filename.c_str()))
|
||||||
|
{
|
||||||
|
frame = cv::imread( filename );
|
||||||
|
|
||||||
detectandshow( &alpr, frame, "", outputJson);
|
detectandshow( &alpr, frame, "", outputJson);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Image file not found: " << filename << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,35 +1,102 @@
|
|||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
|
|
||||||
#ifdef __MACH__
|
|
||||||
#include <mach/clock.h>
|
|
||||||
#include <mach/mach.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
|
|
||||||
|
|
||||||
timespec diff(timespec start, timespec end);
|
timespec diff(timespec start, timespec end);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
@@ -112,7 +112,7 @@ void displayImage(Config* config, string windowName, cv::Mat frame)
|
|||||||
|
|
||||||
vector<Mat> produceThresholds(const Mat img_gray, Config* config)
|
vector<Mat> produceThresholds(const Mat img_gray, Config* config)
|
||||||
{
|
{
|
||||||
const int THRESHOLD_COUNT = 10;
|
const int THRESHOLD_COUNT = 4;
|
||||||
//Mat img_equalized = equalizeBrightness(img_gray);
|
//Mat img_equalized = equalizeBrightness(img_gray);
|
||||||
|
|
||||||
timespec startTime;
|
timespec startTime;
|
||||||
@@ -120,44 +120,37 @@ vector<Mat> produceThresholds(const Mat img_gray, Config* config)
|
|||||||
|
|
||||||
vector<Mat> thresholds;
|
vector<Mat> thresholds;
|
||||||
|
|
||||||
//#pragma omp parallel for
|
|
||||||
for (int i = 0; i < THRESHOLD_COUNT; i++)
|
for (int i = 0; i < THRESHOLD_COUNT; i++)
|
||||||
thresholds.push_back(Mat(img_gray.size(), CV_8U));
|
thresholds.push_back(Mat(img_gray.size(), CV_8U));
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
for (int i = 0; i < THRESHOLD_COUNT; i++)
|
// Adaptive
|
||||||
{
|
//adaptiveThreshold(img_gray, thresholds[i++], 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV , 7, 3);
|
||||||
|
//adaptiveThreshold(img_gray, thresholds[i++], 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV , 13, 3);
|
||||||
|
//adaptiveThreshold(img_gray, thresholds[i++], 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV , 17, 3);
|
||||||
if (i <= 2) //0-2
|
|
||||||
{
|
// Wolf
|
||||||
int k = ((i%3) * 5) + 7; // 7, 12, 17
|
int k = 0, win=18;
|
||||||
if (k==12) k = 13; // change 12 to 13
|
//NiblackSauvolaWolfJolion (img_gray, thresholds[i++], WOLFJOLION, win, win, 0.05 + (k * 0.35));
|
||||||
//#pragma omp ordered
|
//bitwise_not(thresholds[i-1], thresholds[i-1]);
|
||||||
adaptiveThreshold(img_gray, thresholds[i], 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV , k, 3);
|
NiblackSauvolaWolfJolion (img_gray, thresholds[i++], WOLFJOLION, win, win, 0.05 + (k * 0.35));
|
||||||
}
|
bitwise_not(thresholds[i-1], thresholds[i-1]);
|
||||||
else if (i <= 6) //3-6
|
|
||||||
{
|
k = 1; win = 22;
|
||||||
int k = i%2; // 0 or 1
|
NiblackSauvolaWolfJolion (img_gray, thresholds[i++], WOLFJOLION, win, win, 0.05 + (k * 0.35));
|
||||||
int win = 18 + (k * 4); // 18 or 22
|
bitwise_not(thresholds[i-1], thresholds[i-1]);
|
||||||
//#pragma omp ordered
|
//NiblackSauvolaWolfJolion (img_gray, thresholds[i++], WOLFJOLION, win, win, 0.05 + (k * 0.35));
|
||||||
NiblackSauvolaWolfJolion (img_gray, thresholds[i], WOLFJOLION, win, win, 0.05 + (k * 0.35));
|
//bitwise_not(thresholds[i-1], thresholds[i-1]);
|
||||||
bitwise_not(thresholds[i], thresholds[i]);
|
|
||||||
|
// Sauvola
|
||||||
}
|
k = 1;
|
||||||
else if (i <= 9) //7-9
|
NiblackSauvolaWolfJolion (img_gray, thresholds[i++], SAUVOLA, 12, 12, 0.18 * k);
|
||||||
{
|
bitwise_not(thresholds[i-1], thresholds[i-1]);
|
||||||
int k = (i%3) + 1; // 1,2,3
|
k=2;
|
||||||
//#pragma omp ordered
|
NiblackSauvolaWolfJolion (img_gray, thresholds[i++], SAUVOLA, 12, 12, 0.18 * k);
|
||||||
NiblackSauvolaWolfJolion (img_gray, thresholds[i], SAUVOLA, 12, 12, 0.18 * k);
|
bitwise_not(thresholds[i-1], thresholds[i-1]);
|
||||||
bitwise_not(thresholds[i], thresholds[i]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -177,6 +170,12 @@ vector<Mat> produceThresholds(const Mat img_gray, Config* config)
|
|||||||
|
|
||||||
double median(int array[], int arraySize)
|
double median(int array[], int arraySize)
|
||||||
{
|
{
|
||||||
|
if (arraySize == 0)
|
||||||
|
{
|
||||||
|
//std::cerr << "Median calculation requested on empty array" << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
std::sort(&array[0], &array[arraySize]);
|
std::sort(&array[0], &array[arraySize]);
|
||||||
return arraySize % 2 ? array[arraySize / 2] : (array[max(0, arraySize / 2 - 1)] + array[arraySize / 2]) / 2;
|
return arraySize % 2 ? array[arraySize / 2] : (array[max(0, arraySize / 2 - 1)] + array[arraySize / 2]) / 2;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user