diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a89c54..9cf7ec3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,16 +59,18 @@ include_directories(${Tesseract_INCLUDE_DIRS}) # Discover OpenCV directory automatically find_path(OpenCV_DIR NAMES OpenCVConfig.cmake - HINTS ${CMAKE_SOURCE_DIR}/../libraries/opencv/) - + HINTS ${CMAKE_SOURCE_DIR}/../libraries/opencv/OpenCVConfig.cmake +) # Opencv Package FIND_PACKAGE( OpenCV REQUIRED ) IF (${OpenCV_VERSION} VERSION_LESS 2.4.7) MESSAGE(FATAL_ERROR "OpenCV version is not compatible : ${OpenCV_VERSION}") ENDIF() -IF (${OpenCV_VERSION} VERSION_GREATER 2.4.12) - MESSAGE(FATAL_ERROR "OpenCV version is not compatible : ${OpenCV_VERSION}") -ENDIF() + +include_directories(${OpenCV_INCLUDE_DIRS}) + +add_definitions( -DOPENCV_MAJOR_VERSION=${OpenCV_VERSION_MAJOR}) + include_directories(./openalpr ) diff --git a/src/openalpr/edges/platelines.cpp b/src/openalpr/edges/platelines.cpp index 9a5798f..db06cda 100644 --- a/src/openalpr/edges/platelines.cpp +++ b/src/openalpr/edges/platelines.cpp @@ -59,7 +59,7 @@ namespace alpr // Do a bilateral filter to clean the noise but keep edges sharp Mat smoothed(inputImage.size(), inputImage.type()); - adaptiveBilateralFilter(inputImage, smoothed, Size(3,3), 45, 45); + bilateralFilter(inputImage, smoothed, 3, 45, 45); int morph_elem = 2; diff --git a/src/openalpr/motiondetector.cpp b/src/openalpr/motiondetector.cpp index c28b051..faa1459 100644 --- a/src/openalpr/motiondetector.cpp +++ b/src/openalpr/motiondetector.cpp @@ -7,7 +7,12 @@ namespace alpr MotionDetector::MotionDetector() { + #if OPENCV_MAJOR_VERSION == 2 pMOG2 = new BackgroundSubtractorMOG2(); + #else + // OpenCV 3 + pMOG2 = createBackgroundSubtractorMOG2(); + #endif } MotionDetector::~MotionDetector() @@ -17,7 +22,12 @@ MotionDetector::~MotionDetector() void MotionDetector::ResetMotionDetection(cv::Mat* frame) { +#if OPENCV_MAJOR_VERSION == 2 pMOG2->operator()(*frame, fgMaskMOG2, 1); +#else + // OpenCV 3 + pMOG2->apply(*frame, fgMaskMOG2, 1); +#endif } cv::Rect MotionDetector::MotionDetect(cv::Mat* frame) @@ -30,7 +40,14 @@ cv::Rect MotionDetector::MotionDetect(cv::Mat* frame) cv::Rect largest_rect, rect_temp; // Detect motion + +#if OPENCV_MAJOR_VERSION == 2 pMOG2->operator()(*frame, fgMaskMOG2, -1); +#else + // OpenCV 3 + pMOG2->apply(*frame, fgMaskMOG2); +#endif + //Remove noise cv::erode(fgMaskMOG2, fgMaskMOG2, getStructuringElement(cv::MORPH_RECT, cv::Size(6, 6))); // Find the contours of motion areas in the image diff --git a/src/statedetection/featurematcher.cpp b/src/statedetection/featurematcher.cpp index 42f1b33..0b8fb5d 100644 --- a/src/statedetection/featurematcher.cpp +++ b/src/statedetection/featurematcher.cpp @@ -35,9 +35,15 @@ namespace alpr this->descriptorMatcher = new BFMatcher(NORM_HAMMING, false); //this->descriptorMatcher = DescriptorMatcher::create( "FlannBased" ); - +#if OPENCV_MAJOR_VERSION == 2 this->detector = new FastFeatureDetector(10, true); this->extractor = new BRISK(10, 1, 0.9); +#else + // OpenCV 3 + this->detector = FastFeatureDetector::create(); + this->extractor = BRISK::create(10, 1, 0.9); +#endif + } FeatureMatcher::~FeatureMatcher()