From 33e35c082a2a29101f6dc2094230e7a4e47bee10 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 10 Nov 2018 11:04:35 +0000 Subject: [PATCH 1/3] text: reset counters in ERFilterNM::run() --- modules/text/include/opencv2/text/erfilter.hpp | 2 +- modules/text/src/erfilter.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/text/include/opencv2/text/erfilter.hpp b/modules/text/include/opencv2/text/erfilter.hpp index c9bac2b32..d83beb0d4 100644 --- a/modules/text/include/opencv2/text/erfilter.hpp +++ b/modules/text/include/opencv2/text/erfilter.hpp @@ -159,7 +159,7 @@ public: virtual void setMinProbability(float minProbability) = 0; virtual void setMinProbabilityDiff(float minProbabilityDiff) = 0; virtual void setNonMaxSuppression(bool nonMaxSuppression) = 0; - virtual int getNumRejected() = 0; + virtual int getNumRejected() const = 0; }; diff --git a/modules/text/src/erfilter.cpp b/modules/text/src/erfilter.cpp index 529aced13..5214514aa 100644 --- a/modules/text/src/erfilter.cpp +++ b/modules/text/src/erfilter.cpp @@ -145,7 +145,7 @@ public: void setMinProbability(float minProbability) CV_OVERRIDE; void setMinProbabilityDiff(float minProbabilityDiff) CV_OVERRIDE; void setNonMaxSuppression(bool nonMaxSuppression) CV_OVERRIDE; - int getNumRejected() CV_OVERRIDE; + int getNumRejected() const CV_OVERRIDE; private: // pointer to the input/output regions vector @@ -223,6 +223,8 @@ ERFilterNM::ERFilterNM() // input/output for the second one. void ERFilterNM::run( InputArray image, vector& _regions ) { + num_rejected_regions=0; + num_accepted_regions=0; // assert correct image type CV_Assert( image.getMat().type() == CV_8UC1 ); @@ -999,7 +1001,7 @@ void ERFilterNM::setNonMaxSuppression(bool _nonMaxSuppression) return; } -int ERFilterNM::getNumRejected() +int ERFilterNM::getNumRejected() const { return num_rejected_regions; } From ccd99930998783d205a0a10a2aca66403ab256cd Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Tue, 13 Nov 2018 18:25:58 +0100 Subject: [PATCH 2/3] ovis: allow re-initialization by destroying all windows --- modules/ovis/src/ovis.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/ovis/src/ovis.cpp b/modules/ovis/src/ovis.cpp index cd2b299ce..d9592ba91 100644 --- a/modules/ovis/src/ovis.cpp +++ b/modules/ovis/src/ovis.cpp @@ -236,6 +236,8 @@ struct Application : public OgreBites::ApplicationContext, public OgreBites::Inp return ret; } + size_t numWindows() const { return mWindows.size(); } + void locateResources() CV_OVERRIDE { OgreBites::ApplicationContext::locateResources(); @@ -277,9 +279,10 @@ class WindowSceneImpl : public WindowScene Ptr bgplane; Ogre::RenderTarget* depthRTT; + int flags; public: - WindowSceneImpl(Ptr app, const String& _title, const Size& sz, int flags) - : title(_title), root(app->getRoot()), depthRTT(NULL) + WindowSceneImpl(Ptr app, const String& _title, const Size& sz, int _flags) + : title(_title), root(app->getRoot()), depthRTT(NULL), flags(_flags) { if (!app->sceneMgr) { @@ -337,6 +340,25 @@ public: rWin->addViewport(cam); } + ~WindowSceneImpl() + { + if (flags & SCENE_SEPERATE) + { + MaterialManager::getSingleton().remove(bgplane->getMaterial()); + bgplane.release(); + String texName = sceneMgr->getName() + "_Background"; + TextureManager::getSingleton().remove(texName, RESOURCEGROUP_NAME); + } + + if(_app->sceneMgr == sceneMgr && (flags & SCENE_SEPERATE)) + { + // this is the root window owning the context + CV_Assert(_app->numWindows() == 1 && "the first OVIS window must be deleted last"); + _app->closeApp(); + _app.release(); + } + } + void setBackground(InputArray image) CV_OVERRIDE { CV_Assert(bgplane); From a97a0612818cbfb4a91fa9d78f3e85151ba079a4 Mon Sep 17 00:00:00 2001 From: Jukka Komulainen Date: Fri, 16 Nov 2018 20:44:53 +0200 Subject: [PATCH 3/3] Merge pull request #1906 from ytyytyyt:3.4 * fbs_filter add lambda & revise imtypes * fix warnings * fix fbs function prototypes --- .../include/opencv2/ximgproc/edge_filter.hpp | 36 ++++++++------ .../ximgproc/samples/disparity_filtering.cpp | 7 ++- modules/ximgproc/src/fbs_filter.cpp | 47 ++++++++++++------- 3 files changed, 58 insertions(+), 32 deletions(-) diff --git a/modules/ximgproc/include/opencv2/ximgproc/edge_filter.hpp b/modules/ximgproc/include/opencv2/ximgproc/edge_filter.hpp index c6fe6525d..8388d1ab8 100644 --- a/modules/ximgproc/include/opencv2/ximgproc/edge_filter.hpp +++ b/modules/ximgproc/include/opencv2/ximgproc/edge_filter.hpp @@ -375,7 +375,7 @@ void rollingGuidanceFilter(InputArray src, OutputArray dst, int d = -1, double s ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -/** @brief Interface for implementations of The Fast Bilateral Solver. +/** @brief Interface for implementations of Fast Bilateral Solver. For more details about this solver see @cite BarronPoole2016 . */ @@ -389,6 +389,8 @@ public: @param confidence confidence image with unsigned 8-bit or floating-point 32-bit confidence and 1 channel. @param dst destination image. + + @note Confidence images with CV_8U depth are expected to in [0, 255] and CV_32F in [0, 1] range. */ CV_WRAP virtual void filter(InputArray src, InputArray confidence, OutputArray dst) = 0; }; @@ -397,20 +399,23 @@ public: @param guide image serving as guide for filtering. It should have 8-bit depth and either 1 or 3 channels. -@param sigma_spatial parameter, that is similar to spatial space sigma in bilateralFilter. +@param sigma_spatial parameter, that is similar to spatial space sigma (bandwidth) in bilateralFilter. -@param sigma_luma parameter, that is similar to luma space sigma in bilateralFilter. +@param sigma_luma parameter, that is similar to luma space sigma (bandwidth) in bilateralFilter. -@param sigma_chroma parameter, that is similar to chroma space sigma in bilateralFilter. +@param sigma_chroma parameter, that is similar to chroma space sigma (bandwidth) in bilateralFilter. -@param num_iter number of iterations used for solving, 25 is usually enough. +@param lambda smoothness strength parameter for solver. -@param max_tol solving tolerance used for solving. +@param num_iter number of iterations used for solver, 25 is usually enough. + +@param max_tol convergence tolerance used for solver. For more details about the Fast Bilateral Solver parameters, see the original paper @cite BarronPoole2016. */ -CV_EXPORTS_W Ptr createFastBilateralSolverFilter(InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter = 25, double max_tol = 1e-5); +CV_EXPORTS_W Ptr createFastBilateralSolverFilter(InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda = 128.0, int num_iter = 25, double max_tol = 1e-5); + /** @brief Simple one-line Fast Bilateral Solver filter call. If you have multiple images to filter with the same guide then use FastBilateralSolverFilter interface to avoid extra computations. @@ -423,24 +428,27 @@ guide then use FastBilateralSolverFilter interface to avoid extra computations. @param dst destination image. -@param sigma_spatial parameter, that is similar to spatial space sigma in bilateralFilter. +@param sigma_spatial parameter, that is similar to spatial space sigma (bandwidth) in bilateralFilter. -@param sigma_luma parameter, that is similar to luma space sigma in bilateralFilter. +@param sigma_luma parameter, that is similar to luma space sigma (bandwidth) in bilateralFilter. -@param sigma_chroma parameter, that is similar to chroma space sigma in bilateralFilter. +@param sigma_chroma parameter, that is similar to chroma space sigma (bandwidth) in bilateralFilter. -@param num_iter number of iterations used for solving, 25 is usually enough. +@param lambda smoothness strength parameter for solver. -@param max_tol solving tolerance used for solving. +@param num_iter number of iterations used for solver, 25 is usually enough. + +@param max_tol convergence tolerance used for solver. + +For more details about the Fast Bilateral Solver parameters, see the original paper @cite BarronPoole2016. @note Confidence images with CV_8U depth are expected to in [0, 255] and CV_32F in [0, 1] range. */ -CV_EXPORTS_W void fastBilateralSolverFilter(InputArray guide, InputArray src, InputArray confidence, OutputArray dst, double sigma_spatial = 8, double sigma_luma = 8, double sigma_chroma = 8, int num_iter = 25, double max_tol = 1e-5); +CV_EXPORTS_W void fastBilateralSolverFilter(InputArray guide, InputArray src, InputArray confidence, OutputArray dst, double sigma_spatial = 8, double sigma_luma = 8, double sigma_chroma = 8, double lambda = 128.0, int num_iter = 25, double max_tol = 1e-5); ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// - /** @brief Interface for implementations of Fast Global Smoother filter. For more details about this filter see @cite Min2014 and @cite Farbman2008 . diff --git a/modules/ximgproc/samples/disparity_filtering.cpp b/modules/ximgproc/samples/disparity_filtering.cpp index 89dd9adc1..ea06fb77a 100644 --- a/modules/ximgproc/samples/disparity_filtering.cpp +++ b/modules/ximgproc/samples/disparity_filtering.cpp @@ -34,6 +34,7 @@ const String keys = "{fbs_spatial |16.0 | parameter of fbs post-filtering }" "{fbs_luma |8.0 | parameter of fbs post-filtering }" "{fbs_chroma |8.0 | parameter of fbs post-filtering }" + "{fbs_lambda |128.0 | parameter of fbs post-filtering }" ; int main(int argc, char** argv) @@ -63,6 +64,7 @@ int main(int argc, char** argv) double fbs_spatial = parser.get("fbs_spatial"); double fbs_luma = parser.get("fbs_luma"); double fbs_chroma = parser.get("fbs_chroma"); + double fbs_lambda = parser.get("fbs_lambda"); double vis_mult = parser.get("vis_mult"); int wsize; @@ -294,17 +296,18 @@ int main(int argc, char** argv) #ifdef HAVE_EIGEN //! [filtering_fbs] solving_time = (double)getTickCount(); - fastBilateralSolverFilter(left, left_disp_resized, conf_map/255.0f, solved_disp, fbs_spatial, fbs_luma, fbs_chroma); + fastBilateralSolverFilter(left, left_disp_resized, conf_map/255.0f, solved_disp, fbs_spatial, fbs_luma, fbs_chroma, fbs_lambda); solving_time = ((double)getTickCount() - solving_time)/getTickFrequency(); //! [filtering_fbs] //! [filtering_wls2fbs] - fastBilateralSolverFilter(left, filtered_disp, conf_map/255.0f, solved_filtered_disp, fbs_spatial, fbs_luma, fbs_chroma); + fastBilateralSolverFilter(left, filtered_disp, conf_map/255.0f, solved_filtered_disp, fbs_spatial, fbs_luma, fbs_chroma, fbs_lambda); //! [filtering_wls2fbs] #else (void)fbs_spatial; (void)fbs_luma; (void)fbs_chroma; + (void)fbs_lambda; #endif } diff --git a/modules/ximgproc/src/fbs_filter.cpp b/modules/ximgproc/src/fbs_filter.cpp index e88551e52..5f88cc2f2 100644 --- a/modules/ximgproc/src/fbs_filter.cpp +++ b/modules/ximgproc/src/fbs_filter.cpp @@ -77,19 +77,19 @@ namespace ximgproc { public: - static Ptr create(InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol) + static Ptr create(InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol) { CV_Assert(guide.type() == CV_8UC1 || guide.type() == CV_8UC3); FastBilateralSolverFilterImpl *fbs = new FastBilateralSolverFilterImpl(); Mat gui = guide.getMat(); - fbs->init(gui,sigma_spatial,sigma_luma,sigma_chroma,num_iter,max_tol); + fbs->init(gui,sigma_spatial,sigma_luma,sigma_chroma,lambda,num_iter,max_tol); return Ptr(fbs); } void filter(InputArray src, InputArray confidence, OutputArray dst) CV_OVERRIDE { - CV_Assert(!src.empty() && (src.depth() == CV_8U || src.depth() == CV_16S || src.depth() == CV_32F) && src.channels()<=4); + CV_Assert(!src.empty() && (src.depth() == CV_8U || src.depth() == CV_16S || src.depth() == CV_16U || src.depth() == CV_32F) && src.channels()<=4); CV_Assert(!confidence.empty() && (confidence.depth() == CV_8U || confidence.depth() == CV_32F) && confidence.channels()==1); if (src.rows() != rows || src.cols() != cols) { @@ -133,7 +133,7 @@ namespace ximgproc // protected: void solve(cv::Mat& src, cv::Mat& confidence, cv::Mat& dst); - void init(cv::Mat& reference, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol); + void init(cv::Mat& reference, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol); void Splat(Eigen::VectorXf& input, Eigen::VectorXf& dst); void Blur(Eigen::VectorXf& input, Eigen::VectorXf& dst); @@ -174,8 +174,8 @@ namespace ximgproc grid_params() { spatialSigma = 8.0; - lumaSigma = 4.0; - chromaSigma = 4.0; + lumaSigma = 8.0; + chromaSigma = 8.0; } }; @@ -201,9 +201,10 @@ namespace ximgproc - void FastBilateralSolverFilterImpl::init(cv::Mat& reference, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol) + void FastBilateralSolverFilterImpl::init(cv::Mat& reference, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol) { + bs_param.lam = lambda; bs_param.cg_maxiter = num_iter; bs_param.cg_tol = max_tol; @@ -266,7 +267,6 @@ namespace ximgproc // construct Blur matrices Eigen::VectorXf ones_nvertices = Eigen::VectorXf::Ones(nvertices); - Eigen::VectorXf ones_npixels = Eigen::VectorXf::Ones(npixels); diagonal(ones_nvertices,blurs); blurs *= 10; for(int offset = -1; offset <= 1;++offset) @@ -379,7 +379,6 @@ namespace ximgproc // construct Blur matrices Eigen::VectorXf ones_nvertices = Eigen::VectorXf::Ones(nvertices); - Eigen::VectorXf ones_npixels = Eigen::VectorXf::Ones(npixels); diagonal(ones_nvertices,blurs); blurs *= 10; for(int offset = -1; offset <= 1;++offset) @@ -486,6 +485,14 @@ namespace ximgproc x(i) = (cv::saturate_cast(pft[i])+32768.0f)/65535.0f; } } + else if(target.depth() == CV_16U) + { + const uint16_t *pft = reinterpret_cast(target.data); + for (int i = 0; i < npixels; i++) + { + x(i) = cv::saturate_cast(pft[i])/65535.0f; + } + } else if(target.depth() == CV_8U) { const uchar *pft = reinterpret_cast(target.data); @@ -566,7 +573,15 @@ namespace ximgproc int16_t *pftar = (int16_t*) output.data; for (int i = 0; i < int(splat_idx.size()); i++) { - pftar[i] = cv::saturate_cast(y(splat_idx[i]) * 65535.0f - 32768.0f); + pftar[i] = cv::saturate_cast(y(splat_idx[i]) * 65535.0f - 32768.0f); + } + } + else if(target.depth() == CV_16U) + { + uint16_t *pftar = (uint16_t*) output.data; + for (int i = 0; i < int(splat_idx.size()); i++) + { + pftar[i] = cv::saturate_cast(y(splat_idx[i]) * 65535.0f); } } else if (target.depth() == CV_8U) @@ -592,14 +607,14 @@ namespace ximgproc //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// -Ptr createFastBilateralSolverFilter(InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol) +Ptr createFastBilateralSolverFilter(InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol) { - return Ptr(FastBilateralSolverFilterImpl::create(guide, sigma_spatial, sigma_luma, sigma_chroma, num_iter, max_tol)); + return Ptr(FastBilateralSolverFilterImpl::create(guide, sigma_spatial, sigma_luma, sigma_chroma, lambda, num_iter, max_tol)); } -void fastBilateralSolverFilter(InputArray guide, InputArray src, InputArray confidence, OutputArray dst, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol) +void fastBilateralSolverFilter(InputArray guide, InputArray src, InputArray confidence, OutputArray dst, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol) { - Ptr fbs = createFastBilateralSolverFilter(guide, sigma_spatial, sigma_luma, sigma_chroma, num_iter, max_tol); + Ptr fbs = createFastBilateralSolverFilter(guide, sigma_spatial, sigma_luma, sigma_chroma, lambda, num_iter, max_tol); fbs->filter(src, confidence, dst); } @@ -614,12 +629,12 @@ namespace cv namespace ximgproc { -Ptr createFastBilateralSolverFilter(InputArray, double, double, double, int, double) +Ptr createFastBilateralSolverFilter(InputArray, double, double, double, double, int, double) { CV_Error(Error::StsNotImplemented, "createFastBilateralSolverFilter : needs to be compiled with EIGEN"); } -void fastBilateralSolverFilter(InputArray, InputArray, InputArray, OutputArray, double, double, double, int, double) +void fastBilateralSolverFilter(InputArray, InputArray, InputArray, OutputArray, double, double, double, double, int, double) { CV_Error(Error::StsNotImplemented, "fastBilateralSolverFilter : needs to be compiled with EIGEN"); }