Skip to content

Commit

Permalink
fix for missing gpu.hpp when compiling with opencv 3.x and -D COMPILE…
Browse files Browse the repository at this point in the history
…_GPU=1
  • Loading branch information
wildsheepz committed Jan 16, 2018
1 parent de93f21 commit 3804ebf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/openalpr/detection/detectorcuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);

Expand All @@ -83,4 +101,4 @@ namespace alpr

}

#endif
#endif
9 changes: 8 additions & 1 deletion src/openalpr/detection/detectorcuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
};

}
Expand Down

0 comments on commit 3804ebf

Please sign in to comment.