mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 20:09:23 +08:00
add test for convertions in estimateAffine2D* functions
test with integer points to cover conversion bugs.
This commit is contained in:
parent
9408a5ef5d
commit
4ee25c7e95
@ -127,4 +127,32 @@ TEST_P(EstimateAffine2D, testNPoints)
|
||||
}
|
||||
}
|
||||
|
||||
// test conversion from other datatypes than float
|
||||
TEST_P(EstimateAffine2D, testConversion)
|
||||
{
|
||||
Mat aff(2, 3, CV_32S);
|
||||
cv::randu(aff, 1., 3.);
|
||||
|
||||
std::vector<Point> fpts(3);
|
||||
std::vector<Point> tpts(3);
|
||||
|
||||
// setting points that are not in the same line
|
||||
fpts[0] = Point2f( rngIn(1,2), rngIn(5,6) );
|
||||
fpts[1] = Point2f( rngIn(3,4), rngIn(3,4) );
|
||||
fpts[2] = Point2f( rngIn(1,2), rngIn(3,4) );
|
||||
|
||||
transform(fpts, tpts, aff);
|
||||
|
||||
vector<uchar> inliers;
|
||||
Mat aff_est = estimateAffine2D(fpts, tpts, inliers, GetParam() /* method */);
|
||||
|
||||
ASSERT_FALSE(aff_est.empty());
|
||||
|
||||
aff.convertTo(aff, CV_64F); // need to convert before compare
|
||||
EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-3);
|
||||
|
||||
// all must be inliers
|
||||
EXPECT_EQ(countNonZero(inliers), 3);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Calib3d, EstimateAffine2D, Method::all());
|
||||
|
@ -137,4 +137,31 @@ TEST_P(EstimateAffinePartial2D, testNPoints)
|
||||
}
|
||||
}
|
||||
|
||||
// test conversion from other datatypes than float
|
||||
TEST_P(EstimateAffinePartial2D, testConversion)
|
||||
{
|
||||
Mat aff = rngPartialAffMat();
|
||||
aff.convertTo(aff, CV_32S); // convert to int to transform ints properly
|
||||
|
||||
std::vector<Point> fpts(3);
|
||||
std::vector<Point> tpts(3);
|
||||
|
||||
fpts[0] = Point2f( rngIn(1,2), rngIn(5,6) );
|
||||
fpts[1] = Point2f( rngIn(3,4), rngIn(3,4) );
|
||||
fpts[2] = Point2f( rngIn(1,2), rngIn(3,4) );
|
||||
|
||||
transform(fpts, tpts, aff);
|
||||
|
||||
vector<uchar> inliers;
|
||||
Mat aff_est = estimateAffinePartial2D(fpts, tpts, inliers, GetParam() /* method */);
|
||||
|
||||
ASSERT_FALSE(aff_est.empty());
|
||||
|
||||
aff.convertTo(aff, CV_64F); // need to convert back before compare
|
||||
EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-3);
|
||||
|
||||
// all must be inliers
|
||||
EXPECT_EQ(countNonZero(inliers), 3);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Calib3d, EstimateAffinePartial2D, Method::all());
|
||||
|
Loading…
Reference in New Issue
Block a user