mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-05 23:06:56 +08:00
Reformatted JSON output. Moved epoch time to top level. Added total processing time
This commit is contained in:
16
src/main.cpp
16
src/main.cpp
@@ -36,6 +36,7 @@ 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";
|
||||||
|
std::string getJson(Alpr* alpr, std::vector<AlprResult> results);
|
||||||
|
|
||||||
/** 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);
|
||||||
@@ -273,9 +274,16 @@ bool detectandshow( Alpr* alpr, cv::Mat frame, std::string region, bool writeJso
|
|||||||
|
|
||||||
std::vector<AlprResult> results = alpr->recognize(buffer);
|
std::vector<AlprResult> results = alpr->recognize(buffer);
|
||||||
|
|
||||||
|
timespec endTime;
|
||||||
|
getTime(&endTime);
|
||||||
|
double totalProcessingTime = diffclock(startTime, endTime);
|
||||||
|
if (measureProcessingTime)
|
||||||
|
std::cout << "Total Time to process image: " << totalProcessingTime << "ms." << std::endl;
|
||||||
|
|
||||||
|
|
||||||
if (writeJson)
|
if (writeJson)
|
||||||
{
|
{
|
||||||
std::cout << alpr->toJson(results) << std::endl;
|
std::cout << alpr->toJson(results, totalProcessingTime) << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -290,10 +298,8 @@ bool detectandshow( Alpr* alpr, cv::Mat frame, std::string region, bool writeJso
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timespec endTime;
|
|
||||||
getTime(&endTime);
|
|
||||||
if (measureProcessingTime)
|
|
||||||
std::cout << "Total Time to process image: " << diffclock(startTime, endTime) << "ms." << std::endl;
|
|
||||||
|
|
||||||
return results.size() > 0;
|
return results.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,9 +46,9 @@ std::vector<AlprResult> Alpr::recognize(std::vector<unsigned char> imageBuffer)
|
|||||||
return impl->recognize(img);
|
return impl->recognize(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
string Alpr::toJson(const vector< AlprResult > results)
|
string Alpr::toJson(const vector< AlprResult > results, double processing_time_ms)
|
||||||
{
|
{
|
||||||
return impl->toJson(results);
|
return impl->toJson(results, processing_time_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Alpr::setDetectRegion(bool detectRegion)
|
void Alpr::setDetectRegion(bool detectRegion)
|
||||||
|
@@ -73,7 +73,7 @@ class Alpr
|
|||||||
std::vector<AlprResult> recognize(std::string filepath);
|
std::vector<AlprResult> recognize(std::string filepath);
|
||||||
std::vector<AlprResult> recognize(std::vector<unsigned char> imageBuffer);
|
std::vector<AlprResult> recognize(std::vector<unsigned char> imageBuffer);
|
||||||
|
|
||||||
std::string toJson(const std::vector<AlprResult> results);
|
std::string toJson(const std::vector<AlprResult> results, double processing_time_ms = -1);
|
||||||
|
|
||||||
bool isLoaded();
|
bool isLoaded();
|
||||||
|
|
||||||
|
@@ -276,19 +276,28 @@ void plateAnalysisThread(void* arg)
|
|||||||
cout << "Thread: " << tthread::this_thread::get_id() << " Complete" << endl;
|
cout << "Thread: " << tthread::this_thread::get_id() << " Complete" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
string AlprImpl::toJson(const vector< AlprResult > results)
|
string AlprImpl::toJson(const vector< AlprResult > results, double processing_time_ms)
|
||||||
{
|
{
|
||||||
cJSON *root = cJSON_CreateArray();
|
cJSON *root, *jsonResults;
|
||||||
|
root = cJSON_CreateObject();
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(root,"epoch_time", getEpochTime() );
|
||||||
|
if (processing_time_ms >= 0)
|
||||||
|
{
|
||||||
|
cJSON_AddNumberToObject(root,"processing_time_ms", processing_time_ms );
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_AddItemToObject(root, "results", jsonResults=cJSON_CreateArray());
|
||||||
for (int i = 0; i < results.size(); i++)
|
for (int i = 0; i < results.size(); i++)
|
||||||
{
|
{
|
||||||
cJSON *resultObj = createJsonObj( &results[i] );
|
cJSON *resultObj = createJsonObj( &results[i] );
|
||||||
cJSON_AddItemToArray(root, resultObj);
|
cJSON_AddItemToArray(jsonResults, resultObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the JSON object to a string and return
|
// Print the JSON object to a string and return
|
||||||
char *out;
|
char *out;
|
||||||
out=cJSON_PrintUnformatted(root);
|
out=cJSON_PrintUnformatted(root);
|
||||||
|
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
|
|
||||||
string response(out);
|
string response(out);
|
||||||
@@ -306,7 +315,6 @@ cJSON* AlprImpl::createJsonObj(const AlprResult* result)
|
|||||||
root=cJSON_CreateObject();
|
root=cJSON_CreateObject();
|
||||||
|
|
||||||
cJSON_AddStringToObject(root,"plate", result->bestPlate.characters.c_str());
|
cJSON_AddStringToObject(root,"plate", result->bestPlate.characters.c_str());
|
||||||
cJSON_AddNumberToObject(root,"epoch_time", getEpochTime() );
|
|
||||||
cJSON_AddNumberToObject(root,"confidence", result->bestPlate.overall_confidence);
|
cJSON_AddNumberToObject(root,"confidence", result->bestPlate.overall_confidence);
|
||||||
cJSON_AddNumberToObject(root,"matches_template", result->bestPlate.matches_template);
|
cJSON_AddNumberToObject(root,"matches_template", result->bestPlate.matches_template);
|
||||||
|
|
||||||
|
@@ -62,7 +62,7 @@ class AlprImpl
|
|||||||
void setTopN(int topn);
|
void setTopN(int topn);
|
||||||
void setDefaultRegion(string region);
|
void setDefaultRegion(string region);
|
||||||
|
|
||||||
std::string toJson(const vector<AlprResult> results);
|
std::string toJson(const vector<AlprResult> results, double processing_time_ms = -1);
|
||||||
static std::string getVersion();
|
static std::string getVersion();
|
||||||
|
|
||||||
Config* config;
|
Config* config;
|
||||||
|
Reference in New Issue
Block a user