Motion detector compatible with OpenCV 2.4.x

This commit is contained in:
Kees-V
2015-05-13 16:08:03 +02:00
parent 9fc8965a32
commit a107071c77

View File

@@ -4,7 +4,7 @@ using namespace cv;
MotionDetector::MotionDetector() MotionDetector::MotionDetector()
{ {
pMOG2 = cv::createBackgroundSubtractorMOG2(); pMOG2 = new BackgroundSubtractorMOG2();
} }
MotionDetector::~MotionDetector() MotionDetector::~MotionDetector()
@@ -14,7 +14,7 @@ MotionDetector::~MotionDetector()
void MotionDetector::ResetMotionDetection(cv::Mat* frame) void MotionDetector::ResetMotionDetection(cv::Mat* frame)
{ {
pMOG2->apply(*frame, fgMaskMOG2, 1); pMOG2->operator()(*frame, fgMaskMOG2, 1);
} }
cv::Rect MotionDetector::MotionDetect(cv::Mat* frame) cv::Rect MotionDetector::MotionDetect(cv::Mat* frame)
@@ -27,7 +27,7 @@ cv::Rect MotionDetector::MotionDetect(cv::Mat* frame)
cv::Rect largest_rect, rect_temp; cv::Rect largest_rect, rect_temp;
// Detect motion // Detect motion
pMOG2->apply(*frame, fgMaskMOG2, -1); pMOG2->operator()(*frame, fgMaskMOG2, -1);
//Remove noise //Remove noise
cv::erode(fgMaskMOG2, fgMaskMOG2, getStructuringElement(cv::MORPH_RECT, cv::Size(6, 6))); cv::erode(fgMaskMOG2, fgMaskMOG2, getStructuringElement(cv::MORPH_RECT, cv::Size(6, 6)));
// Find the contours of motion areas in the image // Find the contours of motion areas in the image