From 6e3b90de9b12c02e6be93f0f3cde01769cd5078a Mon Sep 17 00:00:00 2001 From: alcinos Date: Thu, 28 Jan 2016 16:26:11 +0100 Subject: [PATCH] Add static creator for TVL1 optical flow class --- modules/core/include/opencv2/core/ptr.inl.hpp | 11 ++++++++++ .../video/include/opencv2/video/tracking.hpp | 15 +++++++++++++ modules/video/src/tvl1flow.cpp | 21 +++++++++++++++++++ modules/video/test/test_tvl1optflow.cpp | 2 +- samples/cpp/tvl1_optical_flow.cpp | 2 +- 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/modules/core/include/opencv2/core/ptr.inl.hpp b/modules/core/include/opencv2/core/ptr.inl.hpp index 3f6f214a8f..8c09d93cd8 100644 --- a/modules/core/include/opencv2/core/ptr.inl.hpp +++ b/modules/core/include/opencv2/core/ptr.inl.hpp @@ -358,6 +358,17 @@ Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)); } +template +Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11) +{ + return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)); +} + +template +Ptr makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11, const A12& a12) +{ + return Ptr(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)); +} } // namespace cv //! @endcond diff --git a/modules/video/include/opencv2/video/tracking.hpp b/modules/video/include/opencv2/video/tracking.hpp index 5afe209ce6..f0993e5f81 100644 --- a/modules/video/include/opencv2/video/tracking.hpp +++ b/modules/video/include/opencv2/video/tracking.hpp @@ -502,6 +502,21 @@ public: virtual int getMedianFiltering() const = 0; /** @copybrief getMedianFiltering @see getMedianFiltering */ virtual void setMedianFiltering(int val) = 0; + + /** @brief Creates instance of cv::DualTVL1OpticalFlow*/ + static Ptr create( + double tau = 0.25, + double lambda = 0.15, + double theta = 0.3, + int nscales = 5, + int warps = 5, + double epsilon = 0.01, + int innnerIterations = 30, + int outerIterations = 10, + double scaleStep = 0.8, + double gamma = 0.0, + int medianFiltering = 5, + bool useInitialFlow = false); }; /** @brief Creates instance of cv::DenseOpticalFlow diff --git a/modules/video/src/tvl1flow.cpp b/modules/video/src/tvl1flow.cpp index b10dc3f344..c0299e5c95 100644 --- a/modules/video/src/tvl1flow.cpp +++ b/modules/video/src/tvl1flow.cpp @@ -89,6 +89,17 @@ namespace { class OpticalFlowDual_TVL1 : public DualTVL1OpticalFlow { public: + + OpticalFlowDual_TVL1(double tau_, double lambda_, double theta_, int nscales_, int warps_, + double epsilon_, int innerIterations_, int outerIterations_, + double scaleStep_, double gamma_, int medianFiltering_, + bool useInitialFlow_) : + tau(tau_), lambda(lambda_), theta(theta_), gamma(gamma_), nscales(nscales_), + warps(warps_), epsilon(epsilon_), innerIterations(innerIterations_), + outerIterations(outerIterations_), useInitialFlow(useInitialFlow_), + scaleStep(scaleStep_), medianFiltering(medianFiltering_) + { + } OpticalFlowDual_TVL1(); void calc(InputArray I0, InputArray I1, InputOutputArray flow); @@ -1450,3 +1461,13 @@ Ptr cv::createOptFlow_DualTVL1() { return makePtr(); } + +Ptr cv::DualTVL1OpticalFlow::create( + double tau, double lambda, double theta, int nscales, int warps, + double epsilon, int innerIterations, int outerIterations, double scaleStep, + double gamma, int medianFilter, bool useInitialFlow) +{ + return makePtr(tau, lambda, theta, nscales, warps, + epsilon, innerIterations, outerIterations, + scaleStep, gamma, medianFilter, useInitialFlow); +} diff --git a/modules/video/test/test_tvl1optflow.cpp b/modules/video/test/test_tvl1optflow.cpp index e4b80637ec..3976f25599 100644 --- a/modules/video/test/test_tvl1optflow.cpp +++ b/modules/video/test/test_tvl1optflow.cpp @@ -154,7 +154,7 @@ TEST(Video_calcOpticalFlowDual_TVL1, Regression) ASSERT_FALSE(frame2.empty()); Mat_ flow; - Ptr tvl1 = createOptFlow_DualTVL1(); + Ptr tvl1 = cv::DualTVL1OpticalFlow::create(); tvl1->calc(frame1, frame2, flow); diff --git a/samples/cpp/tvl1_optical_flow.cpp b/samples/cpp/tvl1_optical_flow.cpp index 55b5558ebe..95871c7298 100644 --- a/samples/cpp/tvl1_optical_flow.cpp +++ b/samples/cpp/tvl1_optical_flow.cpp @@ -185,7 +185,7 @@ int main(int argc, const char* argv[]) } Mat_ flow; - Ptr tvl1 = createOptFlow_DualTVL1(); + Ptr tvl1 = cv::DualTVL1OpticalFlow::create(); const double start = (double)getTickCount(); tvl1->calc(frame0, frame1, flow);