mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #28217 from satyam102006:feature/dis-coarsest-scale
[video] Add setCoarsestScale to DISOpticalFlow (Fixes #25068) #28217 ### Description This PR addresses issue #25068 regarding the number of scales in `DISOpticalFlow`. Currently, `DISOpticalFlow` automatically computes the `coarsest_scale` based on the image size. While generally effective, this behavior can cause errors in specific use cases (e.g., mechanics/speckle pattern analysis) where high pyramid levels degrade quality. This change introduces a manual override: - Added `setCoarsestScale(int val)` and `getCoarsestScale()` to the public API. - Updated `DISOpticalFlowImpl::calc` and `ocl_calc` to use the user-defined scale if set. - Preserved the existing "automatic" behavior as the default (when set to -1). ### Changes - **`modules/video/include/opencv2/video/tracking.hpp`**: Added virtual method declarations. - **`modules/video/src/dis_flow.cpp`**: Implemented `set/getCoarsestScale` in `DISOpticalFlowImpl` and updated calculation logic. - **`modules/video/test/test_OF_accuracy.cpp`**: Added `DenseOpticalFlow_DIS.ManualCoarsestScale` regression test. Fixes #25068
This commit is contained in:
@@ -172,4 +172,29 @@ TEST(DenseOpticalFlow_VariationalRefinement, ReferenceAccuracy)
|
||||
EXPECT_LE(calcRMSE(GT, flow), target_RMSE);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
TEST(DenseOpticalFlow_DIS, ManualCoarsestScale)
|
||||
{
|
||||
Mat prev = Mat::zeros(Size(320, 240), CV_8UC1);
|
||||
Mat next = Mat::zeros(Size(320, 240), CV_8UC1);
|
||||
randu(prev, 0, 255);
|
||||
randu(next, 0, 255);
|
||||
|
||||
Ptr<DISOpticalFlow> dis = DISOpticalFlow::create(DISOpticalFlow::PRESET_FAST);
|
||||
|
||||
EXPECT_EQ(dis->getCoarsestScale(), -1);
|
||||
|
||||
Mat flow;
|
||||
dis->calc(prev, next, flow);
|
||||
EXPECT_FALSE(flow.empty());
|
||||
int manual_scale = 3;
|
||||
dis->setCoarsestScale(manual_scale);
|
||||
EXPECT_EQ(dis->getCoarsestScale(), manual_scale);
|
||||
|
||||
dis->calc(prev, next, flow);
|
||||
EXPECT_FALSE(flow.empty());
|
||||
|
||||
dis->setCoarsestScale(-1);
|
||||
EXPECT_EQ(dis->getCoarsestScale(), -1);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
Reference in New Issue
Block a user