mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 06:46:53 +08:00
Remove trailing whitespace
This commit is contained in:
116
src/main.cpp
116
src/main.cpp
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2013 New Designs Unlimited, LLC
|
||||
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
|
||||
*
|
||||
*
|
||||
* This file is part of OpenAlpr.
|
||||
*
|
||||
*
|
||||
* OpenAlpr is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* it under the terms of the GNU Affero General Public License
|
||||
* version 3 as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
@@ -32,20 +32,20 @@
|
||||
#include "alpr.h"
|
||||
|
||||
|
||||
|
||||
|
||||
const std::string MAIN_WINDOW_NAME = "ALPR main window";
|
||||
|
||||
|
||||
|
||||
|
||||
const bool SAVE_LAST_VIDEO_STILL = false;
|
||||
const std::string LAST_VIDEO_STILL_LOCATION = "/tmp/laststill.jpg";
|
||||
|
||||
|
||||
|
||||
/** Function Headers */
|
||||
bool detectandshow(Alpr* alpr, cv::Mat frame, std::string region, bool writeJson);
|
||||
|
||||
|
||||
|
||||
bool measureProcessingTime = false;
|
||||
|
||||
|
||||
int main( int argc, const char** argv )
|
||||
{
|
||||
std::string filename;
|
||||
@@ -56,19 +56,19 @@
|
||||
std::string templateRegion;
|
||||
std::string country;
|
||||
int topn;
|
||||
|
||||
try {
|
||||
|
||||
|
||||
try {
|
||||
|
||||
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::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<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<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 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);
|
||||
@@ -78,12 +78,12 @@
|
||||
cmd.add( seekToMsArg );
|
||||
cmd.add( topNArg );
|
||||
cmd.add( runtimeDirArg );
|
||||
cmd.add( templateRegionArg );
|
||||
|
||||
cmd.add( templateRegionArg );
|
||||
|
||||
cmd.parse( argc, argv );
|
||||
|
||||
|
||||
filename = fileArg.getValue();
|
||||
|
||||
|
||||
country = countryCodeArg.getValue();
|
||||
seektoms = seekToMsArg.getValue();
|
||||
outputJson = jsonSwitch.getValue();
|
||||
@@ -92,33 +92,33 @@
|
||||
templateRegion = templateRegionArg.getValue();
|
||||
topn = topNArg.getValue();
|
||||
measureProcessingTime = clockSwitch.getValue();
|
||||
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
||||
cv::Mat frame;
|
||||
|
||||
|
||||
|
||||
Alpr alpr(country, runtimePath);
|
||||
alpr.setTopN(topn);
|
||||
|
||||
|
||||
if (detectRegion)
|
||||
alpr.setDetectRegion(detectRegion);
|
||||
|
||||
|
||||
if (strcmp(templateRegion.c_str(), "") != 0)
|
||||
{
|
||||
alpr.setDefaultRegion(templateRegion);
|
||||
}
|
||||
|
||||
|
||||
if (alpr.isLoaded() == false)
|
||||
{
|
||||
std::cerr << "Error loading OpenAlpr" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(filename.c_str(), "webcam") == 0)
|
||||
{
|
||||
int framenum = 0;
|
||||
@@ -141,11 +141,11 @@
|
||||
if (fileExists(filename.c_str()))
|
||||
{
|
||||
int framenum = 0;
|
||||
|
||||
|
||||
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)
|
||||
@@ -153,7 +153,7 @@
|
||||
cv::imwrite(LAST_VIDEO_STILL_LOCATION, frame);
|
||||
}
|
||||
std::cout << "Frame: " << framenum << std::endl;
|
||||
|
||||
|
||||
detectandshow( &alpr, frame, "", outputJson);
|
||||
//create a 1ms delay
|
||||
cv::waitKey(1);
|
||||
@@ -164,29 +164,29 @@
|
||||
{
|
||||
std::cerr << "Video file not found: " << filename << std::endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (hasEnding(filename, ".png") || hasEnding(filename, ".jpg") || hasEnding(filename, ".gif"))
|
||||
{
|
||||
if (fileExists(filename.c_str()))
|
||||
{
|
||||
frame = cv::imread( filename );
|
||||
|
||||
|
||||
detectandshow( &alpr, frame, "", outputJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Image file not found: " << filename << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (DirectoryExists(filename.c_str()))
|
||||
{
|
||||
std::vector<std::string> files = getFilesInDir(filename.c_str());
|
||||
|
||||
|
||||
std::sort( files.begin(), files.end(), stringCompare );
|
||||
|
||||
|
||||
for (int i = 0; i< files.size(); i++)
|
||||
{
|
||||
if (hasEnding(files[i], ".jpg") || hasEnding(files[i], ".png"))
|
||||
@@ -203,7 +203,7 @@
|
||||
//cv::waitKey(50);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -211,28 +211,28 @@
|
||||
std::cerr << "Unknown file type" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool detectandshow( Alpr* alpr, cv::Mat frame, std::string region, bool writeJson)
|
||||
{
|
||||
|
||||
|
||||
|
||||
std::vector<uchar> buffer;
|
||||
cv::imencode(".bmp", frame, buffer );
|
||||
|
||||
|
||||
|
||||
|
||||
timespec startTime;
|
||||
getTime(&startTime);
|
||||
|
||||
|
||||
|
||||
|
||||
std::vector<AlprResult> results = alpr->recognize(buffer);
|
||||
|
||||
|
||||
|
||||
|
||||
if (writeJson)
|
||||
{
|
||||
std::cout << alpr->toJson(results) << std::endl;
|
||||
@@ -242,12 +242,12 @@
|
||||
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;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,14 +255,10 @@
|
||||
getTime(&endTime);
|
||||
if (measureProcessingTime)
|
||||
std::cout << "Total Time to process image: " << diffclock(startTime, endTime) << "ms." << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
if (results.size() > 0)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user