Merge pull request #616 from wildsheepz/master

Fix missing gpu.hpp when compiling with opencv 3.x and -D COMPILE_GPU=1
This commit is contained in:
Matthew Hill
2018-01-30 09:35:59 -05:00
committed by GitHub
2 changed files with 28 additions and 3 deletions

View File

@@ -31,8 +31,11 @@ namespace alpr
DetectorCUDA::DetectorCUDA(Config* config, PreWarp* prewarp) : Detector(config, prewarp) {
#if OPENCV_MAJOR_VERSION == 2
if( this->cuda_cascade.load( get_detector_file() ) )
#else
if( this->cuda_cascade->create( get_detector_file() ) )
#endif
{
this->loaded = true;
printf("--(!)Loaded CUDA classifier\n");
@@ -56,13 +59,28 @@ namespace alpr
timespec startTime;
getTimeMonotonic(&startTime);
#if OPENCV_MAJOR_VERSION == 2
gpu::GpuMat cudaFrame, plateregions_buffer;
#else
cuda::GpuMat cudaFrame, plateregions_buffer;
#endif
Mat plateregions_downloaded;
cudaFrame.upload(frame);
#if OPENCV_MAJOR_VERSION == 2
int numdetected = cuda_cascade.detectMultiScale(cudaFrame, plateregions_buffer,
(double) config->detection_iteration_increase, config->detectionStrictness,
min_plate_size);
#else
cuda_cascade->setScaleFactor((double) config->detection_iteration_increase);
cuda_cascade->setMinNeighbors(config->detectionStrictness);
cuda_cascade->setMinObjectSize(min_plate_size);
cuda_cascade->detectMultiScale(cudaFrame,
plateregions_buffer);
std::vector<Rect> detected;
cuda_cascade->convert(plateregions_buffer, detected);
int numdetected = detected.size();
#endif
plateregions_buffer.colRange(0, numdetected).download(plateregions_downloaded);
@@ -83,4 +101,4 @@ namespace alpr
}
#endif
#endif

View File

@@ -29,7 +29,11 @@
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/ml/ml.hpp"
#if OPENCV_MAJOR_VERSION == 2
#include "opencv2/gpu/gpu.hpp"
#else
#include "opencv2/cudaobjdetect.hpp"
#endif
#include "detector.h"
#include "detectorcpu.h"
@@ -48,8 +52,11 @@ namespace alpr
private:
#if OPENCV_MAJOR_VERSION == 2
cv::gpu::CascadeClassifier_GPU cuda_cascade;
#else
cv::Ptr<cv::cuda::CascadeClassifier> cuda_cascade;
#endif
};
}