epsilon = 0.01;
iterations = 300;
scaleStep = 0.8;
- gamma = 0.0;
+ gamma = 0.0;
useInitialFlow = false;
}
I1s.resize(nscales);
u1s.resize(nscales);
u2s.resize(nscales);
- u3s.resize(nscales);
+ u3s.resize(nscales);
I0.convertTo(I0s[0], CV_32F, I0.depth() == CV_8U ? 1.0 : 255.0);
I1.convertTo(I1s[0], CV_32F, I1.depth() == CV_8U ? 1.0 : 255.0);
u1s[0] = flowx;
u2s[0] = flowy;
- u3s[0].create(I0.size(), CV_32FC1);
+ u3s[0].create(I0.size(), CV_32FC1);
I1x_buf.create(I0.size(), CV_32FC1);
I1y_buf.create(I0.size(), CV_32FC1);
p11_buf.create(I0.size(), CV_32FC1);
p12_buf.create(I0.size(), CV_32FC1);
p21_buf.create(I0.size(), CV_32FC1);
- p22_buf.create(I0.size(), CV_32FC1);
- p31_buf.create(I0.size(), CV_32FC1);
- p32_buf.create(I0.size(), CV_32FC1);
+ p22_buf.create(I0.size(), CV_32FC1);
+ p31_buf.create(I0.size(), CV_32FC1);
+ p32_buf.create(I0.size(), CV_32FC1);
diff_buf.create(I0.size(), CV_32FC1);
{
u1s[s].create(I0s[s].size(), CV_32FC1);
u2s[s].create(I0s[s].size(), CV_32FC1);
- }
- u3s[s].create(I0s[s].size(), CV_32FC1);
+ }
+ u3s[s].create(I0s[s].size(), CV_32FC1);
}
if (!useInitialFlow)
u1s[nscales-1].setTo(Scalar::all(0));
u2s[nscales-1].setTo(Scalar::all(0));
}
- u3s[nscales - 1].setTo(Scalar::all(0));
+ u3s[nscales - 1].setTo(Scalar::all(0));
// pyramidal structure for computing the optical flow
for (int s = nscales - 1; s >= 0; --s)
// zoom the optical flow for the next finer scale
cuda::resize(u1s[s], u1s[s - 1], I0s[s - 1].size());
- cuda::resize(u2s[s], u2s[s - 1], I0s[s - 1].size());
- cuda::resize(u3s[s], u3s[s - 1], I0s[s - 1].size());
+ cuda::resize(u2s[s], u2s[s - 1], I0s[s - 1].size());
+ cuda::resize(u3s[s], u3s[s - 1], I0s[s - 1].size());
// scale the optical flow with the appropriate zoom factor
cuda::multiply(u1s[s - 1], Scalar::all(1/scaleStep), u1s[s - 1]);
void warpBackward(PtrStepSzf I0, PtrStepSzf I1, PtrStepSzf I1x, PtrStepSzf I1y, PtrStepSzf u1, PtrStepSzf u2, PtrStepSzf I1w, PtrStepSzf I1wx, PtrStepSzf I1wy, PtrStepSzf grad, PtrStepSzf rho);
void estimateU(PtrStepSzf I1wx, PtrStepSzf I1wy,
PtrStepSzf grad, PtrStepSzf rho_c,
- PtrStepSzf p11, PtrStepSzf p12, PtrStepSzf p21, PtrStepSzf p22, PtrStepSzf p31, PtrStepSzf p32,
- PtrStepSzf u1, PtrStepSzf u2, PtrStepSzf u3, PtrStepSzf error,
+ PtrStepSzf p11, PtrStepSzf p12, PtrStepSzf p21, PtrStepSzf p22, PtrStepSzf p31, PtrStepSzf p32,
+ PtrStepSzf u1, PtrStepSzf u2, PtrStepSzf u3, PtrStepSzf error,
float l_t, float theta, float gamma, bool calcError);
- void estimateDualVariables(PtrStepSzf u1, PtrStepSzf u2, PtrStepSzf u3, PtrStepSzf p11, PtrStepSzf p12, PtrStepSzf p21, PtrStepSzf p22, PtrStepSzf p31, PtrStepSzf p32, float taut);
+ void estimateDualVariables(PtrStepSzf u1, PtrStepSzf u2, PtrStepSzf u3, PtrStepSzf p11, PtrStepSzf p12, PtrStepSzf p21, PtrStepSzf p22, PtrStepSzf p31, PtrStepSzf p32, float taut);
}
void cv::cuda::OpticalFlowDual_TVL1_CUDA::procOneScale(const GpuMat& I0, const GpuMat& I1, GpuMat& u1, GpuMat& u2, GpuMat& u3)
GpuMat p11 = p11_buf(Rect(0, 0, I0.cols, I0.rows));
GpuMat p12 = p12_buf(Rect(0, 0, I0.cols, I0.rows));
GpuMat p21 = p21_buf(Rect(0, 0, I0.cols, I0.rows));
- GpuMat p22 = p22_buf(Rect(0, 0, I0.cols, I0.rows));
- GpuMat p31 = p31_buf(Rect(0, 0, I0.cols, I0.rows));
- GpuMat p32 = p32_buf(Rect(0, 0, I0.cols, I0.rows));
+ GpuMat p22 = p22_buf(Rect(0, 0, I0.cols, I0.rows));
+ GpuMat p31 = p31_buf(Rect(0, 0, I0.cols, I0.rows));
+ GpuMat p32 = p32_buf(Rect(0, 0, I0.cols, I0.rows));
p11.setTo(Scalar::all(0));
p12.setTo(Scalar::all(0));
p21.setTo(Scalar::all(0));
- p22.setTo(Scalar::all(0));
- p31.setTo(Scalar::all(0));
- p32.setTo(Scalar::all(0));
+ p22.setTo(Scalar::all(0));
+ p31.setTo(Scalar::all(0));
+ p32.setTo(Scalar::all(0));
GpuMat diff = diff_buf(Rect(0, 0, I0.cols, I0.rows));
{
// some tweaks to make sum operation less frequently
bool calcError = (epsilon > 0) && (n & 0x1) && (prevError < scaledEpsilon);
- cv::Mat m1(u3);
- estimateU(I1wx, I1wy, grad, rho_c, p11, p12, p21, p22, p31, p32, u1, u2, u3, diff, l_t, static_cast<float>(theta), gamma, calcError);
+ cv::Mat m1(u3);
+ estimateU(I1wx, I1wy, grad, rho_c, p11, p12, p21, p22, p31, p32, u1, u2, u3, diff, l_t, static_cast<float>(theta), gamma, calcError);
if (calcError)
{
error = cuda::sum(diff, norm_buf)[0];
I0s.clear();
I1s.clear();
u1s.clear();
- u2s.clear();
- u3s.clear();
+ u2s.clear();
+ u3s.clear();
I1x_buf.release();
I1y_buf.release();
p11_buf.release();
p12_buf.release();
p21_buf.release();
- p22_buf.release();
- p31_buf.release();
- p32_buf.release();
+ p22_buf.release();
+ p31_buf.release();
+ p32_buf.release();
diff_buf.release();
norm_buf.release();
const float* I1wyRow = I1wy[y];
const float* u1Row = u1[y];
const float* u2Row = u2[y];
- const float* u3Row = use_gamma?u3[y]:nullptr;
+ const float* u3Row = use_gamma?u3[y]:NULL;
const float* gradRow = grad[y];
const float* rhoRow = rho_c[y];
float* v1Row = v1[y];
float* v2Row = v2[y];
- float* v3Row = use_gamma ? v3[y]:nullptr;
+ float* v3Row = use_gamma ? v3[y]:NULL;
for (int x = 0; x < I1wx.cols; ++x)
{
{
const float* v1Row = v1[y];
const float* v2Row = v2[y];
- const float* v3Row = use_gamma?v3[y]:nullptr;
+ const float* v3Row = use_gamma?v3[y]:NULL;
const float* divP1Row = div_p1[y];
const float* divP2Row = div_p2[y];
- const float* divP3Row = use_gamma?div_p3[y]:nullptr;
+ const float* divP3Row = use_gamma?div_p3[y]:NULL;
float* u1Row = u1[y];
float* u2Row = u2[y];
- float* u3Row = use_gamma?u3[y]:nullptr;
+ float* u3Row = use_gamma?u3[y]:NULL;
for (int x = 0; x < v1.cols; ++x)
for (int n_inner = 0; error > scaledEpsilon && n_inner < innerIterations; ++n_inner)
{
// estimate the values of the variable (v1, v2) (thresholding operator TH)
- estimateV(I1wx, I1wy, u1, u2, u3, grad, rho_c, v1, v2, v3, l_t, gamma);
+ estimateV(I1wx, I1wy, u1, u2, u3, grad, rho_c, v1, v2, v3, l_t, static_cast<float>(gamma));
// compute the divergence of the dual variable (p1, p2, p3)
divergence(p11, p12, div_p1);
if (use_gamma) divergence(p31, p32, div_p3);
// estimate the values of the optical flow (u1, u2)
- error = estimateU(v1, v2, v3, div_p1, div_p2, div_p3, u1, u2, u3, static_cast<float>(theta), gamma);
+ error = estimateU(v1, v2, v3, div_p1, div_p2, div_p3, u1, u2, u3, static_cast<float>(theta), static_cast<float>(gamma));
// compute the gradient of the optical flow (Du1, Du2)
forwardGradient(u1, u1x, u1y);