mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 03:32:56 +08:00
Updated alpr_impl to support detector benchmark
This commit is contained in:
@@ -66,12 +66,12 @@ bool AlprImpl::isLoaded()
|
|||||||
return config->loaded;
|
return config->loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AlprFullDetails AlprImpl::recognizeFullDetails(cv::Mat img)
|
||||||
std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
|
||||||
{
|
{
|
||||||
timespec startTime;
|
timespec startTime;
|
||||||
getTime(&startTime);
|
getTime(&startTime);
|
||||||
|
|
||||||
|
AlprFullDetails response;
|
||||||
|
|
||||||
if (!img.data)
|
if (!img.data)
|
||||||
{
|
{
|
||||||
@@ -80,11 +80,16 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
|||||||
std::cerr << "Invalid image" << std::endl;
|
std::cerr << "Invalid image" << std::endl;
|
||||||
|
|
||||||
vector<AlprResult> emptyVector;
|
vector<AlprResult> emptyVector;
|
||||||
return emptyVector;
|
response.results = emptyVector;
|
||||||
|
|
||||||
|
vector<PlateRegion> emptyVector2;
|
||||||
|
response.plateRegions = emptyVector2;
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find all the candidate regions
|
// Find all the candidate regions
|
||||||
vector<PlateRegion> plateRegions = plateDetector->detect(img);
|
response.plateRegions = plateDetector->detect(img);
|
||||||
|
|
||||||
// Get the number of threads specified and make sure the value is sane (cannot be greater than CPU cores or less than 1)
|
// Get the number of threads specified and make sure the value is sane (cannot be greater than CPU cores or less than 1)
|
||||||
int numThreads = config->multithreading_cores;
|
int numThreads = config->multithreading_cores;
|
||||||
@@ -94,7 +99,7 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
|||||||
numThreads = 1;
|
numThreads = 1;
|
||||||
|
|
||||||
|
|
||||||
PlateDispatcher dispatcher(plateRegions, &img,
|
PlateDispatcher dispatcher(response.plateRegions, &img,
|
||||||
config, stateIdentifier, ocr,
|
config, stateIdentifier, ocr,
|
||||||
topN, detectRegion, defaultRegion);
|
topN, detectRegion, defaultRegion);
|
||||||
|
|
||||||
@@ -123,9 +128,9 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
|||||||
|
|
||||||
if (config->debugGeneral && config->debugShowImages)
|
if (config->debugGeneral && config->debugShowImages)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < plateRegions.size(); i++)
|
for (int i = 0; i < response.plateRegions.size(); i++)
|
||||||
{
|
{
|
||||||
rectangle(img, plateRegions[i].rect, Scalar(0, 0, 255), 2);
|
rectangle(img, response.plateRegions[i].rect, Scalar(0, 0, 255), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < dispatcher.getRecognitionResults().size(); i++)
|
for (int i = 0; i < dispatcher.getRecognitionResults().size(); i++)
|
||||||
@@ -146,7 +151,7 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vector<AlprResult> results = dispatcher.getRecognitionResults();
|
response.results = dispatcher.getRecognitionResults();
|
||||||
|
|
||||||
if (config->debugPauseOnFrame)
|
if (config->debugPauseOnFrame)
|
||||||
{
|
{
|
||||||
@@ -155,7 +160,13 @@ std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
|||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<AlprResult> AlprImpl::recognize(cv::Mat img)
|
||||||
|
{
|
||||||
|
AlprFullDetails fullDetails = recognizeFullDetails(img);
|
||||||
|
return fullDetails.results;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plateAnalysisThread(void* arg)
|
void plateAnalysisThread(void* arg)
|
||||||
|
@@ -48,6 +48,11 @@
|
|||||||
#define ALPR_NULL_PTR 0
|
#define ALPR_NULL_PTR 0
|
||||||
|
|
||||||
|
|
||||||
|
struct AlprFullDetails
|
||||||
|
{
|
||||||
|
std::vector<PlateRegion> plateRegions;
|
||||||
|
std::vector<AlprResult> results;
|
||||||
|
};
|
||||||
|
|
||||||
class AlprImpl
|
class AlprImpl
|
||||||
{
|
{
|
||||||
@@ -56,6 +61,7 @@ class AlprImpl
|
|||||||
AlprImpl(const std::string country, const std::string configFile = "", const std::string runtimeDir = "");
|
AlprImpl(const std::string country, const std::string configFile = "", const std::string runtimeDir = "");
|
||||||
virtual ~AlprImpl();
|
virtual ~AlprImpl();
|
||||||
|
|
||||||
|
AlprFullDetails recognizeFullDetails(cv::Mat img);
|
||||||
std::vector<AlprResult> recognize(cv::Mat img);
|
std::vector<AlprResult> recognize(cv::Mat img);
|
||||||
|
|
||||||
void applyRegionTemplate(AlprResult* result, std::string region);
|
void applyRegionTemplate(AlprResult* result, std::string region);
|
||||||
|
Reference in New Issue
Block a user