mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge branch 4.x
This commit is contained in:
@@ -117,7 +117,7 @@ public:
|
||||
CV_WRAP virtual int getNMixtures() const = 0;
|
||||
/** @brief Sets the number of gaussian components in the background model.
|
||||
|
||||
The model needs to be reinitalized to reserve memory.
|
||||
The model needs to be reinitialized to reserve memory.
|
||||
*/
|
||||
CV_WRAP virtual void setNMixtures(int nmixtures) = 0;//needs reinitialization!
|
||||
|
||||
@@ -268,7 +268,7 @@ public:
|
||||
CV_WRAP virtual int getNSamples() const = 0;
|
||||
/** @brief Sets the number of data samples in the background model.
|
||||
|
||||
The model needs to be reinitalized to reserve memory.
|
||||
The model needs to be reinitialized to reserve memory.
|
||||
*/
|
||||
CV_WRAP virtual void setNSamples(int _nN) = 0;//needs reinitialization!
|
||||
|
||||
|
||||
@@ -700,6 +700,16 @@ public:
|
||||
/** @copybrief getFinestScale @see getFinestScale */
|
||||
CV_WRAP virtual void setFinestScale(int val) = 0;
|
||||
|
||||
/** @brief Sets the coarsest scale
|
||||
@param val Coarsest level of the Gaussian pyramid on which the flow is computed.
|
||||
If set to -1, the auto-computed coarsest scale will be used.
|
||||
*/
|
||||
CV_WRAP virtual void setCoarsestScale(int val) = 0;
|
||||
|
||||
/** @brief Gets the coarsest scale
|
||||
*/
|
||||
CV_WRAP virtual int getCoarsestScale() const = 0;
|
||||
|
||||
/** @brief Size of an image patch for matching (in pixels). Normally, default 8x8 patches work well
|
||||
enough in most cases.
|
||||
@see setPatchSize */
|
||||
|
||||
@@ -55,7 +55,16 @@ PERF_TEST_P(ECCPerfTest, findTransformECC,
|
||||
TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 5, -1));
|
||||
}
|
||||
|
||||
SANITY_CHECK(warpMat, 3e-3);
|
||||
if (transform_type == MOTION_HOMOGRAPHY)
|
||||
{
|
||||
// NOTE: for Mac M1 + KleidiCV
|
||||
// ECCPerfTest_findTransformECC.findTransformECC/6, where GetParam() = (MOTION_HOMOGRAPHY, IMREAD_GRAYSCALE)
|
||||
SANITY_CHECK(warpMat, 8.3e-3);
|
||||
}
|
||||
else
|
||||
{
|
||||
SANITY_CHECK(warpMat, 3e-3);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace opencv_test
|
||||
|
||||
@@ -60,6 +60,7 @@ class DISOpticalFlowImpl CV_FINAL : public DISOpticalFlow
|
||||
|
||||
protected: //!< algorithm parameters
|
||||
int finest_scale, coarsest_scale;
|
||||
int user_coarsest_scale;
|
||||
int patch_size;
|
||||
int patch_stride;
|
||||
int grad_descent_iter;
|
||||
@@ -79,6 +80,8 @@ class DISOpticalFlowImpl CV_FINAL : public DISOpticalFlow
|
||||
public:
|
||||
int getFinestScale() const CV_OVERRIDE { return finest_scale; }
|
||||
void setFinestScale(int val) CV_OVERRIDE { finest_scale = val; }
|
||||
int getCoarsestScale() const CV_OVERRIDE { return user_coarsest_scale; }
|
||||
void setCoarsestScale(int val) CV_OVERRIDE { user_coarsest_scale = val; }
|
||||
int getPatchSize() const CV_OVERRIDE { return patch_size; }
|
||||
void setPatchSize(int val) CV_OVERRIDE { patch_size = val; }
|
||||
int getPatchStride() const CV_OVERRIDE { return patch_stride; }
|
||||
@@ -228,6 +231,7 @@ DISOpticalFlowImpl::DISOpticalFlowImpl()
|
||||
use_mean_normalization = true;
|
||||
use_spatial_propagation = true;
|
||||
coarsest_scale = 10;
|
||||
user_coarsest_scale = -1;
|
||||
|
||||
/* Use separate variational refinement instances for different scales to avoid repeated memory allocation: */
|
||||
int max_possible_scales = 10;
|
||||
@@ -1367,8 +1371,14 @@ bool DISOpticalFlowImpl::ocl_calc(InputArray I0, InputArray I1, InputOutputArray
|
||||
bool use_input_flow = false;
|
||||
if (flow.sameSize(I0) && flow.depth() == CV_32F && flow.channels() == 2)
|
||||
use_input_flow = true;
|
||||
coarsest_scale = min((int)(log(max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) / log(2.0) + 0.5), /* Original code search for maximal movement of width/4 */
|
||||
(int)(log(min(I0Mat.cols, I0Mat.rows) / patch_size) / log(2.0))); /* Deepest pyramid level greater or equal than patch*/
|
||||
|
||||
int max_possible_scale = min((int)(log(max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) / log(2.0) + 0.5), /* Original code search for maximal movement of width/4 */
|
||||
(int)(log(min(I0Mat.cols, I0Mat.rows) / patch_size) / log(2.0))); /* Deepest pyramid level greater or equal than patch*/
|
||||
|
||||
if (user_coarsest_scale != -1)
|
||||
coarsest_scale = min(user_coarsest_scale, max_possible_scale);
|
||||
else
|
||||
coarsest_scale = max_possible_scale;
|
||||
|
||||
if (coarsest_scale<0)
|
||||
CV_Error(cv::Error::StsBadSize, "The input image must have either width or height >= 12");
|
||||
@@ -1449,9 +1459,14 @@ void DISOpticalFlowImpl::calc(InputArray I0, InputArray I1, InputOutputArray flo
|
||||
else
|
||||
flow.create(I1Mat.size(), CV_32FC2);
|
||||
Mat flowMat = flow.getMat();
|
||||
coarsest_scale = min((int)(log(max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) / log(2.0) + 0.5), /* Original code search for maximal movement of width/4 */
|
||||
(int)(log(min(I0Mat.cols, I0Mat.rows) / patch_size) / log(2.0))); /* Deepest pyramid level greater or equal than patch*/
|
||||
|
||||
int max_possible_scale = min((int)(log(max(I0Mat.cols, I0Mat.rows) / (4.0 * patch_size)) / log(2.0) + 0.5), /* Original code search for maximal movement of width/4 */
|
||||
(int)(log(min(I0Mat.cols, I0Mat.rows) / patch_size) / log(2.0))); /* Deepest pyramid level greater or equal than patch*/
|
||||
|
||||
if (user_coarsest_scale != -1)
|
||||
coarsest_scale = min(user_coarsest_scale, max_possible_scale);
|
||||
else
|
||||
coarsest_scale = max_possible_scale;
|
||||
if (coarsest_scale<0)
|
||||
CV_Error(cv::Error::StsBadSize, "The input image must have either width or height >= 12");
|
||||
|
||||
|
||||
@@ -239,7 +239,6 @@ FarnebackUpdateMatrices( const Mat& _R0, const Mat& _R1, const Mat& _flow, Mat&
|
||||
|
||||
#if 1
|
||||
int x1 = cvFloor(fx), y1 = cvFloor(fy);
|
||||
const float* ptr = R1 + y1*step1 + x1*5;
|
||||
float r2, r3, r4, r5, r6;
|
||||
|
||||
fx -= x1; fy -= y1;
|
||||
@@ -247,6 +246,7 @@ FarnebackUpdateMatrices( const Mat& _R0, const Mat& _R1, const Mat& _flow, Mat&
|
||||
if( (unsigned)x1 < (unsigned)(width-1) &&
|
||||
(unsigned)y1 < (unsigned)(height-1) )
|
||||
{
|
||||
const float* ptr = R1 + y1*step1 + x1*5;
|
||||
float a00 = (1.f-fx)*(1.f-fy), a01 = fx*(1.f-fy),
|
||||
a10 = (1.f-fx)*fy, a11 = fx*fy;
|
||||
|
||||
@@ -262,12 +262,12 @@ FarnebackUpdateMatrices( const Mat& _R0, const Mat& _R1, const Mat& _flow, Mat&
|
||||
}
|
||||
#else
|
||||
int x1 = cvRound(fx), y1 = cvRound(fy);
|
||||
const float* ptr = R1 + y1*step1 + x1*5;
|
||||
float r2, r3, r4, r5, r6;
|
||||
|
||||
if( (unsigned)x1 < (unsigned)width &&
|
||||
(unsigned)y1 < (unsigned)height )
|
||||
{
|
||||
const float* ptr = R1 + y1*step1 + x1*5;
|
||||
r2 = ptr[0];
|
||||
r3 = ptr[1];
|
||||
r4 = (R0[x*5+2] + ptr[2])*0.5f;
|
||||
|
||||
@@ -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