Convert files with windows line endings

This commit is contained in:
Philippe Vaucher
2014-03-17 10:40:15 +01:00
parent bdc922c69a
commit 38f83ef6e1
4 changed files with 1048 additions and 1048 deletions

View File

@@ -1,264 +1,264 @@
/* /*
* Copyright (c) 2013 New Designs Unlimited, LLC * Copyright (c) 2013 New Designs Unlimited, LLC
* Opensource Automated License Plate Recognition [http://www.openalpr.com] * Opensource Automated License Plate Recognition [http://www.openalpr.com]
* *
* This file is part of OpenAlpr. * This file is part of OpenAlpr.
* *
* OpenAlpr is free software: you can redistribute it and/or modify * OpenAlpr is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License * it under the terms of the GNU Affero General Public License
* version 3 as published by the Free Software Foundation * version 3 as published by the Free Software Foundation
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details. * GNU Affero General Public License for more details.
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <iostream> #include <iostream>
#include <stdio.h> #include <stdio.h>
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
#include "tclap/CmdLine.h" #include "tclap/CmdLine.h"
#include "support/filesystem.h" #include "support/filesystem.h"
#include "support/timing.h" #include "support/timing.h"
#include "alpr.h" #include "alpr.h"
const std::string MAIN_WINDOW_NAME = "ALPR main window"; const std::string MAIN_WINDOW_NAME = "ALPR main window";
const bool SAVE_LAST_VIDEO_STILL = false; const bool SAVE_LAST_VIDEO_STILL = false;
const std::string LAST_VIDEO_STILL_LOCATION = "/tmp/laststill.jpg"; const std::string LAST_VIDEO_STILL_LOCATION = "/tmp/laststill.jpg";
/** Function Headers */ /** Function Headers */
bool detectandshow(Alpr* alpr, cv::Mat frame, std::string region, bool writeJson); bool detectandshow(Alpr* alpr, cv::Mat frame, std::string region, bool writeJson);
bool measureProcessingTime = false; bool measureProcessingTime = false;
int main( int argc, const char** argv ) int main( int argc, const char** argv )
{ {
std::string filename; std::string filename;
std::string runtimePath = ""; std::string runtimePath = "";
bool outputJson = false; bool outputJson = false;
int seektoms = 0; int seektoms = 0;
bool detectRegion = false; bool detectRegion = false;
std::string templateRegion; std::string templateRegion;
std::string country; std::string country;
int topn; int topn;
try { try {
TCLAP::CmdLine cmd("OpenAlpr Command Line Utility", ' ', OPENALPR_VERSION); TCLAP::CmdLine cmd("OpenAlpr Command Line Utility", ' ', OPENALPR_VERSION);
TCLAP::UnlabeledValueArg<std::string> fileArg( "image_file", "Image containing license plates", true, "", "image_file_path" ); TCLAP::UnlabeledValueArg<std::string> fileArg( "image_file", "Image containing license plates", true, "", "image_file_path" );
TCLAP::ValueArg<std::string> countryCodeArg("c","country","Country code to identify (either us for USA or eu for Europe). Default=us",false, "us" ,"country_code"); TCLAP::ValueArg<std::string> countryCodeArg("c","country","Country code to identify (either us for USA or eu for Europe). Default=us",false, "us" ,"country_code");
TCLAP::ValueArg<int> seekToMsArg("","seek","Seek to the specied millisecond in a video file. Default=0",false, 0 ,"integer_ms"); TCLAP::ValueArg<int> seekToMsArg("","seek","Seek to the specied millisecond in a video file. Default=0",false, 0 ,"integer_ms");
TCLAP::ValueArg<std::string> runtimeDirArg("r","runtime_dir","Path to the OpenAlpr runtime data directory",false, "" ,"runtime_dir"); TCLAP::ValueArg<std::string> runtimeDirArg("r","runtime_dir","Path to the OpenAlpr runtime data directory",false, "" ,"runtime_dir");
TCLAP::ValueArg<std::string> templateRegionArg("t","template_region","Attempt to match the plate number against a region template (e.g., md for Maryland, ca for California)",false, "" ,"region code"); TCLAP::ValueArg<std::string> templateRegionArg("t","template_region","Attempt to match the plate number against a region template (e.g., md for Maryland, ca for California)",false, "" ,"region code");
TCLAP::ValueArg<int> topNArg("n","topn","Max number of possible plate numbers to return. Default=10",false, 10 ,"topN"); TCLAP::ValueArg<int> topNArg("n","topn","Max number of possible plate numbers to return. Default=10",false, 10 ,"topN");
TCLAP::SwitchArg jsonSwitch("j","json","Output recognition results in JSON format. Default=off", cmd, false); TCLAP::SwitchArg jsonSwitch("j","json","Output recognition results in JSON format. Default=off", cmd, false);
TCLAP::SwitchArg detectRegionSwitch("d","detect_region","Attempt to detect the region of the plate image. Default=off", cmd, false); TCLAP::SwitchArg detectRegionSwitch("d","detect_region","Attempt to detect the region of the plate image. Default=off", cmd, false);
TCLAP::SwitchArg clockSwitch("","clock","Measure/print the total time to process image and all plates. Default=off", cmd, false); TCLAP::SwitchArg clockSwitch("","clock","Measure/print the total time to process image and all plates. Default=off", cmd, false);
cmd.add( fileArg ); cmd.add( fileArg );
cmd.add( countryCodeArg ); cmd.add( countryCodeArg );
cmd.add( seekToMsArg ); cmd.add( seekToMsArg );
cmd.add( topNArg ); cmd.add( topNArg );
cmd.add( runtimeDirArg ); cmd.add( runtimeDirArg );
cmd.add( templateRegionArg ); cmd.add( templateRegionArg );
cmd.parse( argc, argv ); cmd.parse( argc, argv );
filename = fileArg.getValue(); filename = fileArg.getValue();
country = countryCodeArg.getValue(); country = countryCodeArg.getValue();
seektoms = seekToMsArg.getValue(); seektoms = seekToMsArg.getValue();
outputJson = jsonSwitch.getValue(); outputJson = jsonSwitch.getValue();
runtimePath = runtimeDirArg.getValue(); runtimePath = runtimeDirArg.getValue();
detectRegion = detectRegionSwitch.getValue(); detectRegion = detectRegionSwitch.getValue();
templateRegion = templateRegionArg.getValue(); templateRegion = templateRegionArg.getValue();
topn = topNArg.getValue(); topn = topNArg.getValue();
measureProcessingTime = clockSwitch.getValue(); measureProcessingTime = clockSwitch.getValue();
} catch (TCLAP::ArgException &e) // catch any exceptions } catch (TCLAP::ArgException &e) // catch any exceptions
{ {
std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
return 1; return 1;
} }
cv::Mat frame; cv::Mat frame;
Alpr alpr(country, runtimePath); Alpr alpr(country, runtimePath);
alpr.setTopN(topn); alpr.setTopN(topn);
if (detectRegion) if (detectRegion)
alpr.setDetectRegion(detectRegion); alpr.setDetectRegion(detectRegion);
if (strcmp(templateRegion.c_str(), "") != 0) if (strcmp(templateRegion.c_str(), "") != 0)
{ {
alpr.setDefaultRegion(templateRegion); alpr.setDefaultRegion(templateRegion);
} }
if (alpr.isLoaded() == false) if (alpr.isLoaded() == false)
{ {
std::cerr << "Error loading OpenAlpr" << std::endl; std::cerr << "Error loading OpenAlpr" << std::endl;
return 1; return 1;
} }
if (strcmp(filename.c_str(), "webcam") == 0) if (strcmp(filename.c_str(), "webcam") == 0)
{ {
int framenum = 0; int framenum = 0;
cv::VideoCapture cap(0); cv::VideoCapture cap(0);
if (!cap.isOpened()) if (!cap.isOpened())
{ {
std::cout << "Error opening webcam" << std::endl; std::cout << "Error opening webcam" << std::endl;
return 1; return 1;
} }
while (cap.read(frame) == true) while (cap.read(frame) == true)
{ {
detectandshow(&alpr, frame, "", outputJson); detectandshow(&alpr, frame, "", outputJson);
cv::waitKey(1); cv::waitKey(1);
framenum++; framenum++;
} }
} }
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"))
{ {
if (fileExists(filename.c_str())) if (fileExists(filename.c_str()))
{ {
int framenum = 0; int framenum = 0;
cv::VideoCapture cap=cv::VideoCapture(); cv::VideoCapture cap=cv::VideoCapture();
cap.open(filename); cap.open(filename);
cap.set(CV_CAP_PROP_POS_MSEC, seektoms); cap.set(CV_CAP_PROP_POS_MSEC, seektoms);
while (cap.read(frame) == true) while (cap.read(frame) == true)
{ {
if (SAVE_LAST_VIDEO_STILL == true) if (SAVE_LAST_VIDEO_STILL == true)
{ {
cv::imwrite(LAST_VIDEO_STILL_LOCATION, frame); cv::imwrite(LAST_VIDEO_STILL_LOCATION, frame);
} }
std::cout << "Frame: " << framenum << std::endl; std::cout << "Frame: " << framenum << std::endl;
detectandshow( &alpr, frame, "", outputJson); detectandshow( &alpr, frame, "", outputJson);
//create a 1ms delay //create a 1ms delay
cv::waitKey(1); cv::waitKey(1);
framenum++; framenum++;
} }
} }
else else
{ {
std::cerr << "Video file not found: " << filename << std::endl; 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"))
{ {
if (fileExists(filename.c_str())) if (fileExists(filename.c_str()))
{ {
frame = cv::imread( filename ); frame = cv::imread( filename );
detectandshow( &alpr, frame, "", outputJson); detectandshow( &alpr, frame, "", outputJson);
} }
else else
{ {
std::cerr << "Image file not found: " << filename << std::endl; std::cerr << "Image file not found: " << filename << std::endl;
} }
} }
else if (DirectoryExists(filename.c_str())) else if (DirectoryExists(filename.c_str()))
{ {
std::vector<std::string> files = getFilesInDir(filename.c_str()); std::vector<std::string> files = getFilesInDir(filename.c_str());
std::sort( files.begin(), files.end(), stringCompare ); std::sort( files.begin(), files.end(), stringCompare );
for (int i = 0; i< files.size(); i++) for (int i = 0; i< files.size(); i++)
{ {
if (hasEnding(files[i], ".jpg") || hasEnding(files[i], ".png")) if (hasEnding(files[i], ".jpg") || hasEnding(files[i], ".png"))
{ {
std::string fullpath = filename + "/" + files[i]; std::string fullpath = filename + "/" + files[i];
std::cout << fullpath << std::endl; std::cout << fullpath << std::endl;
frame = cv::imread( fullpath.c_str() ); frame = cv::imread( fullpath.c_str() );
if (detectandshow( &alpr, frame, "", outputJson)) if (detectandshow( &alpr, frame, "", outputJson))
{ {
//while ((char) cv::waitKey(50) != 'c') { } //while ((char) cv::waitKey(50) != 'c') { }
} }
else else
{ {
//cv::waitKey(50); //cv::waitKey(50);
} }
} }
} }
} }
else else
{ {
std::cerr << "Unknown file type" << std::endl; std::cerr << "Unknown file type" << std::endl;
return 1; return 1;
} }
return 0; return 0;
} }
bool detectandshow( Alpr* alpr, cv::Mat frame, std::string region, bool writeJson) bool detectandshow( Alpr* alpr, cv::Mat frame, std::string region, bool writeJson)
{ {
std::vector<uchar> buffer; std::vector<uchar> buffer;
cv::imencode(".bmp", frame, buffer ); cv::imencode(".bmp", frame, buffer );
timespec startTime; timespec startTime;
getTime(&startTime); getTime(&startTime);
std::vector<AlprResult> results = alpr->recognize(buffer); std::vector<AlprResult> results = alpr->recognize(buffer);
if (writeJson) if (writeJson)
{ {
std::cout << alpr->toJson(results) << std::endl; std::cout << alpr->toJson(results) << std::endl;
} }
else else
{ {
for (int i = 0; i < results.size(); i++) for (int i = 0; i < results.size(); i++)
{ {
std::cout << "plate" << i << ": " << results[i].result_count << " results -- Processing Time = " << results[i].processing_time_ms << "ms." << std::endl; std::cout << "plate" << i << ": " << results[i].result_count << " results -- Processing Time = " << results[i].processing_time_ms << "ms." << std::endl;
for (int k = 0; k < results[i].topNPlates.size(); k++) for (int k = 0; k < results[i].topNPlates.size(); k++)
{ {
std::cout << " - " << results[i].topNPlates[k].characters << "\t confidence: " << results[i].topNPlates[k].overall_confidence << "\t template_match: " << results[i].topNPlates[k].matches_template << std::endl; std::cout << " - " << results[i].topNPlates[k].characters << "\t confidence: " << results[i].topNPlates[k].overall_confidence << "\t template_match: " << results[i].topNPlates[k].matches_template << std::endl;
} }
} }
} }
timespec endTime; timespec endTime;
getTime(&endTime); getTime(&endTime);
if (measureProcessingTime) if (measureProcessingTime)
std::cout << "Total Time to process image: " << diffclock(startTime, endTime) << "ms." << std::endl; std::cout << "Total Time to process image: " << diffclock(startTime, endTime) << "ms." << std::endl;
if (results.size() > 0) if (results.size() > 0)
return true; return true;
return false; return false;
} }

View File

@@ -1,75 +1,75 @@
#ifndef _TREXPP_H_ #ifndef _TREXPP_H_
#define _TREXPP_H_ #define _TREXPP_H_
/*************************************************************** /***************************************************************
T-Rex a tiny regular expression library T-Rex a tiny regular expression library
Copyright (C) 2003-2004 Alberto Demichelis Copyright (C) 2003-2004 Alberto Demichelis
This software is provided 'as-is', without any express This software is provided 'as-is', without any express
or implied warranty. In no event will the authors be held or implied warranty. In no event will the authors be held
liable for any damages arising from the use of this software. liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to alter any purpose, including commercial applications, and to alter
it and redistribute it freely, subject to the following restrictions: it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; 1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software. you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but in the product documentation would be appreciated but
is not required. is not required.
2. Altered source versions must be plainly marked as such, 2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software. and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any 3. This notice may not be removed or altered from any
source distribution. source distribution.
****************************************************************/ ****************************************************************/
extern "C" { extern "C" {
#include "trex.h" #include "trex.h"
} }
struct TRexParseException{TRexParseException(const TRexChar *c):desc(c){}const TRexChar *desc;}; struct TRexParseException{TRexParseException(const TRexChar *c):desc(c){}const TRexChar *desc;};
class TRexpp { class TRexpp {
public: public:
TRexpp() { _exp = (TRex *)0; } TRexpp() { _exp = (TRex *)0; }
~TRexpp() { CleanUp(); } ~TRexpp() { CleanUp(); }
// compiles a regular expression // compiles a regular expression
void Compile(const TRexChar *pattern) { void Compile(const TRexChar *pattern) {
const TRexChar *error; const TRexChar *error;
CleanUp(); CleanUp();
if(!(_exp = trex_compile(pattern,&error))) if(!(_exp = trex_compile(pattern,&error)))
throw TRexParseException(error); throw TRexParseException(error);
} }
// return true if the given text match the expression // return true if the given text match the expression
bool Match(const TRexChar* text) { bool Match(const TRexChar* text) {
return _exp?(trex_match(_exp,text) != 0):false; return _exp?(trex_match(_exp,text) != 0):false;
} }
// Searches for the first match of the expression in a zero terminated string // Searches for the first match of the expression in a zero terminated string
bool Search(const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end) { bool Search(const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end) {
return _exp?(trex_search(_exp,text,out_begin,out_end) != 0):false; return _exp?(trex_search(_exp,text,out_begin,out_end) != 0):false;
} }
// Searches for the first match of the expression in a string sarting at text_begin and ending at text_end // Searches for the first match of the expression in a string sarting at text_begin and ending at text_end
bool SearchRange(const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end) { bool SearchRange(const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end) {
return _exp?(trex_searchrange(_exp,text_begin,text_end,out_begin,out_end) != 0):false; return _exp?(trex_searchrange(_exp,text_begin,text_end,out_begin,out_end) != 0):false;
} }
bool GetSubExp(int n, const TRexChar** out_begin, int *out_len) bool GetSubExp(int n, const TRexChar** out_begin, int *out_len)
{ {
TRexMatch match; TRexMatch match;
TRexBool res = _exp?(trex_getsubexp(_exp,n,&match)):TRex_False; TRexBool res = _exp?(trex_getsubexp(_exp,n,&match)):TRex_False;
if(res) { if(res) {
*out_begin = match.begin; *out_begin = match.begin;
*out_len = match.len; *out_len = match.len;
return true; return true;
} }
return false; return false;
} }
int GetSubExpCount() { return _exp?trex_getsubexpcount(_exp):0; } int GetSubExpCount() { return _exp?trex_getsubexpcount(_exp):0; }
private: private:
void CleanUp() { if(_exp) trex_free(_exp); _exp = (TRex *)0; } void CleanUp() { if(_exp) trex_free(_exp); _exp = (TRex *)0; }
TRex *_exp; TRex *_exp;
}; };
#endif //_TREXPP_H_ #endif //_TREXPP_H_

File diff suppressed because it is too large Load Diff

View File

@@ -1,67 +1,67 @@
#ifndef _TREX_H_ #ifndef _TREX_H_
#define _TREX_H_ #define _TREX_H_
/*************************************************************** /***************************************************************
T-Rex a tiny regular expression library T-Rex a tiny regular expression library
Copyright (C) 2003-2006 Alberto Demichelis Copyright (C) 2003-2006 Alberto Demichelis
This software is provided 'as-is', without any express This software is provided 'as-is', without any express
or implied warranty. In no event will the authors be held or implied warranty. In no event will the authors be held
liable for any damages arising from the use of this software. liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for Permission is granted to anyone to use this software for
any purpose, including commercial applications, and to alter any purpose, including commercial applications, and to alter
it and redistribute it freely, subject to the following restrictions: it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; 1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software. you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but in the product documentation would be appreciated but
is not required. is not required.
2. Altered source versions must be plainly marked as such, 2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software. and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any 3. This notice may not be removed or altered from any
source distribution. source distribution.
****************************************************************/ ****************************************************************/
#ifdef _UNICODE #ifdef _UNICODE
#define TRexChar unsigned short #define TRexChar unsigned short
#define MAX_CHAR 0xFFFF #define MAX_CHAR 0xFFFF
#define _TREXC(c) L##c #define _TREXC(c) L##c
#define trex_strlen wcslen #define trex_strlen wcslen
#define trex_printf wprintf #define trex_printf wprintf
#else #else
#define TRexChar char #define TRexChar char
#define MAX_CHAR 0xFF #define MAX_CHAR 0xFF
#define _TREXC(c) (c) #define _TREXC(c) (c)
#define trex_strlen strlen #define trex_strlen strlen
#define trex_printf printf #define trex_printf printf
#endif #endif
#ifndef TREX_API #ifndef TREX_API
#define TREX_API extern #define TREX_API extern
#endif #endif
#define TRex_True 1 #define TRex_True 1
#define TRex_False 0 #define TRex_False 0
typedef unsigned int TRexBool; typedef unsigned int TRexBool;
typedef struct TRex TRex; typedef struct TRex TRex;
typedef struct { typedef struct {
const TRexChar *begin; const TRexChar *begin;
int len; int len;
} TRexMatch; } TRexMatch;
TREX_API TRex *trex_compile(const TRexChar *pattern,const TRexChar **error); TREX_API TRex *trex_compile(const TRexChar *pattern,const TRexChar **error);
TREX_API void trex_free(TRex *exp); TREX_API void trex_free(TRex *exp);
TREX_API TRexBool trex_match(TRex* exp,const TRexChar* text); TREX_API TRexBool trex_match(TRex* exp,const TRexChar* text);
TREX_API TRexBool trex_search(TRex* exp,const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end); TREX_API TRexBool trex_search(TRex* exp,const TRexChar* text, const TRexChar** out_begin, const TRexChar** out_end);
TREX_API TRexBool trex_searchrange(TRex* exp,const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end); TREX_API TRexBool trex_searchrange(TRex* exp,const TRexChar* text_begin,const TRexChar* text_end,const TRexChar** out_begin, const TRexChar** out_end);
TREX_API int trex_getsubexpcount(TRex* exp); TREX_API int trex_getsubexpcount(TRex* exp);
TREX_API TRexBool trex_getsubexp(TRex* exp, int n, TRexMatch *subexp); TREX_API TRexBool trex_getsubexp(TRex* exp, int n, TRexMatch *subexp);
#endif #endif