diff --git a/examples/tracking/track_conf.json b/examples/tracking/track_conf.json index efe7acae1b86ed32c4c96ddf598bca66b85bf1ea..7040981408e346061e7d64de93d131c11c445aff 100644 --- a/examples/tracking/track_conf.json +++ b/examples/tracking/track_conf.json @@ -1,7 +1,7 @@ { "ball_log_lh": { "type": "cb_log_reg", - "conf": { + "conf": { "weights": [ -4.3645153397769523, -1.7528550846385467, @@ -31,7 +31,11 @@ -5.4301792573145677, -4.7388290757015756, -5.739125161010926 - ] + ], + "gauss_smooth": { + "size": 5, + "sigma": 0 + } } }, "binarizer": { diff --git a/src/tracker.cpp b/src/tracker.cpp index 604d7c4fe12a1146bc8680a5951dc48fd9bc9cf3..d199c6ce058f6af9ccfe03d7ab56817fc3bbb93d 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -16,6 +16,23 @@ namespace ball_tracking { */ namespace { + class GaussSmooth { + private: + int size; + double sigma; + public: + GaussSmooth(const json& conf) { + size = conf.at("size"); + sigma = conf.at("sigma"); + } + + cv::Mat operator()(cv::InputArray _src) { + Mat dst; + GaussianBlur(_src, dst, Size(size,size), sigma, sigma); + return dst; + } + }; + /** * Color and background based logistic regression */ @@ -23,18 +40,32 @@ namespace ball_tracking { private: Mat bkg; //!< Background image Mat weights; //!< Model weights + vector<preproc> pre; //!< Preprocessing functions for the images public: - cv::Mat operator()(cv::InputArray src) { + + Mat pre_chain(cv::InputArray src) { + Mat tmp = src.getMat(); + for (auto p : pre) { + tmp = p(tmp); + } + return tmp; + } + + cv::Mat operator()(cv::InputArray _src) { + Mat src = pre_chain(_src); if (bkg.empty()) { - bkg = src.getMat(); + bkg = src; } return quadf_log_reg(src, bkg, weights); } CB_log_reg(const json& conf) { weights = json2cvmat(conf.at("weights")); + if (conf.count("gauss_smooth")) { + pre.push_back(GaussSmooth(conf.at("gauss_smooth"))); + } if (conf.count("background")) { - bkg = imread(conf.at("background"), CV_LOAD_IMAGE_COLOR); + bkg = pre_chain( imread(conf.at("background"), CV_LOAD_IMAGE_COLOR) ); if (!bkg.data) { throw std::logic_error("File not found for background image"); }