diff --git a/Demo.cpp b/Demo.cpp index b23bbb1248d4645ded1e1b4f9ef4d4fb4ee8d2e4..f48654d679050c189ea901e6b186816227797d21 100644 --- a/Demo.cpp +++ b/Demo.cpp @@ -18,8 +18,8 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>. #include <opencv2/opencv.hpp> using namespace cv; -//#include "package_bgs/bgslibrary.h" -#include "package_bgs/IBGS.h" +#include "package_bgs/bgslibrary.h" + using namespace ibgs; int main(int argc, char **argv) @@ -45,8 +45,7 @@ int main(int argc, char **argv) /* Background Subtraction Methods */ IBGS *bgs; - //bgs = new FrameDifference; - bgs=IBGS::create(std::string("FrameDifference")); + bgs = new FrameDifference; //bgs = new StaticFrameDifference; //bgs = new WeightedMovingMean; //bgs = new WeightedMovingVariance; diff --git a/package_bgs/IBGS.h b/package_bgs/IBGS.h index bfedeffeecb1d013c57feb3c10518ac409bdf130..436594284134f4b088a733051e345576b7a5c556 100644 --- a/package_bgs/IBGS.h +++ b/package_bgs/IBGS.h @@ -27,63 +27,58 @@ along with BGSLibrary. If not, see <http://www.gnu.org/licenses/>. #define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0) - - namespace bgslibrary { - namespace algorithms - { - class IBGS - { - public: - void setShowOutput(const bool _showOutput) { - showOutput = _showOutput; - } - cv::Mat apply(const cv::Mat &img_input) { - setShowOutput(false); - cv::Mat _img_foreground; - cv::Mat _img_background; - process(img_input, _img_foreground, _img_background); + namespace algorithms + { + class IBGS + { + public: + void setShowOutput(const bool _showOutput) { + showOutput = _showOutput; + } + cv::Mat apply(const cv::Mat &img_input) { + setShowOutput(false); + cv::Mat _img_foreground; + cv::Mat _img_background; + process(img_input, _img_foreground, _img_background); _img_background.copyTo(img_background); - return _img_foreground; - } - cv::Mat getBackgroundModel() { - return img_background; - } - virtual void process(const cv::Mat &img_input, cv::Mat &img_foreground, cv::Mat &img_background) = 0; - virtual ~IBGS() {} - // create by name - static IBGS* create(const std::string alg_name); - static std::list<std::string> get_algs_name(); - protected: - bool firstTime = true; - bool showOutput = true; - cv::Mat img_background; - cv::Mat img_foreground; - std::string config_xml; - void setup(const std::string _config_xml) { - config_xml = _config_xml; - if (!config_xml.empty()) { - if (!std::ifstream(config_xml)) - saveConfig(); - loadConfig(); - } - } - void init(const cv::Mat &img_input, cv::Mat &img_outfg, cv::Mat &img_outbg) { - assert(img_input.empty() == false); - //img_outfg = cv::Mat::zeros(img_input.size(), img_input.type()); - //img_outbg = cv::Mat::zeros(img_input.size(), img_input.type()); - img_outfg = cv::Mat::zeros(img_input.size(), CV_8UC1); - img_outbg = cv::Mat::zeros(img_input.size(), CV_8UC3); - } - - private: - virtual void saveConfig() = 0; - virtual void loadConfig() = 0; - }; - } + return _img_foreground; + } + cv::Mat getBackgroundModel() { + return img_background; + } + virtual void process(const cv::Mat &img_input, cv::Mat &img_foreground, cv::Mat &img_background) = 0; + virtual ~IBGS() {} + //static IBGS* create(const std::string alg_name); + //static std::list<std::string> get_algs_name(); + protected: + bool firstTime = true; + bool showOutput = true; + cv::Mat img_background; + cv::Mat img_foreground; + std::string config_xml; + void setup(const std::string _config_xml) { + config_xml = _config_xml; + if (!config_xml.empty()) { + if (!std::ifstream(config_xml)) + saveConfig(); + loadConfig(); + } + } + void init(const cv::Mat &img_input, cv::Mat &img_outfg, cv::Mat &img_outbg) { + assert(img_input.empty() == false); + //img_outfg = cv::Mat::zeros(img_input.size(), img_input.type()); + //img_outbg = cv::Mat::zeros(img_input.size(), img_input.type()); + img_outfg = cv::Mat::zeros(img_input.size(), CV_8UC1); + img_outbg = cv::Mat::zeros(img_input.size(), CV_8UC3); + } + + private: + virtual void saveConfig() = 0; + virtual void loadConfig() = 0; + }; + } } namespace ibgs = bgslibrary::algorithms; - -