|
|
|
@ -59,11 +59,13 @@ using namespace std; |
|
|
|
|
using namespace cv; |
|
|
|
|
using namespace cv::reg; |
|
|
|
|
|
|
|
|
|
#define REG_DEBUG_OUTPUT 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RegTest : public testing::Test |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
void loadImage(); |
|
|
|
|
void loadImage(int dstDataType = CV_32FC3); |
|
|
|
|
|
|
|
|
|
void testShift(); |
|
|
|
|
void testEuclidean(); |
|
|
|
@ -84,20 +86,20 @@ void RegTest::testShift() |
|
|
|
|
mapTest.warp(img1, img2); |
|
|
|
|
|
|
|
|
|
// Register
|
|
|
|
|
MapperGradShift mapper; |
|
|
|
|
Ptr<Mapper> mapper = makePtr<MapperGradShift>(); |
|
|
|
|
MapperPyramid mappPyr(mapper); |
|
|
|
|
Ptr<Map> mapPtr; |
|
|
|
|
mappPyr.calculate(img1, img2, mapPtr); |
|
|
|
|
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2); |
|
|
|
|
|
|
|
|
|
// Print result
|
|
|
|
|
MapShift* mapShift = dynamic_cast<MapShift*>(mapPtr.get()); |
|
|
|
|
Ptr<MapShift> mapShift = MapTypeCaster::toShift(mapPtr); |
|
|
|
|
#if REG_DEBUG_OUTPUT |
|
|
|
|
cout << endl << "--- Testing shift mapper ---" << endl; |
|
|
|
|
cout << Mat(shift) << endl; |
|
|
|
|
cout << Mat(mapShift->getShift()) << endl; |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
// Check accuracy
|
|
|
|
|
Ptr<Map> mapInv(mapShift->inverseMap()); |
|
|
|
|
mapTest.compose(*mapInv.get()); |
|
|
|
|
mapTest.compose(mapInv); |
|
|
|
|
double shNorm = norm(mapTest.getShift()); |
|
|
|
|
EXPECT_LE(shNorm, 0.1); |
|
|
|
|
} |
|
|
|
@ -116,22 +118,22 @@ void RegTest::testEuclidean() |
|
|
|
|
mapTest.warp(img1, img2); |
|
|
|
|
|
|
|
|
|
// Register
|
|
|
|
|
MapperGradEuclid mapper; |
|
|
|
|
Ptr<Mapper> mapper = makePtr<MapperGradEuclid>(); |
|
|
|
|
MapperPyramid mappPyr(mapper); |
|
|
|
|
Ptr<Map> mapPtr; |
|
|
|
|
mappPyr.calculate(img1, img2, mapPtr); |
|
|
|
|
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2); |
|
|
|
|
|
|
|
|
|
// Print result
|
|
|
|
|
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get()); |
|
|
|
|
Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr); |
|
|
|
|
#if REG_DEBUG_OUTPUT |
|
|
|
|
cout << endl << "--- Testing Euclidean mapper ---" << endl; |
|
|
|
|
cout << Mat(linTr) << endl; |
|
|
|
|
cout << Mat(shift) << endl; |
|
|
|
|
cout << Mat(mapAff->getLinTr()) << endl; |
|
|
|
|
cout << Mat(mapAff->getShift()) << endl; |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
// Check accuracy
|
|
|
|
|
Ptr<Map> mapInv(mapAff->inverseMap()); |
|
|
|
|
mapTest.compose(*mapInv.get()); |
|
|
|
|
mapTest.compose(mapInv); |
|
|
|
|
double shNorm = norm(mapTest.getShift()); |
|
|
|
|
EXPECT_LE(shNorm, 0.1); |
|
|
|
|
double linTrNorm = norm(mapTest.getLinTr()); |
|
|
|
@ -154,22 +156,23 @@ void RegTest::testSimilarity() |
|
|
|
|
mapTest.warp(img1, img2); |
|
|
|
|
|
|
|
|
|
// Register
|
|
|
|
|
MapperGradSimilar mapper; |
|
|
|
|
Ptr<Mapper> mapper = makePtr<MapperGradSimilar>(); |
|
|
|
|
MapperPyramid mappPyr(mapper); |
|
|
|
|
Ptr<Map> mapPtr; |
|
|
|
|
mappPyr.calculate(img1, img2, mapPtr); |
|
|
|
|
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2); |
|
|
|
|
|
|
|
|
|
// Print result
|
|
|
|
|
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get()); |
|
|
|
|
Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr); |
|
|
|
|
#if REG_DEBUG_OUTPUT |
|
|
|
|
cout << endl << "--- Testing similarity mapper ---" << endl; |
|
|
|
|
cout << Mat(linTr) << endl; |
|
|
|
|
cout << Mat(shift) << endl; |
|
|
|
|
cout << Mat(mapAff->getLinTr()) << endl; |
|
|
|
|
cout << Mat(mapAff->getShift()) << endl; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Check accuracy
|
|
|
|
|
Ptr<Map> mapInv(mapAff->inverseMap()); |
|
|
|
|
mapTest.compose(*mapInv.get()); |
|
|
|
|
mapTest.compose(mapInv); |
|
|
|
|
double shNorm = norm(mapTest.getShift()); |
|
|
|
|
EXPECT_LE(shNorm, 0.1); |
|
|
|
|
double linTrNorm = norm(mapTest.getLinTr()); |
|
|
|
@ -188,22 +191,23 @@ void RegTest::testAffine() |
|
|
|
|
mapTest.warp(img1, img2); |
|
|
|
|
|
|
|
|
|
// Register
|
|
|
|
|
MapperGradAffine mapper; |
|
|
|
|
Ptr<Mapper> mapper = makePtr<MapperGradAffine>(); |
|
|
|
|
MapperPyramid mappPyr(mapper); |
|
|
|
|
Ptr<Map> mapPtr; |
|
|
|
|
mappPyr.calculate(img1, img2, mapPtr); |
|
|
|
|
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2); |
|
|
|
|
|
|
|
|
|
// Print result
|
|
|
|
|
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get()); |
|
|
|
|
Ptr<MapAffine> mapAff = MapTypeCaster::toAffine(mapPtr); |
|
|
|
|
#if REG_DEBUG_OUTPUT |
|
|
|
|
cout << endl << "--- Testing affine mapper ---" << endl; |
|
|
|
|
cout << Mat(linTr) << endl; |
|
|
|
|
cout << Mat(shift) << endl; |
|
|
|
|
cout << Mat(mapAff->getLinTr()) << endl; |
|
|
|
|
cout << Mat(mapAff->getShift()) << endl; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Check accuracy
|
|
|
|
|
Ptr<Map> mapInv(mapAff->inverseMap()); |
|
|
|
|
mapTest.compose(*mapInv.get()); |
|
|
|
|
mapTest.compose(mapInv); |
|
|
|
|
double shNorm = norm(mapTest.getShift()); |
|
|
|
|
EXPECT_LE(shNorm, 0.1); |
|
|
|
|
double linTrNorm = norm(mapTest.getLinTr()); |
|
|
|
@ -222,34 +226,34 @@ void RegTest::testProjective() |
|
|
|
|
mapTest.warp(img1, img2); |
|
|
|
|
|
|
|
|
|
// Register
|
|
|
|
|
MapperGradProj mapper; |
|
|
|
|
Ptr<Mapper> mapper = makePtr<MapperGradProj>(); |
|
|
|
|
MapperPyramid mappPyr(mapper); |
|
|
|
|
Ptr<Map> mapPtr; |
|
|
|
|
mappPyr.calculate(img1, img2, mapPtr); |
|
|
|
|
Ptr<Map> mapPtr = mappPyr.calculate(img1, img2); |
|
|
|
|
|
|
|
|
|
// Print result
|
|
|
|
|
MapProjec* mapProj = dynamic_cast<MapProjec*>(mapPtr.get()); |
|
|
|
|
Ptr<MapProjec> mapProj = MapTypeCaster::toProjec(mapPtr); |
|
|
|
|
mapProj->normalize(); |
|
|
|
|
#if REG_DEBUG_OUTPUT |
|
|
|
|
cout << endl << "--- Testing projective transformation mapper ---" << endl; |
|
|
|
|
cout << Mat(projTr) << endl; |
|
|
|
|
cout << Mat(mapProj->getProjTr()) << endl; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Check accuracy
|
|
|
|
|
Ptr<Map> mapInv(mapProj->inverseMap()); |
|
|
|
|
mapTest.compose(*mapInv.get()); |
|
|
|
|
mapTest.compose(mapInv); |
|
|
|
|
double projNorm = norm(mapTest.getProjTr()); |
|
|
|
|
EXPECT_LE(projNorm, sqrt(3.) + 0.01); |
|
|
|
|
EXPECT_GE(projNorm, sqrt(3.) - 0.01); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RegTest::loadImage() |
|
|
|
|
void RegTest::loadImage(int dstDataType) |
|
|
|
|
{ |
|
|
|
|
const string imageName = cvtest::TS::ptr()->get_data_path() + "reg/home.png"; |
|
|
|
|
|
|
|
|
|
img1 = imread(imageName, -1); |
|
|
|
|
ASSERT_TRUE(img1.data != 0); |
|
|
|
|
// Convert to double, 3 channels
|
|
|
|
|
img1.convertTo(img1, CV_64FC3); |
|
|
|
|
ASSERT_TRUE(!img1.empty()); |
|
|
|
|
img1.convertTo(img1, dstDataType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -282,3 +286,15 @@ TEST_F(RegTest, projective) |
|
|
|
|
loadImage(); |
|
|
|
|
testProjective(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(RegTest, projective_dt64fc3) |
|
|
|
|
{ |
|
|
|
|
loadImage(CV_64FC3); |
|
|
|
|
testProjective(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(RegTest, projective_dt64fc1) |
|
|
|
|
{ |
|
|
|
|
loadImage(CV_64FC1); |
|
|
|
|
testProjective(); |
|
|
|
|
} |
|
|
|
|