Commit a3a09cf4 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

refactored OpticalFlowDual_TVL1:

* added DenseOpticalFlow interface
* moved OpticalFlowDual_TVL1 to src folder
parent 2181a41a
......@@ -431,13 +431,13 @@ PERF_TEST_P(ImagePair, Video_OpticalFlowDual_TVL1,
{
cv::Mat flow;
cv::OpticalFlowDual_TVL1 alg;
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1();
alg(frame0, frame1, flow);
alg->calc(frame0, frame1, flow);
TEST_CYCLE()
{
alg(frame0, frame1, flow);
alg->calc(frame0, frame1, flow);
}
CPU_SANITY_CHECK(flow);
......
......@@ -431,9 +431,9 @@ GPU_TEST_P(OpticalFlowDual_TVL1, Accuracy)
cv::gpu::GpuMat d_flowy = createMat(frame0.size(), CV_32FC1, useRoi);
d_alg(loadMat(frame0, useRoi), loadMat(frame1, useRoi), d_flowx, d_flowy);
cv::OpticalFlowDual_TVL1 alg;
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1();
cv::Mat flow;
alg(frame0, frame1, flow);
alg->calc(frame0, frame1, flow);
cv::Mat gold[2];
cv::split(flow, gold);
......
......@@ -643,11 +643,11 @@ See [Tao2012]_. And site of project - http://graphics.berkeley.edu/papers/Tao-SA
OpticalFlowDual_TVL1
--------------------
createOptFlow_DualTVL1
----------------------
"Dual TV L1" Optical Flow Algorithm.
.. ocv:class:: OpticalFlowDual_TVL12
.. ocv:function:: Ptr<DenseOpticalFlow> createOptFlow_DualTVL1()
The class implements the "Dual TV L1" optical flow algorithm described in [Zach2007]_ and [Javier2012]_ .
......@@ -685,11 +685,11 @@ Here are important members of the class that control the algorithm, which you ca
OpticalFlowDual_TVL1::operator()
--------------------------------
DenseOpticalFlow::calc
--------------------------
Calculates an optical flow.
.. ocv:function:: void OpticalFlowDual_TVL1::operator ()(InputArray I0, InputArray I1, InputOutputArray flow)
.. ocv:function:: void DenseOpticalFlow::calc(InputArray I0, InputArray I1, InputOutputArray flow)
:param prev: first 8-bit single-channel input image.
......@@ -699,11 +699,11 @@ Calculates an optical flow.
OpticalFlowDual_TVL1::collectGarbage
------------------------------------
DenseOpticalFlow::collectGarbage
--------------------------------
Releases all inner buffers.
.. ocv:function:: void OpticalFlowDual_TVL1::collectGarbage()
.. ocv:function:: void DenseOpticalFlow::collectGarbage()
......
......@@ -352,104 +352,19 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from,
double upscale_sigma_color,
double speed_up_thr);
class CV_EXPORTS DenseOpticalFlow : public Algorithm
{
public:
virtual void calc(InputArray I0, InputArray I1, InputOutputArray flow) = 0;
virtual void collectGarbage() = 0;
};
// Implementation of the Zach, Pock and Bischof Dual TV-L1 Optical Flow method
//
// see reference:
// [1] C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow".
// [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation".
class CV_EXPORTS OpticalFlowDual_TVL1
{
public:
OpticalFlowDual_TVL1();
void operator ()(InputArray I0, InputArray I1, InputOutputArray flow);
void collectGarbage();
/**
* Time step of the numerical scheme.
*/
double tau;
/**
* Weight parameter for the data term, attachment parameter.
* This is the most relevant parameter, which determines the smoothness of the output.
* The smaller this parameter is, the smoother the solutions we obtain.
* It depends on the range of motions of the images, so its value should be adapted to each image sequence.
*/
double lambda;
/**
* Weight parameter for (u - v)^2, tightness parameter.
* It serves as a link between the attachment and the regularization terms.
* In theory, it should have a small value in order to maintain both parts in correspondence.
* The method is stable for a large range of values of this parameter.
*/
double theta;
/**
* Number of scales used to create the pyramid of images.
*/
int nscales;
/**
* Number of warpings per scale.
* Represents the number of times that I1(x+u0) and grad( I1(x+u0) ) are computed per scale.
* This is a parameter that assures the stability of the method.
* It also affects the running time, so it is a compromise between speed and accuracy.
*/
int warps;
/**
* Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time.
* A small value will yield more accurate solutions at the expense of a slower convergence.
*/
double epsilon;
/**
* Stopping criterion iterations number used in the numerical scheme.
*/
int iterations;
bool useInitialFlow;
private:
void procOneScale(const Mat_<float>& I0, const Mat_<float>& I1, Mat_<float>& u1, Mat_<float>& u2);
std::vector<Mat_<float> > I0s;
std::vector<Mat_<float> > I1s;
std::vector<Mat_<float> > u1s;
std::vector<Mat_<float> > u2s;
Mat_<float> I1x_buf;
Mat_<float> I1y_buf;
Mat_<float> flowMap1_buf;
Mat_<float> flowMap2_buf;
Mat_<float> I1w_buf;
Mat_<float> I1wx_buf;
Mat_<float> I1wy_buf;
Mat_<float> grad_buf;
Mat_<float> rho_c_buf;
Mat_<float> v1_buf;
Mat_<float> v2_buf;
Mat_<float> p11_buf;
Mat_<float> p12_buf;
Mat_<float> p21_buf;
Mat_<float> p22_buf;
Mat_<float> div_p1_buf;
Mat_<float> div_p2_buf;
Mat_<float> u1x_buf;
Mat_<float> u1y_buf;
Mat_<float> u2x_buf;
Mat_<float> u2y_buf;
};
CV_EXPORTS Ptr<DenseOpticalFlow> createOptFlow_DualTVL1();
}
......
......@@ -22,12 +22,9 @@ PERF_TEST_P(ImagePair, OpticalFlowDual_TVL1, testing::Values(impair("cv/optflow/
Mat flow;
OpticalFlowDual_TVL1 tvl1;
Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
TEST_CYCLE()
{
tvl1(frame1, frame2, flow);
}
TEST_CYCLE_N(10) tvl1->calc(frame1, frame2, flow);
SANITY_CHECK(flow, 0.5);
}
This diff is collapsed.
......@@ -152,9 +152,9 @@ TEST(Video_calcOpticalFlowDual_TVL1, Regression)
ASSERT_FALSE(frame2.empty());
Mat_<Point2f> flow;
OpticalFlowDual_TVL1 tvl1;
Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
tvl1(frame1, frame2, flow);
tvl1->calc(frame1, frame2, flow);
#ifdef DUMP
writeOpticalFlowToFile(flow, gold_flow_path);
......
......@@ -173,10 +173,10 @@ int main(int argc, const char* argv[])
}
Mat_<Point2f> flow;
OpticalFlowDual_TVL1 tvl1;
Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
const double start = (double)getTickCount();
tvl1(frame0, frame1, flow);
tvl1->calc(frame0, frame1, flow);
const double timeSec = (getTickCount() - start) / getTickFrequency();
cout << "calcOpticalFlowDual_TVL1 : " << timeSec << " sec" << endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment