Skip to content

Commit 4ee25c7

Browse files
committed
add test for convertions in estimateAffine2D* functions
test with integer points to cover conversion bugs.
1 parent 9408a5e commit 4ee25c7

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

modules/calib3d/test/test_affine2d_estimator.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,32 @@ TEST_P(EstimateAffine2D, testNPoints)
127127
}
128128
}
129129

130+
// test conversion from other datatypes than float
131+
TEST_P(EstimateAffine2D, testConversion)
132+
{
133+
Mat aff(2, 3, CV_32S);
134+
cv::randu(aff, 1., 3.);
135+
136+
std::vector<Point> fpts(3);
137+
std::vector<Point> tpts(3);
138+
139+
// setting points that are not in the same line
140+
fpts[0] = Point2f( rngIn(1,2), rngIn(5,6) );
141+
fpts[1] = Point2f( rngIn(3,4), rngIn(3,4) );
142+
fpts[2] = Point2f( rngIn(1,2), rngIn(3,4) );
143+
144+
transform(fpts, tpts, aff);
145+
146+
vector<uchar> inliers;
147+
Mat aff_est = estimateAffine2D(fpts, tpts, inliers, GetParam() /* method */);
148+
149+
ASSERT_FALSE(aff_est.empty());
150+
151+
aff.convertTo(aff, CV_64F); // need to convert before compare
152+
EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-3);
153+
154+
// all must be inliers
155+
EXPECT_EQ(countNonZero(inliers), 3);
156+
}
157+
130158
INSTANTIATE_TEST_CASE_P(Calib3d, EstimateAffine2D, Method::all());

modules/calib3d/test/test_affine_partial2d_estimator.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,31 @@ TEST_P(EstimateAffinePartial2D, testNPoints)
137137
}
138138
}
139139

140+
// test conversion from other datatypes than float
141+
TEST_P(EstimateAffinePartial2D, testConversion)
142+
{
143+
Mat aff = rngPartialAffMat();
144+
aff.convertTo(aff, CV_32S); // convert to int to transform ints properly
145+
146+
std::vector<Point> fpts(3);
147+
std::vector<Point> tpts(3);
148+
149+
fpts[0] = Point2f( rngIn(1,2), rngIn(5,6) );
150+
fpts[1] = Point2f( rngIn(3,4), rngIn(3,4) );
151+
fpts[2] = Point2f( rngIn(1,2), rngIn(3,4) );
152+
153+
transform(fpts, tpts, aff);
154+
155+
vector<uchar> inliers;
156+
Mat aff_est = estimateAffinePartial2D(fpts, tpts, inliers, GetParam() /* method */);
157+
158+
ASSERT_FALSE(aff_est.empty());
159+
160+
aff.convertTo(aff, CV_64F); // need to convert back before compare
161+
EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-3);
162+
163+
// all must be inliers
164+
EXPECT_EQ(countNonZero(inliers), 3);
165+
}
166+
140167
INSTANTIATE_TEST_CASE_P(Calib3d, EstimateAffinePartial2D, Method::all());

0 commit comments

Comments
 (0)