23 lines
664 B
C++
23 lines
664 B
C++
#include "bgremoval.h"
|
|
#include <iostream>
|
|
#include <opencv2/highgui.hpp>
|
|
#include <opencv2/imgproc.hpp>
|
|
#include <opencv2/bgsegm.hpp>
|
|
#include "log.h"
|
|
|
|
bool createMask(const cv::Mat& in, cv::Mat& mask, const cv::Mat& bg)
|
|
{
|
|
if(in.size != bg.size || in.type() != bg.type())
|
|
{
|
|
Log(Log::ERROR)<<"input image and backgournd image size and type needs to be the same";
|
|
return false;
|
|
}
|
|
|
|
cv::Ptr<cv::BackgroundSubtractorMOG2> bgremv = cv::createBackgroundSubtractorMOG2(2,10,false);
|
|
bgremv->apply(bg, mask, 1);
|
|
bgremv->apply(in, mask, 0);
|
|
cv::GaussianBlur(mask,mask,cv::Size(49,49), 15);
|
|
cv::threshold(mask, mask, 70, 255, cv::THRESH_BINARY);
|
|
return true;
|
|
}
|