Skip to content

Commit 1bcb634

Browse files
committed
Fixed coarse scale evaluation for DIS optical flow estimator
1 parent c540409 commit 1bcb634

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/optflow/src/dis_flow.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,8 @@ bool DISOpticalFlowImpl::ocl_calc(InputArray I0, InputArray I1, InputOutputArray
13161316
else
13171317
flow.create(I1Mat.size(), CV_32FC2);
13181318
UMat &u_flowMat = flow.getUMatRef();
1319-
coarsest_scale = (int)(log((2 * I0Mat.cols) / (4.0 * patch_size)) / log(2.0) + 0.5) - 1;
1319+
coarsest_scale = min((int)(log(max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) / log(2.0) + 0.5), /* Original code serach for maximal movement of width/4 */
1320+
(int)(log(min(I0Mat.cols, I0Mat.rows) / patch_size) / log(2.0))); /* Deepest pyramid level greater or equal than patch*/
13201321

13211322
ocl_prepareBuffers(I0Mat, I1Mat, u_flowMat, use_input_flow);
13221323
u_Ux[coarsest_scale].setTo(0.0f);
@@ -1382,7 +1383,8 @@ void DISOpticalFlowImpl::calc(InputArray I0, InputArray I1, InputOutputArray flo
13821383
else
13831384
flow.create(I1Mat.size(), CV_32FC2);
13841385
Mat flowMat = flow.getMat();
1385-
coarsest_scale = (int)(log((2 * I0Mat.cols) / (4.0 * patch_size)) / log(2.0) + 0.5) - 1;
1386+
coarsest_scale = min((int)(log(max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) / log(2.0) + 0.5), /* Original code serach for maximal movement of width/4 */
1387+
(int)(log(min(I0Mat.cols, I0Mat.rows) / patch_size) / log(2.0))); /* Deepest pyramid level greater or equal than patch*/
13861388
int num_stripes = getNumThreads();
13871389

13881390
prepareBuffers(I0Mat, I1Mat, flowMat, use_input_flow);

0 commit comments

Comments
 (0)