|
20 | 20 | // dominant cost is the per-pixel detector loop; output extraction |
21 | 21 | // is sub-dominant. We pass nonmaxSuppression=true to match |
22 | 22 | // openvx-mark's vxFastCornersNode default. |
| 23 | +// * OpticalFlowPyrLK: cv::calcOpticalFlowPyrLK is timed with the same |
| 24 | +// 9x9 window, four pyramid levels, 5 iterations, and 0.01 epsilon |
| 25 | +// used by openvx-mark's vxOpticalFlowPyrLKNode case. |
23 | 26 |
|
| 27 | +#include "benchmark_config.h" |
24 | 28 | #include "opencv_runner.h" |
25 | 29 | #include <opencv2/features2d.hpp> |
26 | 30 | #include <opencv2/imgproc.hpp> |
| 31 | +#include <opencv2/video/tracking.hpp> |
27 | 32 | #include <vector> |
28 | 33 |
|
29 | 34 | namespace opencv_mark { |
@@ -121,6 +126,54 @@ std::vector<OpenCVBenchmarkCase> registerCvFeatureBenchmarks() { |
121 | 126 | cases.push_back(bc); |
122 | 127 | } |
123 | 128 |
|
| 129 | + // OpticalFlowPyrLK — U8 image pair with 100 tracked points. |
| 130 | + { |
| 131 | + OpenCVBenchmarkCase bc; |
| 132 | + bc.name = "OpticalFlowPyrLK"; |
| 133 | + bc.category = "feature"; |
| 134 | + bc.feature_set = "vision"; |
| 135 | + bc.setup_fn = [](uint32_t w, uint32_t h, OpenCVTestData& gen, CaseBuffers& bufs) -> bool { |
| 136 | + bufs.input = gen.makeU8(w, h); |
| 137 | + bufs.input_extra = gen.makeU8(w, h); |
| 138 | + bufs.points_prev.clear(); |
| 139 | + bufs.points_prev.reserve(100); |
| 140 | + for (int i = 0; i < 100; ++i) { |
| 141 | + bufs.points_prev.emplace_back(static_cast<float>((i % 10) * (w / 10)), |
| 142 | + static_cast<float>((i / 10) * (h / 10))); |
| 143 | + } |
| 144 | + bufs.points_next.resize(bufs.points_prev.size()); |
| 145 | + bufs.status.resize(bufs.points_prev.size()); |
| 146 | + bufs.error.resize(bufs.points_prev.size()); |
| 147 | + return true; |
| 148 | + }; |
| 149 | + bc.run_fn = [](CaseBuffers& bufs) { |
| 150 | + cv::calcOpticalFlowPyrLK( |
| 151 | + bufs.input, bufs.input_extra, bufs.points_prev, bufs.points_next, |
| 152 | + bufs.status, bufs.error, |
| 153 | + cv::Size(DEFAULT_OPTFLOW_WINSIZE, DEFAULT_OPTFLOW_WINSIZE), |
| 154 | + DEFAULT_PYRAMID_LEVELS - 1, |
| 155 | + cv::TermCriteria(cv::TermCriteria::COUNT | cv::TermCriteria::EPS, 5, 0.01)); |
| 156 | + }; |
| 157 | + bc.verify_fn = []() -> bool { |
| 158 | + cv::Mat img1(64, 64, CV_8UC1, cv::Scalar(100)); |
| 159 | + cv::Mat img2(64, 64, CV_8UC1, cv::Scalar(100)); |
| 160 | + std::vector<cv::Point2f> prev; |
| 161 | + for (int i = 0; i < 4; ++i) { |
| 162 | + prev.emplace_back(static_cast<float>(16 + (i % 2) * 32), |
| 163 | + static_cast<float>(16 + (i / 2) * 32)); |
| 164 | + } |
| 165 | + std::vector<cv::Point2f> next; |
| 166 | + std::vector<unsigned char> status; |
| 167 | + std::vector<float> error; |
| 168 | + cv::calcOpticalFlowPyrLK( |
| 169 | + img1, img2, prev, next, status, error, |
| 170 | + cv::Size(5, 5), 1, |
| 171 | + cv::TermCriteria(cv::TermCriteria::COUNT | cv::TermCriteria::EPS, 5, 0.01)); |
| 172 | + return status.size() == prev.size(); |
| 173 | + }; |
| 174 | + cases.push_back(bc); |
| 175 | + } |
| 176 | + |
124 | 177 | return cases; |
125 | 178 | } |
126 | 179 |
|
|
0 commit comments