Skip to content

Modify the pyrlk.cl to support winSize from 8*8 to 24*24 for optical …#8863

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
LukeZheZhu:pyrlk_small_winsize
Jun 8, 2017
Merged

Modify the pyrlk.cl to support winSize from 8*8 to 24*24 for optical …#8863
opencv-pushbot merged 1 commit intoopencv:masterfrom
LukeZheZhu:pyrlk_small_winsize

Conversation

@LukeZheZhu
Copy link
Copy Markdown
Contributor

@LukeZheZhu LukeZheZhu commented Jun 7, 2017

System information (version)

Platform:
CPU: Intel 6th generation i5-6260U
GPU: Intel Iris Graphics 540 (Skylake GT3e)
OS: Linux Ubuntu 16.04 LTS x64
Compiler:
gcc: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
OpenCL: intel-opencl-2.0-r4.1.61547
OpenCV:
OpenCV => 3.1.0
WITH_OPENCL true

Detailed description

In pull request #8609, the winSize has been limited to 16*16 - 24*24 for outputing correct err value. As we discussed in that case, I have modified the opencl kernel - pyrlk.cl - to support smaller winSize. Therefore, the pyrlk.cl supports winSize from 8*8 - 24*24.

This pullrequest changes

  1. The /modules/video/src/lkpyramid.cpp
    /modules/video/src/opencl/pyrlk.cl
    are changed in order to support smaller winSize.

  2. The /modules/video/test/ocl/test_optflowpyrlk.cpp is changed to add test case with winSize 11 and 15.

Performance

  1. The original performance test's winSize is 21*21. With this changing, the performance is the same as before.

  2. With the patch shown below, I test the performance with winSize 11*11

index 81c8ed9..d565ec6 100644
--- a/modules/video/perf/opencl/perf_optflow_pyrlk.cpp
+++ b/modules/video/perf/opencl/perf_optflow_pyrlk.cpp
@@ -70,7 +70,7 @@ OCL_PERF_TEST_P(PyrLKOpticalFlowFixture, PyrLKOpticalFlow,
     UMat uFrame0; frame0.copyTo(uFrame0);
     UMat uFrame1; frame1.copyTo(uFrame1);
 
-    const Size winSize = Size(21, 21);
+    const Size winSize = Size(11, 11);
     const int maxLevel = 3;
     const TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01);
     const int flags = 0;
diff --git a/modules/video/perf/perf_optflowpyrlk.cpp b/modules/video/perf/perf_optflowpyrlk.cpp
index a17a0f3..5a36067 100644
--- a/modules/video/perf/perf_optflowpyrlk.cpp
+++ b/modules/video/perf/perf_optflowpyrlk.cpp
@@ -271,3 +271,34 @@ PERF_TEST_P(Path_Win_Deriv_Border_Reuse, OpticalFlowPyrLK_pyr, testing::Combine(
 
     SANITY_CHECK(pyramid);
 }
+
+typedef tr1::tuple< int > Path_Idx_Cn_NPoints_WSize_cpu_t;
+typedef TestBaseWithParam<Path_Idx_Cn_NPoints_WSize_cpu_t> Path_Idx_Cn_NPoints_WSize_cpu;
+PERF_TEST_P(Path_Idx_Cn_NPoints_WSize_cpu, OpticalFlowPyrLK_cpu,
+            testing::Values<int>(1000, 2000, 4000)
+            ) {
+    Mat frame0 = imread(getDataPath("gpu/opticalflow/rubberwhale1.png"), cv::IMREAD_GRAYSCALE);
+    ASSERT_FALSE(frame0.empty()) << "can't load rubberwhale1.png";
+
+    Mat frame1 = imread(getDataPath("gpu/opticalflow/rubberwhale2.png"), cv::IMREAD_GRAYSCALE);
+    ASSERT_FALSE(frame1.empty()) << "can't load rubberwhale2.png";
+
+    const Size winSize = Size(11, 11);
+    const int maxLevel = 3;
+    const TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01);
+    const int flags = 0;
+    const float minEigThreshold = 1e-4f;
+    const double eps = 1.0;
+
+    int pointsCount = get<0>(GetParam());
+
+    vector<Point2f> pts;
+    goodFeaturesToTrack(frame0, pts, pointsCount, 0.01, 0.0);
+
+    declare.in(frame0, frame1, WARMUP_READ);
+    Mat NextPts, Status, Err;
+
+    TEST_CYCLE_N(30)
+        cv::calcOpticalFlowPyrLK(frame0, frame1, pts, NextPts, Status, Err, winSize, maxLevel, criteria, flags, minEigThreshold);
+    SANITY_CHECK(NextPts, eps);
+}```

The test result is showed in the table:
Key Points CPU / ms GPU / ms
1000 4.66 4.0
2000 8.67 6.02
4000 15.63 9.91
With winSize `11*11`, GPU is still faster than CPU on the test platform.

@alalek
Copy link
Copy Markdown
Member

alalek commented Jun 8, 2017

Thank you!
👍

@opencv-pushbot opencv-pushbot merged commit cc47ee3 into opencv:master Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants