Added support for OpenCV 3

This commit is contained in:
Matt Hill
2015-09-12 17:15:02 -04:00
parent 83d6e06e14
commit 32789bfe7a
4 changed files with 32 additions and 7 deletions

View File

@@ -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 )

View File

@@ -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;

View File

@@ -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

View File

@@ -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()