refactored OpticalFlowDual_TVL1:

* added DenseOpticalFlow interface
* moved OpticalFlowDual_TVL1 to src folder
pull/485/head
Vladislav Vinogradov 12 years ago
parent 2181a41a07
commit a3a09cf4d1
  1. 6
      modules/gpu/perf/perf_video.cpp
  2. 4
      modules/gpu/test/test_optflow.cpp
  3. 18
      modules/video/doc/motion_analysis_and_object_tracking.rst
  4. 101
      modules/video/include/opencv2/video/tracking.hpp
  5. 7
      modules/video/perf/perf_tvl1optflow.cpp
  6. 956
      modules/video/src/tvl1flow.cpp
  7. 4
      modules/video/test/test_tvl1optflow.cpp
  8. 4
      samples/cpp/tvl1_optical_flow.cpp

@ -431,13 +431,13 @@ PERF_TEST_P(ImagePair, Video_OpticalFlowDual_TVL1,
{ {
cv::Mat flow; 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() TEST_CYCLE()
{ {
alg(frame0, frame1, flow); alg->calc(frame0, frame1, flow);
} }
CPU_SANITY_CHECK(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); cv::gpu::GpuMat d_flowy = createMat(frame0.size(), CV_32FC1, useRoi);
d_alg(loadMat(frame0, useRoi), loadMat(frame1, useRoi), d_flowx, d_flowy); 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; cv::Mat flow;
alg(frame0, frame1, flow); alg->calc(frame0, frame1, flow);
cv::Mat gold[2]; cv::Mat gold[2];
cv::split(flow, gold); 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. "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]_ . 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. 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. :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. 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 upscale_sigma_color,
double speed_up_thr); 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 // Implementation of the Zach, Pock and Bischof Dual TV-L1 Optical Flow method
// //
// see reference: // see reference:
// [1] C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow". // [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". // [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation".
class CV_EXPORTS OpticalFlowDual_TVL1 CV_EXPORTS Ptr<DenseOpticalFlow> createOptFlow_DualTVL1();
{
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;
};
} }

@ -22,12 +22,9 @@ PERF_TEST_P(ImagePair, OpticalFlowDual_TVL1, testing::Values(impair("cv/optflow/
Mat flow; Mat flow;
OpticalFlowDual_TVL1 tvl1; Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
TEST_CYCLE() TEST_CYCLE_N(10) tvl1->calc(frame1, frame2, flow);
{
tvl1(frame1, frame2, flow);
}
SANITY_CHECK(flow, 0.5); SANITY_CHECK(flow, 0.5);
} }

File diff suppressed because it is too large Load Diff

@ -152,9 +152,9 @@ TEST(Video_calcOpticalFlowDual_TVL1, Regression)
ASSERT_FALSE(frame2.empty()); ASSERT_FALSE(frame2.empty());
Mat_<Point2f> flow; Mat_<Point2f> flow;
OpticalFlowDual_TVL1 tvl1; Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
tvl1(frame1, frame2, flow); tvl1->calc(frame1, frame2, flow);
#ifdef DUMP #ifdef DUMP
writeOpticalFlowToFile(flow, gold_flow_path); writeOpticalFlowToFile(flow, gold_flow_path);

@ -173,10 +173,10 @@ int main(int argc, const char* argv[])
} }
Mat_<Point2f> flow; Mat_<Point2f> flow;
OpticalFlowDual_TVL1 tvl1; Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
const double start = (double)getTickCount(); const double start = (double)getTickCount();
tvl1(frame0, frame1, flow); tvl1->calc(frame0, frame1, flow);
const double timeSec = (getTickCount() - start) / getTickFrequency(); const double timeSec = (getTickCount() - start) / getTickFrequency();
cout << "calcOpticalFlowDual_TVL1 : " << timeSec << " sec" << endl; cout << "calcOpticalFlowDual_TVL1 : " << timeSec << " sec" << endl;

Loading…
Cancel
Save