mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 01:12:47 +08:00
Started initial support for OpenCL. OpenCV doesn't yet officially support OpenCL LBP GPU acceleration -- but it should be coming soon
This commit is contained in:
@@ -7,6 +7,7 @@ state_id_img_size_percent = 2.0
|
|||||||
max_plate_width_percent = 100
|
max_plate_width_percent = 100
|
||||||
max_plate_height_percent = 100
|
max_plate_height_percent = 100
|
||||||
|
|
||||||
|
opencl_enabled = 0
|
||||||
|
|
||||||
ocr_min_font_point = 6
|
ocr_min_font_point = 6
|
||||||
|
|
||||||
|
@@ -31,6 +31,34 @@ AlprImpl::AlprImpl(const std::string country, const std::string runtimeDir)
|
|||||||
this->topN = DEFAULT_TOPN;
|
this->topN = DEFAULT_TOPN;
|
||||||
this->defaultRegion = "";
|
this->defaultRegion = "";
|
||||||
|
|
||||||
|
if (config->opencl_enabled)
|
||||||
|
{
|
||||||
|
|
||||||
|
cv::ocl::PlatformsInfo platinfo;
|
||||||
|
cv::ocl::getOpenCLPlatforms(platinfo);
|
||||||
|
|
||||||
|
for (int i = 0; i < platinfo.size(); i++)
|
||||||
|
{
|
||||||
|
std::cout << platinfo[i]->platformName << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::ocl::DevicesInfo devices;
|
||||||
|
cv::ocl::getOpenCLDevices(devices, cv::ocl::CVCL_DEVICE_TYPE_CPU);
|
||||||
|
|
||||||
|
for (int i = 0; i < devices.size(); i++)
|
||||||
|
std:: cout << devices[i]->deviceName << std::endl;
|
||||||
|
|
||||||
|
if (devices.size() > 0)
|
||||||
|
{
|
||||||
|
cv::ocl::setDevice(devices[0]);
|
||||||
|
|
||||||
|
cout << "Using OpenCL Device: " << devices[0]->deviceName << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "OpenCL initialization failed. Runtime drivers may not be installed." << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AlprImpl::~AlprImpl()
|
AlprImpl::~AlprImpl()
|
||||||
{
|
{
|
||||||
|
@@ -33,6 +33,8 @@
|
|||||||
#include "cjson.h"
|
#include "cjson.h"
|
||||||
|
|
||||||
#include <opencv2/core/core.hpp>
|
#include <opencv2/core/core.hpp>
|
||||||
|
#include "opencv2/ocl/ocl.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DEFAULT_TOPN 25
|
#define DEFAULT_TOPN 25
|
||||||
|
@@ -70,6 +70,8 @@ Config::~Config()
|
|||||||
|
|
||||||
void Config::loadValues(string country)
|
void Config::loadValues(string country)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
opencl_enabled = getBoolean("common", "opencl_enabled", false);
|
||||||
maxPlateWidthPercent = getFloat("common", "max_plate_width_percent", 100);
|
maxPlateWidthPercent = getFloat("common", "max_plate_width_percent", 100);
|
||||||
maxPlateHeightPercent = getFloat("common", "max_plate_height_percent", 100);
|
maxPlateHeightPercent = getFloat("common", "max_plate_height_percent", 100);
|
||||||
|
|
||||||
|
@@ -43,6 +43,8 @@ class Config
|
|||||||
|
|
||||||
string country;
|
string country;
|
||||||
|
|
||||||
|
bool opencl_enabled;
|
||||||
|
|
||||||
float maxPlateWidthPercent;
|
float maxPlateWidthPercent;
|
||||||
float maxPlateHeightPercent;
|
float maxPlateHeightPercent;
|
||||||
|
|
||||||
|
@@ -28,23 +28,34 @@ RegionDetector::RegionDetector(Config* config)
|
|||||||
// Don't scale. Can change this in the future (i.e., maximum resolution preference, or some such).
|
// Don't scale. Can change this in the future (i.e., maximum resolution preference, or some such).
|
||||||
this->scale_factor = 1.0f;
|
this->scale_factor = 1.0f;
|
||||||
|
|
||||||
|
// Load either the regular or OpenCL version of the cascade classifier
|
||||||
|
if (config->opencl_enabled)
|
||||||
|
{
|
||||||
|
this->plate_cascade = new ocl::OclCascadeClassifier();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->plate_cascade = new CascadeClassifier();
|
||||||
|
}
|
||||||
|
|
||||||
// Load the cascade classifier
|
|
||||||
if( this->plate_cascade.load( config->getCascadeRuntimeDir() + config->country + ".xml" ) )
|
if( this->plate_cascade->load( config->getCascadeRuntimeDir() + config->country + ".xml" ) )
|
||||||
{
|
{
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("--(!)Error loading classifier\n");
|
|
||||||
this->loaded = false;
|
this->loaded = false;
|
||||||
|
printf("--(!)Error loading classifier\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RegionDetector::~RegionDetector()
|
RegionDetector::~RegionDetector()
|
||||||
{
|
{
|
||||||
|
delete this->plate_cascade;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -86,11 +97,19 @@ vector<Rect> RegionDetector::doCascade(Mat frame)
|
|||||||
Size minSize(config->minPlateSizeWidthPx * this->scale_factor, config->minPlateSizeHeightPx * this->scale_factor);
|
Size minSize(config->minPlateSizeWidthPx * this->scale_factor, config->minPlateSizeHeightPx * this->scale_factor);
|
||||||
Size maxSize(w * config->maxPlateWidthPercent * this->scale_factor, h * config->maxPlateHeightPercent * this->scale_factor);
|
Size maxSize(w * config->maxPlateWidthPercent * this->scale_factor, h * config->maxPlateHeightPercent * this->scale_factor);
|
||||||
|
|
||||||
|
if (config->opencl_enabled)
|
||||||
|
{
|
||||||
|
ocl::oclMat openclFrame(frame);
|
||||||
|
((ocl::OclCascadeClassifier*) plate_cascade)->detectMultiScale(openclFrame, plates, 1.1, 3, 0, minSize, maxSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
plate_cascade.detectMultiScale( frame, plates, 1.1, 3,
|
plate_cascade->detectMultiScale( frame, plates, 1.1, 3,
|
||||||
0,
|
0,
|
||||||
//0|CV_HAAR_SCALE_IMAGE,
|
//0|CV_HAAR_SCALE_IMAGE,
|
||||||
minSize, maxSize );
|
minSize, maxSize );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (config->debugTiming)
|
if (config->debugTiming)
|
||||||
|
@@ -30,7 +30,8 @@
|
|||||||
#include "opencv2/imgproc/imgproc.hpp"
|
#include "opencv2/imgproc/imgproc.hpp"
|
||||||
#include "opencv2/core/core.hpp"
|
#include "opencv2/core/core.hpp"
|
||||||
#include "opencv2/ml/ml.hpp"
|
#include "opencv2/ml/ml.hpp"
|
||||||
#include "opencv2/highgui/highgui.hpp"
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
|
#include "opencv2/ocl/ocl.hpp"
|
||||||
|
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include "support/timing.h"
|
#include "support/timing.h"
|
||||||
@@ -54,8 +55,8 @@ class RegionDetector
|
|||||||
Config* config;
|
Config* config;
|
||||||
|
|
||||||
float scale_factor;
|
float scale_factor;
|
||||||
CascadeClassifier plate_cascade;
|
CascadeClassifier* plate_cascade;
|
||||||
CvSVM* svmClassifier;
|
|
||||||
bool loaded;
|
bool loaded;
|
||||||
|
|
||||||
vector<Rect> doCascade(Mat frame);
|
vector<Rect> doCascade(Mat frame);
|
||||||
|
Reference in New Issue
Block a user